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.ts31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/app/identity-page/identity-page.component.ts b/src/app/identity-page/identity-page.component.ts
index 296fe4c..0d6e784 100644
--- a/src/app/identity-page/identity-page.component.ts
+++ b/src/app/identity-page/identity-page.component.ts
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
2import { Pipe } from "@angular/core"; 2import { Pipe } from "@angular/core";
3import { ApiService } from '../api.service'; 3import { ApiService } from '../api.service';
4import { IdentityAPI } from '../identity-api'; 4import { IdentityAPI } from '../identity-api';
5import { MessagesService } from '../messages.service';
5 6
6@Component({ 7@Component({
7 selector: 'app-identity-page', 8 selector: 'app-identity-page',
@@ -12,14 +13,19 @@ export class IdentityPageComponent implements OnInit {
12 identities: IdentityAPI[]; 13 identities: IdentityAPI[];
13 filteredItems: IdentityAPI[]; 14 filteredItems: IdentityAPI[];
14 rename: boolean = false; 15 rename: boolean = false;
16 delete: boolean = false;
15 changeIdentity: IdentityAPI; 17 changeIdentity: IdentityAPI;
16 json: any; 18 json: any;
19 is_displayed: boolean = true;
20 request: boolean = false;
17 21
18 constructor(private apiService: ApiService) { } 22 constructor(private apiService: ApiService,private message: MessagesService) { }
19 23
20 getAPIs(): void { 24 getAPIs(): void {
25 this.request = true;
21 this.apiService.getIdentities().subscribe(data => { 26 this.apiService.getIdentities().subscribe(data => {
22 this.identities = data; 27 this.identities = data;
28 this.request = false;
23 this.assignCopy(); 29 this.assignCopy();
24 }); 30 });
25 } 31 }
@@ -33,7 +39,7 @@ export class IdentityPageComponent implements OnInit {
33 } 39 }
34 40
35 filterItem(value : string){ 41 filterItem(value : string){
36 this.onRenameCancel(); 42 this.onReset();
37 if(!value) this.assignCopy(); //when nothing has typed 43 if(!value) this.assignCopy(); //when nothing has typed
38 this.filteredItems = Object.assign([], this.identities).filter( 44 this.filteredItems = Object.assign([], this.identities).filter(
39 item => { 45 item => {
@@ -44,27 +50,40 @@ export class IdentityPageComponent implements OnInit {
44 } 50 }
45 51
46 onClickRename(identity: IdentityAPI){ 52 onClickRename(identity: IdentityAPI){
53 this.is_displayed = false;
47 this.rename = true; 54 this.rename = true;
48 this.changeIdentity = Object.assign({},identity); 55 this.changeIdentity = Object.assign({},identity);
49 } 56 }
50 57
51 onRename(identity: IdentityAPI){ 58 onRename(identity: IdentityAPI){
52 this.rename = false; 59 this.request = true;
60 this.onReset();
53 this.filteredItems = []; 61 this.filteredItems = [];
54 this.json = {'newname':identity.name}; 62 this.json = {'newname':identity.name};
55 this.apiService.changeIdentity(identity.id,this.json).subscribe(data => { 63 this.apiService.changeIdentity(identity.id,this.json).subscribe(data => {
64 this.message.pushSuccess('Rename was successful.');
56 this.getAPIs(); 65 this.getAPIs();
57 }); 66 });
58 } 67 }
59 68
60 onRenameCancel(){ 69 onReset(){
61 this.rename = false; 70 this.rename = false;
71 this.delete = false;
72 this.is_displayed = true;
73 }
74
75 onClickDelete(identity: IdentityAPI){
76 this.is_displayed = false;
77 this.delete = true;
78 this.changeIdentity = Object.assign({},identity);
62 } 79 }
63 80
64 onClickDelete(id: string){ 81 onDelete(id:string){
65 this.onRenameCancel(); 82 this.request = true;
83 this.onReset();
66 this.filteredItems = []; 84 this.filteredItems = [];
67 this.apiService.deleteIdentity(id).subscribe(data => { 85 this.apiService.deleteIdentity(id).subscribe(data => {
86 this.message.pushSuccess('Delete was successful.');
68 this.getAPIs(); 87 this.getAPIs();
69 }); 88 });
70 } 89 }