aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts
diff options
context:
space:
mode:
authorswapnalipode <sp00501638@techmahindra.com>2020-04-18 19:45:12 +0530
committerSwapnali Pode <sp00501638@techmahindra.com>2020-04-21 16:16:20 +0000
commitb85c484da92c3b6721bb241376074fd9d7a712e2 (patch)
treed85aff1e31f31d73853ba528e82017530cd82cec /cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts
parent3c10444c1d9d84b4d7f38b223fd304450cb36eb6 (diff)
Adding Resource dictionary
Adding resource-dictionary Change-Id: Ib23b282e7293843ce94263e82b3f7cdb0fe36c5a Issue-ID: CCSDK-2253 Signed-off-by: swapnalipode <sp00501638@techmahindra.com>
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts161
1 files changed, 161 insertions, 0 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts b/cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts
new file mode 100644
index 000000000..a932327cf
--- /dev/null
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/resource-dictionary/dictionary.store.ts
@@ -0,0 +1,161 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : CDS
+* ================================================================================
+* Copyright (C) 2020 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+
+import { Injectable } from '@angular/core';
+import { Store } from '../../../common/core/stores/Store';
+import { Observable, of } from 'rxjs';
+import { DictionaryDashboardState } from './model/dictionary-dashboard.state';
+import { DictionaryPage } from './model/dictionary.model';
+import { DictionaryApiService } from './dictionary-api.service';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class DictionaryStore extends Store<DictionaryDashboardState> {
+ // TDOD fixed for now as there is no requirement to change it from UI
+ public pageSize = 5;
+ private dictionaryContent: DictionaryPage = new DictionaryPage();
+
+ constructor(private dictionaryServiceList: DictionaryApiService) {
+ super(new DictionaryDashboardState());
+ }
+
+ public search(command: string) {
+ if (command) {
+ this.searchPagedDictionary(command, 0, this.pageSize);
+ } else {
+ this.getPagedDictionary(0, this.pageSize);
+ }
+ }
+
+ public getAll() {
+ console.log('getting all packages...');
+ this.getPagedDictionary(0, this.pageSize);
+ }
+
+ public getPage(pageNumber: number, pageSize: number) {
+ if (this.isCommandExist()) {
+ this.searchPagedDictionary(this.state.command, pageNumber, pageSize);
+ } else {
+ this.getPagedDictionary(pageNumber, pageSize);
+ }
+ }
+
+ public sortPagedDictionary(sortBy: string) {
+ if (this.isCommandExist()) {
+ this.searchPagedDictionary(this.state.command, this.state.currentPage, this.pageSize, sortBy);
+ } else {
+ this.getPagedDictionary(this.state.currentPage, this.pageSize, sortBy);
+ }
+}
+
+ public filterByTags(tags: string[]) {
+ console.log(this.state.currentPage);
+ this.getPagedDictionaryByTags(this.state.command, this.state.currentPage,
+ this.pageSize, this.state.sortBy, tags);
+
+ }
+
+ protected getPagedDictionary(pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) {
+
+ this.dictionaryServiceList.getPagedDictionary(pageNumber, pageSize, sortBy)
+ .subscribe((pages: DictionaryPage) => {
+ console.log(pages);
+ this.setState({
+ ...this.state,
+ page: pages,
+ filteredPackages: pages,
+ command: '',
+ totalPackages: pages.totalElements,
+ currentPage: pageNumber,
+ // this param is set only in get all as it represents the total number of pacakges in the server
+ totalDictionariesWithoutSearchorFilters: pages.totalElements,
+ tags: [],
+ sortBy
+ });
+ });
+ }
+
+ private searchPagedDictionary(keyWord: string, pageNumber: number, pageSize: number, sortBy: string = this.state.sortBy) {
+ this.dictionaryServiceList.getPagedDictionaryByKeyWord(keyWord, pageNumber, pageSize, sortBy)
+ .subscribe((pages: DictionaryPage) => {
+ console.log(pages);
+ this.setState({
+ ...this.state,
+ page: pages,
+ filteredPackages: pages,
+ command: keyWord,
+ totalPackages: pages.totalElements,
+ currentPage: pageNumber,
+ tags: [],
+ sortBy
+ });
+ });
+ }
+
+ private isCommandExist() {
+ return this.state.command;
+ }
+
+ private getPagedDictionaryByTags(keyWord: string, currentPage1: number, pageSize: number, sortBy1: string, tagsSearchable: string[]) {
+ this.getPagedDictionaryByKeyWordFilteredByTags(tagsSearchable)
+ .subscribe((pages: DictionaryPage) => {
+ this.setState({
+ ...this.state,
+ page: this.state.page,
+ filteredPackages: pages,
+ command: keyWord,
+ tags: tagsSearchable,
+ currentPage: currentPage1,
+ sortBy: sortBy1,
+ totalPackages: this.state.page.totalElements,
+ });
+ });
+ }
+
+ private getPagedDictionaryByKeyWordFilteredByTags(tagsSearchable: string[]): Observable<any> {
+ this.dictionaryContent.content = [];
+ if (tagsSearchable && tagsSearchable.length !== 0 && !tagsSearchable.includes('All')) {
+ tagsSearchable.forEach(tag => {
+ if (tag) {
+ this.state.page.content.forEach(dictionaryModel => {
+ if (tag.endsWith(',')) {
+ tag = tag.replace(',', '');
+ }
+ dictionaryModel.tags.split(',').forEach(dictionaryModelTag => {
+ if (dictionaryModelTag === tag) {
+ this.dictionaryContent.content.push(dictionaryModel);
+ }
+ });
+ });
+ } else {
+ this.getPagedDictionary(this.state.currentPage, this.pageSize);
+ return of(this.state.page);
+ }
+ });
+ this.dictionaryContent.content = this.dictionaryContent.content.filter((value, index, self) => self.indexOf(value) === index);
+ console.log('the lenght is ' + this.dictionaryContent.content.length);
+ return of(this.dictionaryContent);
+ } else {
+ this.getPagedDictionary(this.state.currentPage, this.pageSize);
+ return of(this.state.page);
+ }
+ }
+}