helper-data-service.ts 36.8 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
34
        private _ngRedux: NgRedux<IAppState>,
        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("NAIIIIII!");
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
64
65
66
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

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
99
100
101
102
103
104
            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); */
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
124
125
126
127
128
129
            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); */
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
173
174
175
176
177
178
                .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); */
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
197
198
199
200
201
202
                .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); */
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
232
233
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(data));
                }, // put the data returned from the server in our variable
                error => {
234
                    console.log("Error HTTP GET Service in getRegionsWithSchools method"); // in case of failure show this message
235
236
237
                    reject("Error HTTP GET Service");
                },
                () => console.log("region schools service"));//run this code in all cases); */
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
256
257
258
259
260
261
                .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); */
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
324
325
326
327
328
329
                //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); */
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
349
350
351
352
                    window.onbeforeunload = function (e) {
                        var confirmationMessage = "\o/";
                        e.returnValue = confirmationMessage;
                        return confirmationMessage;
                    };
353
354
355
356
357
358
359
                    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
360
        });
361
    }
Open Source Developer's avatar
Open Source Developer committed
362

363
364
365
366
367
368
    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
369

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

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
        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)
        });
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

404
        if (this.authRole === MINISTRY_ROLE)
405
406
407
          this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
        else
          this.createAuthorizationHeader(headers);
408
        let options = new RequestOptions({ headers: headers, withCredentials: true });
409
        let logoutRoute = '/oauth/logout';
410
        if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) {
411
          logoutRoute = '/cas/logout';
412
        }
413
        else if (this.authRole === MINISTRY_ROLE)
414
          logoutRoute = '/ministry/logout';
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
423
424
425
426
427
428
                    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); */
429
430
        });
    }
Open Source Developer's avatar
Open Source Developer committed
431

Open Source Developer's avatar
tranfer    
Open Source Developer committed
432
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
433

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

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

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


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


Open Source Developer's avatar
Open Source Developer committed
481
    getSectorPerSchool() {
482

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

Open Source Developer's avatar
Open Source Developer committed
496
497

    getSpecialityPerSchool( SectorId) {
498

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



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

517
        let SelectIdNew = SelectId.toString();
518
519


520
        this.loginInfo$.getValue().forEach(loginInfoToken => {
521
522
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
523
        });
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/studentperSchool/` + SelectIdNew + '/' + classId + '/' + limitdown + '/' + limitup, 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

Open Source Developer's avatar
transf    
Open Source Developer committed
534
535


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


550
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
551
552


Open Source Developer's avatar
Open Source Developer committed
553

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

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

568
    }
Open Source Developer's avatar
Open Source Developer committed
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
    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(""));
        });

    }

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
    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(""));
        });

    }

614

615
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel, distribfinal) {
616
617
618
619
620
621
622
623

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

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

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 + "/"  +
634
                                  clsel + "/"  + secsel + "/"  + coursel + "/" + distribfinal , options)
635
636
                .map(response => response.json());
          }
637
638
639
640
641
642
643
          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());
            }
644
645
646

    }

647
    informUnlocatedStudents(username, userpassword, unallocated) {
648
649
650
651
652
653

      let headers = new Headers({
          "Content-Type": "application/json",
      });
      this.createMinistryAuthorizationHeader(headers, username, userpassword );
      let options = new RequestOptions({ headers: headers });
654

655
656
657
658
659
      let route="";
      if (unallocated == true)
        route = "ministry/send-unallocated-massive-mail";
      else
        route = "ministry/send-located-massive-mail";
660

661
      return this.http.get(`${AppSettings.API_ENDPOINT}/` + route , options)
662
663
664
          .map(response => response.json());
    }

Open Source Developer's avatar
Open Source Developer committed
665

Open Source Developer's avatar
Open Source Developer committed
666
    getSchoolPerPerfecture(status) {
Open Source Developer's avatar
trans    
Open Source Developer committed
667
668
669
670
671
672
673
674
675
676

        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
677
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/ScoolperPerf/` + status , options)
Open Source Developer's avatar
trans    
Open Source Developer committed
678
679
680
            .map(response => response.json());
    }

Open Source Developer's avatar
trans    
Open Source Developer committed
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
    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());
}

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
744
745
746
747
748
749
750
751
752
753
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());
}

754
755
756
757
758
759
760
761
762
763

getUserRegistryNo(username, userpassword)  {

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

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

764
    return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`  , options)
765
766
767
      .map(response => response.json());
}

768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
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());
}

794
795


796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
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
822

Open Source Developer's avatar
Open Source Developer committed
823

Open Source Developer's avatar
trans    
Open Source Developer committed
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
    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
839

Open Source Developer's avatar
Open Source Developer committed
840
getCapacityPerSchool(taxi, tomeas, specialit) {
841

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

    }
Open Source Developer's avatar
trans    
Open Source Developer committed
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871

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
872
gettypeofschool(){
Open Source Developer's avatar
trans    
Open Source Developer committed
873

Open Source Developer's avatar
Open Source Developer committed
874
875
876
877
878
879
880
881
882
883
884
    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
885

Open Source Developer's avatar
Open Source Developer committed
886
}
Open Source Developer's avatar
trans    
Open Source Developer committed
887

888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
getlimitsofcourse(classid){

    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/getlimitsperCourse/`+ classid , options)
            .map(response => response.json());

}

904
905
906
907
908
909
910
911
912
913
914
915
createPdfServerSide(auth_token, role)  {

  /*
  this.loginInfo$.getValue().forEach(loginInfoToken => {
      this.authToken = loginInfoToken.auth_token;
      this.authRole = loginInfoToken.auth_role;
      console.log("Θα μπει;");
      console.log(this.authToken);
  });
  */

  let headers = new Headers({
916
      //"Content-Type": "application/json",
917
      "Content-Type": "application/json",
918
919
       //"Access-Control-Allow-Origin": "true",

920
921
922
923
924
925
  });
  this.authToken = auth_token;
  this.authRole = role;
  console.log(this.authToken);
  console.log(this.authRole);
  this.createAuthorizationHeader(headers);
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
  let options = new RequestOptions([{ headers: headers }, { responseType: ResponseContentType.Blob }]);
  //let options = new RequestOptions({ headers: headers });
  return this.http.get(`${AppSettings.API_ENDPOINT}/epal/pdf-application/`,   options)

    .map(response => response.json())
    //.map(response => (response.blob())
    //.map((res:Response) => res.blob())
    //.map(response => (<Response>response).blob())
    .subscribe(
        data => {

            console.log("Hello!");
            console.log(data);
            var blob = new Blob([data['pdfString']], {type: 'application/pdf'});
            console.log(blob);
            FileSaver.saveAs(blob, "testData.pdf");
942

943
944
945
946
    },
        err => console.error(err),
    () => console.log('done')
);
947
948


949
  /*
950
951
  return new Promise((resolve, reject) => {
      this.http.post(`${AppSettings.API_ENDPOINT}/epal/pdf-application`, options)
952
          //.map(response => response.json())
953
954
955
          .subscribe(data => {
              resolve(data);
              console.log("Nik");
956
957
958
959

              var blob = new Blob([data['_body']], {type: 'application/pdf'});
              console.log(blob);
              FileSaver.saveAs(blob, "testData.pdf");
960
961
962
963
964
965
966
              //console.log(data['_body']);
          },
          error => {
              reject("Error POST in createPdfServerSide");
          },
          () => console.log("Nikos!!!"));
  });
967
  */
968
969
970
971


}

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

973
}