From c61c111d9ebabbfcb3758dee6cafc356f61f0426 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 1 Oct 2020 12:52:20 -0500 Subject: [PATCH 1/7] modernize devices view --- web/skins/classic/views/devices.php | 19 ++++++++++++------- web/skins/classic/views/js/devices.js | 25 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/web/skins/classic/views/devices.php b/web/skins/classic/views/devices.php index 783d7775a..27a53c86d 100644 --- a/web/skins/classic/views/devices.php +++ b/web/skins/classic/views/devices.php @@ -35,9 +35,16 @@ foreach( dbFetchAll( $sql ) as $row ) xhtmlHeaders(__FILE__, translate('Devices') ); ?> +
- - - + diff --git a/web/skins/classic/views/js/devices.js b/web/skins/classic/views/js/devices.js index 703384ad2..a8d08c9d1 100644 --- a/web/skins/classic/views/js/devices.js +++ b/web/skins/classic/views/js/devices.js @@ -37,4 +37,27 @@ function configureButtons( element, name ) { form.deleteBtn.disabled = !checked; } -window.focus(); +// Manage the New button +function New(el) { + url = el.getAttribute('data-url'); + window.location.assign(url); +} + +function initPage() { + // Manage the BACK button + document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) { + evt.preventDefault(); + window.history.back(); + }); + + // Disable the back button if there is nothing to go back to + $j('#backBtn').prop('disabled', !document.referrer.length); + + // Manage the REFRESH Button + document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) { + evt.preventDefault(); + window.location.reload(true); + }); +} + +$j(document).ready(initPage); From fbded3eb200493e03e58818071f634ac72b0e95e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 1 Oct 2020 14:07:11 -0400 Subject: [PATCH 2/7] Update codeql-analysis.yml Add some build dependencies --- .github/workflows/codeql-analysis.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ce467330a..bfc042066 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -57,7 +57,15 @@ jobs: uses: github/codeql-action/autobuild@v1 # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # 📚 https://git.io/JvXDl- + - name: Clean install dependencies and build + run: | + apt-get install libx264-dev libmp4v2-dev libavdevice-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev + apt-get install libbz2-dev libgcrypt20-dev libcurl4-gnutls-dev libjpeg62-turbo-dev libturbojpeg0-dev + apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev + apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl + apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project From bf66903e2e46a79b95477c5b5d93fb8d205158af Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 1 Oct 2020 14:10:55 -0400 Subject: [PATCH 3/7] Update codeql-analysis.yml Add submodule init --- .github/workflows/codeql-analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index bfc042066..3a80949dd 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -65,6 +65,8 @@ jobs: apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl + git submodule init + git submodule update --init --recursive # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines From 160520b3bf1b94ba5918d496891b16623f7fa6f1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 1 Oct 2020 15:50:35 -0400 Subject: [PATCH 4/7] Update codeql-analysis.yml install dependencies before auto build --- .github/workflows/codeql-analysis.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3a80949dd..192262034 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -51,13 +51,6 @@ jobs: # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl- - name: Clean install dependencies and build run: | apt-get install libx264-dev libmp4v2-dev libavdevice-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev @@ -68,6 +61,14 @@ jobs: git submodule init git submodule update --init --recursive + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl- + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project From 186b8ac947935306890aace5fa8cef849a4f8821 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 1 Oct 2020 15:52:33 -0500 Subject: [PATCH 5/7] convert x10 device view to a modal --- web/ajax/modals/device.php | 54 ++++++++++++++++++ web/includes/actions/device.php | 8 ++- web/skins/classic/views/device.php | 67 ----------------------- web/skins/classic/views/devices.php | 10 ++-- web/skins/classic/views/js/devices.js | 39 +++++++++++-- web/skins/classic/views/js/devices.js.php | 1 + 6 files changed, 100 insertions(+), 79 deletions(-) create mode 100644 web/ajax/modals/device.php delete mode 100644 web/skins/classic/views/device.php create mode 100644 web/skins/classic/views/js/devices.js.php diff --git a/web/ajax/modals/device.php b/web/ajax/modals/device.php new file mode 100644 index 000000000..5a29785ef --- /dev/null +++ b/web/ajax/modals/device.php @@ -0,0 +1,54 @@ + "", + "Name" => "New Device", + "KeyString" => "" + ); +} + +?> + diff --git a/web/includes/actions/device.php b/web/includes/actions/device.php index c1a882d89..29011dd73 100644 --- a/web/includes/actions/device.php +++ b/web/includes/actions/device.php @@ -28,15 +28,17 @@ if ( $action == 'device' ) { if ( !empty($_REQUEST['command']) ) { setDeviceStatusX10($_REQUEST['key'], $_REQUEST['command']); } else if ( isset($_REQUEST['newDevice']) ) { - if ( isset($_REQUEST['did']) ) { + if ( isset($_REQUEST['did']) && $_REQUEST['did'] ) { + ZM\Warning('did value is: '.$_REQUEST['did']); + ZM\Warning('newDevice array value is: '.print_r($_REQUEST['newDevice'],true)); dbQuery('UPDATE Devices SET Name=?, KeyString=? WHERE Id=?', array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString'], $_REQUEST['did']) ); } else { + dbQuery('INSERT INTO Devices SET Name=?, KeyString=?', array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString']) ); } - $refreshParent = true; - $view = 'none'; + $redirect = '?view=devices'; } } else { ZM\Error('Unknown action in device'); diff --git a/web/skins/classic/views/device.php b/web/skins/classic/views/device.php deleted file mode 100644 index fa1a6a9d4..000000000 --- a/web/skins/classic/views/device.php +++ /dev/null @@ -1,67 +0,0 @@ - "", - "Name" => "New Device", - "KeyString" => "" - ); -} - -xhtmlHeaders( __FILE__, translate('Device')." - ".$newDevice['Name'] ); -?> - -
- -
-
- - - - - - - - - - - - - - -
-
- disabled="disabled"/> -
-
-
-
- - diff --git a/web/skins/classic/views/devices.php b/web/skins/classic/views/devices.php index 27a53c86d..7bfdb52c0 100644 --- a/web/skins/classic/views/devices.php +++ b/web/skins/classic/views/devices.php @@ -59,15 +59,15 @@ foreach( $devices as $device ) { if ( $device['Status'] == 'ON' ) { - $fclass = "infoText"; + $fclass = "deviceCol infoText"; } elseif ( $device['Status'] == 'OFF' ) { - $fclass = "warnText"; + $fclass = "deviceCol warnText"; } else { - $fclass = "errorText"; + $fclass = "deviceCol errorText"; } ?> @@ -82,8 +82,8 @@ foreach( $devices as $device )
- - + +
diff --git a/web/skins/classic/views/js/devices.js b/web/skins/classic/views/js/devices.js index a8d08c9d1..eb7810b0f 100644 --- a/web/skins/classic/views/js/devices.js +++ b/web/skins/classic/views/js/devices.js @@ -1,3 +1,5 @@ +var newDeviceBtn = $j('#newDeviceBtn'); + function switchDeviceOn( element, key ) { var form = element.form; form.view.value = currentView; @@ -37,13 +39,42 @@ function configureButtons( element, name ) { form.deleteBtn.disabled = !checked; } -// Manage the New button -function New(el) { - url = el.getAttribute('data-url'); - window.location.assign(url); +// Load the Device Modal HTML via Ajax call +function getDeviceModal(did) { + $j.getJSON(thisUrl + '?request=modal&modal=device&did=' + did) + .done(function(data) { + if ( $j('#deviceModal').length ) { + $j('#deviceModal').replaceWith(data.html); + } else { + $j("body").append(data.html); + } + $j('#deviceModal').modal('show'); + // Manage the Save button + $j('#deviceSaveBtn').click(function(evt) { + evt.preventDefault(); + $j('#deviceModalForm').submit(); + }); + }) + .fail(logAjaxFail); +} + +function enableDeviceModal() { + $j(".deviceCol").click(function(evt) { + evt.preventDefault(); + var did = $j(this).data('did'); + getDeviceModal(did); + }); + newDeviceBtn.click(function(evt) { + evt.preventDefault(); + getDeviceModal(0); + }); } function initPage() { + if ( canEditDevice ) enableDeviceModal(); + + newDeviceBtn.prop('disabled', !canEditDevice); + // Manage the BACK button document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) { evt.preventDefault(); diff --git a/web/skins/classic/views/js/devices.js.php b/web/skins/classic/views/js/devices.js.php new file mode 100644 index 000000000..f80541494 --- /dev/null +++ b/web/skins/classic/views/js/devices.js.php @@ -0,0 +1 @@ +var canEditDevice = ; From a80b4b91fb170b7905537cf329c55bc89d500608 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 1 Oct 2020 16:03:58 -0500 Subject: [PATCH 6/7] fix x10 device edit --- web/skins/classic/views/devices.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/web/skins/classic/views/devices.php b/web/skins/classic/views/devices.php index 7bfdb52c0..4a0688d70 100644 --- a/web/skins/classic/views/devices.php +++ b/web/skins/classic/views/devices.php @@ -55,23 +55,20 @@ xhtmlHeaders(__FILE__, translate('Devices') ); - + From 9fec7c8e5aff5072b33c577b50c905bc9302c7fa Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 1 Oct 2020 17:11:20 -0400 Subject: [PATCH 7/7] Update codeql-analysis.yml remove dependencies, need to figure out how to make it install them. Just do submodule init for now. --- .github/workflows/codeql-analysis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 192262034..e72fb09bb 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -53,11 +53,6 @@ jobs: - name: Clean install dependencies and build run: | - apt-get install libx264-dev libmp4v2-dev libavdevice-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev - apt-get install libbz2-dev libgcrypt20-dev libcurl4-gnutls-dev libjpeg62-turbo-dev libturbojpeg0-dev - apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev - apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl - apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl git submodule init git submodule update --init --recursive
'.validHtmlStr($device['Name']).' ('.validHtmlStr($device['KeyString']).')', canEdit( 'Devices' ) ) ?>'.validHtmlStr($device['Name']).' ('.validHtmlStr($device['KeyString']).')', canEdit( 'Devices' ), $str_opt ) ?> onclick="switchDeviceOn( this, '' )"/> onclick="switchDeviceOff( this, '' )"/> disabled="disabled"/>