-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkin-test.ts
138 lines (125 loc) · 4.3 KB
/
checkin-test.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
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 { Organization } from '../../models/organization';
import { User } from '../../models/user';
import { Person } from '../../models/person';
import { Checkin } from '../../models/checkin';
import { Recipient } from '../../models/recipient';
import { Answer } from '../../models/answer';
import { ApiProvider } from '../../providers/api/api';
import { StorageProvider } from '../../providers/storage/storage';
@IonicPage({
name: 'CheckinTestPage',
segment: 'checkins/test',
defaultHistory: ['CheckinListPage']
})
@Component({
selector: 'page-checkin-test',
templateUrl: 'checkin-test.html',
providers: [ ApiProvider, StorageProvider ],
entryComponents:[ ]
})
export class CheckinTestPage extends BasePrivatePage {
checkin:Checkin = null;
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);
}
ionViewWillEnter() {
super.ionViewWillEnter();
let loading = this.showLoading("Loading...");
this.loadUpdates(false).then((loaded:any) => {
loading.dismiss();
});
}
ionViewDidEnter() {
super.ionViewDidEnter();
if (this.organization) {
this.analytics.trackPage(this, {
organization: this.organization.name
});
}
}
private loadUpdates(cache:boolean=true, event:any=null) {
this.logger.info(this, "loadUpdates");
return Promise.resolve()
.then(() => { return this.loadOrganization(cache); })
.then(() => { return this.loadUser(cache); })
.then(() => { return this.loadCheckin(cache); })
.then(() => {
this.logger.info(this, "loadUpdates", "Loaded");
if (event) {
event.complete();
}
})
.catch((error) => {
this.logger.error(this, "loadUpdates", "Failed", error);
if (event) {
event.complete();
}
this.showToast(error);
});
}
private loadCheckin(cache:boolean=true):Promise<Checkin> {
return new Promise((resolve, reject) => {
this.checkin = new Checkin({
organization_id: this.organization.id,
user_id: this.user.id,
user_initials: this.user.initials,
user_picture: this.user.profile_picture,
message: "Did you receive this test Check-In?",
self_test_check_in: true,
send_via: 'app'
});
this.checkin.answers = [];
this.checkin.answers.push(new Answer({
icon: "icon-check",
type: "positive",
color: "#58AC5D",
answer: "Yes"
}));
this.checkin.recipients = [];
if (this.user) {
let recipient = new Recipient(this.user);
recipient.user_id = this.user.id;
this.checkin.recipients.push(recipient);
}
resolve(this.checkin);
});
}
private cancelCheckin(event:any) {
this.hideModal();
}
private sendCheckin(event:any) {
let loading = this.showLoading("Sending...", true);
this.api.sendCheckin(this.organization, this.checkin).then((checkin:Checkin) => {
this.storage.saveCheckin(this.organization, checkin).then((saved:boolean) => {
loading.dismiss();
this.showToast("Test Check-In sent");
this.hideModal({
checkin: checkin
});
},
(error:any) => {
loading.dismiss();
this.showAlert("Problem Saving Checkin", error);
});
},
(error:any) => {
loading.dismiss();
this.showAlert("Problem Creating Checkin", error);
});
}
}