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

18
19
20
21

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

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

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

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

36

37
    };
38

39
40
41
42
43
44
    ngOnInit() {
        this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
45
46
                    //this.minedu_userName = loginInfoToken.minedu_username;
                    //this.minedu_userPassword = loginInfoToken.minedu_userpassword;
47
48
49
                    console.log("Auth details..");
                    console.log(this.authToken);
                    console.log(this.authRole);
50
51
52
53
54
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
55

56
57
58
59
60
    }

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

62
    createAuthorizationHeader(headers: Headers) {
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
118
119
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
120
121
        });
        this.createAuthorizationHeader(headers);
122
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
123
124
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
125
126
127
128
129
130
131
132
133
134
            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); */
135
136
137
        });
    }

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

162
    getCourseFields() {
163

164
        this.loginInfo$.getValue().forEach(loginInfoToken => {
165
166
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
167
        });
168
169
170
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
171

172
173
174
175
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
176
            "X-CSRF-Token": "EHu964c7gN7M399UfHiHHv06x1Tx5cl-P-9ZyMdmGbw",
177
178
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
179
        });
180
        this.createAuthorizationHeader(headers);
181
        let options = new RequestOptions({ headers: headers });
182
        return new Promise((resolve, reject) => {
183
            this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`, options)
184
185
186
187
188
189
190
191
192
                .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); */
193
194
        });
    };
195

196
    getSectorFields() {
197
        this.loginInfo$.getValue().forEach(loginInfoToken => {
198
199
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
200
201
202
203
204
205
206
207
208
        });
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
209
210
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
211
212
213
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
214
        return new Promise((resolve, reject) => {
215
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
216
217
218
219
220
221
222
223
224
                .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); */
225
226
227
        });
    };

228
    getRegionsWithSchools(classActive, courseActive) {
229
        this.loginInfo$.getValue().forEach(loginInfoToken => {
230
231
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
232
        });
233
234
235
236
237
238
239
240
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
241
242
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
243
        });
244
        this.createAuthorizationHeader(headers);
245
        let options = new RequestOptions({ headers: headers });
246
        return new Promise((resolve, reject) => {
247
            let getConnectionString = null;
248
249
250

            //if (courseActive === -1)
            if (classActive === 1)
251
252
253
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
254
            else if (classActive === 3)
255
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
256

257
            this.http.get(getConnectionString, options)
258
259
260
261
262
263
264
265
266
                .map(response => response.json())
                .subscribe(data => {
                    resolve(this.transformRegionSchoolsSchema(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); */
267
268
269
        });
    };

270
    getSectorsWithCourses() {
271
        this.loginInfo$.getValue().forEach(loginInfoToken => {
272
273
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
274
275
276
277
278
279
280
281
282
        });
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
            "Content-Type": "application/json",
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
283
284
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
285
286
287
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
288
        return new Promise((resolve, reject) => {
289
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
290
291
292
293
294
295
296
297
298
                .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); */
299
300
301
        });
    };

302
303
304
305
306
307
308
309
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

310
        let j = 0;
311
312
313
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
314
                rsa.push(<IRegion>{ 'region_id': regionSchool.region_id, 'region_name': regionSchool.region_name, 'epals': Array<IRegionSchool>() });
315
316
                trackRegionId = regionSchool.region_id;
            }
317
            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 });
318
319
320
321
322
            j++;
        });
        return rsa;
    }

323
324
325
326
327
328
329
330
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

331
        let j = 0;
332
333
334
        sectorCourses.forEach(sectorCourse => {
            if (trackSectorId !== sectorCourse.sector_id) {
                trackIndex++;
335
                rsa.push(<ISector>{ 'sector_id': sectorCourse.sector_id, 'sector_name': sectorCourse.sector_name, 'sector_selected': false, 'courses': Array<ISectorCourse>() });
336
337
                trackSectorId = sectorCourse.sector_id;
            }
338
            rsa[trackIndex].courses.push(<ISectorCourse>{ 'course_id': sectorCourse.course_id, 'course_name': sectorCourse.course_name, 'globalIndex': j, 'selected': false });
339
340
341
342
343
            j++;
        });
        return rsa;
    }

344
    getCriteria() {
345

346
        this.loginInfo$.getValue().forEach(loginInfoToken => {
347
348
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
349
350
351
352
353
354
355
356
357
        });
        let headers = new Headers({
            "Content-Type": "application/json",
            "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list`, options)
358
359
360
361
362
363
364
365
366
367
                //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); */
368
369
        });
    };
Open Source Developer's avatar
Open Source Developer committed
370

371
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
372
373

        this.authToken = oauthtoken;
374
        this.authRole = oauthrole;
375
376
377

        //console.log("MIPOS");

Open Source Developer's avatar
Open Source Developer committed
378
        let headers = new Headers({
379
380
//             "Authorization": "Basic " + btoa(this.authToken + ':' + this.authToken),
    //        "Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
Open Source Developer's avatar
Open Source Developer committed
381
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
382
//            "Authorization": "Basic " + "aGFyaXNwOmhhcmlzcGFzcw==",
Open Source Developer's avatar
Open Source Developer committed
383
            "Content-Type": "application/json",
384
            "Access-Control-Allow-Credentials": "true",
Open Source Developer's avatar
Open Source Developer committed
385
386
387
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
388
        //    "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
389
390
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
Open Source Developer's avatar
Open Source Developer committed
391
392
393
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
394
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
395
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
396
397
398
399
400
401
402
403
404
                .map(response => response.json())
                .subscribe(data => {
                    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
405
        });
406
    }
Open Source Developer's avatar
Open Source Developer committed
407

408
409
410
411
412
413
    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
414

415
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
416
        let rsa = Array<ILoginInfoToken>();
417

418
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
419
        return rsa;
420

421
    }
Open Source Developer's avatar
Open Source Developer committed
422

423
    signOut() {
424
        //loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
425
        this.loginInfo$.getValue().forEach(loginInfoToken => {
426
427
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
428
        });
429

430
        let headers = new Headers({
431
            "Content-Type": "application/json",
432

433
        });
434

435
        if (this.authRole === MINISTRY_ROLE)
436
437
438
          this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
        else
          this.createAuthorizationHeader(headers);
439
        let options = new RequestOptions({ headers: headers, withCredentials: true });
440
        let logoutRoute = '/oauth/logout';
441
        if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE) {
442
          logoutRoute = '/cas/logout';
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

          return new Promise((resolve, reject) => {
              this.http.get(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, options)
                  .map(response => response)
                  .subscribe(data => {
                      this._cookieService.removeAll();
                      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); */
          });
        }
458
        else if (this.authRole === MINISTRY_ROLE)
459
          logoutRoute = '/ministry/logout';
460

461
        return new Promise((resolve, reject) => {
462
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, {}, options)
463
464
                .map(response => response)
                .subscribe(data => {
465
                    this._cookieService.removeAll();
466
467
468
469
470
471
472
                    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); */
473
474
        });
    }
Open Source Developer's avatar
Open Source Developer committed
475
476


Open Source Developer's avatar
Open Source Developer committed
477
478


Open Source Developer's avatar
tranfer    
Open Source Developer committed
479
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
480

481

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

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

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


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


528
529
530
    getSectorPerSchool(SchoolId) {
        let SchoolIdNew = SchoolId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
531
532
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
533
        });
Open Source Developer's avatar
transf    
Open Source Developer committed
534
535
536
537
538
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
539
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperSchool/` + SchoolIdNew, options)
Open Source Developer's avatar
transf    
Open Source Developer committed
540
            .map(response => response.json());
541
    }
Open Source Developer's avatar
transf    
Open Source Developer committed
542

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



Open Source Developer's avatar
paging    
Open Source Developer committed
561
    getStudentPerSchool(SchoolId, SelectId, classId, limitdown, limitup) {
562
563
        let SchoolIdNew = SchoolId.toString();
        let SelectIdNew = SelectId.toString();
564
565


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

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

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


Open Source Developer's avatar
trans    
Open Source Developer committed
582
    saveConfirmStudents(students, type) {
583
        this.loginInfo$.getValue().forEach(loginInfoToken => {
584
585
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans    
Open Source Developer committed
586
587
        });
        let headers = new Headers({
588
            "Content-Type": "application/json",
Open Source Developer's avatar
trans    
Open Source Developer committed
589
590
591
592
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
trans    
Open Source Developer committed
593
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students, type}, options)
594
595
596
597
598
599
600
601
602
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Profile");
                    reject("Error Saving Profile");
                },
                () => console.log("Saving Profile"));
Open Source Developer's avatar
trans    
Open Source Developer committed
603
604
        });

605
    }
Open Source Developer's avatar
trans    
Open Source Developer committed
606
607


Open Source Developer's avatar
Open Source Developer committed
608

609
    saveCapacity(taxi, tomeas, specialit, capacity, schoolid) {
Open Source Developer's avatar
Open Source Developer committed
610

611
        this.loginInfo$.getValue().forEach(loginInfoToken => {
612
613
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
614
615
        });
        let headers = new Headers({
616
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
617
618
619
620
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
621
622
623
624
625
626
627
628
629
630
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/savecapacity/` + taxi + '/' + tomeas + '/' + specialit + '/' + schoolid, { capacity }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Capacity");
                    reject("Error Saving Capacity");
                },
                () => console.log("Saving Capacity"));
Open Source Developer's avatar
Open Source Developer committed
631
632
        });

633
    }
Open Source Developer's avatar
Open Source Developer committed
634

635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
    sendMinisrtyCredentials(username, userpassword) {

        let headers = new Headers({
            "Content-Type": "application/json",
            //"Accept": "*/*",
            //"Access-Control-Allow-Credentials": "true",
            //"X-CSRF-Token": "..."
            //"Authorization": "Basic " + btoa("..."),
        });
        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(""));
        });

    }

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
    makeDistribution(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}/epal/distribution/` , options)
        //    .map(response => response.json());

        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(""));
        });

    }

686

687
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel, clsel, secsel, coursel) {
688
689
690
691
692
693
694
695

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

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

696
697
        //console.log("Testing..");
        //console.log(`${AppSettings.API_ENDPOINT}` + routepath + regionsel);
698

699
700
701
702
703
704
705
706
707
708
709
710
711
        if (routepath == "/ministry/general-report/") {
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath  , options)
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-completeness/") {
          return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/"  + schsel  , options)
                .map(response => response.json());
        }
        else if (routepath == "/ministry/report-all-stat/"){
            return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/"  + schsel + "/"  +
                                  clsel + "/"  + secsel + "/"  + coursel , options)
                .map(response => response.json());
          }
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
    informUnlocatedStudents(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/send-massive-mail`, {username: username, userpassword: userpassword}, options)
              .map(response => response.json())
              .subscribe(data => {
                  resolve(data);
              },
              error => {
                  reject("Error POST in informUnlocatedStudents");
              },
              () => console.log(""));
      });
      */
      return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/send-massive-mail` , options)
          .map(response => response.json());
    }

Open Source Developer's avatar
Open Source Developer committed
739

Open Source Developer's avatar
trans    
Open Source Developer committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
    getSchoolPerPerfecture(PerfectureId) {
        console.log(PerfectureId,"a");
        let PerfectureIdNew = PerfectureId.toString();

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

        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
Open Source Developer's avatar
trans    
Open Source Developer committed
756
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/ScoolperPerf/` + PerfectureIdNew , options)
Open Source Developer's avatar
trans    
Open Source Developer committed
757
758
759
            .map(response => response.json());
    }

Open Source Developer's avatar
trans    
Open Source Developer committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
    getCoursePerPerfecture(PerfectureId){
        console.log(PerfectureId,"a");
        let PerfectureIdNew = PerfectureId.toString();


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

        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());
}

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
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}` + routepath , options)
  //    .map(response => response.json());

  console.log("Test");
  console.log(`${AppSettings.API_ENDPOINT}/adminfields/list/?region=` + regionid);
  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 });

  console.log("Test2");
  console.log(`${AppSettings.API_ENDPOINT}/schoolfields_per_region/list/?region=` + regionid);
  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 });

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

845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861

getUserRegistryNo(username, userpassword)  {

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

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

  //console.log("Test");
  return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/retrieve-registry-id`  , options)
      .map(response => response.json());
}



862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
getSectors(username, userpassword, classid)  {

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

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

  console.log("Test");
  console.log(`${AppSettings.API_ENDPOINT}/sectorfields/list`);
  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
890

Open Source Developer's avatar
Open Source Developer committed
891

Open Source Developer's avatar
trans    
Open Source Developer committed
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
    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
907

Open Source Developer's avatar
trans    
Open Source Developer committed
908
909
910
getCapacityPerSchool(taxi, tomeas, specialit, schoolid) {


911

Open Source Developer's avatar
trans    
Open Source Developer committed
912
913
914
915
916
917
918
919
920
921
922
923
924
        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/findCapacity/` + taxi + '/' + tomeas + '/' + specialit + '/' + schoolid, options)
            .map(response => response.json());

    }
Open Source Developer's avatar
trans    
Open Source Developer committed
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951

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());

    }









952
}