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