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

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

@Injectable()
20
export class HelperDataService implements OnInit, OnDestroy {
21 22

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

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

33
    };
34

35 36 37 38 39 40
    ngOnInit() {
        this._ngRedux.select(state => {
            if (state.loginInfo.size > 0) {
                state.loginInfo.reduce(({}, loginInfoToken) => {
                    this.authToken = loginInfoToken.auth_token;
                    this.authRole = loginInfoToken.auth_role;
41 42
                    //this.minedu_userName = loginInfoToken.minedu_username;
                    //this.minedu_userPassword = loginInfoToken.minedu_userpassword;
43 44 45 46 47
                    return loginInfoToken;
                }, {});
            }
            return state.loginInfo;
        }).subscribe(this.loginInfo$);
48

49 50 51 52 53
    }

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

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

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

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

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

    verifyVerificationCode(verificationCode) {
105
        this.loginInfo$.getValue().forEach(loginInfoToken => {
106 107
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
108 109
        });
        let headers = new Headers({
110 111 112
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
113 114
        });
        this.createAuthorizationHeader(headers);
115
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
116 117
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
118 119 120 121 122 123 124 125 126 127
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/verifyvercode`, { verificationCode: verificationCode }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(<any>data);
                }, // put the data returned from the server in our variable
                error => {
                    console.log("Error Verifying Verification Code"); // in case of failure show this message
                    reject("Error Verifying Verification Code");
                },
                () => console.log("Verifying Verification Code"));//run this code in all cases); */
128 129 130
        });
    }

131
    saveProfile(userProfile) {
132
        this.loginInfo$.getValue().forEach(loginInfoToken => {
133 134
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
135 136
        });
        let headers = new Headers({
137
            "Content-Type": "application/json",
138 139 140 141
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
142 143 144 145 146 147 148 149 150 151
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/user/save`, { userProfile: userProfile }, options)
                .map(response => response.json())
                .subscribe(data => {
                    resolve(data);
                },
                error => {
                    console.log("Error Saving Profile");
                    reject("Error Saving Profile");
                },
                () => console.log("Saving Profile"));
152 153 154
        });
    }

155
    getCourseFields() {
156

157
        this.loginInfo$.getValue().forEach(loginInfoToken => {
158 159
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
160
        });
161 162 163
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
164

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

189
    getSectorFields() {
190
        this.loginInfo$.getValue().forEach(loginInfoToken => {
191 192
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
193 194 195 196 197 198 199 200 201
        });
        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",
202 203
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
204 205 206
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
207
        return new Promise((resolve, reject) => {
208
            this.http.get(`${AppSettings.API_ENDPOINT}/sectorfields/list`, options)
209 210 211 212 213 214 215 216 217
                .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); */
218 219 220
        });
    };

221
    getRegionsWithSchools(classActive, courseActive) {
222
        this.loginInfo$.getValue().forEach(loginInfoToken => {
223 224
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
225
        });
226 227 228 229 230 231 232 233
        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",
234 235
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
236
        });
237
        this.createAuthorizationHeader(headers);
238
        let options = new RequestOptions({ headers: headers });
239
        return new Promise((resolve, reject) => {
240
            let getConnectionString = null;
241 242 243

            //if (courseActive === -1)
            if (classActive === 1)
244 245 246
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
247
            else if (classActive === 3)
248
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
249

250
            this.http.get(getConnectionString, options)
251 252 253 254 255 256 257 258 259
                .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); */
260 261 262
        });
    };

263
    getSectorsWithCourses() {
264
        this.loginInfo$.getValue().forEach(loginInfoToken => {
265 266
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
267 268 269 270 271 272 273 274 275
        });
        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",
276 277
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
278 279 280
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
281
        return new Promise((resolve, reject) => {
282
            this.http.get(`${AppSettings.API_ENDPOINT}/coursesectorfields/list`, options)
283 284 285 286 287 288 289 290 291
                .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); */
292 293 294
        });
    };

295 296 297 298 299 300 301 302
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

303
        let j = 0;
304 305 306
        regionSchools.forEach(regionSchool => {
            if (trackRegionId !== regionSchool.region_id) {
                trackIndex++;
307
                rsa.push(<IRegion>{ 'region_id': regionSchool.region_id, 'region_name': regionSchool.region_name, 'epals': Array<IRegionSchool>() });
308 309
                trackRegionId = regionSchool.region_id;
            }
310
            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 });
311 312 313 314 315
            j++;
        });
        return rsa;
    }

316 317 318 319 320 321 322 323
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

324
        let j = 0;
325 326 327
        sectorCourses.forEach(sectorCourse => {
            if (trackSectorId !== sectorCourse.sector_id) {
                trackIndex++;
328
                rsa.push(<ISector>{ 'sector_id': sectorCourse.sector_id, 'sector_name': sectorCourse.sector_name, 'sector_selected': false, 'courses': Array<ISectorCourse>() });
329 330
                trackSectorId = sectorCourse.sector_id;
            }
331
            rsa[trackIndex].courses.push(<ISectorCourse>{ 'course_id': sectorCourse.course_id, 'course_name': sectorCourse.course_name, 'globalIndex': j, 'selected': false });
332 333 334 335 336
            j++;
        });
        return rsa;
    }

337
    getCriteria() {
338

339
        this.loginInfo$.getValue().forEach(loginInfoToken => {
340 341
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
342 343 344 345 346 347 348 349 350
        });
        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)
351 352 353 354 355 356 357 358 359 360
                //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); */
361 362
        });
    };
Open Source Developer's avatar
Open Source Developer committed
363

364
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
365 366

        this.authToken = oauthtoken;
367
        this.authRole = oauthrole;
368 369 370

        //console.log("MIPOS");

Open Source Developer's avatar
Open Source Developer committed
371 372 373 374 375 376 377 378
        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",
379 380
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
Open Source Developer's avatar
Open Source Developer committed
381 382 383
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
384
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
385
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
386 387 388 389 390 391 392 393 394
                .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
395
        });
396
    }
Open Source Developer's avatar
Open Source Developer committed
397

398 399 400 401 402 403
    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
404

405
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
406
        let rsa = Array<ILoginInfoToken>();
407

408
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
409
        return rsa;
410

411
    }
Open Source Developer's avatar
Open Source Developer committed
412

413
    signOut() {
414
        //loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
415
        this.loginInfo$.getValue().forEach(loginInfoToken => {
416 417
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
418
        });
419

420 421
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
422
            "Content-Type": "application/json",
423 424
            "Accept": "*/*",
            "Access-Control-Allow-Credentials": "true",
425
            "Access-Control-Allow-Origin": "*",
426
            //"X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
427 428
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
429
        });
430

431
        if (this.authRole === MINISTRY_ROLE)
432 433 434
          this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
        else
          this.createAuthorizationHeader(headers);
435
        let options = new RequestOptions({ headers: headers, withCredentials: true });
436
        let logoutRoute = '/oauth/logout';
437
        if (this.authRole === SCHOOL_ROLE || this.authRole === PDE_ROLE || this.authRole === DIDE_ROLE)
438
          logoutRoute = '/cas/logout';
439
        else if (this.authRole === MINISTRY_ROLE)
440
          logoutRoute = '/ministry/logout';
441

442
        return new Promise((resolve, reject) => {
443
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}`, {}, options)
444 445 446 447 448 449 450 451 452
                .map(response => response)
                .subscribe(data => {
                    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); */
453 454
        });
    }
Open Source Developer's avatar
Open Source Developer committed
455 456


Open Source Developer's avatar
Open Source Developer committed
457 458


Open Source Developer's avatar
tranfer  
Open Source Developer committed
459
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
460

461

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

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

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


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


509 510 511
    getSectorPerSchool(SchoolId) {
        let SchoolIdNew = SchoolId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
512 513
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
514
        });
Open Source Developer's avatar
transf  
Open Source Developer committed
515 516 517 518 519
        let headers = new Headers({
            "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
520
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/sectorperSchool/` + SchoolIdNew, options)
Open Source Developer's avatar
transf  
Open Source Developer committed
521
            .map(response => response.json());
522
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
523

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



Open Source Developer's avatar
paging  
Open Source Developer committed
542
    getStudentPerSchool(SchoolId, SelectId, classId, limitdown, limitup) {
543 544
        let SchoolIdNew = SchoolId.toString();
        let SelectIdNew = SelectId.toString();
545 546


547
        this.loginInfo$.getValue().forEach(loginInfoToken => {
548 549
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
550
        });
551

Open Source Developer's avatar
trans  
Open Source Developer committed
552 553 554 555 556
        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
557
        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
558
            .map(response => response.json());
559
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
560

Open Source Developer's avatar
transf  
Open Source Developer committed
561 562


563
    saveConfirmStudents(students) {
564
        this.loginInfo$.getValue().forEach(loginInfoToken => {
565 566
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans  
Open Source Developer committed
567 568
        });
        let headers = new Headers({
569
            "Content-Type": "application/json",
Open Source Developer's avatar
trans  
Open Source Developer committed
570 571 572 573
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
574 575 576 577 578 579 580 581 582 583
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, { students }, options)
                .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
584 585
        });

586
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
587 588


Open Source Developer's avatar
Open Source Developer committed
589

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

592
        this.loginInfo$.getValue().forEach(loginInfoToken => {
593 594
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
595 596
        });
        let headers = new Headers({
597
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
598 599 600 601
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
602 603 604 605 606 607 608 609 610 611
            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
612 613
        });

614
    }
Open Source Developer's avatar
Open Source Developer committed
615

616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
    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(""));
        });

    }

641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
    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(""));
        });

    }

667 668

    makeReport(username, userpassword, routepath) {
669 670 671 672 673 674 675 676

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

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

677
        return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath , options)
678 679 680 681
            .map(response => response.json());

    }

Open Source Developer's avatar
Open Source Developer committed
682

Open Source Developer's avatar
trans  
Open Source Developer committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
    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
701
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/ScoolperPerf/` + PerfectureIdNew , options)
Open Source Developer's avatar
trans  
Open Source Developer committed
702 703 704
            .map(response => response.json());
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
    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());
}


    getLimitPerCateg(categ, classes){
Open Source Developer's avatar
trans  
Open Source Developer committed
729 730
        console.log(categ,classes,"aaaa");
       // let classesNew = classes.toString();
Open Source Developer's avatar
trans  
Open Source Developer committed
731 732 733 734 735 736 737 738 739 740 741 742 743


        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
trans  
Open Source Developer committed
744
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/LimitPerCateg/` + categ + classes , options)
Open Source Developer's avatar
trans  
Open Source Developer committed
745 746
            .map(response => response.json());
}
Open Source Developer's avatar
trans  
Open Source Developer committed
747 748 749



Open Source Developer's avatar
Open Source Developer committed
750

Open Source Developer's avatar
Open Source Developer committed
751

752
}