mirror of
https://github.com/pi-hole/web.git
synced 2026-05-08 09:39:05 +01:00
Fix errors happening when editing groups/clients/domains/lists not being shown. Also fix logic of the strings "enabling/disabling" as the variable "enabled" already has the new (not the current state). This was correct in groups.js, but not the others
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -81,6 +81,7 @@ mg.include('scripts/pi-hole/lua/header_authenticated.lp','r')
|
|||||||
|
|
||||||
<script src="<?=pihole.fileversion('scripts/vendor/bootstrap-select.min.js')?>"></script>
|
<script src="<?=pihole.fileversion('scripts/vendor/bootstrap-select.min.js')?>"></script>
|
||||||
<script src="<?=pihole.fileversion('scripts/vendor/bootstrap-toggle.min.js')?>"></script>
|
<script src="<?=pihole.fileversion('scripts/vendor/bootstrap-toggle.min.js')?>"></script>
|
||||||
|
<script src="<?=pihole.fileversion('scripts/pi-hole/js/groups-common.js')?>"></script>
|
||||||
<script src="<?=pihole.fileversion('scripts/pi-hole/js/groups.js')?>"></script>
|
<script src="<?=pihole.fileversion('scripts/pi-hole/js/groups.js')?>"></script>
|
||||||
|
|
||||||
<? mg.include('scripts/pi-hole/lua/footer.lp','r')?>
|
<? mg.include('scripts/pi-hole/lua/footer.lp','r')?>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global utils:false, groups:false,, apiFailure:false, updateFtlInfo:false, getGroups:false */
|
/* global utils:false, groups:false,, apiFailure:false, updateFtlInfo:false, getGroups:false, processGroupResult:false */
|
||||||
|
|
||||||
var table;
|
var table;
|
||||||
|
|
||||||
@@ -489,6 +489,16 @@ function editClient() {
|
|||||||
var done = "edited";
|
var done = "edited";
|
||||||
var notDone = "editing";
|
var notDone = "editing";
|
||||||
switch (elem) {
|
switch (elem) {
|
||||||
|
case "enabled_" + client:
|
||||||
|
if (!enabled) {
|
||||||
|
done = "disabled";
|
||||||
|
notDone = "disabling";
|
||||||
|
} else {
|
||||||
|
done = "enabled";
|
||||||
|
notDone = "enabling";
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
case "multiselect_" + client:
|
case "multiselect_" + client:
|
||||||
done = "edited groups of";
|
done = "edited groups of";
|
||||||
notDone = "editing groups of";
|
notDone = "editing groups of";
|
||||||
@@ -516,14 +526,9 @@ function editClient() {
|
|||||||
comment: comment,
|
comment: comment,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
}),
|
}),
|
||||||
success: function () {
|
success: function (data) {
|
||||||
utils.enableAll();
|
utils.enableAll();
|
||||||
utils.showAlert(
|
processGroupResult(data, "client", done, notDone);
|
||||||
"success",
|
|
||||||
"fas fa-pencil-alt",
|
|
||||||
"Successfully " + done + " client",
|
|
||||||
clientDecoded
|
|
||||||
);
|
|
||||||
table.ajax.reload(null, false);
|
table.ajax.reload(null, false);
|
||||||
},
|
},
|
||||||
error: function (data, exception) {
|
error: function (data, exception) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global apiFailure:false */
|
/* global apiFailure:false, utils:false */
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
var groups = [];
|
var groups = [];
|
||||||
@@ -24,3 +24,21 @@ function getGroups() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function processGroupResult(data, type, done, notDone) {
|
||||||
|
// Loop over data.processed.success and show toasts
|
||||||
|
data.processed.success.forEach(function (item) {
|
||||||
|
utils.showAlert("success", "fas fa-pencil-alt", `Successfully ${done} ${type}`, item);
|
||||||
|
});
|
||||||
|
// Loop over errors and display them
|
||||||
|
data.processed.errors.forEach(function (error) {
|
||||||
|
console.log(error); // eslint-disable-line no-console
|
||||||
|
utils.showAlert(
|
||||||
|
"error",
|
||||||
|
"",
|
||||||
|
`Error while ${notDone} ${type} ${utils.escapeHtml(error.item)}`,
|
||||||
|
error.error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global utils:false, groups:false,, getGroups:false, updateFtlInfo:false, apiFailure:false */
|
/* global utils:false, groups:false,, getGroups:false, updateFtlInfo:false, apiFailure:false, processGroupResult:false */
|
||||||
|
|
||||||
var table;
|
var table;
|
||||||
var GETDict = {};
|
var GETDict = {};
|
||||||
@@ -581,7 +581,7 @@ function editDomain() {
|
|||||||
var notDone = "editing";
|
var notDone = "editing";
|
||||||
switch (elem) {
|
switch (elem) {
|
||||||
case "enabled_" + domain:
|
case "enabled_" + domain:
|
||||||
if (enabled) {
|
if (!enabled) {
|
||||||
done = "disabled";
|
done = "disabled";
|
||||||
notDone = "disabling";
|
notDone = "disabling";
|
||||||
} else {
|
} else {
|
||||||
@@ -626,14 +626,9 @@ function editDomain() {
|
|||||||
type: oldType,
|
type: oldType,
|
||||||
kind: oldKind,
|
kind: oldKind,
|
||||||
}),
|
}),
|
||||||
success: function () {
|
success: function (data) {
|
||||||
utils.enableAll();
|
utils.enableAll();
|
||||||
utils.showAlert(
|
processGroupResult(data, "domain", done, notDone);
|
||||||
"success",
|
|
||||||
"fas fa-pencil-alt",
|
|
||||||
"Successfully " + done + " domain",
|
|
||||||
domainDecoded
|
|
||||||
);
|
|
||||||
table.ajax.reload(null, false);
|
table.ajax.reload(null, false);
|
||||||
},
|
},
|
||||||
error: function (data, exception) {
|
error: function (data, exception) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global utils:false, groups:false, apiFailure:false, updateFtlInfo:false, getGroups:false */
|
/* global utils:false, groups:false, apiFailure:false, updateFtlInfo:false, getGroups:false, processGroupResult:false */
|
||||||
|
|
||||||
var table;
|
var table;
|
||||||
var GETDict = {};
|
var GETDict = {};
|
||||||
@@ -549,20 +549,19 @@ function editList() {
|
|||||||
const tr = $(this).closest("tr");
|
const tr = $(this).closest("tr");
|
||||||
const type = tr.attr("data-type");
|
const type = tr.attr("data-type");
|
||||||
const address = tr.attr("data-id");
|
const address = tr.attr("data-id");
|
||||||
const status = tr.find("#enabled_" + address).is(":checked");
|
const enabled = tr.find("#enabled_" + address).is(":checked");
|
||||||
const comment = utils.escapeHtml(tr.find("#comment_" + address).val());
|
const comment = utils.escapeHtml(tr.find("#comment_" + address).val());
|
||||||
// Convert list of string integers to list of integers using map(Number)
|
// Convert list of string integers to list of integers using map(Number)
|
||||||
const groups = tr
|
const groups = tr
|
||||||
.find("#multiselect_" + address)
|
.find("#multiselect_" + address)
|
||||||
.val()
|
.val()
|
||||||
.map(Number);
|
.map(Number);
|
||||||
const enabled = tr.find("#enabled_" + address).is(":checked");
|
|
||||||
|
|
||||||
var done = "edited";
|
var done = "edited";
|
||||||
var notDone = "editing";
|
var notDone = "editing";
|
||||||
switch (elem) {
|
switch (elem) {
|
||||||
case "enabled_" + address:
|
case "enabled_" + address:
|
||||||
if (status) {
|
if (!enabled) {
|
||||||
done = "disabled";
|
done = "disabled";
|
||||||
notDone = "disabling";
|
notDone = "disabling";
|
||||||
} else {
|
} else {
|
||||||
@@ -598,14 +597,9 @@ function editList() {
|
|||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
type: type,
|
type: type,
|
||||||
}),
|
}),
|
||||||
success: function () {
|
success: function (data) {
|
||||||
utils.enableAll();
|
utils.enableAll();
|
||||||
utils.showAlert(
|
processGroupResult(data, "list", done, notDone);
|
||||||
"success",
|
|
||||||
"fas fa-pencil-alt",
|
|
||||||
"Successfully " + done + " list",
|
|
||||||
addressDecoded
|
|
||||||
);
|
|
||||||
table.ajax.reload(null, false);
|
table.ajax.reload(null, false);
|
||||||
},
|
},
|
||||||
error: function (data, exception) {
|
error: function (data, exception) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* This file is copyright under the latest version of the EUPL.
|
* This file is copyright under the latest version of the EUPL.
|
||||||
* Please see LICENSE file for your rights under this license. */
|
* Please see LICENSE file for your rights under this license. */
|
||||||
|
|
||||||
/* global utils:false, apiFailure:false, updateFtlInfo:false */
|
/* global utils:false, apiFailure:false, updateFtlInfo:false, processGroupResult:false */
|
||||||
|
|
||||||
var table,
|
var table,
|
||||||
idNames = {};
|
idNames = {};
|
||||||
@@ -344,10 +344,10 @@ function editGroup() {
|
|||||||
var notDone = "editing";
|
var notDone = "editing";
|
||||||
switch (elem) {
|
switch (elem) {
|
||||||
case "enabled_" + id:
|
case "enabled_" + id:
|
||||||
if (enabled === false) {
|
if (!enabled) {
|
||||||
done = "disabled";
|
done = "disabled";
|
||||||
notDone = "disabling";
|
notDone = "disabling";
|
||||||
} else if (enabled === true) {
|
} else {
|
||||||
done = "enabled";
|
done = "enabled";
|
||||||
notDone = "enabling";
|
notDone = "enabling";
|
||||||
}
|
}
|
||||||
@@ -378,9 +378,10 @@ function editGroup() {
|
|||||||
comment: comment,
|
comment: comment,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
}),
|
}),
|
||||||
success: function () {
|
success: function (data) {
|
||||||
utils.enableAll();
|
utils.enableAll();
|
||||||
utils.showAlert("success", "fas fa-pencil-alt", "Successfully " + done + " group", oldName);
|
processGroupResult(data, "group", done, notDone);
|
||||||
|
table.ajax.reload(null, false);
|
||||||
},
|
},
|
||||||
error: function (data, exception) {
|
error: function (data, exception) {
|
||||||
apiFailure(data);
|
apiFailure(data);
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ function showAlert(type, icon, title, message) {
|
|||||||
break;
|
break;
|
||||||
case "error":
|
case "error":
|
||||||
options.icon = "fas fa-times";
|
options.icon = "fas fa-times";
|
||||||
options.title = " <strong>Error, something went wrong!</strong><br>";
|
if (title.length === 0)
|
||||||
|
options.title = " <strong>Error, something went wrong!</strong><br>";
|
||||||
settings.delay *= 2;
|
settings.delay *= 2;
|
||||||
|
|
||||||
// If the message is an API object, nicely format the error message
|
// If the message is an API object, nicely format the error message
|
||||||
|
|||||||
Reference in New Issue
Block a user