aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list.service.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-02-18 12:14:17 +0000
committer杨宇千 <crupest@outlook.com>2019-02-18 12:14:17 +0000
commit7d08ce0d0625b8e6a4c6328d9c9d339cc52db4c2 (patch)
tree328e729bbbc08bcf8a16fc494cb1c6625e35d2a6 /Timeline/ClientApp/src/app/todo-list.service.ts
parent94d9233375f3c8bedcf4dbc62e59f20969af7cb9 (diff)
parent1ff6afb0e9fd11ce37ed0206b992514041391761 (diff)
downloadtimeline-7d08ce0d0625b8e6a4c6328d9c9d339cc52db4c2.tar.gz
timeline-7d08ce0d0625b8e6a4c6328d9c9d339cc52db4c2.tar.bz2
timeline-7d08ce0d0625b8e6a4c6328d9c9d339cc52db4c2.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.ts68
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()
+ );
+ }
+ )
+ );
+ }
+}