From a7aaa99ac2a7dab815670e2ff66343945380839e Mon Sep 17 00:00:00 2001 From: Martin Rojas Miguel Angel Date: Tue, 17 Apr 2018 11:01:06 +0200 Subject: [PATCH] TSK-438 Get categories from classification category service. --- .../classification-details.component.html | 17 +++++-- .../classification-details.component.spec.ts | 24 ++++++---- .../classification-details.component.ts | 45 ++++++++++++++----- web/src/app/app.module.ts | 4 +- .../classification-categories.service.spec.ts | 18 ++++++++ .../classification-categories.service.ts | 23 ++++++++++ web/src/app/shared/tree/tree.component.html | 2 +- 7 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 web/src/app/services/classification-categories-service/classification-categories.service.spec.ts create mode 100644 web/src/app/services/classification-categories-service/classification-categories.service.ts diff --git a/web/src/app/administration/classification/details/classification-details.component.html b/web/src/app/administration/classification/details/classification-details.component.html index 3e3938b65..98e153b45 100644 --- a/web/src/app/administration/classification/details/classification-details.component.html +++ b/web/src/app/administration/classification/details/classification-details.component.html @@ -48,12 +48,21 @@ * Domain is required +
- -
- * Category is required +
diff --git a/web/src/app/administration/classification/details/classification-details.component.spec.ts b/web/src/app/administration/classification/details/classification-details.component.spec.ts index 01d06569e..4f21c1b3d 100644 --- a/web/src/app/administration/classification/details/classification-details.component.spec.ts +++ b/web/src/app/administration/classification/details/classification-details.component.spec.ts @@ -19,6 +19,7 @@ import { ErrorModalService } from 'app/services/errorModal/error-modal.service'; import { AlertService } from 'app/services/alert/alert.service'; import { TreeService } from 'app/services/tree/tree.service'; import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service'; +import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service'; @Component({ @@ -32,13 +33,13 @@ const routes: Routes = [ { path: 'administration/classifications', component: DummyDetailComponent } ]; -describe('ClassificationDetailsComponent', () => { +fdescribe('ClassificationDetailsComponent', () => { let component: ClassificationDetailsComponent; let fixture: ComponentFixture; const treeNodes: Array = new Array(new TreeNodeModel()); const classificationTypes: Array = new Array('type1', 'type2'); let classificationsSpy, classificationsTypesSpy; - let classificationsService, classificationTypesService; + let classificationsService, classificationTypesService, classificationCategoriesService; let treeService; beforeEach(async(() => { @@ -46,7 +47,7 @@ describe('ClassificationDetailsComponent', () => { imports: [FormsModule, HttpClientModule, RouterTestingModule.withRoutes(routes)], declarations: [ClassificationDetailsComponent, SpinnerComponent, DummyDetailComponent], providers: [MasterAndDetailService, RequestInProgressService, ClassificationsService, HttpClient, ErrorModalService, AlertService, - TreeService, ClassificationTypesService] + TreeService, ClassificationTypesService, ClassificationCategoriesService] }) .compileComponents(); })); @@ -56,11 +57,14 @@ describe('ClassificationDetailsComponent', () => { component = fixture.componentInstance; classificationsService = TestBed.get(ClassificationsService); classificationTypesService = TestBed.get(ClassificationTypesService); + classificationCategoriesService = TestBed.get(ClassificationCategoriesService); classificationsSpy = spyOn(classificationsService, 'getClassifications').and.returnValue(Observable.of(treeNodes)); - classificationsTypesSpy = spyOn(classificationTypesService, 'getClassificationTypes') - .and.returnValue(Observable.of(classificationTypes)); + classificationsTypesSpy = spyOn(classificationTypesService, 'getClassificationTypes').and.returnValue(Observable.of([])); + spyOn(classificationCategoriesService, 'getCategories').and.returnValue(Observable.of(['firstCategory', 'secondCategory'])); spyOn(classificationsService, 'deleteClassification').and.returnValue(Observable.of(true)); - + component.classification = new ClassificationDefinition('id1', undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, new LinksClassification({ 'self': '' })); treeService = TestBed.get(TreeService); fixture.detectChanges(); }); @@ -71,10 +75,12 @@ describe('ClassificationDetailsComponent', () => { it('should trigger treeService remove node id after removing a node', () => { const treeServiceSpy = spyOn(treeService, 'setRemovedNodeId'); - component.classification = new ClassificationDefinition('id1', undefined, undefined, undefined, undefined, undefined, undefined, - undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, - undefined, undefined, undefined, new LinksClassification({ 'self': '' })); + component.removeClassification(); expect(treeServiceSpy).toHaveBeenCalledWith('id1'); }); + + it('should selected first classificationCategory if is defined', () => { + expect(component.classification.category).toBe('firstCategory'); + }); }); diff --git a/web/src/app/administration/classification/details/classification-details.component.ts b/web/src/app/administration/classification/details/classification-details.component.ts index b39db51c5..94cef685f 100644 --- a/web/src/app/administration/classification/details/classification-details.component.ts +++ b/web/src/app/administration/classification/details/classification-details.component.ts @@ -17,6 +17,7 @@ import { RequestInProgressService } from 'app/services/requestInProgress/request import { AlertService } from 'app/services/alert/alert.service'; import { TreeService } from 'app/services/tree/tree.service'; import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service'; +import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service'; @Component({ selector: 'taskana-classification-details', @@ -32,6 +33,8 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { classificationTypes: Array = []; badgeMessage = ''; requestInProgress = false; + categories: Array = []; + categorySelected: string; private action: any; private classificationServiceSubscription: Subscription; private classificationSelectedSubscription: Subscription; @@ -40,7 +43,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { private classificationSavingSubscription: Subscription; private classificationRemoveSubscription: Subscription; private selectedClassificationSubscription: Subscription; - + private categoriesSubscription: Subscription; constructor(private classificationsService: ClassificationsService, private route: ActivatedRoute, @@ -50,11 +53,10 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { private requestInProgressService: RequestInProgressService, private alertService: AlertService, private treeService: TreeService, - private classificationTypeService: ClassificationTypesService) { } - + private classificationTypeService: ClassificationTypesService, + private categoryService: ClassificationCategoriesService) { } ngOnInit() { - this.classificationTypeService.getClassificationTypes().subscribe((classificationTypes: Array) => { this.classificationTypes = classificationTypes; }) @@ -87,9 +89,16 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { this.masterAndDetailSubscription = this.masterAndDetailService.getShowDetail().subscribe(showDetail => { this.showDetail = showDetail; }); - } + this.categoriesSubscription = this.categoryService.getCategories().subscribe((categories: Array) => { + this.categories = categories; + if (categories.length > 0) { + this.classification.category = categories[0]; + } + }); + } + backClicked(): void { this.classificationsService.selectClassification(undefined); this.router.navigate(['./'], { relativeTo: this.route.parent }); @@ -150,6 +159,11 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { this.classification = { ...this.classificationClone }; } + + selectCategory(category: string) { + this.classification.category = category; + } + private afterRequest() { this.requestInProgressService.setRequestInProgress(false); this.classificationsService.triggerClassificationSaved(); @@ -162,13 +176,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { private getClassificationInformation(classificationIdSelected: string) { if (this.action === ACTION.CREATE) { // CREATE - this.classification = new ClassificationDefinition(); - this.selectedClassificationSubscription = this.classificationTypeService.getSelectedClassificationType().subscribe(value => { - if (this.classification) { this.classification.type = value; } - }); - this.addDateToClassification(); - this.classification.parentId = classificationIdSelected; - this.classificationClone = { ...this.classification }; + this.initClassificationCreation(classificationIdSelected); } else { this.requestInProgress = true; this.classificationServiceSubscription = this.classificationsService.getClassification(classificationIdSelected) @@ -186,7 +194,19 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { this.classification.modified = date; } + private initClassificationCreation(classificationIdSelected: string) { + this.classification = new ClassificationDefinition(); + this.selectedClassificationSubscription = this.classificationTypeService.getSelectedClassificationType().subscribe(value => { + if (this.classification) { this.classification.type = value; } + }); + this.classification.category = this.categories[0]; + this.addDateToClassification(); + this.classification.parentId = classificationIdSelected; + this.classificationClone = { ...this.classification }; + } + ngOnDestroy(): void { + if (this.masterAndDetailSubscription) { this.masterAndDetailSubscription.unsubscribe(); } if (this.routeSubscription) { this.routeSubscription.unsubscribe(); } if (this.classificationSelectedSubscription) { this.classificationSelectedSubscription.unsubscribe(); } @@ -194,6 +214,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy { if (this.classificationSavingSubscription) { this.classificationSavingSubscription.unsubscribe(); } if (this.classificationRemoveSubscription) { this.classificationRemoveSubscription.unsubscribe(); } if (this.selectedClassificationSubscription) { this.selectedClassificationSubscription.unsubscribe(); } + if (this.categoriesSubscription) { this.categoriesSubscription.unsubscribe(); } } } diff --git a/web/src/app/app.module.ts b/web/src/app/app.module.ts index 026e6c6f1..fd19bbdd9 100644 --- a/web/src/app/app.module.ts +++ b/web/src/app/app.module.ts @@ -57,6 +57,7 @@ import { SelectedRouteService } from './services/selected-route/selected-route'; import { ClassificationsService } from './services/classifications/classifications.service'; import { TreeService } from './services/tree/tree.service'; import { ClassificationTypesService } from './services/classification-types/classification-types.service'; +import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service'; /** * Pipes @@ -133,7 +134,8 @@ const DECLARATIONS = [ SelectedRouteService, ClassificationsService, TreeService, - ClassificationTypesService + ClassificationTypesService, + ClassificationCategoriesService ], bootstrap: [AppComponent] }) diff --git a/web/src/app/services/classification-categories-service/classification-categories.service.spec.ts b/web/src/app/services/classification-categories-service/classification-categories.service.spec.ts new file mode 100644 index 000000000..bb08243a0 --- /dev/null +++ b/web/src/app/services/classification-categories-service/classification-categories.service.spec.ts @@ -0,0 +1,18 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClient, HttpClientModule } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; + +import { ClassificationCategoriesService } from './classification-categories.service'; + +describe('CategoryService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientModule], + providers: [HttpClient, ClassificationCategoriesService] + }); + }); + + it('should be created', inject([ClassificationCategoriesService], (service: ClassificationCategoriesService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/web/src/app/services/classification-categories-service/classification-categories.service.ts b/web/src/app/services/classification-categories-service/classification-categories.service.ts new file mode 100644 index 000000000..47e7d79f0 --- /dev/null +++ b/web/src/app/services/classification-categories-service/classification-categories.service.ts @@ -0,0 +1,23 @@ +import { HttpClient, HttpHeaders } from '@angular/common/http'; + +import { Injectable } from '@angular/core'; +import { environment } from 'environments/environment'; +import { Observable } from 'rxjs/Observable'; + +@Injectable() +export class ClassificationCategoriesService { + + private url = environment.taskanaRestUrl + '/v1/classification-categories'; + httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + 'Authorization': 'Basic VEVBTUxFQURfMTpURUFNTEVBRF8x' + }) + }; + + constructor(private httpClient: HttpClient) { } + + getCategories(): Observable> { + return this.httpClient.get>(this.url, this.httpOptions); + }; +} diff --git a/web/src/app/shared/tree/tree.component.html b/web/src/app/shared/tree/tree.component.html index bad496c29..3106eab69 100644 --- a/web/src/app/shared/tree/tree.component.html +++ b/web/src/app/shared/tree/tree.component.html @@ -1,7 +1,7 @@ -