helper-data-service.ts 41.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
    getCourseFields() {
158

159
        this.loginInfo$.getValue().forEach(loginInfoToken => {
160
161
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
162
        });
163
164
165
        let headers = new Headers({
            "Content-Type": "application/json",
        });
166
        this.createAuthorizationHeader(headers);
167
        let options = new RequestOptions({ headers: headers });
168
        return new Promise((resolve, reject) => {
169
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
170
171
172
                .map(response => <ICourseField[]>response.json())
                .subscribe(data => {
                    resolve(data);
173
                },
174
                error => {
175
                    console.log("Error HTTP GET Service");
176
177
                    reject("Error HTTP GET Service");
                },
178
                () => console.log("Course Fields Received"));
179
180
        });
    };
181

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

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

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

228
            this.http.get(getConnectionString, options)
229
230
231
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(data));
232
                },
233
                error => {
234
                    console.log("Error HTTP GET Service in getRegionsWithSchools method");
235
236
                    reject("Error HTTP GET Service");
                },
237
                () => console.log("region schools service"));
238
239
240
        });
    };

241
    getSectorsWithCourses() {
242
        this.loginInfo$.getValue().forEach(loginInfoToken => {
243
244
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
245
246
247
248
249
250
        });
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
251
        return new Promise((resolve, reject) => {
252
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
253
254
255
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformSectorCoursesSchema(data));
256
                },
257
                error => {
258
                    console.log("Error HTTP GET Service");
259
260
                    reject("Error HTTP GET Service");
                },
261
                () => console.log("region schools service"));
262
263
264
        });
    };

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

        trackRegionId = "";
        trackIndex = -1;

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

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

        trackSectorId = "";
        trackIndex = -1;

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

307
    getCriteria() {
308

309
        this.loginInfo$.getValue().forEach(loginInfoToken => {
310
311
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
312
313
314
315
316
317
318
319
        });
        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)
320
321
322
323
                //this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list?category=${category}`, options)
                .map(response => <ISectorField[]>response.json())
                .subscribe(data => {
                    resolve(data);
324
                },
325
                error => {
326
                    console.log("Error HTTP GET Service");
327
328
                    reject("Error HTTP GET Service");
                },
329
                () => console.log("Sector Fields Received"));
330
331
        });
    };
Open Source Developer's avatar
Open Source Developer committed
332

333
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
334
335

        this.authToken = oauthtoken;
336
        this.authRole = oauthrole;
337

Open Source Developer's avatar
Open Source Developer committed
338
339
        let headers = new Headers({
            "Content-Type": "application/json",
340
            "Access-Control-Allow-Credentials": "true",
Open Source Developer's avatar
Open Source Developer committed
341
342
343
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
344
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
345
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
346
347
                .map(response => response.json())
                .subscribe(data => {
348
                    window.onbeforeunload = function (e) {
349
                        let confirmationMessage = "\o/";
350
351
352
                        e.returnValue = confirmationMessage;
                        return confirmationMessage;
                    };
353
                    resolve(this.transformUserSchema(data, oauthtoken, oauthrole));
354
                },
355
                error => {
356
                    console.log("Error HTTP GET Service");
357
358
359
                    reject("Error HTTP GET Service");
                },
                () => console.log("UserName Received"));
Open Source Developer's avatar
Open Source Developer committed
360
        });
361
    }
Open Source Developer's avatar
Open Source Developer committed
362

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

Open Source Developer's avatar
Open Source Developer committed
369

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

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

390
    }
Open Source Developer's avatar
Open Source Developer committed
391

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

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

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

416
        return new Promise((resolve, reject) => {
417
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options)
418
                .map(response => response.json())
419
                .subscribe(data => {
420
                    this._cookieService.removeAll();
421
                    window.onbeforeunload = function () { console.log("unloading") };
422
                    resolve(data);
423
                },
424
                error => {
425
                    console.log("Error Logout");
426
427
                    reject("Error Logout");
                },
428
                () => console.log("Logging out"));
429
430
        });
    }
Open Source Developer's avatar
Open Source Developer committed
431

432
433
434
435
436
437
438
439
440
441
442
443
444
    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 => {
445
                    console.log("Error Logout");
446
447
                    reject("Error Logout");
                },
448
                () => console.log("Logging out"));
449
450
451
        });
    }

Open Source Developer's avatar
tranfer    
Open Source Developer committed
452
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
453

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

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

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


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


Open Source Developer's avatar
Open Source Developer committed
501
    getSectorPerSchool() {
502

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

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

Open Source Developer's avatar
Open Source Developer committed
517

518
    getSpecialityPerSchool(SectorId) {
519

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



536
    getStudentPerSchool(SelectId, classId, limitdown, limitup) {
537

538
        let SelectIdNew = SelectId.toString();
539
540


541
        this.loginInfo$.getValue().forEach(loginInfoToken => {
542
543
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
544
        });
545

Open Source Developer's avatar
trans    
Open Source Developer committed
546
547
548
549
550
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
551
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/studentperschool/` + SelectIdNew + "/" + classId + "/" + limitdown + "/" + limitup, options)
Open Source Developer's avatar
trans    
Open Source Developer committed
552
            .map(response => response.json());
553
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
554

Open Source Developer's avatar
transf    
Open Source Developer committed
555
556


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


571
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
572
573


Open Source Developer's avatar
Open Source Developer committed
574

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

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

589
    }
Open Source Developer's avatar
Open Source Developer committed
590

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

    }

612
613
614
615
616
617
    makeDistribution(username, userpassword) {

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

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

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

    }

635

636
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel, distribfinal) {
637
638
639
640
641

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

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

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

    }

668
    informUnlocatedStudents(username, userpassword, unallocated) {
669

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

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

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

Open Source Developer's avatar
Open Source Developer committed
688

689
    getSchools() {
Open Source Developer's avatar
trans    
Open Source Developer committed
690
691
692
693
694
695
696
697
698
699

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

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

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

723
    getRegions(username, userpassword) {
724

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

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

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

737
    }
738

739
    getAdminAreas(username, userpassword, regionid) {
740

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

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

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

752
    getSchoolsPerRegion(username, userpassword, regionid) {
753

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

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

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

765
    getSchoolsPerAdminArea(username, userpassword, adminid) {
766

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

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

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

778

779
    getUserRegistryNo(username, userpassword) {
780

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

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

788
789
790
        return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`, options)
            .map(response => response.json());
    }
791

792
    retrieveAdminSettings(username, userpassword) {
793

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

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

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

805
    storeAdminSettings(username, userpassword, capac, dirview, applogin, appresults, secondperiod) {
806

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

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

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


820
    getSectors(username, userpassword, classid) {
821

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

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

829
830
831
        return this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
            .map(response => response.json());
    }
Νίκος Κατσαούνος's avatar