From 4a996af242d3aa5a2b11320db008a6a56e4ee6f8 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 11 Jan 2014 19:09:55 +0200 Subject: [PATCH] erroneous cameras can now be disabled using the UI switch --- src/handlers.py | 43 +++++++++++++++++++++++++------------------ static/css/base.css | 24 ------------------------ static/css/main.css | 23 +++++++++++++++++++++++ static/js/base.js | 0 static/js/main.js | 26 +++++++++++++++++++------- templates/base.html | 2 -- 6 files changed, 67 insertions(+), 51 deletions(-) delete mode 100644 static/css/base.css delete mode 100644 static/js/base.js diff --git a/src/handlers.py b/src/handlers.py index fe48233..9cd5a4e 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -251,25 +251,32 @@ class ConfigHandler(BaseHandler): camera_config['@enabled'] = ui_config['enabled'] config.set_camera(camera_id, camera_config) - # remove the fields that should not get to the remote side - del ui_config['device'] - del ui_config['proto'] - del ui_config['enabled'] - - try: - remote.set_config( - camera_config.get('@host'), - camera_config.get('@port'), - camera_config.get('@username'), - camera_config.get('@password'), - camera_config.get('@remote_camera_id'), - ui_config) - - except Exception as e: - logging.error('failed to set remote camera config: %(msg)s' % {'msg': unicode(e)}) + # when the camera_config supplied has only the enabled state, + # the camera was probably disabled due to errors + + if camera_config.has_key('device'): + # remove the fields that should not get to the remote side + del ui_config['device'] + del ui_config['proto'] + del ui_config['enabled'] - if not no_finish: - return self.finish_json({'error': unicode(e)}) + try: + remote.set_config( + camera_config.get('@host'), + camera_config.get('@port'), + camera_config.get('@username'), + camera_config.get('@password'), + camera_config.get('@remote_camera_id'), + ui_config) + + except Exception as e: + logging.error('failed to set remote camera config: %(msg)s' % {'msg': unicode(e)}) + + if not no_finish: + return self.finish_json({'error': unicode(e)}) + + elif not no_finish: + return self.finish_json({'error': unicode(e)}) else: logging.debug('setting main config') diff --git a/static/css/base.css b/static/css/base.css deleted file mode 100644 index a50ba03..0000000 --- a/static/css/base.css +++ /dev/null @@ -1,24 +0,0 @@ - - - /* basic */ - -* { - padding: 0px; - border: 0px solid black; - margin: 0px; - outline: 0px; - border-spacing: 0px; - border-collapse: separate; -} - -html { - height: 100%; -} - -body { - height: 100%; - color: #dddddd; - font-size: 22px; - background-color: #212121; -} - diff --git a/static/css/main.css b/static/css/main.css index 6d14543..32812e2 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,5 +1,28 @@ + /* basic */ + +* { + padding: 0px; + border: 0px solid black; + margin: 0px; + outline: 0px; + border-spacing: 0px; + border-collapse: separate; +} + +html { + height: 100%; +} + +body { + height: 100%; + color: #dddddd; + font-size: 22px; + background-color: #212121; +} + + /* fonts */ @font-face { diff --git a/static/js/base.js b/static/js/base.js deleted file mode 100644 index e69de29..0000000 diff --git a/static/js/main.js b/static/js/main.js index dc383b0..00dd7ee 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -342,13 +342,15 @@ function updateConfigUi() { objs.not($('#motionEyeSwitch').parents('div').get(0)).each(markHide); } - if (($('#videoDeviceSelect').find('option').length < 2) /* no camera configured */ || - $('#videoDeviceSwitch')[0].disabled /* device disabled for some reason (config error) */) { - + if ($('#videoDeviceSelect').find('option').length < 2) { /* no camera configured */ $('#videoDeviceSwitch').parent().each(markHide); $('#videoDeviceSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHide); } + if ($('#videoDeviceSwitch')[0].error) { /* config error */ + $('#videoDeviceSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHide); + } + /* advanced settings */ var showAdvanced = $('#showAdvancedSwitch').get(0).checked; if (!showAdvanced) { @@ -500,6 +502,12 @@ function dict2MainUi(dict) { } function cameraUi2Dict() { + if ($('#videoDeviceSwitch')[0].error) { /* config error */ + return { + 'enabled': $('#videoDeviceSwitch')[0].checked, + }; + } + var dict = { /* video device */ 'enabled': $('#videoDeviceSwitch')[0].checked, @@ -601,13 +609,16 @@ function cameraUi2Dict() { function dict2CameraUi(dict) { if (dict == null) { - $('#videoDeviceSwitch')[0].disabled = true; + /* errors while getting the configuration */ + + $('#videoDeviceSwitch')[0].error = true; + $('#videoDeviceSwitch')[0].checked = true; updateConfigUi(); return; } else { - $('#videoDeviceSwitch')[0].disabled = false; + $('#videoDeviceSwitch')[0].error = false; } /* video device */ @@ -919,8 +930,9 @@ function fetchCurrentConfig(onFetch) { } videoDeviceSelect.append(''); - if (cameras.length > 0) { - videoDeviceSelect[0].selectedIndex = 0; + var enabledCameras = cameras.filter(function (camera) {return camera['enabled'];}); + if (enabledCameras.length > 0) { + videoDeviceSelect[0].selectedIndex = cameras.indexOf(enabledCameras[0]); fetchCurrentCameraConfig(); } else { diff --git a/templates/base.html b/templates/base.html index ddab2af..085a047 100644 --- a/templates/base.html +++ b/templates/base.html @@ -9,7 +9,6 @@ {% block title %}{% endblock %} {% block style %} - {% endblock %} {% block script %} @@ -17,7 +16,6 @@ -