helper-data-service.ts 27.4 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
    createAuthorizationHeader(headers: Headers) {
50
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
51
52
    }

53
    getEpalUserData() {
54
        this.loginInfo$.getValue().forEach(loginInfoToken => {
55
56
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
57
        });
58
59
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
60
61
62
63
64
65
66
67
68
        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());
    };

69
    sendVerificationCode(email) {
70
        this.loginInfo$.getValue().forEach(loginInfoToken => {
71
72
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
73
        });
74
75
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
76
        let headers = new Headers({
77
78
79
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
80
81
        });
        this.createAuthorizationHeader(headers);
82
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
83
84
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
85
86
87
88
89
90
91
92
93
94
            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); */
95
96
97
98
        });
    }

    verifyVerificationCode(verificationCode) {
99
        this.loginInfo$.getValue().forEach(loginInfoToken => {
100
101
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
102
        });
103
104
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
105
        let headers = new Headers({
106
107
108
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
109
110
        });
        this.createAuthorizationHeader(headers);
111
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
112
113
114
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            console.log("verificationCode=" + verificationCode);
115
116
117
118
119
120
121
122
123
124
            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); */
125
126
127
        });
    }

128
    saveProfile(userProfile) {
129
        this.loginInfo$.getValue().forEach(loginInfoToken => {
130
131
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
132
        });
133
134
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
135
        let headers = new Headers({
136
            "Content-Type": "application/json",
137
138
139
140
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
141
142
143
144
145
146
147
148
149
150
            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"));
151
152
153
        });
    }

154
    getCourseFields() {
155

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

166
167
168
169
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
170
            "X-CSRF-Token": "EHu964c7gN7M399UfHiHHv06x1Tx5cl-P-9ZyMdmGbw",
171
172
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
173
        });
174
        this.createAuthorizationHeader(headers);
175
        let options = new RequestOptions({ headers: headers });
176
        return new Promise((resolve, reject) => {
177
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
178
179
180
181
182
183
184
185
186
                .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); */
187
188
        });
    };
189

190
    getSectorFields() {
191
        this.loginInfo$.getValue().forEach(loginInfoToken => {
192
193
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
194
        });
195
196
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
197
198
199
200
201
202
203
204
        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",
205
206
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
207
208
209
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
210
        return new Promise((resolve, reject) => {
211
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
212
213
214
215
216
217
218
219
220
                .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); */
221
222
223
        });
    };

224
    getRegionsWithSchools(classActive, courseActive) {
225
        this.loginInfo$.getValue().forEach(loginInfoToken => {
226
227
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
228
        });
229
230
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
231
232
233
234
235
236
237
238
        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",
239
240
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
241
        });
242
        this.createAuthorizationHeader(headers);
243
        let options = new RequestOptions({ headers: headers });
244
        return new Promise((resolve, reject) => {
245
            let getConnectionString = null;
246
247
248

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

255
            this.http.get(getConnectionString, options)
256
257
258
259
260
261
262
263
264
                .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); */
265
266
267
        });
    };

268
    getSectorsWithCourses() {
269
        this.loginInfo$.getValue().forEach(loginInfoToken => {
270
271
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
272
        });
273
274
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
275
276
277
278
279
280
281
282
        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",
283
284
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
285
286
287
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
288
        return new Promise((resolve, reject) => {
289
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
290
291
292
293
294
295
296
297
298
                .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); */
299
300
301
        });
    };

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

        trackRegionId = "";
        trackIndex = -1;

310
        let j = 0;
311
312
313
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
314
                rsa.push(<IRegion>{ 'region_id': regionSchool.region_id, 'region_name': regionSchool.region_name, 'epals': Array<IRegionSchool>() });
315
316
                trackRegionId = regionSchool.region_id;
            }
317
            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 });
318
319
320
321
322
            j++;
        });
        return rsa;
    }

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

        trackSectorId = "";
        trackIndex = -1;

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

344
    getCriteria() {
345

346
        this.loginInfo$.getValue().forEach(loginInfoToken => {
347
348
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
349
        });
350
351
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
352
353
354
355
356
357
358
359
        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)
360
361
362
363
364
365
366
367
368
369
                //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); */
370
371
        });
    };
Open Source Developer's avatar
Open Source Developer committed
372

373
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
374
375

        this.authToken = oauthtoken;
376
        this.authRole = oauthrole;
Open Source Developer's avatar
Open Source Developer committed
377
378
379
380
381
382
383
384
        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",
385
386
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
Open Source Developer's avatar
Open Source Developer committed
387
388
389
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
390
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
391
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
392
393
394
395
396
397
398
399
400
                .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
401
        });
402
    }
Open Source Developer's avatar
Open Source Developer committed
403

Open Source Developer's avatar
Open Source Developer committed
404

405
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
406
        let rsa = Array<ILoginInfoToken>();
407

408
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
409
        return rsa;
410

411
    }
Open Source Developer's avatar
Open Source Developer committed
412

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


425
            "Content-Type": "application/json",
426
427
428
429
430
431
            "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",
432
433
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
434
435
436
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers, withCredentials: true });
437
438
439
440
441
        let logoutRoute = '/oauth/logout';
        console.log(this.authRole);
        if (this.authRole === 'director')
            logoutRoute = '/cas/logout';

442
        return new Promise((resolve, reject) => {
443
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}`, {}, options)
444
445
446
447
448
449
450
451
452
                .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); */
453
454
        });
    }
Open Source Developer's avatar
Open Source Developer committed
455
456


Open Source Developer's avatar
Open Source Developer committed
457
458


Open Source Developer's avatar
tranfer    
Open Source Developer committed
459
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
460

461

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

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

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


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


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

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



552
553
554
    getStudentPerSchool(SchoolId, SelectId, classId) {
        let SchoolIdNew = SchoolId.toString();
        let SelectIdNew = SelectId.toString();
555
556


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


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

Open Source Developer's avatar
transf    
Open Source Developer committed
574
575


576
577
    saveConfirmStudents(students) {
        console.log(students, "hds");
578
        this.loginInfo$.getValue().forEach(loginInfoToken => {
579
580
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
581
        });
582
583
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
trans    
Open Source Developer committed
584
        let headers = new Headers({
585
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
586
587
588
589
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
590
591
592
593
594
595
596
597
598
599
            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
600
601
        });

602
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
603
604


Open Source Developer's avatar
Open Source Developer committed
605

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

608
        console.log(taxi, capacity, "hds");
609
        this.loginInfo$.getValue().forEach(loginInfoToken => {
610
611
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
612
        });
613
614
        console.log("authToken=" + this.authToken);
        console.log("authRole=" + this.authRole);
Open Source Developer's avatar
Open Source Developer committed
615
        let headers = new Headers({
616
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
617
618
619
620
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
621
622
623
624
625
626
627
628
629
630
            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
631
632
        });

633
    }
Open Source Developer's avatar
Open Source Developer committed
634
635
636



Open Source Developer's avatar
Open Source Developer committed
637

638
}