-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgroup-details.ts
206 lines (191 loc) · 6.16 KB
/
group-details.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { Component, NgZone } from '@angular/core';
import { IonicPage, Platform, NavParams, NavController, ViewController, ModalController, ToastController, AlertController, LoadingController, ActionSheetController } from 'ionic-angular';
import { BasePrivatePage } from '../../pages/base-private-page/base-private-page';
import { GroupEditPage } from '../../pages/group-edit/group-edit';
import { PersonDetailsPage } from '../../pages/person-details/person-details';
import { Organization } from '../../models/organization';
import { User } from '../../models/user';
import { Person } from '../../models/person';
import { Group } from '../../models/group';
import { ApiProvider } from '../../providers/api/api';
import { StorageProvider } from '../../providers/storage/storage';
@IonicPage({
name: 'GroupDetailsPage',
segment: 'groups/:group_id',
defaultHistory: ['GroupListPage']
})
@Component({
selector: 'page-group-details',
templateUrl: 'group-details.html',
providers: [ ApiProvider, StorageProvider ],
entryComponents:[ GroupEditPage, PersonDetailsPage ]
})
export class GroupDetailsPage extends BasePrivatePage {
organization:Organization = null;
user:User = null;
group:Group = null;
loading:boolean = false;
constructor(
protected zone:NgZone,
protected platform:Platform,
protected navParams:NavParams,
protected navController:NavController,
protected viewController:ViewController,
protected modalController:ModalController,
protected toastController:ToastController,
protected alertController:AlertController,
protected loadingController:LoadingController,
protected actionController:ActionSheetController,
protected api:ApiProvider,
protected storage:StorageProvider) {
super(zone, platform, navParams, navController, viewController, modalController, toastController, alertController, loadingController, actionController, storage);
}
ionViewDidLoad() {
super.ionViewDidLoad();
let loading = this.showLoading("Loading...");
this.loadUpdates(true).then((loaded:any) => {
loading.dismiss();
});
}
ionViewDidEnter() {
super.ionViewDidEnter();
if (this.organization && this.group) {
this.analytics.trackPage(this, {
organization: this.organization.name,
group: this.group.name
});
}
}
private loadUpdates(cache:boolean=true, event:any=null) {
this.loading = true;
return Promise.resolve()
.then(() => this.loadOrganization(cache))
.then(() => this.loadUser(cache))
.then(() => this.loadGroup(cache))
.then(() => this.loadMembers(cache))
.then(() => {
this.logger.info(this, "loadUpdates", "Loaded");
if (event) {
event.complete();
}
this.loading = false;
})
.catch((error) => {
this.logger.info(this, "loadUpdates", "Failed", error);
if (event) {
event.complete();
}
this.loading = false;
this.showToast(error);
});
}
private loadGroup(cache:boolean=true, event:any=null):Promise<Group> {
return new Promise((resolve, reject) => {
if (cache && this.group) {
if (event) {
event.complete();
}
resolve(this.group);
}
else if (this.hasParameter("group")){
this.group = this.getParameter<Group>("group");
if (event) {
event.complete();
}
resolve(this.group);
}
else if (this.hasParameter("group_id")) {
let groupId = this.getParameter<number>("group_id");
this.promiseFallback(cache,
this.storage.getGroup(this.organization, groupId),
this.api.getGroup(this.organization, groupId)).then((group:Group) => {
this.storage.saveGroup(this.organization, group).then((saved:any) => {
this.group = group;
if (event) {
event.complete();
}
resolve(group);
});
},
(error:any) => {
reject(error);
if (event) {
event.complete();
}
});
}
else {
if (event) {
event.complete();
}
reject("Group Not Provided");
}
});
}
private loadMembers(cache:boolean=true):Promise<Person[]> {
return new Promise((resolve, reject) => {
if (cache && this.group.member_count == this.group.members.length) {
resolve(this.group.members);
}
else {
this.promiseFallback(cache,
this.storage.getGroupMembers(this.organization, this.group),
this.api.getGroupMembers(this.organization, this.group), this.group.member_count).then((people:Person[]) => {
this.group.members = people;
resolve(this.group.members);
});
}
});
}
private editGroup(event:any) {
this.logger.info(this, "editGroup");
let modal = this.showModal(GroupEditPage, {
organization: this.organization,
user: this.user,
person: this.user,
group: this.group
});
modal.onDidDismiss((data:any) => {
this.logger.info(this, "editGroup", "Modal", data);
if (data) {
if (data.deleted) {
this.logger.info(this, "editGroup", "Modal", "Deleted");
this.closePage();
}
else if (data.canceled) {
this.logger.info(this, "editGroup", "Modal", "Canceled");
}
else {
let loading = this.showLoading("Loading...");
this.loadGroup(true).then(group => {
this.group = group;
loading.dismiss();
});
}
}
});
}
private showPerson(person:Person) {
this.logger.info(this, "showPerson", person);
if (this.tablet || this.website) {
this.showModal(PersonDetailsPage, {
organization: this.organization,
user: this.user,
person: person
});
}
else {
this.showPage(PersonDetailsPage, {
organization: this.organization,
user: this.user,
person: person
});
}
}
get canEdit() {
if (this.group && this.group.isExternal()) {
return false;
}
return this.user.isOwner() || this.user.isAdmin();
}
}