From dc1acb96b7b25b6d7c125e4e7b89fc5b8085beb8 Mon Sep 17 00:00:00 2001 From: Sanborn Date: Mon, 6 Mar 2017 14:37:49 +0530 Subject: [PATCH] fix(mock): Fixed mock for work item types --- src/app/iteration/iteration.component.ts | 1 + src/app/shared/mock-data.service.ts | 4 ++++ src/app/shared/mock-data/schema-mock-generator.ts | 8 +++++++- .../shared/mock-data/work-item-mock-generator.ts | 2 +- src/app/shared/mock-http.ts | 10 +++++++++- .../work-item-quick-add.component.ts | 7 ++++--- src/app/work-item/work-item.service.ts | 14 +++++++++++--- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/app/iteration/iteration.component.ts b/src/app/iteration/iteration.component.ts index 4aeb6319c..4c26d86c9 100644 --- a/src/app/iteration/iteration.component.ts +++ b/src/app/iteration/iteration.component.ts @@ -49,6 +49,7 @@ export class IterationComponent implements OnInit, OnDestroy { this.listenToEvents(); this.loggedIn = this.auth.isLoggedIn(); this.getAndfilterIterations(); + this.editEnabled = true; this.spaceSubscription = this.broadcaster.on('spaceChanged').subscribe(space => { if (space) { console.log('[IterationComponent] New Space selected: ' + space.attributes.name); diff --git a/src/app/shared/mock-data.service.ts b/src/app/shared/mock-data.service.ts index 591848d92..093ad1063 100644 --- a/src/app/shared/mock-data.service.ts +++ b/src/app/shared/mock-data.service.ts @@ -350,6 +350,10 @@ export class MockDataService { return this.schemaMockGenerator.getWorkItemTypes(); } + public getWorkItemTypeById(id: string): any { + return this.schemaMockGenerator.getWorkItemTypeById(id); + } + public getWorkItemLinkTypes(): any { return this.schemaMockGenerator.getWorkItemLinkTypes(); } diff --git a/src/app/shared/mock-data/schema-mock-generator.ts b/src/app/shared/mock-data/schema-mock-generator.ts index 041786996..be680a506 100644 --- a/src/app/shared/mock-data/schema-mock-generator.ts +++ b/src/app/shared/mock-data/schema-mock-generator.ts @@ -103,7 +103,7 @@ export class SchemaMockGenerator { /* * Creates the work item types structure. */ - public getWorkItemTypes() { + public getWorkItemTypes(): any[] { if (this.workItemTypes) return this.workItemTypes; else { @@ -706,6 +706,12 @@ export class SchemaMockGenerator { } } + public getWorkItemTypeById(id) { + let allWorkItemTypes = this.getWorkItemTypes(); + let item = allWorkItemTypes.find((item) => item.id === id); + return item ? item : allWorkItemTypes[0]; + } + public renderText(text: string) { return { attributes: { diff --git a/src/app/shared/mock-data/work-item-mock-generator.ts b/src/app/shared/mock-data/work-item-mock-generator.ts index 0f5ccea49..b71144a58 100644 --- a/src/app/shared/mock-data/work-item-mock-generator.ts +++ b/src/app/shared/mock-data/work-item-mock-generator.ts @@ -149,7 +149,7 @@ export class WorkItemMockGenerator { 'assignees': { }, 'baseType': { 'data': { - 'id': 'planneritem', + 'id': '86af5178-9b41-469b-9096-57e5155c3f31', 'type': 'workitemtypes' } }, diff --git a/src/app/shared/mock-http.ts b/src/app/shared/mock-http.ts index ab1d60979..83b17359f 100644 --- a/src/app/shared/mock-http.ts +++ b/src/app/shared/mock-http.ts @@ -71,6 +71,10 @@ export class MockHttp extends Http { result['extraPath'] = result.path.replace(/^\/workitemlinks\//, ''); result['path'] = '/workitemlinks'; } + if (result.path.indexOf('/workitemtypes/') == 0) { + result['extraPath'] = result.path.replace(/^\/workitemtypes\//, ''); + result['path'] = '/workitemtypes'; + } // if request hat a /space prefix, note the space id, the re-parse the extra path if (result.path.indexOf('/spaces/') == 0) { console.log('Space prefix detected, reparsing url..'); @@ -171,7 +175,11 @@ export class MockHttp extends Http { // add new paths here switch (path.path) { case '/workitemtypes': - return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypes() } ); + if (path.extraPath) { + return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypeById(path.extraPath) } ); + } else { + return this.createResponse(url.toString(), 200, 'ok', { data: this.mockDataService.getWorkItemTypes() } ); + } case '/workitems': if (path.extraPath) { return this.createResponse(url.toString(), 200, 'ok', this.mockDataService.getWorkItemOrEntity(path.extraPath) ); diff --git a/src/app/work-item/work-item-quick-add/work-item-quick-add.component.ts b/src/app/work-item/work-item-quick-add/work-item-quick-add.component.ts index 06d5f2bb2..fd129f1c4 100644 --- a/src/app/work-item/work-item-quick-add/work-item-quick-add.component.ts +++ b/src/app/work-item/work-item-quick-add/work-item-quick-add.component.ts @@ -16,7 +16,7 @@ import { } from '@angular/core'; import { Subscription } from 'rxjs/Subscription'; -import { Logger, Broadcaster } from 'ngx-login-client'; +import { Logger, Broadcaster, AuthenticationService } from 'ngx-login-client'; import { WorkItem, WorkItemAttributes, WorkItemRelations } from '../../models/work-item'; import { WorkItemService } from '../work-item.service'; @@ -47,12 +47,13 @@ export class WorkItemQuickAddComponent implements OnInit, OnDestroy, AfterViewIn private workItemService: WorkItemService, private broadcaster: Broadcaster, private logger: Logger, - private renderer: Renderer) {} + private renderer: Renderer, + private auth: AuthenticationService) {} ngOnInit(): void { this.createWorkItemObj(); this.showQuickAdd = false; - this.showQuickAddBtn = false; + this.showQuickAddBtn = this.auth.isLoggedIn(); this.spaceSubscription = this.broadcaster.on('spaceChanged').subscribe(space => { if (space) { console.log('[WorkItemQuickAddComponent] New Space selected: ' + space.attributes.name); diff --git a/src/app/work-item/work-item.service.ts b/src/app/work-item/work-item.service.ts index 0a38390a3..5e7b797fe 100644 --- a/src/app/work-item/work-item.service.ts +++ b/src/app/work-item/work-item.service.ts @@ -597,12 +597,20 @@ export class WorkItemService { } else { let workItemTypeUrl = this.baseApiUrl + 'workitemtypes/' + id; return this.http.get(workItemTypeUrl) - .map((response) => { + .toPromise() + .then((response) => { workItemType = response.json().data as WorkItemType; this.workItemTypes.push(workItemType); return workItemType; - }) - .toPromise(); + }); + // FIXME: Use observavble instead promise + // Can't use observable now, because the mock will not support that + // .map((response) => { + // workItemType = response.json().data as WorkItemType; + // this.workItemTypes.push(workItemType); + // return workItemType; + // }) + // .toPromise(); } } else { return Promise.resolve( {} as WorkItemType );