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

401 402 403 404 405 406
    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
407

408
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
409
        let rsa = Array<ILoginInfoToken>();
410

411
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
412
        return rsa;
413

414
    }
Open Source Developer's avatar
Open Source Developer committed
415

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

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

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

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


Open Source Developer's avatar
Open Source Developer committed
460 461


Open Source Developer's avatar
tranfer  
Open Source Developer committed
462
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
463

464

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

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

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


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


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

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



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


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

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

Open Source Developer's avatar
transf  
Open Source Developer committed
563 564


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

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


Open Source Developer's avatar
Open Source Developer committed
591

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

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

616
    }
Open Source Developer's avatar
Open Source Developer committed
617

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

    }

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

    }

669 670

    makeReport(username, userpassword, routepath) {
671 672 673 674 675 676 677 678

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

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

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

    }

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
    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
708

Open Source Developer's avatar
trans  
Open Source Developer committed
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
    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
727
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/ScoolperPerf/` + PerfectureIdNew , options)
Open Source Developer's avatar
trans  
Open Source Developer committed
728 729 730
            .map(response => response.json());
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
    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());
}


Open Source Developer's avatar
Open Source Developer committed
754

Open Source Developer's avatar
Open Source Developer committed
755

756
}