diff --git a/app/javascript/vue/global_search/container.vue b/app/javascript/vue/global_search/container.vue index 48c1ebd86..f34c457cf 100644 --- a/app/javascript/vue/global_search/container.vue +++ b/app/javascript/vue/global_search/container.vue @@ -24,24 +24,19 @@ {{ i18n.t('search.index.task_results') }} - - - - - @@ -73,10 +80,11 @@ import RepositoryRowsComponent from './groups/repository_rows.vue'; import ProtocolsComponent from './groups/protocols.vue'; import LabelTemplatesComponent from './groups/label_templates.vue'; import ReportsComponent from './groups/reports.vue'; -import SearchFilters from './filters.vue'; +import FiltersModal from './filters_modal.vue'; import GeneralDropdown from '../shared/general_dropdown.vue'; export default { + emits: ['search', 'selectGroup'], name: 'GlobalSearch', props: { query: { @@ -94,6 +102,10 @@ export default { usersUrl: { type: String, required: true + }, + currentTeam: { + type: Number || String, + required: true } }, components: { @@ -108,12 +120,14 @@ export default { ProtocolsComponent, LabelTemplatesComponent, ReportsComponent, - SearchFilters, + FiltersModal, GeneralDropdown }, data() { return { + filters: {}, localQuery: this.query, + filterModalOpened: false, activeGroup: null, searchGroups: [ 'FoldersComponent', @@ -130,6 +144,48 @@ export default { ] }; }, + computed: { + activeFilters() { + return Object.keys(this.filters).filter((key) => { + if (key === 'created_at' || key === 'updated_at') { + return this.filters[key].on || this.filters[key].from || this.filters[key].to; + } if (key === 'teams' || key === 'users') { + return this.filters[key].length > 0; + } + return this.filters[key]; + }); + } + }, + created() { + const urlParams = new URLSearchParams(window.location.search); + this.filters = { + created_at: { + on: null, + from: null, + to: null + }, + updated_at: { + on: null, + from: null, + to: null + }, + include_archived: urlParams.get('include_archived') === 'true', + teams: urlParams.getAll('teams[]').map((team) => parseInt(team, 10)), + users: urlParams.getAll('users[]').map((user) => parseInt(user, 10)), + group: urlParams.get('group') + }; + ['created_at', 'updated_at'].forEach((key) => { + ['on', 'from', 'to', 'mode'].forEach((subKey) => { + if (urlParams.get(`${key}[${subKey}]`)) { + this.filters[key][subKey] = subKey !== 'mode' ? new Date(urlParams.get(`${key}[${subKey}]`)) : urlParams.get(`${key}[${subKey}]`); + } + }); + }); + + if (this.filters.group) { + this.activeGroup = this.filters.group; + } + }, methods: { setActiveGroup(group) { if (group === this.activeGroup) { @@ -137,9 +193,36 @@ export default { } else { this.activeGroup = group; } + + this.filters.group = this.activeGroup; }, changeQuery(event) { this.localQuery = event.target.value; + }, + applyFilters(filters) { + this.filters = filters; + this.filterModalOpened = false; + + this.activeGroup = this.filters.group; + }, + resetFilters() { + this.filters = { + created_at: { + on: null, + from: null, + to: null + }, + updated_at: { + on: null, + from: null, + to: null + }, + include_archived: false, + teams: [], + users: [], + group: null + }; + this.activeGroup = null; } } }; diff --git a/app/javascript/vue/global_search/filters.vue b/app/javascript/vue/global_search/filters.vue index fa896c1da..04f5e8999 100644 --- a/app/javascript/vue/global_search/filters.vue +++ b/app/javascript/vue/global_search/filters.vue @@ -1,5 +1,5 @@