helper-data-service.ts 40.3 KB
Newer Older
1
import {Http, Headers, RequestOptions, ResponseContentType, Response } 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
import * as FileSaver from 'file-saver';
19
20
21
22

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

@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
43
    ngOnInit() {
        this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
44
                    //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
61
62
      console.log("Αυτά είναι Α:");
      console.log(this.authToken);
      console.log(this.authRole);
63
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
64
65
    }

66
67
68
69
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

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

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

    verifyVerificationCode(verificationCode) {
112
        this.loginInfo$.getValue().forEach(loginInfoToken => {
113
114
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
115
116
        });
        let headers = new Headers({
117
            "Content-Type": "application/json",
118
119
        });
        this.createAuthorizationHeader(headers);
120
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
121
122
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
123
124
125
126
127
128
129
130
131
132
            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); */
133
134
135
        });
    }

136
    saveProfile(userProfile) {
137
        this.loginInfo$.getValue().forEach(loginInfoToken => {
138
139
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
140
141
        });
        let headers = new Headers({
142
            "Content-Type": "application/json",
143
144
145
146
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
147
148
149
150
151
152
153
154
155
156
            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"));
157
158
159
        });
    }

160
    getCourseFields() {
161

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

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

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

            if (classActive === 1)
223
224
225
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
226
            else if (classActive === 3)
227
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
228
229
230
            else if (classActive === 4)
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool_night/list?course_id=${courseActive}`;

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

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

268
269
270
271
272
273
274
275
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

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

289
290
291
292
293
294
295
296
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

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

310
    getCriteria() {
311

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

336
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
337
338

        this.authToken = oauthtoken;
339
        this.authRole = oauthrole;
340

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

366
367
368
369
    setMineduCurrentUser(minedu_username, minedu_pwd, role) {
        this.minedu_userName = minedu_username;
        this.minedu_userPassword = minedu_pwd;
        this.authRole = role;
370
    }
371

Open Source Developer's avatar
Open Source Developer committed
372

373
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
374
        let rsa = Array<ILoginInfoToken>();
375

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
        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)
        });
391
        return rsa;
392

393
    }
Open Source Developer's avatar
Open Source Developer committed
394

395
    signOut() {
396
        //loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
397
        this.loginInfo$.getValue().forEach(loginInfoToken => {
398
399
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
400
        });
401

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

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

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

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
    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 => {
                    console.log("Error Logout"); // in case of failure show this message
                    reject("Error Logout");
                },
                () => console.log("Logging out"));//run this code in all cases); */
        });
    }

Open Source Developer's avatar
tranfer    
Open Source Developer committed
455
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
456

457
        this.loginInfo$.getValue().forEach(loginInfoToken => {
458
459
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
460
461
462
463
464
465
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
466
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/subapplic`, options)
Open Source Developer's avatar
Open Source Developer committed
467
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
468
    }
Open Source Developer's avatar
Open Source Developer committed
469

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

471
472
473
    getStudentDetails(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
474
            console.log("Nai");
475
476
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
477
        });
Open Source Developer's avatar
Open Source Developer committed
478
479
480
481
482
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
483
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/student/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
484
            .map(response => response.json());
485
    }
Open Source Developer's avatar
Open Source Developer committed
486
487


488
489
490
    getEpalchosen(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
491
492
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
493
        });
Open Source Developer's avatar
Open Source Developer committed
494
495
496
497
498
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
499
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/epalchosen/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
500
            .map(response => response.json());
501
    }
Open Source Developer's avatar
tranfer    
Open Source Developer committed
502
503


Open Source Developer's avatar
Open Source Developer committed
504
    getSectorPerSchool() {
505

506
        this.loginInfo$.getValue().forEach(loginInfoToken => {
507
508
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
509
        });
Open Source Developer's avatar
transf    
Open Source Developer committed
510
511
512
513
514
        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
515

Open Source Developer's avatar
Open Source Developer committed
516
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperschool/` , options)
Open Source Developer's avatar
bug    
Open Source Developer committed
517
         .map(response => response.json());
518
    }
Open Source Developer's avatar
transf    
Open Source Developer committed
519

Open Source Developer's avatar
Open Source Developer committed
520

521
    getSpecialityPerSchool(SectorId) {
522

523
524
        let SectorIdNew = SectorId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
525
526
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
527
        });
Open Source Developer's avatar
trans    
Open Source Developer committed
528
529
530
531
532
        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
533
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/specialityperschool/` + SectorIdNew, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
534
            .map(response => response.json());
535
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
536
537
538



539
    getStudentPerSchool(SelectId, classId, limitdown, limitup) {
540

541
        let SelectIdNew = SelectId.toString();
542
543


544
        this.loginInfo$.getValue().forEach(loginInfoToken => {
545
546
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
547
        });
548

Open Source Developer's avatar
trans    
Open Source Developer committed
549
550
551
552
553
        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
554
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/studentperschool/` + SelectIdNew + '/' + classId + '/' + limitdown + '/' + limitup, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
555
            .map(response => response.json());
556
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
557

Open Source Developer's avatar
transf    
Open Source Developer committed
558
559


Open Source Developer's avatar
trans    
Open Source Developer committed
560
    saveConfirmStudents(students, type) {
561
        this.loginInfo$.getValue().forEach(loginInfoToken => {
562
563
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
564
565
        });
        let headers = new Headers({
566
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
567
568
569
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
570
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students, type }, options)
Open Source Developer's avatar
Open Source Developer committed
571
            .map(response => response.json());
572
573


574
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
575
576


Open Source Developer's avatar
Open Source Developer committed
577

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

580
        this.loginInfo$.getValue().forEach(loginInfoToken => {
581
582
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
583
584
        });
        let headers = new Headers({
585
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
586
587
588
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
Open Source Developer committed
589
        return this.http.post(`${AppSettings.API_ENDPOINT}/epal/savecapacity/` + taxi + '/' + tomeas + '/' + specialit, { capacity }, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
590
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
591

592
    }
Open Source Developer's avatar
Open Source Developer committed
593

594
595
596
597
598
599
600
601
    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) => {
602
            this.http.post(`${AppSettings.API_ENDPOINT}/ministry/login`, { username: username, userpassword: userpassword }, options)
603
604
605
606
607
608
609
610
611
612
613
614
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error Sending Ministry Credentials");
                },
                () => console.log(""));
        });

    }

615
616
617
618
619
620
    makeDistribution(username, userpassword) {

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

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

        return new Promise((resolve, reject) => {
625
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution`, { username: username, userpassword: userpassword }, options)
626
627
628
629
630
631
632
633
634
635
636
637
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    reject("Error POST in makeDistribution");
                },
                () => console.log(""));
        });

    }

638

639
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel, distribfinal) {
640
641
642
643
644

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

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

648
        if (routepath == "/ministry/general-report/") {
649
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath, options)
650
651
652
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-completeness/") {
653
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/" + schsel, options)
654
655
                .map(response => response.json());
        }
656
657
658
        else if (routepath == "/ministry/report-all-stat/") {
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/" + schsel + "/" +
                clsel + "/" + secsel + "/" + coursel + "/" + distribfinal, options)
659
                .map(response => response.json());
660
661
662
663
        }
        else if (routepath == "/ministry/report-no-capacity/") {
            let capacityFilter = 0;
            if (regionsel)
664
                capacityFilter = 1;
665
666
667
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + capacityFilter, options)
                .map(response => response.json());
        }
668
669
670

    }

671
    informUnlocatedStudents(username, userpassword, unallocated) {
672

673
674
675
676
677
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createMinistryAuthorizationHeader(headers, username, userpassword);
        let options = new RequestOptions({ headers: headers });
678

679
        let route = "";
680
        if (unallocated == 1)
681
            route = "ministry/send-unallocated-massive-mail";
682
683
684
        else if(unallocated == 2)
            route = "ministry/send-unallocated-sc-massive-mail";
        else if(unallocated == 3)
685
            route = "ministry/send-located-massive-mail";
686

687
688
        return this.http.get(`${AppSettings.API_ENDPOINT}/` + route, options)
            .map(response => response.json());
689
690
    }

Open Source Developer's avatar
Open Source Developer committed
691

692
    getSchools() {
Open Source Developer's avatar
trans    
Open Source Developer committed
693
694
695
696
697
698
699
700
701
702

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

707
    getCoursePerPerfecture(PerfectureId) {
Open Source Developer's avatar
trans    
Open Source Developer committed
708
709
710
711
712
713
714
715
716
717
718
719
720
        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
721

Open Source Developer's avatar
Open Source Developer committed
722
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/coursespersch/` + PerfectureIdNew , options)
Open Source Developer's avatar
bug    
Open Source Developer committed
723

Open Source Developer's avatar
trans    
Open Source Developer committed
724
            .map(response => response.json());
725
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
726

727
    getRegions(username, userpassword) {
728

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

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

736
737
738
739
        //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());
740

741
    }
742

743
    getAdminAreas(username, userpassword, regionid) {
744

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

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

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

756
    getSchoolsPerRegion(username, userpassword, regionid) {
757

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

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

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

769
    getSchoolsPerAdminArea(username, userpassword, adminid) {
770

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

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

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

782

783
    getUserRegistryNo(username, userpassword) {
784

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

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

792
793
794
        return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`, options)
            .map(response => response.json());
    }
795

796
    retrieveAdminSettings(username, userpassword) {
797

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

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

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

809
    storeAdminSettings(username, userpassword, capac, dirview, applogin, appresults)  {
810

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

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

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


824
    getSectors(username, userpassword, classid) {
825

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

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

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

837
    getCourses(username, userpassword, sectorid) {
838

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

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

846
847
848
        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
849

Open Source Developer's avatar
Open Source Developer committed
850

Open Source Developer's avatar
trans    
Open Source Developer committed
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
    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
866

867
    getCapacityPerSchool(taxi, tomeas, specialit) {
868

Open Source Developer's avatar
trans    
Open Source Developer committed
869
870
871
872
873
874
875
876
877
        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
878
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/findcapacity/` + taxi + '/' + tomeas + '/' + specialit, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
879
880
881
            .map(response => response.json());

    }
Open Source Developer's avatar
trans    
Open Source Developer committed
882

883
    getSchoolId() {
Open Source Developer's avatar
trans    
Open Source Developer committed
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898