-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgallery.page.ts
More file actions
149 lines (132 loc) · 3.49 KB
/
gallery.page.ts
File metadata and controls
149 lines (132 loc) · 3.49 KB
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
import { Component } from '@angular/core';
import { NavController, ToastController } from 'ionic-angular';
// Services
import { AssessmentService } from '../../services/assessment.service';
import { SubmissionService } from '../../services/submission.service';
// Others
import * as _ from 'lodash';
import * as moment from 'moment';
@Component({
selector: 'gallery-page',
templateUrl: 'gallery.html'
})
export class GalleryPage {
_mock = {
avatar: {
name: 'Jose',
photo: 'https://unsplash.it/100/100'
},
photos: [
{
name: 'Test 1',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 2',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 3',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 4',
photo: 'https://unsplash.it/50/50'
}
]
};
assessments: any;
avatarName: any;
avatarPhoto: any;
name: string;
photos: any[];
refresher = null;
constructor(
public navCtrl: NavController,
public toastCtrl: ToastController,
public assessmentService: AssessmentService,
public submissionService: SubmissionService
) {}
// @TODO: Move to shared function later...
_error(err) {
let toast = this.toastCtrl.create({
message: err,
duration: 5000,
position: 'bottom',
dismissOnPageChange: true
});
toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
toast.present();
}
_pullData() {
this.assessmentService.getAll().toPromise()
.then((result) => {
this.assessments = result;
return this.submissionService.getSubmissions();
})
.then((result) => {
let extractedPhotos = this.submissionService.extractPhotos(result);
if (this.assessments.success || _.isArray(extractedPhotos)) {
_.forEach(this.assessments.data, (assessment) => {
if (assessment.Assessment.assessment_type === 'checkin') {
let foundPhoto = _.find(extractedPhotos, function(p) {
return p.assessment_id == assessment.Assessment.id;
});
if (foundPhoto) {
this.photos.push({
name: assessment.Assessment.name,
photo: foundPhoto.photo,
submitted: moment.utc(foundPhoto.submitted).local().format("D-M-YYYY, hA")
});
}
}
});
this.photos = _.sortBy(this.photos, 'submitted');
}
if (this.refresher) {
this.refresher.complete();
}
})
.catch((err) => {
if (this.refresher) {
this.refresher.complete();
}
this._error(err)
});
}
doRefresh(refresher) {
this.refresher = refresher;
this._pullData();
// @TODO Remove it later...
this.avatarName = this._mock.avatar.name;
this.avatarPhoto = this._mock.avatar.photo;
}
ionViewWillEnter() {
// @TODO We should not block user if no linkedin photo...
this._pullData();
// @TODO Remove it later...
this.avatarName = this._mock.avatar.name;
this.avatarPhoto = this._mock.avatar.photo;
this.photos = [
{
name: 'Test 1',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 2',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 3',
photo: 'https://unsplash.it/50/50'
},
{
name: 'Test 4',
photo: 'https://unsplash.it/50/50'
}
];
console.log('this.photos', this.photos)
}
}