helper-data-service.ts 28.5 KB
Newer Older
1
import {Http, Headers, RequestOptions} from '@angular/http';
2
3
import {Injectable, OnInit, OnDestroy} from '@angular/core';
import {BehaviorSubject} from "rxjs/Rx";
4
5
import 'rxjs/add/operator/map';
import { ICourseField } from '../store/coursefields/coursefields.types';
6
import { ISectorField } from '../store/sectorfields/sectorfields.types';
7
import { IRegion, IRegions, IRegionSchool } from '../store/regionschools/regionschools.types';
8
import { ISector, ISectors, ISectorCourse } from '../store/sectorcourses/sectorcourses.types';
Open Source Developer's avatar
Open Source Developer committed
9
//import { IClassField } from '../store/classfields/classfields.types';
10
import { AppSettings } from '../app.settings';
11
12
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../store/store';
13
import { ILoginInfo, ILoginInfoToken } from '../store/logininfo/logininfo.types';
14
import { LOGININFO_INITIAL_STATE } from '../store/logininfo/logininfo.initial-state';
15
16
17
18
19


const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };

@Injectable()
20
export class HelperDataService implements OnInit, OnDestroy {
21
22

    private authToken: string;
23
24
    private authRole: string;
    private loginInfo$: BehaviorSubject<ILoginInfo>;
25
26
27
28

    constructor(
        private http: Http,
        private _ngRedux: NgRedux<IAppState>) {
29
        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
30

31
    };
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    ngOnInit() {
        this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
    }

    ngOnDestroy() {
        this.loginInfo$.unsubscribe();
    }
49

50
    createAuthorizationHeader(headers: Headers) {
51
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
52
53
    }

54
55
56
57
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

58
    getEpalUserData() {
59
        this.loginInfo$.getValue().forEach(loginInfoToken => {
60
61
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
62
63
64
65
66
67
68
69
70
71
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/userdata`, options)
            .map(response => response.json());
    };

72
    sendVerificationCode(email) {
73
        this.loginInfo$.getValue().forEach(loginInfoToken => {
74
75
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
76
        });
77
78
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
79
        let headers = new Headers({
80
81
82
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
83
84
        });
        this.createAuthorizationHeader(headers);
85
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
86
87
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
88
89
90
91
92
93
94
95
96
97
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/sendvercode`, { userEmail: email }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error Sending Verification Code"); // in case of failure show this message
                    reject("Error Sending Verification Code");
                },
                () => console.log("Sending Verification Code"));//run this code in all cases); */
98
99
100
101
        });
    }

    verifyVerificationCode(verificationCode) {
102
        this.loginInfo$.getValue().forEach(loginInfoToken => {
103
104
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
105
        });
106
107
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
108
        let headers = new Headers({
109
110
111
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
112
113
        });
        this.createAuthorizationHeader(headers);
114
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
115
116
117
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            console.log("verificationCode=" + verificationCode);
118
119
120
121
122
123
124
125
126
127
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/verifyvercode`, { verificationCode: verificationCode }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(<any>data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error Verifying Verification Code"); // in case of failure show this message
                    reject("Error Verifying Verification Code");
                },
                () => console.log("Verifying Verification Code"));//run this code in all cases); */
128
129
130
        });
    }

131
    saveProfile(userProfile) {
132
        this.loginInfo$.getValue().forEach(loginInfoToken => {
133
134
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
135
        });
136
137
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
138
        let headers = new Headers({
139
            "Content-Type": "application/json",
140
141
142
143
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
144
145
146
147
148
149
150
151
152
153
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/save`, { userProfile: userProfile }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Profile");
                    reject("Error Saving Profile");
                },
                () => console.log("Saving Profile"));
154
155
156
        });
    }

157
    getCourseFields() {
158

159
        this.loginInfo$.getValue().forEach(loginInfoToken => {
160
161
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
162
        });
163
164
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
165
166
167
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
168

169
170
171
172
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
173
            "X-CSRF-Token": "EHu964c7gN7M399UfHiHHv06x1Tx5cl-P-9ZyMdmGbw",
174
175
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
176
        });
177
        this.createAuthorizationHeader(headers);
178
        let options = new RequestOptions({ headers: headers });
179
        return new Promise((resolve, reject) => {
180
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
181
182
183
184
185
186
187
188
189
                .map(response => <ICourseField[]>response.json())
                .subscribe(data => {
                    resolve(data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("Course Fields Received"));//run this code in all cases); */
190
191
        });
    };
192

193
    getSectorFields() {
194
        this.loginInfo$.getValue().forEach(loginInfoToken => {
195
196
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
197
        });
198
199
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
200
201
202
203
204
205
206
207
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
208
209
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
210
211
212
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
213
        return new Promise((resolve, reject) => {
214
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
215
216
217
218
219
220
221
222
223
                .map(response => <ISectorField[]>response.json())
                .subscribe(data => {
                    resolve(data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("Sector Fields Received"));//run this code in all cases); */
224
225
226
        });
    };

227
    getRegionsWithSchools(classActive, courseActive) {
228
        this.loginInfo$.getValue().forEach(loginInfoToken => {
229
230
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
231
        });
232
233
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
234
235
236
237
238
239
240
241
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
242
243
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
244
        });
245
        this.createAuthorizationHeader(headers);
246
        let options = new RequestOptions({ headers: headers });
247
        return new Promise((resolve, reject) => {
248
            let getConnectionString = null;
249
250
251

            //if (courseActive === -1)
            if (classActive === 1)
252
253
254
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
255
            else if (classActive === 3)
256
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
257

258
            this.http.get(getConnectionString, options)
259
260
261
262
263
264
265
266
267
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(data));
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("region schools service"));//run this code in all cases); */
268
269
270
        });
    };

271
    getSectorsWithCourses() {
272
        this.loginInfo$.getValue().forEach(loginInfoToken => {
273
274
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
275
        });
276
277
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
278
279
280
281
282
283
284
285
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
286
287
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
288
289
290
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
291
        return new Promise((resolve, reject) => {
292
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
293
294
295
296
297
298
299
300
301
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformSectorCoursesSchema(data));
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("region schools service"));//run this code in all cases); */
302
303
304
        });
    };

305
306
307
308
309
310
311
312
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

313
        let j = 0;
314
315
316
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
317
                rsa.push(<IRegion>{ 'region_id': regionSchool.region_id, 'region_name': regionSchool.region_name, 'epals': Array<IRegionSchool>() });
318
319
                trackRegionId = regionSchool.region_id;
            }
320
            rsa[trackIndex].epals.push(<IRegionSchool>{ 'epal_id': regionSchool.epal_id, 'epal_name': regionSchool.epal_name, 'epal_special_case': regionSchool.epal_special_case, 'globalIndex': j, 'selected': false, 'order_id': 0 });
321
322
323
324
325
            j++;
        });
        return rsa;
    }

326
327
328
329
330
331
332
333
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

334
        let j = 0;
335
336
337
        sectorCourses.forEach(sectorCourse => {
            if (trackSectorId !== sectorCourse.sector_id) {
                trackIndex++;
338
                rsa.push(<ISector>{ 'sector_id': sectorCourse.sector_id, 'sector_name': sectorCourse.sector_name, 'sector_selected': false, 'courses': Array<ISectorCourse>() });
339
340
                trackSectorId = sectorCourse.sector_id;
            }
341
            rsa[trackIndex].courses.push(<ISectorCourse>{ 'course_id': sectorCourse.course_id, 'course_name': sectorCourse.course_name, 'globalIndex': j, 'selected': false });
342
343
344
345
346
            j++;
        });
        return rsa;
    }

347
    getCriteria() {
348

349
        this.loginInfo$.getValue().forEach(loginInfoToken => {
350
351
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
352
        });
353
354
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
355
356
357
358
359
360
361
362
        let headers = new Headers({
            "Content-Type": "application/json",
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list`, options)
363
364
365
366
367
368
369
370
371
372
                //this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list?category=${category}`, options)
                .map(response => <ISectorField[]>response.json())
                .subscribe(data => {
                    resolve(data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("Sector Fields Received"));//run this code in all cases); */
373
374
        });
    };
Open Source Developer's avatar
Open Source Developer committed
375

376
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
377
378

        this.authToken = oauthtoken;
379
        this.authRole = oauthrole;
Open Source Developer's avatar
Open Source Developer committed
380
381
382
383
384
385
386
387
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
388
389
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
Open Source Developer's avatar
Open Source Developer committed
390
391
392
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
393
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
394
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
395
396
397
398
399
400
401
402
403
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformUserSchema(data, oauthtoken, oauthrole));
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error HTTP GET Service"); // in case of failure show this message
                    reject("Error HTTP GET Service");
                },
                () => console.log("UserName Received"));
Open Source Developer's avatar
Open Source Developer committed
404
        });
405
    }
Open Source Developer's avatar
Open Source Developer committed
406

Open Source Developer's avatar
Open Source Developer committed
407

408
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
409
        let rsa = Array<ILoginInfoToken>();
410

411
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
412
        return rsa;
413

414
    }
Open Source Developer's avatar
Open Source Developer committed
415

416
    signOut() {
417
        this.loginInfo$.getValue().forEach(loginInfoToken => {
418
419
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
420
        });
421
422
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
423
424
425
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
Open Source Developer's avatar
Open Source Developer committed
426
427


428
            "Content-Type": "application/json",
429
430
431
432
433
434
            "Accept": "*/*",
            "Access-Control-Allow-Credentials": "true",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
435
436
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
437
438
439
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers, withCredentials: true });
440
441
442
443
444
        let logoutRoute = '/oauth/logout';
        console.log(this.authRole);
        if (this.authRole === 'director')
            logoutRoute = '/cas/logout';

445
        return new Promise((resolve, reject) => {
446
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}`, {}, options)
447
448
449
450
451
452
453
454
455
                .map(response => response)
                .subscribe(data => {
                    resolve(data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error Logout"); // in case of failure show this message
                    reject("Error Logout");
                },
                () => console.log("Logging out"));//run this code in all cases); */
456
457
        });
    }
Open Source Developer's avatar
Open Source Developer committed
458
459


Open Source Developer's avatar
Open Source Developer committed
460
461


Open Source Developer's avatar
tranfer    
Open Source Developer committed
462
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
463

464

465
        this.loginInfo$.getValue().forEach(loginInfoToken => {
466
467
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
468
        });
469
470
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
Open Source Developer committed
471
472
        let headers = new Headers({
            "Content-Type": "application/json",
473
            "id": ""
Open Source Developer's avatar
Open Source Developer committed
474
475
476
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
477
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/subapplic`, options)
Open Source Developer's avatar
Open Source Developer committed
478
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
479
    }
Open Source Developer's avatar
Open Source Developer committed
480

Open Source Developer's avatar
tranfer    
Open Source Developer committed
481

482
483
484
    getStudentDetails(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
485
486
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
487
488
489
        });
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
Open Source Developer committed
490
491
492
493
494
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
495
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/student/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
496
            .map(response => response.json());
497
    }
Open Source Developer's avatar
Open Source Developer committed
498
499


500
501
502
    getEpalchosen(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
503
504
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
505
506
507
        });
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
Open Source Developer committed
508
509
510
511
512
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
513
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/epalchosen/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
514
            .map(response => response.json());
515
    }
Open Source Developer's avatar
tranfer    
Open Source Developer committed
516
517


518
519
520
    getSectorPerSchool(SchoolId) {
        let SchoolIdNew = SchoolId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
521
522
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
523
524
525
        });
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
transf    
Open Source Developer committed
526
527
528
529
530
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
531
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperSchool/` + SchoolIdNew, options)
Open Source Developer's avatar
transf    
Open Source Developer committed
532
            .map(response => response.json());
533
    }
Open Source Developer's avatar
transf    
Open Source Developer committed
534

535
536
537
538
    getSpecialityPerSchool(SchoolId, SectorId) {
        let SchoolIdNew = SchoolId.toString();
        let SectorIdNew = SectorId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
539
540
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
541
542
543
        });
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
trans    
Open Source Developer committed
544
545
546
547
548
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
549
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/specialityperSchool/` + SchoolIdNew + '/' + SectorIdNew, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
550
            .map(response => response.json());
551
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
552
553
554



555
556
557
    getStudentPerSchool(SchoolId, SelectId, classId) {
        let SchoolIdNew = SchoolId.toString();
        let SelectIdNew = SelectId.toString();
558
559


560
        this.loginInfo$.getValue().forEach(loginInfoToken => {
561
562
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
563
564
565
        });
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
566
567


Open Source Developer's avatar
trans    
Open Source Developer committed
568
569
570
571
572
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
573
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/studentperSchool/` + SchoolIdNew + '/' + SelectIdNew + '/' + classId, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
574
            .map(response => response.json());
575
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
576

Open Source Developer's avatar
transf    
Open Source Developer committed
577
578


579
580
    saveConfirmStudents(students) {
        console.log(students, "hds");
581
        this.loginInfo$.getValue().forEach(loginInfoToken => {
582
583
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
584
        });
585
586
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
trans    
Open Source Developer committed
587
        let headers = new Headers({
588
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
589
590
591
592
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
593
594
595
596
597
598
599
600
601
602
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Profile");
                    reject("Error Saving Profile");
                },
                () => console.log("Saving Profile"));
Open Source Developer's avatar
trans    
Open Source Developer committed
603
604
        });

605
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
606
607


Open Source Developer's avatar
Open Source Developer committed
608

609
    saveCapacity(taxi, tomeas, specialit, capacity, schoolid) {
Open Source Developer's avatar
Open Source Developer committed
610

611
        console.log(taxi, capacity, "hds");
612
        this.loginInfo$.getValue().forEach(loginInfoToken => {
613
614
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
615
        });
616
617
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
Open Source Developer committed
618
        let headers = new Headers({
619
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
620
621
622
623
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
624
625
626
627
628
629
630
631
632
633
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/savecapacity/` + taxi + '/' + tomeas + '/' + specialit + '/' + schoolid, { capacity }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Capacity");
                    reject("Error Saving Capacity");
                },
                () => console.log("Saving Capacity"));
Open Source Developer's avatar
Open Source Developer committed
634
635
        });

636
    }
Open Source Developer's avatar
Open Source Developer committed
637

638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
    sendMinisrtyCredentials(username, userpassword) {

        let headers = new Headers({
            "Content-Type": "application/json",
            //"Accept": "*/*",
            //"Access-Control-Allow-Credentials": "true",
            //"X-CSRF-Token": "..."
            //"Authorization": "Basic " + btoa("..."),
        });
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            this.http.post(`${AppSettings.API_ENDPOINT}/ministry/login`,  {username: username, userpassword: userpassword}, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    //console.log("Error Sending Ministry Credentials");
                    reject("Error Sending Ministry Credentials");
                },
                () => console.log(""));
        });

    }

Open Source Developer's avatar
Open Source Developer committed
664
665


Open Source Developer's avatar
Open Source Developer committed
666

667
}