helper-data-service.ts 33.9 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
import { SCHOOL_ROLE, STUDENT_ROLE, PDE_ROLE, DIDE_ROLE, MINISTRY_ROLE } from '../constants';
16
17
import { CookieService } from 'ngx-cookie';

18
19
20
21

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

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

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

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

36

37
    };
38

39
40
41
42
43
44
45
46
47
48
49
    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$);
50

51
52
53
54
55
    }

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

57
    createAuthorizationHeader(headers: Headers) {
58
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
59
60
    }

61
62
63
64
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

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

79
    sendVerificationCode(email) {
80
        this.loginInfo$.getValue().forEach(loginInfoToken => {
81
82
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
83
84
        });
        let headers = new Headers({
85
86
87
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
88
89
        });
        this.createAuthorizationHeader(headers);
90
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
91
92
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
93
94
95
96
97
98
99
100
101
102
            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); */
103
104
105
106
        });
    }

    verifyVerificationCode(verificationCode) {
107
        this.loginInfo$.getValue().forEach(loginInfoToken => {
108
109
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
110
111
        });
        let headers = new Headers({
112
            "Content-Type": "application/json",
113
114
        });
        this.createAuthorizationHeader(headers);
115
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
116
117
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
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
        });
        let headers = new Headers({
137
            "Content-Type": "application/json",
138
139
140
141
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
142
143
144
145
146
147
148
149
150
151
            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"));
152
153
154
        });
    }

155
    getCourseFields() {
156

157
        this.loginInfo$.getValue().forEach(loginInfoToken => {
158
159
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
160
        });
161
162
163
        let headers = new Headers({
            "Content-Type": "application/json",
        });
164
        this.createAuthorizationHeader(headers);
165
        let options = new RequestOptions({ headers: headers });
166
        return new Promise((resolve, reject) => {
167
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
168
169
170
171
172
173
174
175
176
                .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); */
177
178
        });
    };
179

180
    getSectorFields() {
181
        this.loginInfo$.getValue().forEach(loginInfoToken => {
182
183
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
184
185
186
187
188
189
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
190
        return new Promise((resolve, reject) => {
191
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
192
193
194
195
196
197
198
199
200
                .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); */
201
202
203
        });
    };

204
    getRegionsWithSchools(classActive, courseActive) {
205
        this.loginInfo$.getValue().forEach(loginInfoToken => {
206
207
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
208
        });
209
210
211
        let headers = new Headers({
            "Content-Type": "application/json",
        });
212
        this.createAuthorizationHeader(headers);
213
        let options = new RequestOptions({ headers: headers });
214
        return new Promise((resolve, reject) => {
215
            let getConnectionString = null;
216
217

            if (classActive === 1)
218
219
220
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
221
            else if (classActive === 3)
222
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
223
224
225
            else if (classActive === 4)
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool_night/list?course_id=${courseActive}`;

226
            this.http.get(getConnectionString, options)
227
228
229
230
231
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(data));
                }, // put the data returned from the server in our variable
                error => {
232
                    console.log("Error HTTP GET Service in getRegionsWithSchools method"); // in case of failure show this message
233
234
235
                    reject("Error HTTP GET Service");
                },
                () => console.log("region schools service"));//run this code in all cases); */
236
237
238
        });
    };

239
    getSectorsWithCourses() {
240
        this.loginInfo$.getValue().forEach(loginInfoToken => {
241
242
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
243
244
245
246
247
248
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
249
        return new Promise((resolve, reject) => {
250
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
251
252
253
254
255
256
257
258
259
                .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); */
260
261
262
        });
    };

263
264
265
266
267
268
269
270
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

271
        let j = 0;
272
273
274
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
275
                rsa.push(<IRegion>{ 'region_id': regionSchool.region_id, 'region_name': regionSchool.region_name, 'epals': Array<IRegionSchool>() });
276
277
                trackRegionId = regionSchool.region_id;
            }
278
            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 });
279
280
281
282
283
            j++;
        });
        return rsa;
    }

284
285
286
287
288
289
290
291
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

292
        let j = 0;
293
294
295
        sectorCourses.forEach(sectorCourse => {
            if (trackSectorId !== sectorCourse.sector_id) {
                trackIndex++;
296
                rsa.push(<ISector>{ 'sector_id': sectorCourse.sector_id, 'sector_name': sectorCourse.sector_name, 'sector_selected': false, 'courses': Array<ISectorCourse>() });
297
298
                trackSectorId = sectorCourse.sector_id;
            }
299
            rsa[trackIndex].courses.push(<ISectorCourse>{ 'course_id': sectorCourse.course_id, 'course_name': sectorCourse.course_name, 'globalIndex': j, 'selected': false });
300
301
302
303
304
            j++;
        });
        return rsa;
    }

305
    getCriteria() {
306

307
        this.loginInfo$.getValue().forEach(loginInfoToken => {
308
309
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
310
311
312
313
314
315
316
317
        });
        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)
318
319
320
321
322
323
324
325
326
327
                //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); */
328
329
        });
    };
Open Source Developer's avatar
Open Source Developer committed
330

331
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
332
333

        this.authToken = oauthtoken;
334
        this.authRole = oauthrole;
335

Open Source Developer's avatar
Open Source Developer committed
336
337
        let headers = new Headers({
            "Content-Type": "application/json",
338
            "Access-Control-Allow-Credentials": "true",
Open Source Developer's avatar
Open Source Developer committed
339
340
341
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
342
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
343
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
344
345
                .map(response => response.json())
                .subscribe(data => {
346
347
348
349
350
                    window.onbeforeunload = function (e) {
                        var confirmationMessage = "\o/";
                        e.returnValue = confirmationMessage;
                        return confirmationMessage;
                    };
351
352
353
354
355
356
357
                    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
358
        });
359
    }
Open Source Developer's avatar
Open Source Developer committed
360

361
362
363
364
365
366
    setMineduCurrentUser(minedu_username, minedu_pwd, role) {
        this.minedu_userName = minedu_username;
        this.minedu_userPassword = minedu_pwd;
        this.authRole = role;
      }

Open Source Developer's avatar
Open Source Developer committed
367

368
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
369
        let rsa = Array<ILoginInfoToken>();
370

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
        rsa.push(<ILoginInfoToken>{
            '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)
        });
386
        return rsa;
387

388
    }
Open Source Developer's avatar
Open Source Developer committed
389

390
    signOut() {
391
        //loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
392
        this.loginInfo$.getValue().forEach(loginInfoToken => {
393
394
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
395
        });
396

397
        let headers = new Headers({
398
            "Content-Type": "application/json",
399

400
        });
401

402
        if (this.authRole === MINISTRY_ROLE)
403
404
405
          this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
        else
          this.createAuthorizationHeader(headers);
406
        let options = new RequestOptions({ headers: headers, withCredentials: true });
407
        let logoutRoute = '/oauth/logout';
408
        if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) {
409
          logoutRoute = '/cas/logout';
410
        }
411
        else if (this.authRole === MINISTRY_ROLE)
412
          logoutRoute = '/ministry/logout';
413

414
        return new Promise((resolve, reject) => {
415
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options)
416
                .map(response => response.json())
417
                .subscribe(data => {
418
                    this._cookieService.removeAll();
419
                    window.onbeforeunload = function () {console.log("unloading")};
420
421
422
423
424
425
426
                    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); */
427
428
        });
    }
Open Source Developer's avatar
Open Source Developer committed
429

Open Source Developer's avatar
tranfer    
Open Source Developer committed
430
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
431

432
        this.loginInfo$.getValue().forEach(loginInfoToken => {
433
434
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
435
436
437
438
439
440
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
441
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/subapplic`, options)
Open Source Developer's avatar
Open Source Developer committed
442
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
443
    }
Open Source Developer's avatar
Open Source Developer committed
444

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

446
447
448
    getStudentDetails(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
449
450
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
451
        });
Open Source Developer's avatar
Open Source Developer committed
452
453
454
455
456
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
457
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/student/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
458
            .map(response => response.json());
459
    }
Open Source Developer's avatar
Open Source Developer committed
460
461


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


Open Source Developer's avatar
Open Source Developer committed
478
    getSectorPerSchool() {
479

480
        this.loginInfo$.getValue().forEach(loginInfoToken => {
481
482
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
483
        });
Open Source Developer's avatar
transf    
Open Source Developer committed
484
485
486
487
488
        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
489
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperSchool/` , options)
Open Source Developer's avatar
transf    
Open Source Developer committed
490
            .map(response => response.json());
491
    }
Open Source Developer's avatar
transf    
Open Source Developer committed
492

Open Source Developer's avatar
Open Source Developer committed
493
494

    getSpecialityPerSchool( SectorId) {
495

496
497
        let SectorIdNew = SectorId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
498
499
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
500
        });
Open Source Developer's avatar
trans    
Open Source Developer committed
501
502
503
504
505
        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
506
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/specialityperSchool/` + SectorIdNew, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
507
            .map(response => response.json());
508
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
509
510
511



Open Source Developer's avatar
Open Source Developer committed
512
    getStudentPerSchool( SelectId, classId, limitdown, limitup) {
513

514
        let SelectIdNew = SelectId.toString();
515
516


517
        this.loginInfo$.getValue().forEach(loginInfoToken => {
518
519
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
520
        });
521

Open Source Developer's avatar
trans    
Open Source Developer committed
522
523
524
525
526
        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
527
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/studentperSchool/` + SelectIdNew + '/' + classId + '/' + limitdown + '/' + limitup, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
528
            .map(response => response.json());
529
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
530

Open Source Developer's avatar
transf    
Open Source Developer committed
531
532


Open Source Developer's avatar
trans    
Open Source Developer committed
533
    saveConfirmStudents(students, type) {
534
        this.loginInfo$.getValue().forEach(loginInfoToken => {
535
536
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
537
538
        });
        let headers = new Headers({
539
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
540
541
542
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
Open Source Developer committed
543
544
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students, type}, options)
            .map(response => response.json());
545
546


547
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
548
549


Open Source Developer's avatar
Open Source Developer committed
550

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

553
        this.loginInfo$.getValue().forEach(loginInfoToken => {
554
555
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
556
557
        });
        let headers = new Headers({
558
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
559
560
561
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
Open Source Developer committed
562
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/savecapacity/` + taxi + '/' + tomeas + '/' + specialit, { capacity }, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
563
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
564

565
    }
Open Source Developer's avatar
Open Source Developer committed
566

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
    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) => {
            this.http.post(`${AppSettings.API_ENDPOINT}/ministry/login`,  {username: username, userpassword: userpassword}, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error Sending Ministry Credentials");
                },
                () => console.log(""));
        });

    }

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
    makeDistribution(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) => {
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution`, {username: username, userpassword: userpassword}, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error POST in makeDistribution");
                },
                () => console.log(""));
        });

    }

611

612
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel) {
613
614
615
616
617
618
619
620

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

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

621
622
623
624
625
626
627
628
629
630
631
632
633
        if (routepath == "/ministry/general-report/") {
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath  , options)
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-completeness/") {
          return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/"  + schsel  , options)
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-all-stat/"){
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/"  + schsel + "/"  +
                                  clsel + "/"  + secsel + "/"  + coursel , options)
                .map(response => response.json());
          }
634
635
636
637
638
639
640
          else if (routepath == "/ministry/report-no-capacity/"){
              let capacityFilter = 0;
              if (regionsel)
                capacityFilter = 1;
              return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + capacityFilter, options)
                  .map(response => response.json());
            }
641
642
643

    }

644
645
646
647
648
649
650
651
652
653
654
    informUnlocatedStudents(username, userpassword) {

      let headers = new Headers({
          "Content-Type": "application/json",
      });
      this.createMinistryAuthorizationHeader(headers, username, userpassword );
      let options = new RequestOptions({ headers: headers });
      return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/send-massive-mail` , options)
          .map(response => response.json());
    }

Open Source Developer's avatar
Open Source Developer committed
655

Open Source Developer's avatar
Open Source Developer committed
656
    getSchoolPerPerfecture() {
Open Source Developer's avatar
trans    
Open Source Developer committed
657
658
659
660
661
662
663
664
665
666

        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 });
667
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/schools-per-perf/` , options)
Open Source Developer's avatar
trans    
Open Source Developer committed
668
669
670
            .map(response => response.json());
    }

Open Source Developer's avatar
trans    
Open Source Developer committed
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
    getCoursePerPerfecture(PerfectureId){
        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 });
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/CoursesperSch/` + PerfectureIdNew , options)
            .map(response => response.json());
}

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
getRegions(username, userpassword)  {

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

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

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

}

getAdminAreas(username, userpassword, regionid)  {

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

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

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

getSchoolsPerRegion(username, userpassword, regionid)  {

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

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

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

getSchoolsPerAdminArea(username, userpassword, adminid)  {

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

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

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

744
745
746
747
748
749
750
751
752
753

getUserRegistryNo(username, userpassword)  {

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

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

754
    return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`  , options)
755
756
757
      .map(response => response.json());
}

758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
retrieveAdminSettings(username, userpassword)  {

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

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

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

storeAdminSettings(username, userpassword, capac, dirview, applogin)  {

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

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

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

784
785


786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
getSectors(username, userpassword, classid)  {

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

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

  return this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list` , options)
      .map(response => response.json());
}

getCourses(username, userpassword, sectorid)  {

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

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

  return this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list/?sector_id=` + sectorid , options)
      .map(response => response.json());
}

Open Source Developer's avatar
trans    
Open Source Developer committed
812

Open Source Developer's avatar
Open Source Developer committed
813

Open Source Developer's avatar
trans    
Open Source Developer committed
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
    getCritiria(headerid, type) {
        let headerIdNew = headerid.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 });
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/critiriachosen/` + headerIdNew + '/' + type, options)
            .map(response => response.json());
    }

Open Source Developer's avatar
Open Source Developer committed
829

Open Source Developer's avatar
Open Source Developer committed
830
getCapacityPerSchool(taxi, tomeas, specialit) {
Open Source Developer's avatar
trans    
Open Source Developer committed
831
832
833
834
835
836
837
838
839
840

        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
Open Source Developer committed
841
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/findCapacity/` + taxi + '/' + tomeas + '/' + specialit, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
842
843
844
            .map(response => response.json());

    }
Open Source Developer's avatar
trans    
Open Source Developer committed
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861

getSchoolId() {

        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 });
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/getschool/`, options)
            .map(response => response.json());

    }

Open Source Developer's avatar
Open Source Developer committed
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
gettypeofschool(){

    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 });
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/gettypeofschool/`, options)
            .map(response => response.json());

}
Open Source Developer's avatar
trans    
Open Source Developer committed
877
878


879
}