aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-02-18 00:11:24 +0800
committercrupest <crupest@outlook.com>2019-02-18 00:11:24 +0800
commit5194cfc3fc9bbe6d2e03fdceb4ed58a8b7c0f6a9 (patch)
treec0269613f78380f202be80718c247d7e7a31bfa2
parent94d9233375f3c8bedcf4dbc62e59f20969af7cb9 (diff)
downloadtimeline-5194cfc3fc9bbe6d2e03fdceb4ed58a8b7c0f6a9.tar.gz
timeline-5194cfc3fc9bbe6d2e03fdceb4ed58a8b7c0f6a9.tar.bz2
timeline-5194cfc3fc9bbe6d2e03fdceb4ed58a8b7c0f6a9.zip
Add todo list request service.
-rw-r--r--Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.html4
-rw-r--r--Timeline/ClientApp/src/app/todo-list-page/todo-list-page.component.ts7
-rw-r--r--Timeline/ClientApp/src/app/todo-list.service.spec.ts12
-rw-r--r--Timeline/ClientApp/src/app/todo-list.service.ts50
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()
+ );
+ }
+}