hide peers

This commit is contained in:
j 2019-02-09 20:55:23 +05:30
parent ad2d763fbb
commit dad9b53b54
4 changed files with 114 additions and 5 deletions

View file

@ -368,6 +368,7 @@
"showFilters": true,
"showIconInfo": true,
"showInfo": true,
"showPeers": true,
"showSection": {
"notifications": {
"received": true,

78
oml/annotation/models.py Normal file
View file

@ -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

View file

@ -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);
});

View file

@ -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});