Compare commits

..

No commits in common. "d552975d6c35daebf44946a00b94a7c9500ae6e7" and "1b379690dd5103d31b39aee7519665159a69c5e5" have entirely different histories.

3 changed files with 46 additions and 62 deletions

View file

@ -160,34 +160,32 @@ export default {
/** /**
* Returns applied filters based on query params. * Returns applied filters based on query params.
* @returns {{ status: number[], active: any[], tags: number[] }} The current filter state. * @returns {{ status: number[], active: bool, tags: number[] }} The current filter state.
*/ */
filterState() { filterState() {
// Since query params are always strings, convert them to the correct type // Since query params are always strings, convert them to the correct type
let status = this.$route.query["status"] || []; let status = this.$route.query["status"] || null;
if (status) {
if (!Array.isArray(status)) { if (!Array.isArray(status)) {
status = [ status ]; status = [ status ];
} }
status = status.map(Number); status = status.map(Number);
}
// Casting to boolean does not work here as Boolean("false") === true // Casting to boolean does not work here as Boolean("false") === true
let active = this.$route.query["active"] || []; let active = this.$route.query["active"] || null;
if (active) {
if (!Array.isArray(active)) { if (!Array.isArray(active)) {
active = [ active ]; active = [ active ];
} }
active = active.map(val => { active = active.map(val => val === "true");
if (val === "true") {
return true;
} }
if (val === "false") { let tags = this.$route.query["tags"] || null;
return false; if (tags) {
}
return val;
});
let tags = this.$route.query["tags"] || [];
if (!Array.isArray(tags)) { if (!Array.isArray(tags)) {
tags = [ tags ]; tags = [ tags ];
} }
tags = tags.map(Number); tags = tags.map(Number);
}
return { return {
status, status,
active, active,
@ -200,11 +198,12 @@ export default {
return this.$route.query.searchText || ""; return this.$route.query.searchText || "";
}, },
set(value) { set(value) {
let newQuery = { ...this.$route.query }; const newQuery = {
if (value === "") { ...this.$route.query,
searchText: value,
};
if (!value) {
delete newQuery.searchText; delete newQuery.searchText;
} else {
newQuery.searchText = value;
} }
this.$router.replace({ this.$router.replace({
query: newQuery, query: newQuery,
@ -287,17 +286,26 @@ export default {
}, },
/** /**
* Update the MonitorList Filter * Update the MonitorList Filter
* @param {{ status: number[], active: any[], tags: number[] }} newFilter Object with new filter * @param {{ status: number[], active: bool, tags: number[] }} newFilter Object with new filter
* @returns {void} * @returns {void}
*/ */
updateFilter(newFilter) { updateFilter(newFilter) {
this.$router.replace({ let newQuery = {
query: {
...this.$route.query, ...this.$route.query,
status: newFilter.status, ...newFilter,
active: newFilter.active, };
tags: newFilter.tags, if (!newFilter.status || newFilter.status.length === 0) {
}, delete newQuery.status;
}
if (!newFilter.active || newFilter.active.length === 0) {
delete newQuery.active;
}
if (!newFilter.tags || newFilter.tags.length === 0) {
delete newQuery.tags;
}
this.$router.replace({
query: newQuery,
}); });
}, },
/** /**

View file

@ -80,9 +80,8 @@
<MonitorListFilterDropdown :filterActive="filterState.active?.length > 0"> <MonitorListFilterDropdown :filterActive="filterState.active?.length > 0">
<template #status> <template #status>
<span v-if="filterState.active?.length === 1"> <span v-if="filterState.active?.length === 1">
<span v-if="filterState.active[0] === true">{{ $t("Running") }}</span> <span v-if="filterState.active[0]">{{ $t("Running") }}</span>
<span v-else-if="filterState.active[0] === false">{{ $t("filterActivePaused") }}</span> <span v-else>{{ $t("filterActivePaused") }}</span>
<span v-else>{{ $t("Unknown") }}</span>
</span> </span>
<span v-else> <span v-else>
{{ $t("filterActive") }} {{ $t("filterActive") }}
@ -187,31 +186,10 @@ export default {
}); });
return num; return num;
},
/**
* Returns an array of invalid filters assuming tagsList has been fetched
* @returns {Array} Array of invalid filters
*/
invalidFilters() {
const filters = [];
if (!this.filterState.status.every((val) => val >= 0 && val <= 3)) {
filters.push(this.$t("Status"));
}
if (!this.filterState.active.every((val) => val === true || val === false)) {
filters.push(this.$t("Active"));
}
if (!this.filterState.tags.every((val) => this.tagsList.find(tag => tag.id === val))) {
filters.push(this.$t("Tags"));
}
return filters;
} }
}, },
mounted() { mounted() {
this.getExistingTags(() => { this.getExistingTags();
if (this.invalidFilters.length > 0) {
this.$root.toastError(this.$t("InvalidFilters", [ this.invalidFilters.join(", ") ]));
}
});
}, },
methods: { methods: {
toggleStatusFilter(status) { toggleStatusFilter(status) {
@ -264,15 +242,14 @@ export default {
}, },
clearFilters() { clearFilters() {
this.$emit("updateFilter", { this.$emit("updateFilter", {
status: [], status: null,
}); });
}, },
getExistingTags(callback) { getExistingTags() {
this.$root.getSocket().emit("getTags", (res) => { this.$root.getSocket().emit("getTags", (res) => {
if (res.ok) { if (res.ok) {
this.tagsList = res.tags; this.tagsList = res.tags;
} }
callback();
}); });
}, },
getTaggedMonitorCount(tag) { getTaggedMonitorCount(tag) {

View file

@ -1060,6 +1060,5 @@
"RabbitMQ Password": "RabbitMQ Password", "RabbitMQ Password": "RabbitMQ Password",
"rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.", "rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.",
"SendGrid API Key": "SendGrid API Key", "SendGrid API Key": "SendGrid API Key",
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas", "Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
"InvalidFilters": "The following filters are invalid: {0}"
} }