From 54d6d43fabf5ab86c6e34984d4b5bbcffe8cd54a Mon Sep 17 00:00:00 2001 From: j Date: Wed, 13 Jan 2016 21:46:31 +0530 Subject: [PATCH] update lists on list change --- oml/changelog.py | 16 ++++++++-------- static/js/folders.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/oml/changelog.py b/oml/changelog.py index b945f62..d97ecba 100644 --- a/oml/changelog.py +++ b/oml/changelog.py @@ -200,7 +200,7 @@ class Changelog(db.Model): if name == '': return True l = List.create(user.id, name) - trigger_event('addlist', {'id': l.public_id}) + trigger_event('addlist', {'id': l.public_id, 'user': user.id}) return True def action_editlist(self, user, timestamp, name, new): @@ -209,7 +209,7 @@ class Changelog(db.Model): if 'name' in new: l.name = new['name'] l.save() - trigger_event('editlist', {'id': l.public_id}) + trigger_event('editlist', {'id': l.public_id, 'user': user.id}) return True def action_orderlists(self, user, timestamp, lists): @@ -220,7 +220,7 @@ class Changelog(db.Model): l.index_ = idx l.save() idx += 1 - trigger_event('orderlists', {}) + trigger_event('orderlists', {'user': user.id}) return True def action_removelist(self, user, timestamp, name): @@ -356,7 +356,7 @@ class Changelog(db.Model): new_id = data[2]['name'] r = revision if old_id not in changes.get('addlist', []): - action[old_id] = [revision, timestamp, new_id] + action[old_id] = [revision, timestamp, {'name': new_id}] r += 1 for a in ('addlist', 'addlistitems', 'removelistitems'): if a in changes and old_id in changes[a]: @@ -448,10 +448,10 @@ class Changelog(db.Model): if orderlists: ids = [l.name for l in List.query.filter_by(user_id=user_id,type='static').order_by('index_') if l.name] if len(ids) > 1: - _changes.append([-1, timestamp, ['orderlists', ids]]) + _changes.append([-1, timestamp, json.dumps(['orderlists', ids])]) if _changes: - r = revision - len(_changes) + 1 - for c in _changes: + r = revision + for c in reversed(_changes): c[0] = r - r += 1 + r -= 1 return _changes diff --git a/static/js/folders.js b/static/js/folders.js index 3a0b30d..402c92f 100644 --- a/static/js/folders.js +++ b/static/js/folders.js @@ -343,10 +343,28 @@ oml.ui.folders = function() { that.updateItems(); } }, + addlist: function(data) { + var index = Ox.getIndexById(ui._users, data.user); + if (index > -1) { + that.updateUser(index); + } + }, change: function(data) { Ox.print('got change event') Ox.Request.clearCache(); }, + editlist: function(data) { + var index = Ox.getIndexById(ui._users, data.user); + if (index > -1) { + that.updateUser(index); + } + }, + orderlists: function(data) { + var index = Ox.getIndexById(ui._users, data.user); + if (index > -1) { + that.updateUser(index); + } + }, peering: function(data, event) { Ox.Request.clearCache('getUsers'); if (Ox.contains(['peering.accept', 'peering.remove'], event)) {