From: Calin Crisan Date: Sun, 6 Dec 2015 19:32:17 +0000 (+0200) Subject: added support for layout columns prefs X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=0f290edfae367ade931af5f7cfa7babaef8ea5fb;p=motioneye-debian added support for layout columns prefs --- diff --git a/motioneye/handlers.py b/motioneye/handlers.py index 28dcef2..fec73cb 100644 --- a/motioneye/handlers.py +++ b/motioneye/handlers.py @@ -121,8 +121,8 @@ class BaseHandler(RequestHandler): return None - def get_pref(self, key, default=None): - return prefs.get(self.current_user or 'anonymous', key, default) + def get_pref(self, key): + return prefs.get(self.current_user or 'anonymous', key) def set_pref(self, key, value): return prefs.set(self.current_user or 'anonymous', key, value) @@ -1496,10 +1496,10 @@ class ActionHandler(BaseHandler): class PrefsHandler(BaseHandler): - def get(self, key): + def get(self, key=None): self.finish_json(self.get_pref(key)) - def post(self, key): + def post(self, key=None): try: value = json.loads(self.request.body) diff --git a/motioneye/prefs.py b/motioneye/prefs.py index f2e00fb..35f3e96 100644 --- a/motioneye/prefs.py +++ b/motioneye/prefs.py @@ -23,6 +23,9 @@ import settings _PREFS_FILE_NAME = 'prefs.json' +_DEFAULT_PREFS = { + 'layout_columns': 3 +} _prefs = None @@ -55,7 +58,7 @@ def _load(): file.close() else: - logging.debug('preferences file "%s" does not exist, using default preferences') + logging.debug('preferences file "%s" does not exist, using default preferences' % file_path) def _save(): @@ -81,17 +84,25 @@ def _save(): file.close() -def get(username, key, default=None): +def get(username, key=None): if _prefs is None: _load() - return _prefs.get(username, {}).get(key, default) + if key: + return _prefs.get(username, {}).get(key, _DEFAULT_PREFS.get(key)) + + else: + return _prefs.get(username, _DEFAULT_PREFS) def set(username, key, value): if _prefs is None: _load() - _prefs.setdefault(username, {})[key] = value - _save() + if key: + _prefs.setdefault(username, {})[key] = value + + else: + _prefs[username] = value + _save() diff --git a/motioneye/server.py b/motioneye/server.py index a9d006d..3b65296 100644 --- a/motioneye/server.py +++ b/motioneye/server.py @@ -177,7 +177,7 @@ handler_mapping = [ (r'^/movie/(?P\d+)/(?Pdownload|preview|delete)/(?P.+?)/?$', handlers.MovieHandler), (r'^/movie/(?P\d+)/(?Pdelete_all)/(?P.*?)/?$', handlers.MovieHandler), (r'^/action/(?P\d+)/(?P\w+)/?$', handlers.ActionHandler), - (r'^/prefs/(?P\w+)/?$', handlers.PrefsHandler), + (r'^/prefs/(?P\w+)?/?$', handlers.PrefsHandler), (r'^/_relay_event/?$', handlers.RelayEventHandler), (r'^/log/(?P\w+)/?$', handlers.LogHandler), (r'^/update/?$', handlers.UpdateHandler), diff --git a/motioneye/static/css/main.css b/motioneye/static/css/main.css index 2f72dd3..d614faf 100644 --- a/motioneye/static/css/main.css +++ b/motioneye/static/css/main.css @@ -172,18 +172,6 @@ div.button.logout-button { height: 48px; } -body.admin div.logout-button { - display: none; -} - -body.admin div.settings-top-bar.closed div.logout-button { - display: inline-block; -} - -body:not(.admin) div.settings-top-bar div.logout-button { - display: none; -} - div.button.rem-camera-button { display: none; border: 1px solid transparent; @@ -270,10 +258,6 @@ div.settings.open { min-width: 360px; } -body:not(.admin) div.settings { - display: none !important; -} - div.settings-container { position: relative; padding-top: 10px; @@ -308,10 +292,6 @@ div.settings-top-bar.open { min-width: 360px; } -body:not(.admin) div.settings-top-bar { - display: none !important; -} - div.settings-top-bar.closed div.apply-button { display: none !important; } @@ -321,6 +301,9 @@ div.settings-section-title { text-align: right; background-color: rgba(100, 100, 100, 0.3); padding: 5px 0.5em 5px 5px; + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; } a.settings-section-title { @@ -1225,6 +1208,12 @@ img.camera-progress { div.camera-frame { width: 100% !important; } + + #layoutColumnsRow { + /* layout columns are ignored on small screens, + * so hide the prefs row as well */ + display: none !important; + } } @media all and (max-height: 320px) { diff --git a/motioneye/static/js/main.js b/motioneye/static/js/main.js index 37e81e5..8482c6c 100644 --- a/motioneye/static/js/main.js +++ b/motioneye/static/js/main.js @@ -693,8 +693,14 @@ function initUI() { }); }); - /* various change handlers */ + /* prefs change handlers */ + $('#layoutColumnsSlider').change(function () { + var columns = parseInt(this.value); + setLayoutColumns(columns); + savePrefs(); + }); + /* various change handlers */ $('#storageDeviceSelect').change(function () { $('#rootDirectoryEntry').val('/'); }); @@ -1011,6 +1017,11 @@ function updateConfigUI() { } }); + if (!isAdmin()) { + $('#generalSectionDiv').each(markHideLogic); + $('#generalSectionDiv').next().each(markHideLogic); + } + if ($('#cameraSelect').find('option').length < 2) { /* no camera configured */ $('#videoDeviceEnabledSwitch').parent().each(markHideLogic); $('#videoDeviceEnabledSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHideLogic); @@ -1243,6 +1254,29 @@ function configUiValid() { return valid; } +function prefsUi2Dict() { + var dict = { + 'layout_columns': $('#layoutColumnsSlider').val() + }; + + return dict; +} + +function dict2PrefsUi(dict) { + $('#layoutColumnsSlider').val(dict['layout_columns']); + + updateConfigUI(); +} + +function applyPrefs(dict) { + setLayoutColumns(dict['layout_columns']); +} + +function savePrefs() { + var prefs = prefsUi2Dict(); + ajax('POST', basePath + 'prefs/', prefs); +} + function mainUi2Dict() { var dict = { 'show_advanced': $('#showAdvancedSwitch')[0].checked, @@ -2549,6 +2583,9 @@ function fetchCurrentConfig(onFetch) { /* normal user with no cameras doesn't make too much sense - force login */ doLogout(); } + + $('#cameraSelect').hide(); + $('#remCameraButton').hide(); if (onFetch) { onFetch(data); @@ -2571,21 +2608,32 @@ function fetchCurrentConfig(onFetch) { /* add a progress indicator */ getPageContainer().append(''); - if (isAdmin()) { - /* fetch the main configuration */ - ajax('GET', basePath + 'config/main/get/', null, function (data) { - if (data == null || data.error) { - showErrorMessage(data && data.error); - return; - } - - dict2MainUi(data); + /* fetch the prefs */ + ajax('GET', basePath + 'prefs/', null, function (data) { + if (data == null || data.error) { + showErrorMessage(data && data.error); + return; + } + + dict2PrefsUi(data); + applyPrefs(data); + + if (isAdmin()) { + /* fetch the main configuration */ + ajax('GET', basePath + 'config/main/get/', null, function (data) { + if (data == null || data.error) { + showErrorMessage(data && data.error); + return; + } + + dict2MainUi(data); + fetchCameraList(); + }); + } + else { fetchCameraList(); - }); - } - else { - fetchCameraList(); - } + } + }); } function fetchCurrentCameraConfig(onFetch) { @@ -3813,7 +3861,7 @@ function addCameraFrameUi(cameraConfig) { var cameraImg = cameraFrameDiv.find('img.camera'); var progressImg = cameraFrameDiv.find('img.camera-progress'); - /* no camera buttons if not admin */ + /* no configure button unless admin */ if (!isAdmin()) { configureButton.hide(); } diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index a28d830..f7664ce 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -84,7 +84,6 @@
Apply
{% if hostname %}
{{hostname}}
{% endif %} -