diff options
author | 2019-11-27 20:19:49 +0000 | |
---|---|---|
committer | 2019-11-27 20:19:49 +0000 | |
commit | ddc61816d0a201d550e439e49b2814a785541e01 (patch) | |
tree | 37124960cf96b50c85c584c28709c16ea39f23b6 /cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts | |
parent | 55b06b518ca4c4bb671bedf0d8a1d3a4f9c65f6b (diff) | |
parent | eea49075a4a8bb62a5a15ec31adfe52e1f1f3b7a (diff) |
Merge "filter packages by tag rename filter-by-keyword to search-by-packages"
Diffstat (limited to 'cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts')
-rw-r--r-- | cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts | 73 |
1 files changed, 60 insertions, 13 deletions
diff --git a/cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts b/cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts index 799946dbc..d770bf737 100644 --- a/cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts +++ b/cds-ui/client-frankfurt/src/app/modules/feature-modules/packages/packages.store.ts @@ -23,35 +23,82 @@ import {Injectable} from '@angular/core'; import {BluePrintPage} from './model/BluePrint.model'; import {Store} from '../../../common/core/stores/Store'; import {PackagesListService} from './packages-list.service'; +import {PackagesDashboardState} from './model/packages-dashboard.state'; @Injectable({ providedIn: 'root' }) -export class PackagesStore extends Store<BluePrintPage> { - private bluePrintModels: BluePrintPage; - +export class PackagesStore extends Store<PackagesDashboardState> { // TDOD fixed for now as there is no requirement to change it from UI - public pageSize = 2; + public pageSize = 5; constructor(private packagesServiceList: PackagesListService) { - super(new BluePrintPage()); + super(new PackagesDashboardState()); + } + + public getAll() { + console.log('getting all packages...'); + this.getPagedPackages(0, this.pageSize); + } + + public search(command: string) { + if (command) { + this.searchPagedPackages(command, 0, this.pageSize); + } else { + this.getPagedPackages(0, this.pageSize); + } + } + + public getPage(pageNumber: number, pageSize: number) { + if (this.isCommandExist()) { + this.searchPagedPackages(this.state.command, pageNumber, pageSize); + } else { + this.getPagedPackages(pageNumber, pageSize); + } } - getPagedPackages(pageNumber: number, pageSize: number) { - this.packagesServiceList.getPagedPackages(pageNumber, pageSize) + public sortPagedPackages(sortBy: string) { + if (this.isCommandExist()) { + this.searchPagedPackages(this.state.command, this.state.currentPage, this.pageSize, sortBy); + } else { + this.getPagedPackages(this.state.currentPage, this.pageSize, sortBy); + } + + } + + private getPagedPackages(pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) { + + this.packagesServiceList.getPagedPackages(pageNumber, pageSize, sortBy) .subscribe((pages: BluePrintPage[]) => { - this.setState(pages[0]); + this.setState({ + ...this.state, + page: pages[0], + command: '', + totalPackages: pages[0].totalElements, + currentPage: pageNumber, + // this param is set only in get all as it represents the total number of pacakges in the server + totalPackagesWithoutSearchorFilters: pages[0].totalElements, + sortBy + }); }); } - getPagedPackagesByKeyWord(keyWord: string, pageNumber: number, pageSize: number) { - this.packagesServiceList.getPagedPackagesByKeyWord(keyWord, pageNumber, pageSize) + private searchPagedPackages(keyWord: string, pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) { + this.packagesServiceList.getPagedPackagesByKeyWord(keyWord, pageNumber, pageSize, sortBy) .subscribe((pages: BluePrintPage[]) => { - this.setState(pages[0]); + this.setState({ + ...this.state, + page: pages[0], + command: keyWord, + totalPackages: pages[0].totalElements, + currentPage: pageNumber, + sortBy + }); }); - } - + private isCommandExist() { + return this.state.command; + } } |