helper-data-service.ts 24.7 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
    createAuthorizationHeader(headers: Headers) {
50
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
51 52
    }

53 54 55
    getEpalUserData() {
        this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
56
            this.authRole = loginInfoToken.get(0).auth_role;
57 58 59 60 61 62 63 64 65 66
        });
        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());
    };

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

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

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

146
    getCourseFields() {
147 148 149

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

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

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

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

            //if (courseActive === -1)
            if (classActive === 1)
235
              getConnectionString = `${AppSettings.API_ENDPOINT}/regions/list`;
236 237 238
              else if (classActive === 2)
                  getConnectionString = `${AppSettings.API_ENDPOINT}/sectorsperschool/list?sector_id=${courseActive}`;
            else if (classActive === 3)
239 240
              getConnectionString = `${AppSettings.API_ENDPOINT}/coursesperschool/list?course_id=${courseActive}`;

241
            this.http.get(getConnectionString, options)
242 243 244 245 246 247 248 249 250
                .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); */
251 252 253
        });
    };

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

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    transformRegionSchoolsSchema(regionSchools: any) {
        let rsa = Array<IRegion>();
        let trackRegionId: string;
        let trackIndex: number;

        trackRegionId = "";
        trackIndex = -1;

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

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

        trackSectorId = "";
        trackIndex = -1;

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

328
    getCriteria() {
329

330 331 332
        this.loginInfo$.forEach(loginInfoToken => {
            console.log(loginInfoToken.get(0));
            this.authToken = loginInfoToken.get(0).auth_token;
333
            this.authRole = loginInfoToken.get(0).auth_role;
334 335 336 337 338 339 340 341 342
        });
        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)
343
            //this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list?category=${category}`, options)
344 345 346 347 348 349 350 351 352 353 354
            .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); */
        });
    };
Open Source Developer's avatar
Open Source Developer committed
355

356
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
357 358

        this.authToken = oauthtoken;
359
        this.authRole = oauthrole;
Open Source Developer's avatar
Open Source Developer committed
360 361 362 363 364 365 366 367 368 369 370 371 372
        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",
//            "X-oauth-enabled": "true",
//            "X-Auth-Token": this.authToken
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
373
           return new Promise((resolve, reject) => {
Open Source Developer's avatar
Open Source Developer committed
374
            this.http.get(`${AppSettings.API_ENDPOINT}/epal/curuser`, options)
Open Source Developer's avatar
Open Source Developer committed
375 376
            .map(response => response.json())
            .subscribe(data => {
377
                resolve(this.transformUserSchema(data, oauthtoken, oauthrole));
Open Source Developer's avatar
Open Source Developer committed
378
            }, // put the data returned from the server in our variable
Open Source Developer's avatar
Open Source Developer committed
379
            error => {
Open Source Developer's avatar
Open Source Developer committed
380
                console.log("Error HTTP GET Service"); // in case of failure show this message
Open Source Developer's avatar
Open Source Developer committed
381 382
                reject("Error HTTP GET Service");
            },
383
            () => console.log("UserName Received"));
Open Source Developer's avatar
Open Source Developer committed
384
        });
385
}
Open Source Developer's avatar
Open Source Developer committed
386

Open Source Developer's avatar
Open Source Developer committed
387

Open Source Developer's avatar
trans  
Open Source Developer committed
388
        transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
389
        let rsa = Array<ILoginInfoToken>();
390

391 392
            rsa.push(<ILoginInfoToken>{'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name':userlogin.name});
        return rsa;
393

394
        }
Open Source Developer's avatar
Open Source Developer committed
395

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


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

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


Open Source Developer's avatar
Open Source Developer committed
438 439


Open Source Developer's avatar
tranfer  
Open Source Developer committed
440
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
441

442

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

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

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


 getEpalchosen(headerid)
     {
         let headerIdNew = headerid.toString();
         this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
        });
        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/epalchosen/`+headerIdNew, options )
Open Source Developer's avatar
Open Source Developer committed
485 486
            .map(response => response.json());
     }
Open Source Developer's avatar
tranfer  
Open Source Developer committed
487 488


Open Source Developer's avatar
transf  
Open Source Developer committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
    getSectorPerSchool(SchoolId)
     {
         let SchoolIdNew = SchoolId.toString();
         this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
        });
        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/sectorperSchool/`+SchoolIdNew, options )
            .map(response => response.json());
     }

Open Source Developer's avatar
trans  
Open Source Developer committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
     getSpecialityPerSchool(SchoolId, SectorId)
     {
         let SchoolIdNew = SchoolId.toString();
         let SectorIdNew = SectorId.toString();
         this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
        });
        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/specialityperSchool/`+SchoolIdNew+'/'+SectorIdNew, options )
            .map(response => response.json());
     }



Open Source Developer's avatar
trans  
Open Source Developer committed
522
      getStudentPerSchool(SchoolId, SelectId, classId)
Open Source Developer's avatar
trans  
Open Source Developer committed
523 524 525
     {
         let SchoolIdNew = SchoolId.toString();
         let SelectIdNew = SelectId.toString();
526 527 528 529 530 531 532 533 534 535


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


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
trans  
Open Source Developer committed
541
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/studentperSchool/`+SchoolIdNew+'/'+SelectIdNew+'/'+classId, options )
Open Source Developer's avatar
trans  
Open Source Developer committed
542 543 544
            .map(response => response.json());
     }

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


Open Source Developer's avatar
trans  
Open Source Developer committed
547 548 549 550 551 552 553 554 555 556 557 558
    saveConfirmStudents(students)
    {
        console.log(students,"hds");
        this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
        });
        let headers = new Headers({
           "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
Open Source Developer's avatar
trans  
Open Source Developer committed
559
            this.http.post(`${AppSettings.API_ENDPOINT}/epal/confirmstudent`, {students}, options)
Open Source Developer's avatar
trans  
Open Source Developer committed
560 561 562 563 564 565 566 567 568 569 570
            .map(response => response.json())
            .subscribe(data => {
                resolve(data);
            },
            error => {
                console.log("Error Saving Profile");
                reject("Error Saving Profile");
            },
            () => console.log("Saving Profile"));
        });

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


Open Source Developer's avatar
Open Source Developer committed
574

Open Source Developer's avatar
Open Source Developer committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
 saveCapacity(taxi,tomeas, specialit, capacity, schoolid)
    {

        console.log(taxi, capacity,"hds");
        this.loginInfo$.forEach(loginInfoToken => {
            this.authToken = loginInfoToken.get(0).auth_token;
        });
        let headers = new Headers({
           "Content-Type": "application/json",
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
            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"));
        });

600
    }
Open Source Developer's avatar
Open Source Developer committed
601 602 603



Open Source Developer's avatar
Open Source Developer committed
604

605
}