diff options
author | crupest <crupest@outlook.com> | 2019-02-18 00:11:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-02-18 00:11:24 +0800 |
commit | 633e7357b41b5b3e99df887215bed620034eda6a (patch) | |
tree | cae8958b853ee87a885d2a8e73e8df78220e2cf6 | |
parent | 122a28595e45c6ec48a773ca1284238566d497d3 (diff) | |
download | timeline-633e7357b41b5b3e99df887215bed620034eda6a.tar.gz timeline-633e7357b41b5b3e99df887215bed620034eda6a.tar.bz2 timeline-633e7357b41b5b3e99df887215bed620034eda6a.zip |
Add todo list request service.
4 files changed, 70 insertions, 3 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.html b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.html index 0d005c83..6287c14e 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.html +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.html @@ -1,3 +1,3 @@ -<p> - todo-list-page works! +<p *ngFor="let item of items"> + {{item}} </p> diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.ts b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.ts index 37de232b..6037e1ea 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.ts +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { TodoListService } from '../todo-list.service'; @Component({ selector: 'app-todo-list-page', @@ -7,7 +8,11 @@ import { Component, OnInit } from '@angular/core'; }) export class TodoListPageComponent implements OnInit { - constructor() { } + items: string[]; + + constructor(private todoService: TodoListService) { + todoService.getWorkItemList().subscribe(result => this.items = result); + } ngOnInit() { } diff --git a/Timeline/ClientApp/src/app/todo-list.service.spec.ts b/Timeline/ClientApp/src/app/todo-list.service.spec.ts new file mode 100644 index 00000000..529ba8cc --- /dev/null +++ b/Timeline/ClientApp/src/app/todo-list.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { TodoListService } from './todo-list.service'; + +describe('TodoListServiceService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: TodoListService = TestBed.get(TodoListService); + expect(service).toBeTruthy(); + }); +}); diff --git a/Timeline/ClientApp/src/app/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list.service.ts new file mode 100644 index 00000000..e92a11c9 --- /dev/null +++ b/Timeline/ClientApp/src/app/todo-list.service.ts @@ -0,0 +1,50 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { switchMap, concatMap, map, toArray } from 'rxjs/operators'; + +interface WiqlWorkItemResult { + id: number; + url: string; +} + +interface WiqlResult { + workItems: WiqlWorkItemResult[]; +} + +interface WorkItemResult { + id: number; + fields: { [name: string]: any }; +} + +@Injectable({ + providedIn: 'root' +}) +export class TodoListService { + + private username = 'crupest'; + private pat = 'ehnmegogmk6r7qlkpy6zdl2hnfl6ntqbvggzxvvgp4a5vhr7lmnq'; + private organization = 'crupest-web'; + private project = 'Timeline'; + private fieldId = 'System.Title'; + + private headers: HttpHeaders; + + constructor(private client: HttpClient) { + this.headers = new HttpHeaders({ + 'Accept': 'application/json', + 'Authorization': `Basic ${btoa(this.username + ':' + this.pat)}` + }); + } + + getWorkItemList(): Observable<string[]> { + return this.client.post<WiqlResult>(`https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { + query: 'SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = @project' + }, { headers: this.headers }).pipe( + switchMap(result => result.workItems), + concatMap(result => this.client.get<WorkItemResult>(result.url, {headers: this.headers})), + map(result => <string>(result.fields[this.fieldId])), + toArray() + ); + } +} |