From fe3dacb883024e573a71b2e45b4b6c897df5b0e9 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 15 Jun 2021 08:59:36 +0200 Subject: [PATCH 01/12] add inner scroll to categories --- src/app/modules/project/overview/overview.component.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/modules/project/overview/overview.component.scss b/src/app/modules/project/overview/overview.component.scss index 4205a2f2..8cc6b7d6 100644 --- a/src/app/modules/project/overview/overview.component.scss +++ b/src/app/modules/project/overview/overview.component.scss @@ -263,6 +263,8 @@ /* Customize the label (the container) */ display: flex; flex-direction: column; + overflow-y: auto; + max-height: 250px; gap: 10px; .container { display: flex; From 5b6b966a7ea05479c9d670fb5127f2f146fd4d90 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 15 Jun 2021 09:44:07 +0200 Subject: [PATCH 02/12] Fix routing behaviour (replacing history instead of pushing --- .../project/overview/overview.component.ts | 61 +++++++++++-------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 57018738..f6e6171e 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -153,7 +153,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { private categoryService: CategoryService, private route: ActivatedRoute) { this.searchControl = new FormControl(''); - this.sortOptionControl = new FormControl(this.sortSelectOptions); + this.sortOptionControl = new FormControl(this.sortSelectOptions[0]); this.paginationOptionControl = new FormControl(this.paginationDropDownOptions[0]); @@ -368,15 +368,8 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.modalSubscriptions.push( this.modalService.onHide.subscribe(() => { if (this.location.path().startsWith('/project/details')) { - const queryString = `query=${this.searchControl.value}` - + `&sortOption=${this.currentSortOptions}` - + `&pagination=${this.amountOfProjectsOnSinglePage}` - + `&page=${this.currentPage}` - + `&categories=${JSON.stringify(this.categories?.map( - category => category.selected ? category.id : null) - .filter(category => category) - )}`; - this.location.replaceState(`/project/overview/`, queryString); + this.updateQueryParams(); + this.location.replaceState("/project/overview"); this.updateSEOTags(); this.onInternalQueryChange(); } @@ -389,33 +382,36 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.router.navigate( [], { + replaceUrl: true, queryParams: { query: this.searchControl.value, - sortOption: this.currentSortOptions, pagination: this.amountOfProjectsOnSinglePage, - categories: JSON.stringify( - this.categories?.map(category => - category.selected ? category.id : null - ).filter(category => category) - ) + sortOption: this.sortOptionControl.value.value, + categories: JSON.stringify(this.categories?.map( + category => category.selected ? category.id : null) + .filter(category => category)) }, - queryParamsHandling: 'merge' - }); + queryParamsHandling: "merge" + } + ); } private processQueryParams() { - this.route.queryParams.subscribe(({query, categories: selectedCategories, sortOption, pagination}) => { - if (query !== 'null' && query !== 'undefined') { + this.route.queryParams.subscribe((params) => { + + const {query, sortOption, pagination} = params; + let {categories: selectedCategories} = params; + if (query && query !== 'null' && query !== 'undefined') { this.searchControl.setValue(query); } if (selectedCategories) { selectedCategories = JSON.parse(selectedCategories); - if (selectedCategories.count > 0) { + if (selectedCategories.length > 0) { this.categories = this.categories?.map(category => { return { ...category, - selected: selectedCategories.contains(category.id) + selected: selectedCategories.indexOf(category.id) >= 0 }; }); } @@ -423,14 +419,15 @@ export class OverviewComponent implements OnInit, AfterViewInit { if (sortOption) { this.currentSortOptions = sortOption; - this.sortOptionControl.setValue(this.sortSelectOptions.find(option => option.value === sortOption)); + const parsed = this.sortSelectOptions.find(option => option.value === sortOption); + this.sortOptionControl.setValue(parsed ? parsed : this.sortSelectOptions[0]); } if (pagination) { const parsed = this.paginationDropDownOptions.find(option => option.amountOnPage === parseInt(pagination, 10)); - this.paginationOptionControl.setValue(parsed ? parsed : 12); + this.paginationOptionControl.setValue(parsed ? parsed : this.paginationDropDownOptions[0]); this.amountOfProjectsOnSinglePage = parsed ? parsed.amountOnPage : 12; } @@ -438,6 +435,22 @@ export class OverviewComponent implements OnInit, AfterViewInit { }); } + private buildQueryParams() { + const categories = this.categories?.map( + category => category.selected ? category.id : null) + .filter(category => category); + + const queryValue = this.searchControl.value; + const sortOptionValue = this.sortOptionControl.value.value; + const paginationValue = this.amountOfProjectsOnSinglePage; + const categoriesValue = JSON.stringify(categories); + + return `query=${queryValue}` + + `&sortOption=${sortOptionValue}` + + `&pagination=${paginationValue}` + + `&categories=${categoriesValue}`; + } + /** * Methods to update the title and description through the SEO service */ From 2bb8aecd0956f0502449a83ef73df8f1797fdd52 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 15 Jun 2021 10:50:04 +0200 Subject: [PATCH 03/12] Fix modal behaviour --- .../modules/project/overview/overview.component.scss | 2 +- .../modules/project/overview/overview.component.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.scss b/src/app/modules/project/overview/overview.component.scss index 8cc6b7d6..bd0288d9 100644 --- a/src/app/modules/project/overview/overview.component.scss +++ b/src/app/modules/project/overview/overview.component.scss @@ -264,7 +264,7 @@ display: flex; flex-direction: column; overflow-y: auto; - max-height: 250px; + max-height: 300px; gap: 10px; .container { display: flex; diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index f6e6171e..e4676d0e 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -214,6 +214,10 @@ export class OverviewComponent implements OnInit, AfterViewInit { return; } + if(value === '') { + this.onInternalQueryChange(); + } + this.currentSearchInput = value; this.searchSubject.next(value); } @@ -241,7 +245,8 @@ export class OverviewComponent implements OnInit, AfterViewInit { } else { this.createProjectModal(id); } - this.location.replaceState(`/project/details/${id}-${name}`); + + this.location.replaceState(`/project/details/${id}-${name}`, this.buildQueryParams()); } /** @@ -369,7 +374,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.modalService.onHide.subscribe(() => { if (this.location.path().startsWith('/project/details')) { this.updateQueryParams(); - this.location.replaceState("/project/overview"); + this.location.replaceState("/project/overview", this.buildQueryParams()); this.updateSEOTags(); this.onInternalQueryChange(); } @@ -440,7 +445,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { category => category.selected ? category.id : null) .filter(category => category); - const queryValue = this.searchControl.value; + const queryValue = this.currentSearchInput; const sortOptionValue = this.sortOptionControl.value.value; const paginationValue = this.amountOfProjectsOnSinglePage; const categoriesValue = JSON.stringify(categories); From 494f9d3f48d321de935c0a7414b40941a3a44ab7 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Thu, 17 Jun 2021 10:08:15 +0200 Subject: [PATCH 04/12] fix linter issues --- src/app/modules/project/overview/overview.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index e4676d0e..6edc3983 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -214,7 +214,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { return; } - if(value === '') { + if (value === '') { this.onInternalQueryChange(); } @@ -374,7 +374,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.modalService.onHide.subscribe(() => { if (this.location.path().startsWith('/project/details')) { this.updateQueryParams(); - this.location.replaceState("/project/overview", this.buildQueryParams()); + this.location.replaceState('/project/overview', this.buildQueryParams()); this.updateSEOTags(); this.onInternalQueryChange(); } @@ -396,7 +396,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { category => category.selected ? category.id : null) .filter(category => category)) }, - queryParamsHandling: "merge" + queryParamsHandling: 'merge' } ); } From 0b8cf40908f3eabf02d976f9e6190fec3101632f Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 22 Jun 2021 14:44:20 +0200 Subject: [PATCH 05/12] Fix url changing to detail instead of overview --- src/app/modules/project/overview/overview.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 6edc3983..86e1171e 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -385,7 +385,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { private updateQueryParams() { this.router.navigate( - [], + ['project/overview'], { replaceUrl: true, queryParams: { From b058960126e0a8f24f2ef26c1edaa0b5e4886243 Mon Sep 17 00:00:00 2001 From: Niray Mak <44868678+niraymak@users.noreply.github.com> Date: Wed, 23 Jun 2021 09:01:08 +0200 Subject: [PATCH 06/12] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467da9aa..b99fed3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Changed +- URL does now contain project overview filter parameters - [#517](https://github.com/DigitalExcellence/dex-frontend/issues/517) + ### Deprecated ### Removed From 96e36aef6f8f9701e63f470720faae29472b0f11 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Thu, 24 Jun 2021 10:00:22 +0200 Subject: [PATCH 07/12] Make sure there's always an empty spot for images --- .../modules/project/overview/overview.component.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 86e1171e..0bf30399 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -17,7 +17,7 @@ import { AfterViewInit, Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { Location } from '@angular/common'; -import { debounceTime, finalize } from 'rxjs/operators'; +import { debounceTime, distinctUntilChanged, filter, finalize } from 'rxjs/operators'; import { Project } from 'src/app/models/domain/project'; import { FormBuilder, FormControl } from '@angular/forms'; import { InternalSearchService } from 'src/app/services/internal-search.service'; @@ -163,7 +163,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { // Subscribe to search subject to debounce the input and afterwards searchAndFilter. this.searchSubject .pipe( - debounceTime(500) + filter(Boolean), + debounceTime(500), + distinctUntilChanged() ) .subscribe((result) => { if (!result) { @@ -214,11 +216,13 @@ export class OverviewComponent implements OnInit, AfterViewInit { return; } + this.currentSearchInput = value; + if (value === '') { - this.onInternalQueryChange(); + return this.onInternalQueryChange(); } - this.currentSearchInput = value; + // If the field is empty we don't want to update the searchSubject anymore because the debounce will mess with the query. this.searchSubject.next(value); } @@ -299,7 +303,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { */ private onInternalQueryChange(): void { const internalSearchQuery: InternalSearchQuery = { - query: this.currentSearchInput === '' ? null : this.currentSearchInput, + query: !this.currentSearchInput || this.currentSearchInput === '' ? null : this.currentSearchInput, // If there is a search query, search on all pages page: !this.currentSearchInput ? this.currentPage : null, amountOnPage: this.amountOfProjectsOnSinglePage, From 5f9e81bcc120c7aa4917b3bbc967ea314d162433 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Thu, 24 Jun 2021 10:05:02 +0200 Subject: [PATCH 08/12] Cancel the debounce when the search query is empty --- src/app/modules/project/overview/overview.component.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 0bf30399..4ad5f280 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -341,11 +341,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.projectsToDisplay = response.results; this.totalNrOfProjects = response.totalCount; - if (this.projects.length < this.amountOfProjectsOnSinglePage && this.currentPage <= 1) { - this.showPaginationFooter = false; - } else { - this.showPaginationFooter = true; - } + this.showPaginationFooter = !(this.projects.length < this.amountOfProjectsOnSinglePage && this.currentPage <= 1); } /** From 7b79a59bc1b1bec46976ac95a9908ec8e3ea1b61 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 29 Jun 2021 14:29:59 +0200 Subject: [PATCH 09/12] remove console.log --- src/app/modules/project/edit/edit.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/modules/project/edit/edit.component.ts b/src/app/modules/project/edit/edit.component.ts index 62b17c69..0dbde9f0 100644 --- a/src/app/modules/project/edit/edit.component.ts +++ b/src/app/modules/project/edit/edit.component.ts @@ -378,7 +378,6 @@ export class EditComponent implements OnInit { * Method which will send the requests to the API to edit the project */ private editProject(edittedProject) { - console.log(edittedProject); this.projectService .put(this.project.id, edittedProject) .pipe( From 051da29b8efd36f7ae8496ec3f587e74c32160b3 Mon Sep 17 00:00:00 2001 From: Walter Sajtos Date: Tue, 29 Jun 2021 14:31:14 +0200 Subject: [PATCH 10/12] fix navigation behaviour --- .../project/overview/overview.component.ts | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index cbf62dd5..3b340eae 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -174,6 +174,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { return; } this.onInternalQueryChange(); + this.updateQueryParams(); }); this.searchControl.valueChanges.subscribe((value) => this.onSearchInputValueChange(value)); @@ -221,7 +222,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.currentSearchInput = value; if (value === '') { + return this.onInternalQueryChange(); + this.updateQueryParams(); } // If the field is empty we don't want to update the searchSubject anymore because the debounce will mess with the query. @@ -262,7 +265,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { */ public pageChanged(event: PageChangedEvent): void { this.currentPage = event.page; + this.onInternalQueryChange(); + this.updateQueryParams(); } /** @@ -275,7 +280,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { if (this.amountOfProjectsOnSinglePage === this.paginationResponse.totalCount) { this.currentPage = 1; } + this.onInternalQueryChange(); + this.updateQueryParams(); } /** @@ -288,7 +295,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { } this.currentSortType = this.sortOptionControl.value.value.split(',')[0]; this.currentSortDirection = this.sortOptionControl.value.value.split(',')[1]; + this.onInternalQueryChange(); + this.updateQueryParams(); } public onCategoryChange(categoryId: number): void { @@ -296,7 +305,9 @@ export class OverviewComponent implements OnInit, AfterViewInit { category.id === categoryId ? {...category, selected: !category.selected} : category); + this.onInternalQueryChange(); + this.updateQueryParams(); } /** @@ -316,7 +327,6 @@ export class OverviewComponent implements OnInit, AfterViewInit { .filter(value => value) }; - this.updateQueryParams(); if (internalSearchQuery.query == null) { // No search query provided use projectService. @@ -375,9 +385,11 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.modalSubscriptions.push( this.modalService.onHide.subscribe(() => { if (this.location.path().startsWith('/project/details')) { - this.updateQueryParams(); - this.location.replaceState('/project/overview', this.buildQueryParams()); + // this.updateQueryParams(); + // this.location.replaceState('/project/overview', this.buildQueryParams()); this.updateSEOTags(); + + this.updateQueryParams(); this.onInternalQueryChange(); } } @@ -387,25 +399,24 @@ export class OverviewComponent implements OnInit, AfterViewInit { private updateQueryParams() { this.router.navigate( - ['project/overview'], + ['/project/overview'], { - replaceUrl: true, queryParams: { query: this.searchControl.value, + sortOption: this.currentSortOptions, pagination: this.amountOfProjectsOnSinglePage, - sortOption: this.sortOptionControl.value.value, - categories: JSON.stringify(this.categories?.map( - category => category.selected ? category.id : null) - .filter(category => category)) + categories: JSON.stringify( + this.categories?.map(category => + category.selected ? category.id : null + ).filter(category => category) + ) }, queryParamsHandling: 'merge' - } - ); + }); } private processQueryParams() { this.route.queryParams.subscribe((params) => { - const {query, sortOption, pagination} = params; let {categories: selectedCategories} = params; if (query && query !== 'null' && query !== 'undefined') { From 447dd521b7e00ea7351ff97e3784e4221723e349 Mon Sep 17 00:00:00 2001 From: Niray Mak <44868678+niraymak@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:06:29 +0200 Subject: [PATCH 11/12] changed unreachable code --- src/app/modules/project/overview/overview.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 3b340eae..886a1366 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -222,9 +222,8 @@ export class OverviewComponent implements OnInit, AfterViewInit { this.currentSearchInput = value; if (value === '') { - - return this.onInternalQueryChange(); this.updateQueryParams(); + return this.onInternalQueryChange(); } // If the field is empty we don't want to update the searchSubject anymore because the debounce will mess with the query. From d342cf7810561e064762da5dd669463b54e2a286 Mon Sep 17 00:00:00 2001 From: Niray Mak <44868678+niraymak@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:18:26 +0200 Subject: [PATCH 12/12] fix sortoptions param update --- src/app/modules/project/overview/overview.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/modules/project/overview/overview.component.ts b/src/app/modules/project/overview/overview.component.ts index 886a1366..b66aa330 100644 --- a/src/app/modules/project/overview/overview.component.ts +++ b/src/app/modules/project/overview/overview.component.ts @@ -31,7 +31,7 @@ import { SearchResultsResource } from 'src/app/models/resources/search-results'; import { SEOService } from 'src/app/services/seo.service'; import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; import { DetailsComponent } from 'src/app/modules/project/details/details.component'; -import { Subscription } from 'rxjs'; +import { Subscription, VirtualTimeScheduler } from 'rxjs'; import { CategoryService } from 'src/app/services/category.service'; import { ProjectCategory } from 'src/app/models/domain/projectCategory'; @@ -294,7 +294,7 @@ export class OverviewComponent implements OnInit, AfterViewInit { } this.currentSortType = this.sortOptionControl.value.value.split(',')[0]; this.currentSortDirection = this.sortOptionControl.value.value.split(',')[1]; - + this.currentSortOptions = this.sortOptionControl.value.value; this.onInternalQueryChange(); this.updateQueryParams(); }