From 5a6c48613f13ab182b7c8331c04e4aeffbdfc791 Mon Sep 17 00:00:00 2001 From: Florian Heubeck Date: Mon, 31 Jul 2023 16:52:41 +0200 Subject: [PATCH 1/2] Issue #562: Propagate searchText query to List views Signed-off-by: Florian Heubeck --- src/views/policy/PolicyList.vue | 1 + src/views/portfolio/licenses/LicenseList.vue | 1 + src/views/portfolio/projects/ProjectList.vue | 1 + src/views/portfolio/vulnerabilities/VulnerabilityList.vue | 1 + 4 files changed, 4 insertions(+) diff --git a/src/views/policy/PolicyList.vue b/src/views/policy/PolicyList.vue index b61b86ce7..fe5ef25dc 100644 --- a/src/views/policy/PolicyList.vue +++ b/src/views/policy/PolicyList.vue @@ -89,6 +89,7 @@ queryParamsType: 'pageSize', pageList: '[10, 25, 50, 100]', pageSize: (localStorage && localStorage.getItem("PolicyListPageSize") !== null) ? Number(localStorage.getItem("PolicyListPageSize")) : 10, + searchText: (this.$route.query.searchText ? this.$route.query.searchText : ''), icons: { refresh: 'fa-refresh' }, diff --git a/src/views/portfolio/licenses/LicenseList.vue b/src/views/portfolio/licenses/LicenseList.vue index 5c26fa9d2..7565e6bc9 100644 --- a/src/views/portfolio/licenses/LicenseList.vue +++ b/src/views/portfolio/licenses/LicenseList.vue @@ -107,6 +107,7 @@ pageSize: (localStorage && localStorage.getItem("LicenseListPageSize") !== null) ? Number(localStorage.getItem("LicenseListPageSize")) : 10, sortName: (localStorage && localStorage.getItem("LicenseListSortName") !== null) ? localStorage.getItem("LicenseListSortName") : undefined, sortOrder: (localStorage && localStorage.getItem("LicenseListSortOrder") !== null) ? localStorage.getItem("LicenseListSortOrder") : undefined, + searchText: (this.$route.query.searchText ? this.$route.query.searchText : ''), icons: { refresh: 'fa-refresh' }, diff --git a/src/views/portfolio/projects/ProjectList.vue b/src/views/portfolio/projects/ProjectList.vue index ee39ac432..33855bca8 100644 --- a/src/views/portfolio/projects/ProjectList.vue +++ b/src/views/portfolio/projects/ProjectList.vue @@ -304,6 +304,7 @@ import ProjectCreateProjectModal from "./ProjectCreateProjectModal"; pageSize: (localStorage && localStorage.getItem("ProjectListPageSize") !== null) ? Number(localStorage.getItem("ProjectListPageSize")) : 10, sortName: (localStorage && localStorage.getItem("ProjectListSortName") !== null) ? localStorage.getItem("ProjectListSortName") : undefined, sortOrder: (localStorage && localStorage.getItem("ProjectListSortOrder") !== null) ? localStorage.getItem("ProjectListSortOrder") : undefined, + searchText: (this.$route.query.searchText ? this.$route.query.searchText : ''), icons: { refresh: 'fa-refresh' }, diff --git a/src/views/portfolio/vulnerabilities/VulnerabilityList.vue b/src/views/portfolio/vulnerabilities/VulnerabilityList.vue index 1ba7b48aa..981336031 100644 --- a/src/views/portfolio/vulnerabilities/VulnerabilityList.vue +++ b/src/views/portfolio/vulnerabilities/VulnerabilityList.vue @@ -139,6 +139,7 @@ import VulnerabilityCreateVulnerabilityModal from "./VulnerabilityCreateVulnerab pageSize: (localStorage && localStorage.getItem("VulnerabilityListPageSize") !== null) ? Number(localStorage.getItem("VulnerabilityListPageSize")) : 10, sortName: (localStorage && localStorage.getItem("VulnerabilityListSortName") !== null) ? localStorage.getItem("VulnerabilityListSortName") : undefined, sortOrder: (localStorage && localStorage.getItem("VulnerabilityListSortOrder") !== null) ? localStorage.getItem("VulnerabilityListSortOrder") : undefined, + searchText: (this.$route.query.searchText ? this.$route.query.searchText : ''), icons: { refresh: 'fa-refresh' }, From 472447396d14bbf2e81e4cc0361424f75c400e3f Mon Sep 17 00:00:00 2001 From: Florian Heubeck Date: Mon, 31 Jul 2023 20:54:53 +0200 Subject: [PATCH 2/2] Issue #562: Update searchText query parameter via router Signed-off-by: Florian Heubeck --- src/mixins/routerMixin.js | 13 +++++++++++++ src/views/policy/PolicyList.vue | 6 +++++- src/views/portfolio/licenses/LicenseList.vue | 6 +++++- src/views/portfolio/projects/ProjectList.vue | 4 +++- .../portfolio/vulnerabilities/VulnerabilityList.vue | 8 ++++++-- 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/mixins/routerMixin.js diff --git a/src/mixins/routerMixin.js b/src/mixins/routerMixin.js new file mode 100644 index 000000000..0363c227b --- /dev/null +++ b/src/mixins/routerMixin.js @@ -0,0 +1,13 @@ +export default { + methods: { + setSearchTextQuery (searchText) { + let queries = JSON.parse(JSON.stringify(this.$route.query)); + if (searchText === '') { + delete queries.searchText; + } else { + queries.searchText = searchText; + } + this.$router.replace({query: queries}); + } + } +} diff --git a/src/views/policy/PolicyList.vue b/src/views/policy/PolicyList.vue index fe5ef25dc..2710b31c2 100644 --- a/src/views/policy/PolicyList.vue +++ b/src/views/policy/PolicyList.vue @@ -20,6 +20,7 @@ import xssFilters from "xss-filters"; import CreatePolicyModal from "./CreatePolicyModal"; import permissionsMixin from "../../mixins/permissionsMixin"; + import routerMixin from "../../mixins/routerMixin"; import i18n from "../../i18n"; import ActionableListGroupItem from "../components/ActionableListGroupItem"; import BInputGroupFormInput from "../../forms/BInputGroupFormInput"; @@ -33,7 +34,7 @@ import { Switch as cSwitch } from '@coreui/vue'; export default { - mixins: [permissionsMixin, bootstrapTableMixin], + mixins: [permissionsMixin, bootstrapTableMixin, routerMixin], components: { CreatePolicyModal }, @@ -355,6 +356,9 @@ localStorage.setItem("PolicyListPageSize", size.toString()) } }), + onSearch: ((text) => { + this.setSearchTextQuery(text); + }) } }; } diff --git a/src/views/portfolio/licenses/LicenseList.vue b/src/views/portfolio/licenses/LicenseList.vue index 7565e6bc9..50cc949a6 100644 --- a/src/views/portfolio/licenses/LicenseList.vue +++ b/src/views/portfolio/licenses/LicenseList.vue @@ -22,11 +22,12 @@ import PortfolioWidgetRow from "../../dashboard/PortfolioWidgetRow"; import xssFilters from "xss-filters"; import permissionsMixin from "../../../mixins/permissionsMixin"; + import routerMixin from "../../../mixins/routerMixin"; import LicenseAddLicenseModal from "@/views/portfolio/licenses/LicenseAddLicenseModal"; import {loadUserPreferencesForBootstrapTable} from "@/shared/utils"; export default { - mixins: [permissionsMixin], + mixins: [permissionsMixin, routerMixin], components: { LicenseAddLicenseModal, PortfolioWidgetRow @@ -132,6 +133,9 @@ localStorage.setItem("LicenseListSortName", name); localStorage.setItem("LicenseListSortOrder", order); } + }), + onSearch: ((text) => { + this.setSearchTextQuery(text); }) } }; diff --git a/src/views/portfolio/projects/ProjectList.vue b/src/views/portfolio/projects/ProjectList.vue index 33855bca8..da1eccd2d 100644 --- a/src/views/portfolio/projects/ProjectList.vue +++ b/src/views/portfolio/projects/ProjectList.vue @@ -28,6 +28,7 @@ import MurmurHash2 from "imurmurhash"; import Vue from 'vue'; import xssFilters from "xss-filters"; import permissionsMixin from "../../../mixins/permissionsMixin"; +import routerMixin from "../../../mixins/routerMixin"; import common from "../../../shared/common"; import PolicyViolationProgressBar from "../../components/PolicyViolationProgressBar"; import SeverityProgressBar from "../../components/SeverityProgressBar"; @@ -35,7 +36,7 @@ import PortfolioWidgetRow from "../../dashboard/PortfolioWidgetRow"; import ProjectCreateProjectModal from "./ProjectCreateProjectModal"; export default { - mixins: [permissionsMixin], + mixins: [permissionsMixin, routerMixin], components: { cSwitch, ProjectCreateProjectModal, @@ -343,6 +344,7 @@ import ProjectCreateProjectModal from "./ProjectCreateProjectModal"; this.showFlatView = false; } } + this.setSearchTextQuery(text); }), onPageChange: ((number, size) => { if (localStorage) { diff --git a/src/views/portfolio/vulnerabilities/VulnerabilityList.vue b/src/views/portfolio/vulnerabilities/VulnerabilityList.vue index 981336031..debf1e8b2 100644 --- a/src/views/portfolio/vulnerabilities/VulnerabilityList.vue +++ b/src/views/portfolio/vulnerabilities/VulnerabilityList.vue @@ -22,12 +22,13 @@ import $ from "jquery"; import xssFilters from "xss-filters"; import permissionsMixin from "../../../mixins/permissionsMixin"; +import routerMixin from "../../../mixins/routerMixin"; import common from "../../../shared/common"; import PortfolioWidgetRow from "../../dashboard/PortfolioWidgetRow"; import VulnerabilityCreateVulnerabilityModal from "./VulnerabilityCreateVulnerabilityModal"; export default { - mixins: [permissionsMixin], + mixins: [permissionsMixin, routerMixin], components: { VulnerabilityCreateVulnerabilityModal, PortfolioWidgetRow @@ -164,7 +165,10 @@ import VulnerabilityCreateVulnerabilityModal from "./VulnerabilityCreateVulnerab localStorage.setItem("VulnerabilityListSortName", name); localStorage.setItem("VulnerabilityListSortOrder", order); } - }) + }), + onSearch: ((text) => { + this.setSearchTextQuery(text); + }), } }; }