TSK-438 Get categories from classification category service.
This commit is contained in:
parent
fea40d79bc
commit
a7aaa99ac2
|
@ -48,12 +48,21 @@
|
||||||
* Domain is required
|
* Domain is required
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group required">
|
<div class="form-group required">
|
||||||
<label for="classification-category" class="control-label">Category</label>
|
<label for="classification-category" class="control-label">Category</label>
|
||||||
<input type="text" required #category="ngModel" class="form-control" id="classification-category" placeholder="category"
|
<div class="dropdown clearfix btn-group">
|
||||||
[(ngModel)]="classification.category" name="classification.category">
|
<button class="btn btn-default" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<div *ngIf="!category.valid" class="required-text">
|
{{classification.category}}
|
||||||
* Category is required
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu" aria-labelledby="dropdownMenu">
|
||||||
|
<li>
|
||||||
|
<a *ngFor="let category of categories" (click)="selectCategory(category)">
|
||||||
|
{{category}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { ErrorModalService } from 'app/services/errorModal/error-modal.service';
|
||||||
import { AlertService } from 'app/services/alert/alert.service';
|
import { AlertService } from 'app/services/alert/alert.service';
|
||||||
import { TreeService } from 'app/services/tree/tree.service';
|
import { TreeService } from 'app/services/tree/tree.service';
|
||||||
import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service';
|
import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service';
|
||||||
|
import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -32,13 +33,13 @@ const routes: Routes = [
|
||||||
{ path: 'administration/classifications', component: DummyDetailComponent }
|
{ path: 'administration/classifications', component: DummyDetailComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('ClassificationDetailsComponent', () => {
|
fdescribe('ClassificationDetailsComponent', () => {
|
||||||
let component: ClassificationDetailsComponent;
|
let component: ClassificationDetailsComponent;
|
||||||
let fixture: ComponentFixture<ClassificationDetailsComponent>;
|
let fixture: ComponentFixture<ClassificationDetailsComponent>;
|
||||||
const treeNodes: Array<TreeNodeModel> = new Array(new TreeNodeModel());
|
const treeNodes: Array<TreeNodeModel> = new Array(new TreeNodeModel());
|
||||||
const classificationTypes: Array<string> = new Array<string>('type1', 'type2');
|
const classificationTypes: Array<string> = new Array<string>('type1', 'type2');
|
||||||
let classificationsSpy, classificationsTypesSpy;
|
let classificationsSpy, classificationsTypesSpy;
|
||||||
let classificationsService, classificationTypesService;
|
let classificationsService, classificationTypesService, classificationCategoriesService;
|
||||||
let treeService;
|
let treeService;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
|
@ -46,7 +47,7 @@ describe('ClassificationDetailsComponent', () => {
|
||||||
imports: [FormsModule, HttpClientModule, RouterTestingModule.withRoutes(routes)],
|
imports: [FormsModule, HttpClientModule, RouterTestingModule.withRoutes(routes)],
|
||||||
declarations: [ClassificationDetailsComponent, SpinnerComponent, DummyDetailComponent],
|
declarations: [ClassificationDetailsComponent, SpinnerComponent, DummyDetailComponent],
|
||||||
providers: [MasterAndDetailService, RequestInProgressService, ClassificationsService, HttpClient, ErrorModalService, AlertService,
|
providers: [MasterAndDetailService, RequestInProgressService, ClassificationsService, HttpClient, ErrorModalService, AlertService,
|
||||||
TreeService, ClassificationTypesService]
|
TreeService, ClassificationTypesService, ClassificationCategoriesService]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@ -56,11 +57,14 @@ describe('ClassificationDetailsComponent', () => {
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
classificationsService = TestBed.get(ClassificationsService);
|
classificationsService = TestBed.get(ClassificationsService);
|
||||||
classificationTypesService = TestBed.get(ClassificationTypesService);
|
classificationTypesService = TestBed.get(ClassificationTypesService);
|
||||||
|
classificationCategoriesService = TestBed.get(ClassificationCategoriesService);
|
||||||
classificationsSpy = spyOn(classificationsService, 'getClassifications').and.returnValue(Observable.of(treeNodes));
|
classificationsSpy = spyOn(classificationsService, 'getClassifications').and.returnValue(Observable.of(treeNodes));
|
||||||
classificationsTypesSpy = spyOn(classificationTypesService, 'getClassificationTypes')
|
classificationsTypesSpy = spyOn(classificationTypesService, 'getClassificationTypes').and.returnValue(Observable.of([]));
|
||||||
.and.returnValue(Observable.of(classificationTypes));
|
spyOn(classificationCategoriesService, 'getCategories').and.returnValue(Observable.of(['firstCategory', 'secondCategory']));
|
||||||
spyOn(classificationsService, 'deleteClassification').and.returnValue(Observable.of(true));
|
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);
|
treeService = TestBed.get(TreeService);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
@ -71,10 +75,12 @@ describe('ClassificationDetailsComponent', () => {
|
||||||
|
|
||||||
it('should trigger treeService remove node id after removing a node', () => {
|
it('should trigger treeService remove node id after removing a node', () => {
|
||||||
const treeServiceSpy = spyOn(treeService, 'setRemovedNodeId');
|
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();
|
component.removeClassification();
|
||||||
expect(treeServiceSpy).toHaveBeenCalledWith('id1');
|
expect(treeServiceSpy).toHaveBeenCalledWith('id1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should selected first classificationCategory if is defined', () => {
|
||||||
|
expect(component.classification.category).toBe('firstCategory');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { RequestInProgressService } from 'app/services/requestInProgress/request
|
||||||
import { AlertService } from 'app/services/alert/alert.service';
|
import { AlertService } from 'app/services/alert/alert.service';
|
||||||
import { TreeService } from 'app/services/tree/tree.service';
|
import { TreeService } from 'app/services/tree/tree.service';
|
||||||
import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service';
|
import { ClassificationTypesService } from 'app/services/classification-types/classification-types.service';
|
||||||
|
import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'taskana-classification-details',
|
selector: 'taskana-classification-details',
|
||||||
|
@ -32,6 +33,8 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
classificationTypes: Array<string> = [];
|
classificationTypes: Array<string> = [];
|
||||||
badgeMessage = '';
|
badgeMessage = '';
|
||||||
requestInProgress = false;
|
requestInProgress = false;
|
||||||
|
categories: Array<string> = [];
|
||||||
|
categorySelected: string;
|
||||||
private action: any;
|
private action: any;
|
||||||
private classificationServiceSubscription: Subscription;
|
private classificationServiceSubscription: Subscription;
|
||||||
private classificationSelectedSubscription: Subscription;
|
private classificationSelectedSubscription: Subscription;
|
||||||
|
@ -40,7 +43,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
private classificationSavingSubscription: Subscription;
|
private classificationSavingSubscription: Subscription;
|
||||||
private classificationRemoveSubscription: Subscription;
|
private classificationRemoveSubscription: Subscription;
|
||||||
private selectedClassificationSubscription: Subscription;
|
private selectedClassificationSubscription: Subscription;
|
||||||
|
private categoriesSubscription: Subscription;
|
||||||
|
|
||||||
constructor(private classificationsService: ClassificationsService,
|
constructor(private classificationsService: ClassificationsService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -50,11 +53,10 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
private requestInProgressService: RequestInProgressService,
|
private requestInProgressService: RequestInProgressService,
|
||||||
private alertService: AlertService,
|
private alertService: AlertService,
|
||||||
private treeService: TreeService,
|
private treeService: TreeService,
|
||||||
private classificationTypeService: ClassificationTypesService) { }
|
private classificationTypeService: ClassificationTypesService,
|
||||||
|
private categoryService: ClassificationCategoriesService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
this.classificationTypeService.getClassificationTypes().subscribe((classificationTypes: Array<string>) => {
|
this.classificationTypeService.getClassificationTypes().subscribe((classificationTypes: Array<string>) => {
|
||||||
this.classificationTypes = classificationTypes;
|
this.classificationTypes = classificationTypes;
|
||||||
})
|
})
|
||||||
|
@ -87,9 +89,16 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
this.masterAndDetailSubscription = this.masterAndDetailService.getShowDetail().subscribe(showDetail => {
|
this.masterAndDetailSubscription = this.masterAndDetailService.getShowDetail().subscribe(showDetail => {
|
||||||
this.showDetail = showDetail;
|
this.showDetail = showDetail;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
this.categoriesSubscription = this.categoryService.getCategories().subscribe((categories: Array<string>) => {
|
||||||
|
this.categories = categories;
|
||||||
|
if (categories.length > 0) {
|
||||||
|
this.classification.category = categories[0];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
backClicked(): void {
|
backClicked(): void {
|
||||||
this.classificationsService.selectClassification(undefined);
|
this.classificationsService.selectClassification(undefined);
|
||||||
this.router.navigate(['./'], { relativeTo: this.route.parent });
|
this.router.navigate(['./'], { relativeTo: this.route.parent });
|
||||||
|
@ -150,6 +159,11 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
this.classification = { ...this.classificationClone };
|
this.classification = { ...this.classificationClone };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
selectCategory(category: string) {
|
||||||
|
this.classification.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
private afterRequest() {
|
private afterRequest() {
|
||||||
this.requestInProgressService.setRequestInProgress(false);
|
this.requestInProgressService.setRequestInProgress(false);
|
||||||
this.classificationsService.triggerClassificationSaved();
|
this.classificationsService.triggerClassificationSaved();
|
||||||
|
@ -162,13 +176,7 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private getClassificationInformation(classificationIdSelected: string) {
|
private getClassificationInformation(classificationIdSelected: string) {
|
||||||
if (this.action === ACTION.CREATE) { // CREATE
|
if (this.action === ACTION.CREATE) { // CREATE
|
||||||
this.classification = new ClassificationDefinition();
|
this.initClassificationCreation(classificationIdSelected);
|
||||||
this.selectedClassificationSubscription = this.classificationTypeService.getSelectedClassificationType().subscribe(value => {
|
|
||||||
if (this.classification) { this.classification.type = value; }
|
|
||||||
});
|
|
||||||
this.addDateToClassification();
|
|
||||||
this.classification.parentId = classificationIdSelected;
|
|
||||||
this.classificationClone = { ...this.classification };
|
|
||||||
} else {
|
} else {
|
||||||
this.requestInProgress = true;
|
this.requestInProgress = true;
|
||||||
this.classificationServiceSubscription = this.classificationsService.getClassification(classificationIdSelected)
|
this.classificationServiceSubscription = this.classificationsService.getClassification(classificationIdSelected)
|
||||||
|
@ -186,7 +194,19 @@ export class ClassificationDetailsComponent implements OnInit, OnDestroy {
|
||||||
this.classification.modified = date;
|
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 {
|
ngOnDestroy(): void {
|
||||||
|
|
||||||
if (this.masterAndDetailSubscription) { this.masterAndDetailSubscription.unsubscribe(); }
|
if (this.masterAndDetailSubscription) { this.masterAndDetailSubscription.unsubscribe(); }
|
||||||
if (this.routeSubscription) { this.routeSubscription.unsubscribe(); }
|
if (this.routeSubscription) { this.routeSubscription.unsubscribe(); }
|
||||||
if (this.classificationSelectedSubscription) { this.classificationSelectedSubscription.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.classificationSavingSubscription) { this.classificationSavingSubscription.unsubscribe(); }
|
||||||
if (this.classificationRemoveSubscription) { this.classificationRemoveSubscription.unsubscribe(); }
|
if (this.classificationRemoveSubscription) { this.classificationRemoveSubscription.unsubscribe(); }
|
||||||
if (this.selectedClassificationSubscription) { this.selectedClassificationSubscription.unsubscribe(); }
|
if (this.selectedClassificationSubscription) { this.selectedClassificationSubscription.unsubscribe(); }
|
||||||
|
if (this.categoriesSubscription) { this.categoriesSubscription.unsubscribe(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import { SelectedRouteService } from './services/selected-route/selected-route';
|
||||||
import { ClassificationsService } from './services/classifications/classifications.service';
|
import { ClassificationsService } from './services/classifications/classifications.service';
|
||||||
import { TreeService } from './services/tree/tree.service';
|
import { TreeService } from './services/tree/tree.service';
|
||||||
import { ClassificationTypesService } from './services/classification-types/classification-types.service';
|
import { ClassificationTypesService } from './services/classification-types/classification-types.service';
|
||||||
|
import { ClassificationCategoriesService } from 'app/services/classification-categories-service/classification-categories.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pipes
|
* Pipes
|
||||||
|
@ -133,7 +134,8 @@ const DECLARATIONS = [
|
||||||
SelectedRouteService,
|
SelectedRouteService,
|
||||||
ClassificationsService,
|
ClassificationsService,
|
||||||
TreeService,
|
TreeService,
|
||||||
ClassificationTypesService
|
ClassificationTypesService,
|
||||||
|
ClassificationCategoriesService
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
|
|
@ -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();
|
||||||
|
}));
|
||||||
|
});
|
|
@ -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<Array<string>> {
|
||||||
|
return this.httpClient.get<Array<string>>(this.url, this.httpOptions);
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<tree-root #tree [nodes]="treeNodes" [options]="options" (activate)="onActivate($event)" (deactivate)="onDeactivate($event)">
|
<tree-root #tree [nodes]="treeNodes" [options]="options" (activate)="onActivate($event)" (deactivate)="onDeactivate($event)">
|
||||||
<ng-template #treeNodeTemplate let-node let-index="index">
|
<ng-template #treeNodeTemplate let-node let-index="index">
|
||||||
<span class="text-top">
|
<span class="text-top">
|
||||||
<svg-icon class="blue small fa-fw" src="./assets/icons/{{node.data.category === 'EXTERN'? 'external':
|
<svg-icon class="blue small fa-fw" src="./assets/icons/{{node.data.category === 'EXTERNAL'? 'external':
|
||||||
node.data.category === 'AUTOMATIC'? 'automatic':
|
node.data.category === 'AUTOMATIC'? 'automatic':
|
||||||
node.data.category === 'MANUAL'? 'manual':
|
node.data.category === 'MANUAL'? 'manual':
|
||||||
'closed'}}.svg"></svg-icon>
|
'closed'}}.svg"></svg-icon>
|
||||||
|
|
Loading…
Reference in New Issue