helper-data-service.ts 26.6 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 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 24
    private authRole: string;
    private loginInfo$: BehaviorSubject<ILoginInfo>;
25 26 27 28

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

31
    };
32

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

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

50
    createAuthorizationHeader(headers: Headers) {
51
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
52 53
    }

54 55 56 57
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

58
    getEpalUserData() {
59
        this.loginInfo$.getValue().forEach(loginInfoToken => {
60 61
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
62 63 64 65 66 67 68 69 70 71
        });
        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());
    };

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

    verifyVerificationCode(verificationCode) {
100
        this.loginInfo$.getValue().forEach(loginInfoToken => {
101 102
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
103 104
        });
        let headers = new Headers({
105 106 107
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
108 109
        });
        this.createAuthorizationHeader(headers);
110
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
111 112
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
113 114 115 116 117 118 119 120 121 122
            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); */
123 124 125
        });
    }

126
    saveProfile(userProfile) {
127
        this.loginInfo$.getValue().forEach(loginInfoToken => {
128 129
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
130 131
        });
        let headers = new Headers({
132
            "Content-Type": "application/json",
133 134 135 136
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
137 138 139 140 141 142 143 144 145 146
            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"));
147 148 149
        });
    }

150
    getCourseFields() {
151

152
        this.loginInfo$.getValue().forEach(loginInfoToken => {
153 154
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
155
        });
156 157 158
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
159

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

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

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

            //if (courseActive === -1)
            if (classActive === 1)
239 240 241
                getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
            else if (classActive === 2)
                getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
242
            else if (classActive === 3)
243
                getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;
244

245
            this.http.get(getConnectionString, options)
246 247 248 249 250 251 252 253 254
                .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); */
255 256 257
        });
    };

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

290 291 292 293 294 295 296 297
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

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

311 312 313 314 315 316 317 318
    transformSectorCoursesSchema(sectorCourses: any) {
        let rsa = Array<ISector>();
        let trackSectorId: string;
        let trackIndex: number;

        trackSectorId = "";
        trackIndex = -1;

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

332
    getCriteria() {
333

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

359
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
360 361

        this.authToken = oauthtoken;
362
        this.authRole = oauthrole;
Open Source Developer's avatar
Open Source Developer committed
363 364 365 366 367 368 369 370
        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",
371 372
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
Open Source Developer's avatar
Open Source Developer committed
373 374 375
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
376
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
377
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
378 379 380 381 382 383 384 385 386
                .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
387
        });
388
    }
Open Source Developer's avatar
Open Source Developer committed
389

Open Source Developer's avatar
Open Source Developer committed
390

391
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
392
        let rsa = Array<ILoginInfoToken>();
393

394
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
395
        return rsa;
396

397
    }
Open Source Developer's avatar
Open Source Developer committed
398

399
    signOut() {
400
        this.loginInfo$.getValue().forEach(loginInfoToken => {
401 402
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
403 404 405 406
        });
        let headers = new Headers({
            //"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
            // "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
Open Source Developer's avatar
Open Source Developer committed
407 408


409
            "Content-Type": "application/json",
410 411
            "Accept": "*/*",
            "Access-Control-Allow-Credentials": "true",
412
            "Access-Control-Allow-Origin": "*",
413 414 415 416
            // "Content-Type": "text/plain",  // try to skip preflight
            //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
            //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
            "X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
417 418
            //            "X-oauth-enabled": "true",
            //            "X-Auth-Token": this.authToken
419 420 421
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers, withCredentials: true });
422 423 424 425
        let logoutRoute = '/oauth/logout';
        if (this.authRole === 'director')
            logoutRoute = '/cas/logout';

426
        return new Promise((resolve, reject) => {
427
            this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}`, {}, options)
428 429 430 431 432 433 434 435 436
                .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); */
437 438
        });
    }
Open Source Developer's avatar
Open Source Developer committed
439 440


Open Source Developer's avatar
Open Source Developer committed
441 442


Open Source Developer's avatar
tranfer  
Open Source Developer committed
443
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
444

445

446
        this.loginInfo$.getValue().forEach(loginInfoToken => {
447 448
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
449 450 451
        });
        let headers = new Headers({
            "Content-Type": "application/json",
452
            "id": ""
Open Source Developer's avatar
Open Source Developer committed
453 454 455
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
456
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/subapplic`, options)
Open Source Developer's avatar
Open Source Developer committed
457
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
458
    }
Open Source Developer's avatar
Open Source Developer committed
459

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

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


477 478 479
    getEpalchosen(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/epalchosen/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
489
            .map(response => response.json());
490
    }
Open Source Developer's avatar
tranfer  
Open Source Developer committed
491 492


493 494 495
    getSectorPerSchool(SchoolId) {
        let SchoolIdNew = SchoolId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
496 497
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
498
        });
Open Source Developer's avatar
transf  
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/sectorperSchool/` + SchoolIdNew, options)
Open Source Developer's avatar
transf  
Open Source Developer committed
505
            .map(response => response.json());
506
    }
Open Source Developer's avatar
transf  
Open Source Developer committed
507

508 509 510 511
    getSpecialityPerSchool(SchoolId, SectorId) {
        let SchoolIdNew = SchoolId.toString();
        let SectorIdNew = SectorId.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
512 513
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
514
        });
Open Source Developer's avatar
trans  
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/specialityperSchool/` + SchoolIdNew + '/' + SectorIdNew, options)
Open Source Developer's avatar
trans  
Open Source Developer committed
521
            .map(response => response.json());
522
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
523 524 525



Open Source Developer's avatar
paging  
Open Source Developer committed
526
    getStudentPerSchool(SchoolId, SelectId, classId, limitdown, limitup) {
527 528
        let SchoolIdNew = SchoolId.toString();
        let SelectIdNew = SelectId.toString();
529 530


531
        this.loginInfo$.getValue().forEach(loginInfoToken => {
532 533
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
534
        });
535

Open Source Developer's avatar
trans  
Open Source Developer committed
536 537 538 539 540
        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
541
        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
542
            .map(response => response.json());
543
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
544

Open Source Developer's avatar
transf  
Open Source Developer committed
545 546


547
    saveConfirmStudents(students) {
548
        this.loginInfo$.getValue().forEach(loginInfoToken => {
549 550
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
trans  
Open Source Developer committed
551 552
        });
        let headers = new Headers({
553
            "Content-Type": "application/json",
Open Source Developer's avatar
trans  
Open Source Developer committed
554 555 556 557
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
558 559 560 561 562 563 564 565 566 567
            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
568 569
        });

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


Open Source Developer's avatar
Open Source Developer committed
573

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

576
        this.loginInfo$.getValue().forEach(loginInfoToken => {
577 578
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
579 580
        });
        let headers = new Headers({
581
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
582 583 584 585
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
586 587 588 589 590 591 592 593 594 595
            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
596 597
        });

598
    }
Open Source Developer's avatar
Open Source Developer committed
599

600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    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(""));
        });

    }

Open Source Developer's avatar
Open Source Developer committed
625 626


Open Source Developer's avatar
Open Source Developer committed
627

628
}