aboutsummaryrefslogtreecommitdiff
path: root/src/app/identity-page/identity-page.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/identity-page/identity-page.component.ts')
-rw-r--r--src/app/identity-page/identity-page.component.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/app/identity-page/identity-page.component.ts b/src/app/identity-page/identity-page.component.ts
new file mode 100644
index 0000000..296fe4c
--- /dev/null
+++ b/src/app/identity-page/identity-page.component.ts
@@ -0,0 +1,72 @@
1import { Component, OnInit } from '@angular/core';
2import { Pipe } from "@angular/core";
3import { ApiService } from '../api.service';
4import { IdentityAPI } from '../identity-api';
5
6@Component({
7 selector: 'app-identity-page',
8 templateUrl: './identity-page.component.html'
9})
10export class IdentityPageComponent implements OnInit {
11
12 identities: IdentityAPI[];
13 filteredItems: IdentityAPI[];
14 rename: boolean = false;
15 changeIdentity: IdentityAPI;
16 json: any;
17
18 constructor(private apiService: ApiService) { }
19
20 getAPIs(): void {
21 this.apiService.getIdentities().subscribe(data => {
22 this.identities = data;
23 this.assignCopy();
24 });
25 }
26
27 ngOnInit() {
28 this.getAPIs();
29 }
30
31 assignCopy(){
32 this.filteredItems = Object.assign([], this.identities);
33 }
34
35 filterItem(value : string){
36 this.onRenameCancel();
37 if(!value) this.assignCopy(); //when nothing has typed
38 this.filteredItems = Object.assign([], this.identities).filter(
39 item => {
40 return ((item.name.indexOf(value) > -1) ||
41 (item.id.indexOf(value) > -1) ||
42 (item.type.indexOf(value) > -1 ))
43 });
44 }
45
46 onClickRename(identity: IdentityAPI){
47 this.rename = true;
48 this.changeIdentity = Object.assign({},identity);
49 }
50
51 onRename(identity: IdentityAPI){
52 this.rename = false;
53 this.filteredItems = [];
54 this.json = {'newname':identity.name};
55 this.apiService.changeIdentity(identity.id,this.json).subscribe(data => {
56 this.getAPIs();
57 });
58 }
59
60 onRenameCancel(){
61 this.rename = false;
62 }
63
64 onClickDelete(id: string){
65 this.onRenameCancel();
66 this.filteredItems = [];
67 this.apiService.deleteIdentity(id).subscribe(data => {
68 this.getAPIs();
69 });
70 }
71
72}