From c52bd5126a734a83f87aa8661d8d85ab50d82cde Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 4 Dec 2016 16:25:02 +0200 Subject: [PATCH] added support for ?camera_ids=1,2,... query argument --- motioneye/static/js/main.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/motioneye/static/js/main.js b/motioneye/static/js/main.js index ec78416..1cd5e8a 100644 --- a/motioneye/static/js/main.js +++ b/motioneye/static/js/main.js @@ -1366,7 +1366,12 @@ function updateConfigUI() { $('#generalSectionDiv').next().each(markHideLogic); } - if ($('#cameraSelect').find('option').length < 2) { /* no camera configured */ + var query = splitUrl().params; + var minEntries = 2; + if (query.camera_ids) { + minEntries = 1; + } + if ($('#cameraSelect').find('option').length < minEntries) { /* no camera configured */ $('#videoDeviceEnabledSwitch').parent().each(markHideLogic); $('#videoDeviceEnabledSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHideLogic); } @@ -3061,6 +3066,15 @@ function fetchCurrentConfig(onFetch) { var i, cameras = data.cameras; + /* filter shown cameras by query */ + var query = splitUrl().params; + if (query.camera_ids) { + var cameraIds = query.camera_ids.split(','); + cameras = cameras.filter(function (c){ + return cameraIds.indexOf(String(c.id)) >= 0; + }); + } + if (isAdmin()) { var cameraSelect = $('#cameraSelect'); cameraSelect.html(''); @@ -3068,7 +3082,10 @@ function fetchCurrentConfig(onFetch) { var camera = cameras[i]; cameraSelect.append(''); } - cameraSelect.append(''); + + if (!query.camera_ids) { + cameraSelect.append(''); + } var enabledCameras = cameras.filter(function (camera) {return camera['enabled'];}); if (enabledCameras.length > 0) { /* prefer the first enabled camera */ @@ -3117,7 +3134,10 @@ function fetchCurrentConfig(onFetch) { } /* add a progress indicator */ - getPageContainer().append(''); + var pageContainer = getPageContainer(); + if (!pageContainer.children('img.main-loading-progress').length) { + pageContainer.append(''); + } /* fetch the prefs */ ajax('GET', basePath + 'prefs/', null, function (data) { @@ -4687,7 +4707,8 @@ function recreateCameraFrames(cameras) { /* overlay is always hidden after creating the frames */ hideCameraOverlay(); - if ($('#cameraSelect').find('option').length < 2 && isAdmin()) { + var query = splitUrl().params; + if ($('#cameraSelect').find('option').length < 2 && isAdmin() && !query.camera_ids) { /* invite the user to add a camera */ var addCameraLink = $('
' + 'You have not configured any camera yet. Click here to add one...
'); -- 2.39.5