From dad9b53b54257fa0ae7a35f7f8749caa24cbb50b Mon Sep 17 00:00:00 2001 From: j Date: Sat, 9 Feb 2019 20:55:23 +0530 Subject: [PATCH] hide peers --- config.json | 1 + oml/annotation/models.py | 78 ++++++++++++++++++++++++++++++++++++++++ static/js/folders.js | 15 ++++++-- static/js/mainMenu.js | 25 +++++++++++-- 4 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 oml/annotation/models.py diff --git a/config.json b/config.json index cfd416b..de8f773 100644 --- a/config.json +++ b/config.json @@ -368,6 +368,7 @@ "showFilters": true, "showIconInfo": true, "showInfo": true, + "showPeers": true, "showSection": { "notifications": { "received": true, diff --git a/oml/annotation/models.py b/oml/annotation/models.py new file mode 100644 index 0000000..78fd835 --- /dev/null +++ b/oml/annotation/models.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +from datetime import datetime +import json +import logging +import os +import shutil + +from sqlalchemy.orm import load_only +import ox +import sqlalchemy as sa + +from changelog import add_record +from db import MutableDict +import db +import json_pickler +import settings +import state +import utils +import media +from websocket import trigger_event + + +logger = logging.getLogger(__name__) + + +class Annotation(db.Model): + __tablename__ = 'annotation' + + _id = sa.Column(sa.Integer(), primary_key=True) + id = sa.Column(sa.String(43)) + created = sa.Column(sa.DateTime()) + modified = sa.Column(sa.DateTime()) + + user = sa.orm.relationship('User', backref=sa.orm.backref('annotations', lazy='dynamic')) + item = sa.orm.relationship('Item', backref=sa.orm.backref('items', lazy='dynamic')) + data = sa.Column(MutableDict.as_mutable(sa.PickleType(pickler=json_pickler))) + + def __init__(self, item_id, user_id, data): + self.created = datetime.utcnow() + self.modified = datetime.utcnow() + self.item_id = item_id + self.user_id = user_id + self.data = data + + @classmethod + def create(cls, **kwargs): + a = cls(**kwargs) + state.db.session.add(a) + state.db.session.commit() + + @classmethod + def get(cls, user, item_id, annotation_id): + for a in cls.query.filter_by(item_id=item_id, user=user, _id=annotation_id): + if a.data.get('id') == annotation_id: + return a + + @classmethod + def get_by_item(cls, user, item_id): + annotations = [] + for a in cls.query.filter_by(item_id=item_id): + annotations.append(a.json()) + return annotations + + def save(self): + _id = self.data.get('id') + if _id: + self._id = _id + state.db.session.add(self) + state.db.session.commit() + + def json(self): + data = self.data.copy() + data['created'] = self.created + data['modified'] = self.modified + data['user'] = self.user_id + data['_id'] = ox.toAZ(self.id) + return data + diff --git a/static/js/folders.js b/static/js/folders.js index 17775b9..b96e9c7 100644 --- a/static/js/folders.js +++ b/static/js/folders.js @@ -20,6 +20,9 @@ oml.ui.folders = function() { oml_showfolder: function() { oml.resizeListFolders(); }, + oml_showpeers: function() { + that.updateElement(); + }, oml_showinfo: function() { oml.resizeListFolders(); } @@ -48,9 +51,15 @@ oml.ui.folders = function() { function getUsersAndLists(callback) { oml.getUsers(function(users_) { - users = users_.filter(function(user) { - return user.id == oml.user.id || user.peered; - }); + if (ui.showPeers) { + users = users_.filter(function(user) { + return user.id == oml.user.id || user.peered; + }); + } else { + users = users_.filter(function(user) { + return user.id == oml.user.id; + }); + } oml.getLists(function(lists) { callback(users, lists); }); diff --git a/static/js/mainMenu.js b/static/js/mainMenu.js index 501cc03..039595a 100644 --- a/static/js/mainMenu.js +++ b/static/js/mainMenu.js @@ -214,6 +214,12 @@ oml.ui.mainMenu = function() { title: Ox._((ui.showSidebar ? 'Hide' : 'Show') + ' Sidebar'), keyboard: 'shift s' }, + { + id: 'showpeers', + title: Ox._((ui.showPeers ? 'Hide' : 'Show') + ' Peers'), + keyboard: 'shift p', + disabled: !ui.showSidebar + }, { id: 'showinfo', title: Ox._((ui.showInfo ? 'Hide' : 'Show') + ' Info'), @@ -539,6 +545,8 @@ oml.ui.mainMenu = function() { oml.history.clear(); } else if (id == 'showsidebar') { oml.UI.set({showSidebar: !ui.showSidebar}); + } else if (id == 'showpeers') { + oml.UI.set({showPeers: !ui.showPeers}); } else if (id == 'showinfo') { oml.UI.set({showInfo: !ui.showInfo}); } else if (id == 'showfilters') { @@ -636,12 +644,16 @@ oml.ui.mainMenu = function() { that[action]('viewMenu_iconsSubmenu_extension'); that[action]('viewMenu_iconsSubmenu_size'); }, + oml_showpeers: function(data) { + that.setItemTitle('showpeers', Ox._((data.value ? 'Hide' : 'Show') + ' Peers')); + }, oml_showinfo: function(data) { that.setItemTitle('showinfo', Ox._((data.value ? 'Hide' : 'Show') + ' Info')); }, oml_showsidebar: function(data) { that.setItemTitle('showsidebar', Ox._((data.value ? 'Hide' : 'Show') + ' Sidebar')); that[data.value ? 'enableItem' : 'disableItem']('showinfo'); + that[data.value ? 'enableItem' : 'disableItem']('showpeers'); }, }); Ox.Event.bind({ @@ -726,8 +738,17 @@ oml.ui.mainMenu = function() { key_shift_f: function() { !ui.item && oml.UI.set({showFilters: !ui.showFilters}); }, - key_shift_i: function() { - ui.showSidebar && oml.UI.set({showInfo: !ui.showInfo}); + key_shift_p: function(event, name, target) { + // FIXME: event triggers twice + if (target.hasClass('OxFocus')) { + ui.showSidebar && oml.UI.set({showPeers: !ui.showPeers}); + } + }, + key_shift_i: function(event, name, target) { + // FIXME: event triggers twice + if (target.hasClass('OxFocus')) { + ui.showSidebar && oml.UI.set({showInfo: !ui.showInfo}); + } }, key_shift_s: function() { oml.UI.set({showSidebar: !ui.showSidebar});