2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
22 import {Injectable} from '@angular/core';
23 import {BluePrintPage} from './model/BluePrint.model';
24 import {Store} from '../../../common/core/stores/Store';
25 import {PackagesListService} from './packages-list.service';
26 import {PackagesDashboardState} from './model/packages-dashboard.state';
32 export class PackagesStore extends Store<PackagesDashboardState> {
33 // TDOD fixed for now as there is no requirement to change it from UI
36 constructor(private packagesServiceList: PackagesListService) {
37 super(new PackagesDashboardState());
41 console.log('getting all packages...');
42 this.getPagedPackages(0, this.pageSize);
45 public search(command: string) {
47 this.searchPagedPackages(command, 0, this.pageSize);
49 this.getPagedPackages(0, this.pageSize);
53 public getPage(pageNumber: number, pageSize: number) {
54 if (this.isCommandExist()) {
55 this.searchPagedPackages(this.state.command, pageNumber, pageSize);
57 this.getPagedPackages(pageNumber, pageSize);
61 public sortPagedPackages(sortBy: string) {
62 if (this.isCommandExist()) {
63 this.searchPagedPackages(this.state.command, this.state.currentPage, this.pageSize, sortBy);
65 this.getPagedPackages(this.state.currentPage, this.pageSize, sortBy);
70 private getPagedPackages(pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) {
72 this.packagesServiceList.getPagedPackages(pageNumber, pageSize, sortBy)
73 .subscribe((pages: BluePrintPage[]) => {
78 totalPackages: pages[0].totalElements,
79 currentPage: pageNumber,
80 // this param is set only in get all as it represents the total number of pacakges in the server
81 totalPackagesWithoutSearchorFilters: pages[0].totalElements,
87 private searchPagedPackages(keyWord: string, pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) {
88 this.packagesServiceList.getPagedPackagesByKeyWord(keyWord, pageNumber, pageSize, sortBy)
89 .subscribe((pages: BluePrintPage[]) => {
94 totalPackages: pages[0].totalElements,
95 currentPage: pageNumber,
101 private isCommandExist() {
102 return this.state.command;