_CAMERA_CONFIG_FILE_NAME = 'thread-%(id)s.conf'
-
-_MAIN_CONFIG_FILE_PATH = os.path.join(settings.CONF_PATH, 'motion.conf')
-_CAMERA_CONFIG_FILE_PATH = os.path.join(settings.CONF_PATH, _CAMERA_CONFIG_FILE_NAME)
+_MAIN_CONFIG_FILE_NAME = 'motion.conf'
_main_config_cache = None
_camera_config_cache = None
if not as_lines and _main_config_cache is not None:
return _main_config_cache
- config_file_path = os.path.join(settings.PROJECT_PATH, _MAIN_CONFIG_FILE_PATH)
+ config_file_path = os.path.join(settings.CONF_PATH, _MAIN_CONFIG_FILE_NAME)
logging.debug('reading main config from file %(path)s...' % {'path': config_file_path})
except Exception as e:
logging.error('could not read main config file %(path)s: %(msg)s' % {
- 'path': _MAIN_CONFIG_FILE_PATH, 'msg': unicode(e)})
+ 'path': config_file_path, 'msg': unicode(e)})
raise
_set_default_motion(data)
+ config_file_path = os.path.join(settings.CONF_PATH, _MAIN_CONFIG_FILE_NAME)
+
# read the actual configuration from file
lines = get_main(as_lines=True)
threads.append(match.groups()[0])
# write the configuration to file
- logging.debug('writing main config to %(path)s...' % {'path': _MAIN_CONFIG_FILE_PATH})
+ logging.debug('writing main config to %(path)s...' % {'path': config_file_path})
try:
- file = open(_MAIN_CONFIG_FILE_PATH, 'w')
+ file = open(config_file_path, 'w')
except Exception as e:
logging.error('could not open main config file %(path)s for writing: %(msg)s' % {
- 'path': _MAIN_CONFIG_FILE_PATH, 'msg': unicode(e)})
+ 'path': config_file_path, 'msg': unicode(e)})
raise
except Exception as e:
logging.error('could not write main config file %(path)s: %(msg)s' % {
- 'path': _MAIN_CONFIG_FILE_PATH, 'msg': unicode(e)})
+ 'path': config_file_path, 'msg': unicode(e)})
raise
if not as_lines and _camera_config_cache is not None and camera_id in _camera_config_cache:
return _camera_config_cache[camera_id]
- camera_config_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id}
+ camera_config_path = os.path.join(settings.CONF_PATH, _CAMERA_CONFIG_FILE_NAME) % {'id': camera_id}
logging.debug('reading camera config from %(path)s...' % {'path': camera_config_path})
logging.warn('failed to create target directory: %(msg)s' % {'msg': unicode(e)})
# read the actual configuration from file
- config_file_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id}
+ config_file_path = os.path.join(settings.CONF_PATH, _CAMERA_CONFIG_FILE_NAME) % {'id': camera_id}
if os.path.isfile(config_file_path):
lines = get_camera(camera_id, as_lines=True)
lines = []
# write the configuration to file
- camera_config_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id}
+ camera_config_path = os.path.join(settings.CONF_PATH, _CAMERA_CONFIG_FILE_NAME) % {'id': camera_id}
logging.debug('writing camera config to %(path)s...' % {'path': camera_config_path})
try:
global _camera_config_cache
camera_config_name = _CAMERA_CONFIG_FILE_NAME % {'id': camera_id}
- camera_config_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id}
+ camera_config_path = os.path.join(settings.CONF_PATH, _CAMERA_CONFIG_FILE_NAME) % {'id': camera_id}
# remove the camera from the main config
main_config = get_main()
var refreshDisabled = 0;
var fullScreenCameraId = null;
var thresholdSlider = null;
+var inProgress = false;
/* utils */
updateConfigUi();
}
else {
- fetchCurrentCameraConfig();
+ showProgress();
+ fetchCurrentCameraConfig(endProgress);
}
});
$('input.general').change(pushMainConfig);
'input.working-schedule, select.working-schedule').change(pushCameraConfig);
/* preview controls */
- $('#brightnessSlider').change(pushPreview);
- $('#contrastSlider').change(pushPreview);
- $('#saturationSlider').change(pushPreview);
- $('#hueSlider').change(pushPreview);
+ $('#brightnessSlider').change(function () {pushPreview('brightness');});
+ $('#contrastSlider').change(function () {pushPreview('contrast');});
+ $('#saturationSlider').change(function () {pushPreview('saturation');});
+ $('#hueSlider').change(function () {pushPreview('hue');});
/* apply button */
$('#applyButton').click(function () {
$('#videoDeviceSelect').val(cameraId).change();
}
- $('div.settings').addClass('open');
+ $('div.settings').addClass('open').removeClass('closed');
$('div.page-container').addClass('stretched');
- $('div.settings-top-bar').addClass('open');
+ $('div.settings-top-bar').addClass('open').removeClass('closed');
updateConfigUi();
}
function closeSettings() {
hideApply();
- $('div.settings').removeClass('open');
+ $('div.settings').removeClass('open').addClass('closed');
$('div.page-container').removeClass('stretched');
- $('div.settings-top-bar').removeClass('open');
+ $('div.settings-top-bar').removeClass('open').addClass('closed');
}
function isSettingsOpen() {
/* apply button */
function showApply() {
- if (!$('div.settings-container').is(':visible')) {
- return; /* settings panel is not open */
- }
-
var applyButton = $('#applyButton');
applyButton.html('Apply');
applyButton.css('display', 'inline-block');
- applyButton.animate({'opacity': '1'}, 100);
applyButton.removeClass('progress');
+ setTimeout(function () {
+ applyButton.css('opacity', '1');
+ }, 10);
}
function showProgress() {
+ if (inProgress) {
+ return; /* already in progress */
+ }
+
+ inProgress = true;
refreshDisabled++;
/* replace the main page message with a progress indicator */
$('div.add-camera-message').html('<img class="main-loading-progress" src="' + staticUrl + 'img/main-loading-progress.gif">');
- if (!$('div.settings-container').is(':visible')) {
- return; /* settings panel is not open */
- }
-
- var applyButton = $('#applyButton');
-
- if (applyButton.hasClass('progress')) {
- return; /* progress already visible */
- }
-
- applyButton.html('<img class="apply-progress" src="' + staticUrl + 'img/apply-progress.gif">');
- applyButton.css('display', 'inline-block');
- applyButton.animate({'opacity': '1'}, 100);
- applyButton.addClass('progress');
+ /* show the apply button progress indicator */
+ $('#applyButton').html('<img class="apply-progress" src="' + staticUrl + 'img/apply-progress.gif">');
+ /* show the camera progress indicators */
$('div.camera-progress').css('opacity', '0.5');
+
+ /* remove the settings progress lock */
+ $('div.settings-progress').css('width', '100%').css('opacity', '0.9');
}
function hideApply() {
- if (!$('div.settings-container').is(':visible')) {
- return; /* settings panel is not open */
- }
-
var applyButton = $('#applyButton');
- applyButton.animate({'opacity': '0'}, 100, function () {
- applyButton.removeClass('progress');
+ applyButton.css('opacity', '0');
+ applyButton.removeClass('progress');
+
+ setTimeout(function () {
applyButton.css('display', 'none');
- });
+ }, 500);
}
function endProgress() {
+ if (!inProgress) {
+ return; /* not in progress */
+ }
+
+ inProgress = false;
refreshDisabled--;
- $('div.add-camera-message').remove(); /* remove any existing message on the main page */
+ /* remove any existing message on the main page */
+ $('div.add-camera-message').remove();
+
+ /* deal with the apply button */
if (Object.keys(pushConfigs).length === 0) {
hideApply();
}
showApply();
}
+ /* hide the settings progress lock */
+ $('div.settings-progress').css('opacity', '0');
+
+ /* hide the camera progress indicator */
$('div.camera-progress').css('opacity', '0');
-}
-function isProgress() {
- var applyButton = $('#applyButton');
-
- return applyButton.hasClass('progress');
+ setTimeout(function () {
+ $('div.settings-progress').css('width', '0px');
+ }, 500);
}
function isApplyVisible() {
var deviceName = $('#videoDeviceSelect').find('option[value=' + cameraId + ']').text();
- runConfirmDialog('Remove device ' + deviceName + '?', function () {
+ runConfirmDialog('Remove camera ' + deviceName + '?', function () {
showProgress();
ajax('POST', '/config/' + cameraId + '/rem/', null, function (data) {
if (data == null || data.error) {
return;
}
- endProgress();
- fetchCurrentConfig();
+ fetchCurrentConfig(endProgress);
});
});
}
/* fetch & push */
-function fetchCurrentConfig() {
+function fetchCurrentConfig(onFetch) {
function fetchCameraList() {
/* fetch the camera list */
ajax('GET', '/config/list/', null, function (data) {
if (data == null || data.error) {
showErrorMessage(data && data.error);
data = {cameras: []};
+ if (onFetch) {
+ onFetch(null);
+ }
}
var i, cameras = data.cameras;
else {
recreateCameraFrames(cameras);
}
+
+ if (onFetch) {
+ onFetch(data);
+ }
});
}
}
}
-function fetchCurrentCameraConfig() {
+function fetchCurrentCameraConfig(onFetch) {
var cameraId = $('#videoDeviceSelect').val();
if (cameraId != null) {
ajax('GET', '/config/' + cameraId + '/get/', null, function (data) {
if (data == null || data.error) {
showErrorMessage(data && data.error);
dict2CameraUi(null);
+ if (onFetch) {
+ onFetch(null);
+ }
return;
}
dict2CameraUi(data);
+ if (onFetch) {
+ onFetch(data);
+ }
});
}
else {
}
}
-function pushPreview() {
+function pushPreview(control) {
var cameraId = $('#videoDeviceSelect').val();
+
var brightness = $('#brightnessSlider').val();
var contrast= $('#contrastSlider').val();
var saturation = $('#saturationSlider').val();
var data = {};
- if (brightness !== '') {
+ if (brightness !== '' && (!control || control == 'brightness')) {
data.brightness = brightness;
}
- if (contrast !== '') {
+ if (contrast !== '' && (!control || control == 'contrast')) {
data.contrast = contrast;
}
- if (saturation !== '') {
+ if (saturation !== '' && (!control || control == 'saturation')) {
data.saturation = saturation;
}
- if (hue !== '') {
+ if (hue !== '' && (!control || control == 'hue')) {
data.hue = hue;
}
function doConfigureCamera(cameraId) {
- if (isProgress()) {
+ if (inProgress) {
return;
}
openSettings(cameraId);
}
- /* not used anymore */
-function doCloseCamera(cameraId) {
- if (isProgress()) {
- return;
- }
-
- remCameraFrameUi(cameraId);
- showProgress();
- ajax('GET', '/config/' + cameraId + '/get/', null, function (data) {
- if (data == null || data.error) {
- endProgress();
- showErrorMessage(data && data.error);
- return;
- }
-
- data['enabled'] = false;
- ajax('POST', '/config/' + cameraId + '/set/', data, function (data) {
- if (data == null || data.error) {
- showErrorMessage(data && data.error);
- return;
- }
-
- endProgress();
-
- /* if the current camera in the settings panel is the closed camera,
- * we refresh its settings and update the UI */
- if ($('#videoDeviceSelect').val() === '' + cameraId) {
- fetchCurrentCameraConfig();
- }
- });
- });
-}
-
function doFullScreenCamera(cameraId) {
- if (isProgress()) {
+ if (inProgress) {
return;
}
});
initUI();
- fetchCurrentConfig();
+ showProgress();
+ fetchCurrentConfig(endProgress);
refreshCameraFrames();
checkCameraErrors();
});