helper-data-service.ts 42.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Http, Headers, RequestOptions, ResponseContentType, Response } from "@angular/http";
import { Injectable, OnInit, OnDestroy } from "@angular/core";
import { BehaviorSubject } from "rxjs/Rx";
import "rxjs/add/operator/map";
import { ICourseField } from "../store/coursefields/coursefields.types";
import { ISectorField } from "../store/sectorfields/sectorfields.types";
import { IRegion, IRegions, IRegionSchool } from "../store/regionschools/regionschools.types";
import { ISector, ISectors, ISectorCourse } from "../store/sectorcourses/sectorcourses.types";
// import { IClassField } from "../store/classfields/classfields.types";
import { AppSettings } from "../app.settings";
import { NgRedux, select } from "ng2-redux";
import { IAppState } from "../store/store";
import { ILoginInfo, ILoginInfoToken } from "../store/logininfo/logininfo.types";
import { LOGININFO_INITIAL_STATE } from "../store/logininfo/logininfo.initial-state";
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from "../constants";
import { CookieService } from "ngx-cookie";

import * as FileSaver from "file-saver";

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

@Injectable()
23
export class HelperDataService implements OnInit, OnDestroy {
24
25

    private authToken: string;
26
    private authRole: string;
27
28
    private minedu_userName: string;
    private minedu_userPassword: string;
29
    private loginInfo$: BehaviorSubject<ILoginInfo>;
30
31
32

    constructor(
        private http: Http,
33
        private _ngRedux: NgRedux<IAppState>,
34
        private _cookieService: CookieService) {
35
        this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
36

37

38
    };
39

40
41
42
    ngOnInit() {
        this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
43
44
                state.loginInfo.reduce(({ }, loginInfoToken) => {
                    // console.log("INSIDE!");
45
46
47
48
49
50
51
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
52

53
54
55
56
57
    }

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

59
    createAuthorizationHeader(headers: Headers) {
60
        headers.append("Authorization", "Basic " + btoa(this.authToken + ":" + this.authToken));
61
62
    }

63
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
64
        headers.append("Authorization", "Basic " + btoa(username + ":" + passwd));
65
66
    }

67
    getEpalUserData() {
68
        this.loginInfo$.getValue().forEach(loginInfoToken => {
69
70
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
71
72
73
74
75
76
77
78
79
80
        });
        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());
    };

81
    sendVerificationCode(email) {
82
        this.loginInfo$.getValue().forEach(loginInfoToken => {
83
84
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
85
86
        });
        let headers = new Headers({
87
88
89
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
90
91
        });
        this.createAuthorizationHeader(headers);
92
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
93
94
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
95
96
97
98
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/sendvercode`, { userEmail: email }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
99
                },
100
                error => {
101
                    console.log("Error Sending Verification Code");
102
103
                    reject("Error Sending Verification Code");
                },
104
                () => console.log("Sending Verification Code"));
105
106
107
108
        });
    }

    verifyVerificationCode(verificationCode) {
109
        this.loginInfo$.getValue().forEach(loginInfoToken => {
110
111
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
112
113
        });
        let headers = new Headers({
114
            "Content-Type": "application/json",
115
116
        });
        this.createAuthorizationHeader(headers);
117
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
118
119
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
120
121
122
123
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/verifyvercode`, { verificationCode: verificationCode }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(<any>data);
124
                },
125
                error => {
126
                    console.log("Error Verifying Verification Code");
127
128
                    reject("Error Verifying Verification Code");
                },
129
                () => console.log("Verifying Verification Code"));
130
131
132
        });
    }

133
    saveProfile(userProfile) {
134
        this.loginInfo$.getValue().forEach(loginInfoToken => {
135
136
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
137
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        });
    }

    deleteApplication(appId) {
        this.loginInfo$.getValue().forEach(loginInfoToken => {
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/application/delete`, { applicationId: appId }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(<any>data);
                },
                error => {
                    console.log("Error Removing Application");
                    reject("Error Removing Application");
                },
                () => console.log("Removing Application"));
179
180
181
        });
    }

182
    getCourseFields() {
183

184
        this.loginInfo$.getValue().forEach(loginInfoToken => {
185
186
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
187
        });
188
189
190
        let headers = new Headers({
            "Content-Type": "application/json",
        });
191
        this.createAuthorizationHeader(headers);
192
        let options = new RequestOptions({ headers: headers });
193
        return new Promise((resolve, reject) => {
194
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
195
196
197
                .map(response => <ICourseField[]>response.json())
                .subscribe(data => {
                    resolve(data);
198
                },
199
                error => {
200
                    console.log("Error HTTP GET Service");
201
202
                    reject("Error HTTP GET Service");
                },
203
                () => console.log("Course Fields Received"));
204
205
        });
    };
206

207
    getSectorFields() {
208
        this.loginInfo$.getValue().forEach(loginInfoToken => {
209
210
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
211
212
213
214
215
216
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
217
        return new Promise((resolve, reject) => {
218
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
219
220
221
                .map(response => <ISectorField[]>response.json())
                .subscribe(data => {
                    resolve(data);
222
                },
223
                error => {
224
                    console.log("Error HTTP GET Service");
225
226
                    reject("Error HTTP GET Service");
                },
227
                () => console.log("Sector Fields Received"));
228
229
230
        });
    };

231
    getRegionsWithSchools(classActive, courseActive) {
232
        this.loginInfo$.getValue().forEach(loginInfoToken => {
233
234
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
235
        });
236
237
238
        let headers = new Headers({
            "Content-Type": "application/json",
        });
239
        this.createAuthorizationHeader(headers);
240
        let options = new RequestOptions({ headers: headers });
241
        return new Promise((resolve, reject) => {
242
            let getConnectionString = null;
243
244

            if (classActive === 1)
245
246
247
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
248
            else if (classActive === 3)
249
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
250
251
252
            else if (classActive === 4)
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool_night/list?course_id=${courseActive}`;

253
            this.http.get(getConnectionString, options)
254
255
256
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(data));
257
                },
258
                error => {
259
                    console.log("Error HTTP GET Service in getRegionsWithSchools method");
260
261
                    reject("Error HTTP GET Service");
                },
262
                () => console.log("region schools service"));
263
264
265
        });
    };

266
    getSectorsWithCourses() {
267
        this.loginInfo$.getValue().forEach(loginInfoToken => {
268
269
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
270
271
272
273
274
275
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
276
        return new Promise((resolve, reject) => {
277
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
278
279
280
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformSectorCoursesSchema(data));
281
                },
282
                error => {
283
                    console.log("Error HTTP GET Service");
284
285
                    reject("Error HTTP GET Service");
                },
286
                () => console.log("region schools service"));
287
288
289
        });
    };

290
291
292
293
294
295
296
297
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

298
        let j = 0;
299
300
301
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
302
                rsa.push(<IRegion>{ "region_id": regionSchool.region_id, "region_name": regionSchool.region_name, "epals": Array<IRegionSchool>() });
303
304
                trackRegionId = regionSchool.region_id;
            }
305
            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 });
306
307
308
309
310
            j++;
        });
        return rsa;
    }

311
312
313
314
315
316
317
318
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

319
        let j = 0;
320
321
322
        sectorCourses.forEach(sectorCourse => {
            if (trackSectorId !== sectorCourse.sector_id) {
                trackIndex++;
323
                rsa.push(<ISector>{ "sector_id": sectorCourse.sector_id, "sector_name": sectorCourse.sector_name, "sector_selected": false, "courses": Array<ISectorCourse>() });
324
325
                trackSectorId = sectorCourse.sector_id;
            }
326
            rsa[trackIndex].courses.push(<ISectorCourse>{ "course_id": sectorCourse.course_id, "course_name": sectorCourse.course_name, "globalIndex": j, "selected": false });
327
328
329
330
331
            j++;
        });
        return rsa;
    }

332
    getCriteria() {
333

334
        this.loginInfo$.getValue().forEach(loginInfoToken => {
335
336
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
337
338
339
340
341
342
343
344
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list`, options)
345
346
347
348
                //this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list?category=${category}`, options)
                .map(response => <ISectorField[]>response.json())
                .subscribe(data => {
                    resolve(data);
349
                },
350
                error => {
351
                    console.log("Error HTTP GET Service");
352
353
                    reject("Error HTTP GET Service");
                },
354
                () => console.log("Sector Fields Received"));
355
356
        });
    };
Open Source Developer's avatar
Open Source Developer committed
357

358
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
359
360

        this.authToken = oauthtoken;
361
        this.authRole = oauthrole;
362

Open Source Developer's avatar
Open Source Developer committed
363
364
        let headers = new Headers({
            "Content-Type": "application/json",
365
            "Access-Control-Allow-Credentials": "true",
Open Source Developer's avatar
Open Source Developer committed
366
367
368
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
369
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
370
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
371
372
                .map(response => response.json())
                .subscribe(data => {
373
                    window.onbeforeunload = function (e) {
374
                        let confirmationMessage = "\o/";
375
376
377
                        e.returnValue = confirmationMessage;
                        return confirmationMessage;
                    };
378
                    resolve(this.transformUserSchema(data, oauthtoken, oauthrole));
379
                },
380
                error => {
381
                    console.log("Error HTTP GET Service");
382
383
384
                    reject("Error HTTP GET Service");
                },
                () => console.log("UserName Received"));
Open Source Developer's avatar
Open Source Developer committed
385
        });
386
    }
Open Source Developer's avatar
Open Source Developer committed
387

388
389
390
391
    setMineduCurrentUser(minedu_username, minedu_pwd, role) {
        this.minedu_userName = minedu_username;
        this.minedu_userPassword = minedu_pwd;
        this.authRole = role;
392
    }
393

Open Source Developer's avatar
Open Source Developer committed
394

395
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
396
        let rsa = Array<ILoginInfoToken>();
397

398
        rsa.push(<ILoginInfoToken>{
399
400
401
402
403
404
405
406
407
408
409
410
411
            "auth_token": oauthtoken,
            "auth_role": oauthrole,
            "cu_name": userlogin.cu_name,
            "cu_surname": userlogin.cu_surname,
            "cu_fathername": userlogin.cu_fathername,
            "cu_mothername": userlogin.cu_mothername,
            "cu_email": userlogin.cu_email,
            "minedu_username": userlogin.minedu_username,
            "minedu_userpassword": userlogin.minedu_userpassword,
            "lock_capacity": parseInt(userlogin.lock_capacity),
            "lock_students": parseInt(userlogin.lock_students),
            "lock_application": parseInt(userlogin.lock_application),
            "disclaimer_checked": parseInt(userlogin.disclaimer_checked)
412
        });
413
        return rsa;
414

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

417
    signOut() {
418
        // loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
419
        this.loginInfo$.getValue().forEach(loginInfoToken => {
420
421
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
422
        });
423

424
        let headers = new Headers({
425
            "Content-Type": "application/json",
426
        });
427

428
        let options = new RequestOptions({ headers: headers, withCredentials: true });
429
        let logoutRoute = "/oauth/logout";
430
431
432
433
434
        if (this.authRole === MINISTRY_ROLE) {
            this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
        } else {
            this.createAuthorizationHeader(headers);
        }
435
        if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) {
436
            logoutRoute = "/cas/logout";
437
        } else if (this.authRole === MINISTRY_ROLE) {
438
            logoutRoute = "/ministry/logout";
439
        }
440

441
        return new Promise((resolve, reject) => {
442
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options)
443
                .map(response => response.json())
444
                .subscribe(data => {
445
                    this._cookieService.removeAll();
446
                    window.onbeforeunload = function () { console.log("unloading") };
447
                    resolve(data);
448
                },
449
                error => {
450
                    console.log("Error Logout");
451
452
                    reject("Error Logout");
                },
453
                () => console.log("Logging out"));
454
455
        });
    }
Open Source Developer's avatar
Open Source Developer committed
456

457
458
459
460
461
462
463
464
465
466
467
468
469
    casSignOut() {
        let headers = new Headers({
            "Content-Type": "application/json"
        });
        return new Promise((resolve, reject) => {
            this.http.post(`${AppSettings.API_ENDPOINT}/cas/logoutcas${AppSettings.API_ENDPOINT_PARAMS}`, {}, { headers: headers })
                .map(response => response.json())
                .subscribe(data => {
                    this._cookieService.removeAll();
                    window.onbeforeunload = function () { console.log("unloading") };
                    resolve(data);
                },
                error => {
470
                    console.log("Error Logout");
471
472
                    reject("Error Logout");
                },
473
                () => console.log("Logging out"));
474
475
476
        });
    }

Open Source Developer's avatar
tranfer    
Open Source Developer committed
477
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
478

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

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

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


510
511
512
    getEpalchosen(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
513
514
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
515
        });
Open Source Developer's avatar
Open Source Developer committed
516
517
518
519
520
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
521
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/epalchosen/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
522
            .map(response => response.json());
523
    }
Open Source Developer's avatar
tranfer    
Open Source Developer committed
524
525


Open Source Developer's avatar
Open Source Developer committed
526
    getSectorPerSchool() {
527

528
        this.loginInfo$.getValue().forEach(loginInfoToken => {
529
530
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
531
        });
Open Source Developer's avatar
transf    
Open Source Developer committed
532
533
534
535
536
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
bug    
Open Source Developer committed
537

538
539
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperschool/`, options)
            .map(response => response.json());
540
    }
Open Source Developer's avatar
transf    
Open Source Developer committed
541

Open Source Developer's avatar
Open Source Developer committed
542

543
    getSpecialityPerSchool(SectorId) {
544

545
546
        let SectorIdNew = SectorId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
547
548
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
549
        });
Open Source Developer's avatar
trans    
Open Source Developer committed
550
551
552
553
554
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
Open Source Developer committed
555
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/specialityperschool/` + SectorIdNew, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
556
            .map(response => response.json());
557
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
558
559
560



561
    getStudentPerSchool(SelectId, classId, limitdown, limitup) {
562

563
        let SelectIdNew = SelectId.toString();
564
565


566
        this.loginInfo$.getValue().forEach(loginInfoToken => {
567
568
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
569
        });
570

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

Open Source Developer's avatar
transf    
Open Source Developer committed
580
581


Open Source Developer's avatar
trans    
Open Source Developer committed
582
    saveConfirmStudents(students, type) {
583
        this.loginInfo$.getValue().forEach(loginInfoToken => {
584
585
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
586
587
        });
        let headers = new Headers({
588
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
589
590
591
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
592
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students, type }, options)
Open Source Developer's avatar
Open Source Developer committed
593
            .map(response => response.json());
594
595


596
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
597
598


Open Source Developer's avatar
Open Source Developer committed
599

Open Source Developer's avatar
Open Source Developer committed
600
    saveCapacity(taxi, tomeas, specialit, capacity) {
Open Source Developer's avatar
Open Source Developer committed
601

602
        this.loginInfo$.getValue().forEach(loginInfoToken => {
603
604
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
605
606
        });
        let headers = new Headers({
607
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
608
609
610
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
611
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/savecapacity/` + taxi + "/" + tomeas + "/" + specialit, { capacity }, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
612
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
613

614
    }
Open Source Developer's avatar
Open Source Developer committed
615

616
617
618
619
620
621
622
623
    sendMinisrtyCredentials(username, userpassword) {

        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
624
            this.http.post(`${AppSettings.API_ENDPOINT}/ministry/login`, { username: username, userpassword: userpassword }, options)
625
626
627
628
629
630
631
632
633
634
635
636
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error Sending Ministry Credentials");
                },
                () => console.log(""));
        });

    }

637
638
639
640
641
642
    makeDistribution(username, userpassword) {

        let headers = new Headers({
            "Content-Type": "application/json",
        });

643
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
644
645
646
        let options = new RequestOptions({ headers: headers });

        return new Promise((resolve, reject) => {
647
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution`, { username: username, userpassword: userpassword }, options)
648
649
650
651
652
653
654
655
656
657
658
659
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error POST in makeDistribution");
                },
                () => console.log(""));
        });

    }

660

661
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel, distribfinal) {
662
663
664
665
666

        let headers = new Headers({
            "Content-Type": "application/json",
        });

667
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
668
669
        let options = new RequestOptions({ headers: headers });

670
        if (routepath == "/ministry/general-report/") {
671
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath, options)
672
673
674
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-completeness/") {
675
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/" + schsel, options)
676
677
                .map(response => response.json());
        }
678
679
680
        else if (routepath == "/ministry/report-all-stat/") {
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/" + schsel + "/" +
                clsel + "/" + secsel + "/" + coursel + "/" + distribfinal, options)
681
                .map(response => response.json());
682
683
684
685
        }
        else if (routepath == "/ministry/report-no-capacity/") {
            let capacityFilter = 0;
            if (regionsel)
686
                capacityFilter = 1;
687
688
689
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + capacityFilter, options)
                .map(response => response.json());
        }
690
691
692

    }

693
    informUnlocatedStudents(username, userpassword, unallocated) {
694

695
696
697
698
699
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
700

701
        let route = "";
702
        if (unallocated == 1)
703
            route = "ministry/send-unallocated-massive-mail";
704
705
706
        else if(unallocated == 2)
            route = "ministry/send-unallocated-sc-massive-mail";
        else if(unallocated == 3)
707
            route = "ministry/send-located-massive-mail";
708

709
710
        return this.http.get(`${AppSettings.API_ENDPOINT}/` + route, options)
            .map(response => response.json());
711
712
    }

Open Source Developer's avatar
Open Source Developer committed
713

714
    getSchools() {
Open Source Developer's avatar
trans    
Open Source Developer committed
715
716
717
718
719
720
721
722
723
724

        this.loginInfo$.getValue().forEach(loginInfoToken => {
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
725
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/schools-per-perf/`, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
726
727
728
            .map(response => response.json());
    }

729
    getCoursePerPerfecture(PerfectureId) {
Open Source Developer's avatar
trans    
Open Source Developer committed
730
731
732
733
734
735
736
737
738
739
740
741
742
        let PerfectureIdNew = PerfectureId.toString();


        this.loginInfo$.getValue().forEach(loginInfoToken => {
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
        });

        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
bug    
Open Source Developer committed
743

744
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/coursespersch/` + PerfectureIdNew, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
745
            .map(response => response.json());
746
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
747

748
    getRegions(username, userpassword) {
749

750
751
752
        let headers = new Headers({
            "Content-Type": "application/json",
        });
753

754
755
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
756

757
        // return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath , options)
758
759
760
        //    .map(response => response.json());
        return this.http.get(`${AppSettings.API_ENDPOINT}/regionfields/list`, options)
            .map(response => response.json());
761

762
    }
763

764
    getAdminAreas(username, userpassword, regionid) {
765

766
767
768
        let headers = new Headers({
            "Content-Type": "application/json",
        });
769

770
771
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
772

773
774
775
        return this.http.get(`${AppSettings.API_ENDPOINT}/adminfields/list/?region=` + regionid, options)
            .map(response => response.json());
    }
776

777
    getSchoolsPerRegion(username, userpassword, regionid) {
778

779
780
781
        let headers = new Headers({
            "Content-Type": "application/json",
        });
782

783
784
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
785

786
787
788
        return this.http.get(`${AppSettings.API_ENDPOINT}/schoolfields_per_region/list/?region=` + regionid, options)
            .map(response => response.json());
    }
789

790
    getSchoolsPerAdminArea(username, userpassword, adminid) {
791

792
793
794
        let headers = new Headers({
            "Content-Type": "application/json",
        });
795

796
797
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
798

799
800
801
        return this.http.get(`${AppSettings.API_ENDPOINT}/schoolfields_per_admin/list/?adminarea=` + adminid, options)
            .map(response => response.json());
    }
802

803

804
    getUserRegistryNo(username, userpassword) {
805

806
807
808
        let headers = new Headers({
            "Content-Type": "application/json",
        });
809

810
811
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
812

813
814
815
        return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`, options)
            .map(response => response.json());
    }
816

817
    retrieveAdminSettings(username, userpassword) {
818

819
820
821
        let headers = new Headers({
            "Content-Type": "application/json",
        });
822

823
824
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
825

826
827
828
        return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-settings`, options)
            .map(response => response.json());
    }
829

830
    storeAdminSettings(username, userpassword, capac, dirview, applogin, appresults) {
831

832
833
834
        let headers = new Headers({
            "Content-Type": "application/json",
        });
835

836
837
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
838

839
        return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/store-settings/` +
840
841
            Number(capac) + "/" + Number(dirview) + "/" + Number(applogin) + "/" + Number(appresults), options)
            .map(response => response.json());
842
    }
843
844


845
    getSectors(username, userpassword, classid) {
846

847
848
849
        let headers = new Headers({
            "Content-Type": "application/json",
        });
850