mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
DevDetails refactor
This commit is contained in:
@@ -164,6 +164,7 @@
|
||||
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="fa fa-caret-down "></span></button>
|
||||
<ul id="dropdownOwner" class="dropdown-menu dropdown-menu-right">
|
||||
<li id="dropdownOwner_initSettingDropdown"></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -238,6 +239,7 @@
|
||||
<span class="fa fa-caret-down"></span>
|
||||
</button>
|
||||
<ul id="dropdownGroup" class="dropdown-menu dropdown-menu-right">
|
||||
<li id="dropdownGroup_initSettingDropdown"></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -255,7 +257,7 @@
|
||||
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
<span class="fa fa-caret-down"></span></button>
|
||||
<ul id="dropdownLocation" class="dropdown-menu dropdown-menu-right">
|
||||
|
||||
<li id="dropdownLocation_initSettingDropdown"></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -333,6 +335,7 @@
|
||||
<button type="button" class="btn btn-info dropdown-toggle" data-mynodemac="" data-toggle="dropdown" aria-expanded="false" id="buttonNetworkNodeMac">
|
||||
<span class="fa fa-caret-down"></span></button>
|
||||
<ul id="dropdownNetworkNodeMac" class="dropdown-menu dropdown-menu-right">
|
||||
<li id="dropdownNetworkNodeMac_initSettingDropdown"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -824,19 +827,17 @@ function initializeiCheck () {
|
||||
// -----------------------------------------------------------------------------
|
||||
function initializeCombos () {
|
||||
// Initialize combos with queries
|
||||
initializeCombo ( '#dropdownOwner', 'getOwners', 'txtOwner', true);
|
||||
initializeCombo ( '#dropdownDeviceType', 'getDeviceTypes', 'txtDeviceType', true);
|
||||
initializeCombo ( '#dropdownGroup', 'getGroups', 'txtGroup', true);
|
||||
initializeCombo ( '#dropdownLocation', 'getLocations', 'txtLocation', true);
|
||||
initializeCombo ( '#dropdownNetworkNodeMac', 'getNetworkNodes', 'txtNetworkNodeMac', false);
|
||||
|
||||
|
||||
// initSettingDropdown("NEWDEV_dev_Network_Node_MAC_ADDR", [], "dropdownNetworkNodeMac", generateList)
|
||||
|
||||
initializeCombo ( '#dropdownDeviceType', 'getDeviceTypes', 'txtDeviceType', true);
|
||||
initializeCombo ( '#dropdownIcon', 'getIcons', 'txtIcon', false);
|
||||
initializeCombo ( '#dropdownAction', 'getActions', 'txtAction', false);
|
||||
initializeCombo ( '#dropdownDevices', 'getDevices', 'txtFromDevice', false);
|
||||
|
||||
initSettingDropdown("NEWDEV_dev_Owner", [], "dropdownOwner_initSettingDropdown", generatedevDetailsList, 'txtOwner' )
|
||||
initSettingDropdown("NEWDEV_dev_Group", [], "dropdownGroup_initSettingDropdown", generatedevDetailsList, 'txtGroup' )
|
||||
initSettingDropdown("NEWDEV_dev_Location", [], "dropdownLocation_initSettingDropdown", generatedevDetailsList, 'txtLocation' )
|
||||
initSettingDropdown("NEWDEV_dev_Network_Node_MAC_ADDR", [], "dropdownNetworkNodeMac_initSettingDropdown", generatedevDetailsList, 'txtNetworkNodeMac' )
|
||||
|
||||
// Initialize static combos
|
||||
initializeComboSkipRepeated ();
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Read data and place intotarget location, callback processies the results
|
||||
function readData(sqlQuery, processDataCallback, valuesArray, targetLocation) {
|
||||
function readData(sqlQuery, processDataCallback, valuesArray, targetLocation, targetField) {
|
||||
var apiUrl = `php/server/dbHelper.php?action=read&rawSql=${encodeURIComponent(sqlQuery)}`;
|
||||
$.get(apiUrl, function(data) {
|
||||
// Process the JSON data using the provided callback function
|
||||
|
||||
data = JSON.parse(data)
|
||||
|
||||
var htmlResult = processDataCallback(data, valuesArray);
|
||||
var htmlResult = processDataCallback(data, valuesArray, targetField);
|
||||
|
||||
// Place the resulting HTML into the specified placeholder div
|
||||
$("#" + targetLocation).replaceWith(htmlResult);
|
||||
|
||||
@@ -113,21 +113,17 @@ $(function () {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Initiate dropdown
|
||||
function initSettingDropdown(settingKey, valuesArray, targetLocation, callbackToGenerateEntries)
|
||||
function initSettingDropdown(settingKey, valuesArray, targetLocation, callbackToGenerateEntries, targetField)
|
||||
{
|
||||
|
||||
var optionsHtml = ""
|
||||
var targetLocation_options = settingKey + "_initSettingDropdown"
|
||||
|
||||
optionsArray = createArray(getSettingOptions(settingKey))
|
||||
|
||||
// check if the result is a SQL query
|
||||
if(isSQLQuery(optionsArray[0]))
|
||||
{
|
||||
|
||||
optionsHtml += `<option id="${targetLocation_options}"></option>`;
|
||||
|
||||
readData(optionsArray[0], callbackToGenerateEntries, valuesArray, targetLocation_options);
|
||||
{
|
||||
readData(optionsArray[0], callbackToGenerateEntries, valuesArray, targetLocation, targetField);
|
||||
|
||||
} else // this should be already an array, e.g. from a setting or pre-defined
|
||||
{
|
||||
@@ -144,9 +140,6 @@ function initSettingDropdown(settingKey, valuesArray, targetLocation, callbackTo
|
||||
}, 50);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +173,31 @@ function generateList(data, valuesArray) {
|
||||
|
||||
listHtml += `<li ${selected}>${item.name}</li>`;
|
||||
});
|
||||
listHtml += "";
|
||||
|
||||
return listHtml;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Processor to generate a list
|
||||
function generatedevDetailsList(data, valuesArray, targetField) {
|
||||
|
||||
var listHtml = "";
|
||||
|
||||
console.log(data);
|
||||
data.forEach(function(item) {
|
||||
|
||||
let selected = valuesArray.includes(item.id) ? 'selected' : '';
|
||||
|
||||
|
||||
console.log(item);
|
||||
|
||||
// listHtml += `<li ${selected}>${item.name}</li>`;
|
||||
listHtml += `<li ${selected}>
|
||||
<a href="javascript:void(0)" onclick="setTextValue('${targetField}','${item.id}')">${item.name}</a>
|
||||
</li>`;
|
||||
|
||||
});
|
||||
|
||||
return listHtml;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
switch ($action) {
|
||||
case 'getDeviceData': getDeviceData(); break;
|
||||
case 'setDeviceData': setDeviceData(); break;
|
||||
case 'getNetworkNodes': getNetworkNodes(); break;
|
||||
case 'deleteDevice': deleteDevice(); break;
|
||||
case 'deleteAllWithEmptyMACs': deleteAllWithEmptyMACs(); break;
|
||||
case 'createBackupDB': createBackupDB(); break;
|
||||
@@ -47,10 +46,8 @@
|
||||
case 'getDevicesList': getDevicesList(); break;
|
||||
case 'getDevicesListCalendar': getDevicesListCalendar(); break;
|
||||
|
||||
case 'getOwners': getOwners(); break;
|
||||
case 'getDeviceTypes': getDeviceTypes(); break;
|
||||
case 'getGroups': getGroups(); break;
|
||||
case 'getLocations': getLocations(); break;
|
||||
|
||||
case 'updateNetworkLeaf': updateNetworkLeaf(); break;
|
||||
case 'overwriteIconType': overwriteIconType(); break;
|
||||
case 'getIcons': getIcons(); break;
|
||||
@@ -743,74 +740,9 @@ function getDevicesListCalendar() {
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Query the List of Owners
|
||||
//------------------------------------------------------------------------------
|
||||
function getOwners() {
|
||||
global $db;
|
||||
|
||||
// SQL
|
||||
$sql = 'SELECT DISTINCT 1 as dev_Order, dev_Owner
|
||||
FROM Devices
|
||||
WHERE dev_Owner <> "(unknown)" AND dev_Owner <> ""
|
||||
AND dev_Favorite = 1
|
||||
UNION
|
||||
SELECT DISTINCT 2 as dev_Order, dev_Owner
|
||||
FROM Devices
|
||||
WHERE dev_Owner <> "(unknown)" AND dev_Owner <> ""
|
||||
AND dev_Favorite = 0
|
||||
AND dev_Owner NOT IN
|
||||
(SELECT dev_Owner FROM Devices WHERE dev_Favorite = 1)
|
||||
ORDER BY 1,2 ';
|
||||
$result = $db->query($sql);
|
||||
|
||||
// arrays of rows
|
||||
$tableData = array();
|
||||
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
$tableData[] = array ('order' => $row['dev_Order'],
|
||||
'name' => $row['dev_Owner']);
|
||||
}
|
||||
|
||||
// Return json
|
||||
echo (json_encode ($tableData));
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Query Device Data
|
||||
//------------------------------------------------------------------------------
|
||||
function getNetworkNodes() {
|
||||
global $db;
|
||||
|
||||
// Device Data
|
||||
$networkDeviceTypes = str_replace("]", "",(str_replace("[", "", getSettingValue("NETWORK_DEVICE_TYPES"))));
|
||||
|
||||
|
||||
$sql = 'SELECT * FROM Devices WHERE dev_DeviceType in ( '. $networkDeviceTypes .' )';
|
||||
|
||||
// echo $sql;
|
||||
|
||||
$result = $db->query($sql);
|
||||
|
||||
// arrays of rows
|
||||
$tableData = array();
|
||||
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
// Push row data
|
||||
$tableData[] = array('id' => $row['dev_MAC'],
|
||||
'name' => $row['dev_Name'] );
|
||||
}
|
||||
|
||||
// Add an empty option at the bottom
|
||||
$tableData[] = array('id' => '', 'name' => '❌'.lang("Network_ManageUnassign")); // Add empty option
|
||||
|
||||
// Control no rows
|
||||
if (empty($tableData)) {
|
||||
$tableData = [];
|
||||
}
|
||||
|
||||
// Return json
|
||||
echo (json_encode ($tableData));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function getIcons() {
|
||||
@@ -951,86 +883,6 @@ function getDeviceTypes() {
|
||||
// Return json
|
||||
echo (json_encode ($tableData));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// Query the List of groups
|
||||
//------------------------------------------------------------------------------
|
||||
function getGroups() {
|
||||
global $db;
|
||||
|
||||
// SQL
|
||||
$sql = 'SELECT DISTINCT 1 as dev_Order, dev_Group
|
||||
FROM Devices
|
||||
WHERE dev_Group NOT IN ("(unknown)", "Others") AND dev_Group <> ""
|
||||
UNION SELECT 1 as dev_Order, "Always on"
|
||||
UNION SELECT 1 as dev_Order, "Friends"
|
||||
UNION SELECT 1 as dev_Order, "Personal"
|
||||
UNION SELECT 2 as dev_Order, "Others"
|
||||
ORDER BY 1,2 ';
|
||||
$result = $db->query($sql);
|
||||
|
||||
// arrays of rows
|
||||
$tableData = array();
|
||||
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
$tableData[] = array ('order' => $row['dev_Order'],
|
||||
'name' => $row['dev_Group']);
|
||||
}
|
||||
|
||||
// Return json
|
||||
echo (json_encode ($tableData));
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Query the List of locations
|
||||
//------------------------------------------------------------------------------
|
||||
function getLocations() {
|
||||
global $db;
|
||||
|
||||
// SQL
|
||||
$sql = 'SELECT DISTINCT 9 as dev_Order, dev_Location
|
||||
FROM Devices
|
||||
WHERE dev_Location <> ""
|
||||
AND dev_Location NOT IN (
|
||||
"Bathroom", "Bedroom", "Dining room", "Hallway",
|
||||
"Kitchen", "Laundry", "Living room", "Study",
|
||||
"Attic", "Basement", "Garage",
|
||||
"Back yard", "Garden", "Terrace",
|
||||
"Other")
|
||||
|
||||
UNION SELECT 1 as dev_Order, "Bathroom"
|
||||
UNION SELECT 1 as dev_Order, "Bedroom"
|
||||
UNION SELECT 1 as dev_Order, "Dining room"
|
||||
UNION SELECT 1 as dev_Order, "Hall"
|
||||
UNION SELECT 1 as dev_Order, "Kitchen"
|
||||
UNION SELECT 1 as dev_Order, "Laundry"
|
||||
UNION SELECT 1 as dev_Order, "Living room"
|
||||
UNION SELECT 1 as dev_Order, "Study"
|
||||
|
||||
UNION SELECT 2 as dev_Order, "Attic"
|
||||
UNION SELECT 2 as dev_Order, "Basement"
|
||||
UNION SELECT 2 as dev_Order, "Garage"
|
||||
|
||||
UNION SELECT 3 as dev_Order, "Back yard"
|
||||
UNION SELECT 3 as dev_Order, "Garden"
|
||||
UNION SELECT 3 as dev_Order, "Terrace"
|
||||
|
||||
UNION SELECT 10 as dev_Order, "Other"
|
||||
ORDER BY 1,2 ';
|
||||
|
||||
|
||||
|
||||
$result = $db->query($sql);
|
||||
|
||||
// arrays of rows
|
||||
$tableData = array();
|
||||
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
$tableData[] = array ('order' => $row['dev_Order'],
|
||||
'name' => $row['dev_Location']);
|
||||
}
|
||||
|
||||
// Return json
|
||||
echo (json_encode ($tableData));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
function updateNetworkLeaf()
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
{
|
||||
"name" : "value",
|
||||
"type" : "sql",
|
||||
"value" : "SELECT DISTINCT '' as id, '' as name UNION SELECT dev_Owner as id, dev_Owner as name FROM (SELECT dev_Owner FROM Devices UNION SELECT 'House' ) AS all_devices ORDER BY id;"
|
||||
"value" : "SELECT DISTINCT '' as id, '❌None' as name UNION SELECT dev_Owner as id, dev_Owner as name FROM (SELECT dev_Owner FROM Devices UNION SELECT 'House' ) AS all_devices ORDER BY id;"
|
||||
}
|
||||
],
|
||||
"localized": ["name", "description"],
|
||||
@@ -139,7 +139,7 @@
|
||||
{
|
||||
"name" : "value",
|
||||
"type" : "sql",
|
||||
"value" : "SELECT '' as id, '' as name UNION SELECT dev_DeviceType as id, dev_DeviceType as name FROM (SELECT dev_DeviceType FROM Devices UNION SELECT 'Smartphone' UNION SELECT 'Tablet' UNION SELECT 'Laptop' UNION SELECT 'PC' UNION SELECT 'Printer' UNION SELECT 'Server' UNION SELECT 'NAS' UNION SELECT 'Domotic' UNION SELECT 'Game Console' UNION SELECT 'SmartTV' UNION SELECT 'Clock' UNION SELECT 'House Appliance' UNION SELECT 'Phone' UNION SELECT 'AP' UNION SELECT 'Gateway' UNION SELECT 'Firewall' UNION SELECT 'Switch' UNION SELECT 'WLAN' UNION SELECT 'Router' UNION SELECT 'Other') AS all_devices ORDER BY id;"
|
||||
"value" : "SELECT Distinct id, name FROM (SELECT '' as id, '❌None' as name UNION SELECT dev_DeviceType as id, dev_DeviceType as name FROM (SELECT dev_DeviceType FROM Devices where dev_DeviceType <> '' UNION SELECT 'Smartphone' UNION SELECT 'Tablet' UNION SELECT 'Laptop' UNION SELECT 'PC' UNION SELECT 'Printer' UNION SELECT 'Server' UNION SELECT 'NAS' UNION SELECT 'Domotic' UNION SELECT 'Game Console' UNION SELECT 'SmartTV' UNION SELECT 'Clock' UNION SELECT 'House Appliance' UNION SELECT 'Phone' UNION SELECT 'AP' UNION SELECT 'Gateway' UNION SELECT 'Firewall' UNION SELECT 'Switch' UNION SELECT 'WLAN' UNION SELECT 'Router' UNION SELECT 'Other') AS all_devices ORDER BY id);"
|
||||
},
|
||||
{
|
||||
"name" : "uilang",
|
||||
@@ -210,7 +210,7 @@
|
||||
{
|
||||
"name" : "value",
|
||||
"type" : "sql",
|
||||
"value" : "SELECT DISTINCT '' as id, '' as name UNION SELECT dev_Group as id, dev_Group as name FROM (SELECT dev_Group FROM Devices UNION SELECT 'Personal' ) AS all_devices ORDER BY id;"
|
||||
"value" : "SELECT DISTINCT '' as id, '❌None' as name UNION SELECT dev_Group as id, dev_Group as name FROM (SELECT dev_Group FROM Devices WHERE dev_Group <> '' UNION SELECT 'Personal' UNION SELECT 'Always on' UNION SELECT 'Friends' UNION SELECT 'Others' ) AS all_devices ORDER BY id;"
|
||||
}
|
||||
],
|
||||
"localized": ["name", "description"],
|
||||
@@ -494,7 +494,7 @@
|
||||
{
|
||||
"name" : "value",
|
||||
"type" : "sql",
|
||||
"value" : "SELECT DISTINCT '' as id, '' as name UNION SELECT dev_Location as id, dev_Location as name FROM (SELECT dev_Location FROM Devices where dev_Location not in (null, 'null', '') UNION SELECT 'Bathroom' UNION SELECT 'Bedroom' UNION SELECT 'Dining room' UNION SELECT 'Hall' UNION SELECT 'Kitchen' UNION SELECT 'Laundry' UNION SELECT 'Living room' UNION SELECT 'Study' UNION SELECT 'Attic' UNION SELECT 'Basement' UNION SELECT 'Garage' UNION SELECT 'Back yard' UNION SELECT 'Garden' UNION SELECT 'Terrace') AS all_devices ORDER BY id; "
|
||||
"value" : "SELECT DISTINCT '' as id, '❌None' as name UNION SELECT dev_Location as id, dev_Location as name FROM (SELECT dev_Location FROM Devices where dev_Location not in (null, 'null', '') UNION SELECT 'Bathroom' UNION SELECT 'Bedroom' UNION SELECT 'Dining room' UNION SELECT 'Hall' UNION SELECT 'Kitchen' UNION SELECT 'Laundry' UNION SELECT 'Living room' UNION SELECT 'Study' UNION SELECT 'Attic' UNION SELECT 'Basement' UNION SELECT 'Garage' UNION SELECT 'Back yard' UNION SELECT 'Garden' UNION SELECT 'Terrace') AS all_devices ORDER BY id; "
|
||||
}
|
||||
],
|
||||
"localized": ["name", "description"],
|
||||
@@ -539,7 +539,7 @@
|
||||
{
|
||||
"name" : "value",
|
||||
"type" : "sql",
|
||||
"value" : "SELECT '' as name, '' as id UNION SELECT Dev_Name as name, dev_MAC as id FROM Devices WHERE EXISTS (SELECT 1 FROM Settings WHERE Code_Name = 'NETWORK_DEVICE_TYPES' AND LOWER(value) LIKE '%' || LOWER(dev_DeviceType) || '%' AND dev_DeviceType <> '')"
|
||||
"value" : "SELECT '❌None' as name, '' as id UNION SELECT Dev_Name as name, dev_MAC as id FROM Devices WHERE EXISTS (SELECT 1 FROM Settings WHERE Code_Name = 'NETWORK_DEVICE_TYPES' AND LOWER(value) LIKE '%' || LOWER(dev_DeviceType) || '%' AND dev_DeviceType <> '')"
|
||||
},
|
||||
{
|
||||
"name" : "target_macs",
|
||||
|
||||
@@ -528,23 +528,16 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
// generate a list of options for a input select
|
||||
function generateInputOptions(pluginsData, set, input, isMultiSelect = false)
|
||||
{
|
||||
|
||||
var optionsHtml = ""
|
||||
|
||||
multi = isMultiSelect ? "multiple" : "";
|
||||
|
||||
optionsArray = getSettingOptions(set['Code_Name'] )
|
||||
valuesArray = createArray(set['Value']);
|
||||
|
||||
valuesArray = createArray(set['Value']);
|
||||
|
||||
var targetLocation = set['Code_Name'] + "_initSettingDropdown";
|
||||
|
||||
// placeholder option which will be replaced on callback
|
||||
optionsHtml += `<option id="${targetLocation}" temporary="temporary"></option>`;
|
||||
// create unique ID
|
||||
var targetLocation = set['Code_Name'] + "_initSettingDropdown";
|
||||
|
||||
// execute AJAX callabck + SQL query resolution
|
||||
initSettingDropdown(set['Code_Name'] , valuesArray, targetLocation, generateDropdownOptions)
|
||||
|
||||
initSettingDropdown(set['Code_Name'] , valuesArray, targetLocation, generateDropdownOptions)
|
||||
|
||||
// main selection dropdown wrapper
|
||||
input += `
|
||||
@@ -553,7 +546,8 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||
class="form-control"
|
||||
name="${set['Code_Name']}"
|
||||
id="${set['Code_Name']}" ${multi}>
|
||||
${optionsHtml}
|
||||
|
||||
<option id="${targetLocation}" temporary="temporary"></option>
|
||||
|
||||
</select>`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user