TSK-438 Get categories from classification category service.
This commit is contained in:
parent
fea40d79bc
commit
a7aaa99ac2
|
@ -48,12 +48,21 @@
|
|||
* Domain is required
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group required">
|
||||
<label for="classification-category" class="control-label">Category</label>
|
||||
<input type="text" required #category="ngModel" class="form-control" id="classification-category" placeholder="category"
|
||||
[(ngModel)]="classification.category" name="classification.category">
|
||||
<div *ngIf="!category.valid" class="required-text">
|
||||
* Category is required
|
||||
<div class="dropdown clearfix btn-group">
|
||||
<button class="btn btn-default" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
{{classification.category}}
|
||||
<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 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 { 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<ClassificationDetailsComponent>;
|
||||
const treeNodes: Array<TreeNodeModel> = new Array(new TreeNodeModel());
|
||||
const classificationTypes: Array<string> = new Array<string>('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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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<string> = [];
|
||||
badgeMessage = '';
|
||||
requestInProgress = false;
|
||||
categories: Array<string> = [];
|
||||
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<string>) => {
|
||||
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<string>) => {
|
||||
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(); }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
})
|
||||
|
|
|
@ -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)">
|
||||
<ng-template #treeNodeTemplate let-node let-index="index">
|
||||
<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 === 'MANUAL'? 'manual':
|
||||
'closed'}}.svg"></svg-icon>
|
||||
|
|
Loading…
Reference in New Issue