diff options
author | crupest <crupest@outlook.com> | 2019-02-20 18:23:05 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-02-20 18:23:05 +0800 |
commit | 2bcdc32c4c6d37a6d40aa4fdfc7b04478a76e961 (patch) | |
tree | da41fde0f5c7717f9e7665225015326bf99a0321 | |
parent | 133b90cdbafabab0640bfb3179899fb4f3df4dbe (diff) | |
download | timeline-2bcdc32c4c6d37a6d40aa4fdfc7b04478a76e961.tar.gz timeline-2bcdc32c4c6d37a6d40aa4fdfc7b04478a76e961.tar.bz2 timeline-2bcdc32c4c6d37a6d40aa4fdfc7b04478a76e961.zip |
Move some config of todo page to server side.
-rw-r--r-- | Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts | 26 | ||||
-rw-r--r-- | Timeline/Configs/TodoListConfig.cs | 12 | ||||
-rw-r--r-- | Timeline/Configs/TodoPageConfig.cs | 21 | ||||
-rw-r--r-- | Timeline/Controllers/TodoListController.cs | 11 | ||||
-rw-r--r-- | Timeline/Startup.cs | 2 | ||||
-rw-r--r-- | Timeline/appsettings.json | 6 |
6 files changed, 46 insertions, 32 deletions
diff --git a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts index 0b54653b..0718b64b 100644 --- a/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts +++ b/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts @@ -3,6 +3,13 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { switchMap, concatMap, map, toArray } from 'rxjs/operators'; +interface AzureDevOpsAccessInfo { + username: string; + personalAccessToken: string; + organization: string; + project: string; +} + interface WiqlWorkItemResult { id: number; url: string; @@ -17,6 +24,7 @@ interface WorkItemResult { fields: { [name: string]: any }; } + export interface WorkItem { id: number; title: string; @@ -28,33 +36,25 @@ export interface WorkItem { }) export class TodoListService { - private username = 'crupest'; - private organization = 'crupest-web'; - private project = 'Timeline'; private titleFieldName = 'System.Title'; private stateFieldName = 'System.State'; constructor(private client: HttpClient) { } - private getAzureDevOpsPat(): Observable<string> { - return this.client.get('/api/TodoList/AzureDevOpsPat', { - headers: { - 'Accept': 'text/plain' - }, - responseType: 'text' - }); + private getAzureDevOpsPat(): Observable<AzureDevOpsAccessInfo> { + return this.client.get<AzureDevOpsAccessInfo>('/api/TodoPage/AzureDevOpsAccessInfo'); } getWorkItemList(): Observable<WorkItem[]> { return this.getAzureDevOpsPat().pipe( switchMap( - pat => { + accessInfo => { const headers = new HttpHeaders({ 'Accept': 'application/json', - 'Authorization': `Basic ${btoa(this.username + ':' + pat)}` + 'Authorization': `Basic ${btoa(accessInfo.username + ':' + accessInfo.personalAccessToken)}` }); return this.client.post<WiqlResult>( - `https://dev.azure.com/${this.organization}/${this.project}/_apis/wit/wiql?api-version=5.0`, { + `https://dev.azure.com/${accessInfo.organization}/${accessInfo.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), diff --git a/Timeline/Configs/TodoListConfig.cs b/Timeline/Configs/TodoListConfig.cs deleted file mode 100644 index a69e8d03..00000000 --- a/Timeline/Configs/TodoListConfig.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Timeline.Configs -{ - public class TodoListConfig - { - public string AzureDevOpsPat { get; set; } - } -} diff --git a/Timeline/Configs/TodoPageConfig.cs b/Timeline/Configs/TodoPageConfig.cs new file mode 100644 index 00000000..d49e9dc3 --- /dev/null +++ b/Timeline/Configs/TodoPageConfig.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Timeline.Configs +{ + public class AzureDevOpsAccessInfo + { + public string Username { get; set; } + public string PersonalAccessToken { get; set; } + public string Organization { get; set; } + public string Project { get; set; } + + } + + public class TodoPageConfig + { + public AzureDevOpsAccessInfo AzureDevOpsAccessInfo { get; set; } + } +} diff --git a/Timeline/Controllers/TodoListController.cs b/Timeline/Controllers/TodoListController.cs index b773ed2e..257c1d85 100644 --- a/Timeline/Controllers/TodoListController.cs +++ b/Timeline/Controllers/TodoListController.cs @@ -10,21 +10,20 @@ using Timeline.Configs; namespace Timeline.Controllers { [Route("api/[controller]")] - public class TodoListController : Controller + public class TodoPageController : Controller { - private readonly IOptionsMonitor<TodoListConfig> _config; + private readonly IOptionsMonitor<TodoPageConfig> _config; - public TodoListController(IOptionsMonitor<TodoListConfig> config) + public TodoPageController(IOptionsMonitor<TodoPageConfig> config) { _config = config; } [HttpGet("[action]")] [AllowAnonymous] - [Produces("text/plain")] - public ActionResult<string> AzureDevOpsPat() + public ActionResult<AzureDevOpsAccessInfo> AzureDevOpsAccessInfo() { - return Ok(_config.CurrentValue.AzureDevOpsPat); + return Ok(_config.CurrentValue.AzureDevOpsAccessInfo); } } } diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index a6bde7fd..e06a98d5 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -41,7 +41,7 @@ namespace Timeline }); - services.Configure<TodoListConfig>(Configuration.GetSection("TodoListConfig")); + services.Configure<TodoPageConfig>(Configuration.GetSection("TodoPageConfig")); services.Configure<JwtConfig>(Configuration.GetSection("JwtConfig")); var jwtConfig = Configuration.GetSection("JwtConfig").Get<JwtConfig>(); diff --git a/Timeline/appsettings.json b/Timeline/appsettings.json index a914603c..8dc28bc8 100644 --- a/Timeline/appsettings.json +++ b/Timeline/appsettings.json @@ -7,5 +7,11 @@ "JwtConfig": { "Issuer": "crupest.xyz", "Audience": "crupest.xyz" + }, + "TodoPageConfig": { + "AzureDevOpsAccessInfo": { + "Organization": "crupest-web", + "Project": "Timeline" + } } } |