diff options
author | 杨宇千 <crupest@outlook.com> | 2019-02-18 12:14:17 +0000 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-02-18 12:14:17 +0000 |
commit | ddf2848df70c40f443773cd1b76d9db13cd1fa23 (patch) | |
tree | 8e1e2ac2dd6df278f59a97a37e5d374bc2644843 /Timeline/ClientApp/src/app/todo-list.service.ts | |
parent | 122a28595e45c6ec48a773ca1284238566d497d3 (diff) | |
parent | 1f0a978ad2b8e5bcd57eef37baca93e00fd6b20b (diff) | |
download | timeline-ddf2848df70c40f443773cd1b76d9db13cd1fa23.tar.gz timeline-ddf2848df70c40f443773cd1b76d9db13cd1fa23.tar.bz2 timeline-ddf2848df70c40f443773cd1b76d9db13cd1fa23.zip |
Merged PR 1: Develop todo list page.
Related work items: #1
Diffstat (limited to 'Timeline/ClientApp/src/app/todo-list.service.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/todo-list.service.ts | 68 |
1 files changed, 68 insertions, 0 deletions
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..238919d3 --- /dev/null +++ b/Timeline/ClientApp/src/app/todo-list.service.ts @@ -0,0 +1,68 @@ +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 }; +} + +export interface WorkItem { + id: number; + title: string; +} + +@Injectable({ + providedIn: 'root' +}) +export class TodoListService { + + private username = 'crupest'; + private organization = 'crupest-web'; + private project = 'Timeline'; + private fieldId = 'System.Title'; + + + constructor(private client: HttpClient) { } + + private getAzureDevOpsPat(): Observable<string> { + return this.client.get('/api/TodoList/AzureDevOpsPat', { + headers: { + 'Accept': 'text/plain' + }, + responseType: 'text' + }); + } + + getWorkItemList(): Observable<WorkItem[]> { + return this.getAzureDevOpsPat().pipe( + switchMap( + pat => { + const headers = new HttpHeaders({ + 'Accept': 'application/json', + 'Authorization': `Basic ${btoa(this.username + ':' + pat)}` + }); + 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: headers }).pipe( + switchMap(result => result.workItems), + concatMap(result => this.client.get<WorkItemResult>(result.url, { headers: headers })), + map(result => <WorkItem>{ id: result.id, title: result.fields[this.fieldId] }), + toArray() + ); + } + ) + ); + } +} |