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

18 19 20 21

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

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

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

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

36

37
    };
38

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

53 54 55 56 57
    }

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

59
    createAuthorizationHeader(headers: Headers) {
60
        headers.append('Authorization', 'Basic ' + btoa(this.authToken + ':' + this.authToken));
61 62
    }

63 64 65 66
    createMinistryAuthorizationHeader(headers: Headers, username: string, passwd: string) {
        headers.append('Authorization', 'Basic ' + btoa(username + ':' + passwd));
    }

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

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

    verifyVerificationCode(verificationCode) {
109
        this.loginInfo$.getValue().forEach(loginInfoToken => {
110 111
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
112 113
        });
        let headers = new Headers({
114 115 116
            "Content-Type": "application/json",
            //            "Accept": "*/*",
            //            "Access-Control-Allow-Credentials": "true",
117 118
        });
        this.createAuthorizationHeader(headers);
119
        //        let options = new RequestOptions({ headers: headers, withCredentials: true });
120 121
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
122 123 124 125 126 127 128 129 130 131
            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); */
132 133 134
        });
    }

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

159
    getCourseFields() {
160

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

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

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

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

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

254
            this.http.get(getConnectionString, options)
255 256 257 258 259 260 261 262 263
                .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); */
264 265 266
        });
    };

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

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

        trackRegionId = "";
        trackIndex = -1;

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

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

        trackSectorId = "";
        trackIndex = -1;

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

341
    getCriteria() {
342

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

368
    getCurrentUser(oauthtoken, oauthrole) {
Open Source Developer's avatar
Open Source Developer committed
369 370

        this.authToken = oauthtoken;
371
        this.authRole = oauthrole;
372 373 374

        //console.log("MIPOS");

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

405 406 407 408 409 410
    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
411

412
    transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
413
        let rsa = Array<ILoginInfoToken>();
414

415
        rsa.push(<ILoginInfoToken>{ 'auth_token': oauthtoken, 'auth_role': oauthrole, 'cu_name': userlogin.name });
416
        return rsa;
417

418
    }
Open Source Developer's avatar
Open Source Developer committed
419

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

427
        let headers = new Headers({
428
            "Content-Type": "application/json",
429

430
        });
431

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

          return new Promise((resolve, reject) => {
              this.http.get(`${AppSettings.API_ENDPOINT}${logoutRoute}${AppSettings.API_ENDPOINT_PARAMS}`, options)
                  .map(response => response)
                  .subscribe(data => {
                      this._cookieService.removeAll();
                      resolve(data);
                  }, // put the data returned from the server in our variable
                  error => {
                      console.log("Error Logout"); // in case of failure show this message
                      reject("Error Logout");
                  },
                  () => console.log("Logging out"));//run this code in all cases); */
          });
        }
455
        else if (this.authRole === MINISTRY_ROLE)
456
          logoutRoute = '/ministry/logout';
457

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


Open Source Developer's avatar
Open Source Developer committed
474 475


Open Source Developer's avatar
tranfer  
Open Source Developer committed
476
    getSubmittedPreviw() {
Open Source Developer's avatar
Open Source Developer committed
477

478

479
        this.loginInfo$.getValue().forEach(loginInfoToken => {
480 481
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
482 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/subapplic`, options)
Open Source Developer's avatar
Open Source Developer committed
489
            .map(response => response.json());
Open Source Developer's avatar
Open Source Developer committed
490
    }
Open Source Developer's avatar
Open Source Developer committed
491

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

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


509 510 511
    getEpalchosen(headerid) {
        let headerIdNew = headerid.toString();
        this.loginInfo$.getValue().forEach(loginInfoToken => {
512 513
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
514
        });
Open Source Developer's avatar
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/epalchosen/` + headerIdNew, options)
Open Source Developer's avatar
Open Source Developer committed
521
            .map(response => response.json());
522
    }
Open Source Developer's avatar
tranfer  
Open Source Developer committed
523 524


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

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



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


563
        this.loginInfo$.getValue().forEach(loginInfoToken => {
564 565
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
566
        });
567

Open Source Developer's avatar
trans  
Open Source Developer committed
568 569 570 571 572
        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
573
        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
574
            .map(response => response.json());
575
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
576

Open Source Developer's avatar
transf  
Open Source Developer committed
577 578


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

602
    }
Open Source Developer's avatar
trans  
Open Source Developer committed
603 604


Open Source Developer's avatar
Open Source Developer committed
605

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

608
        this.loginInfo$.getValue().forEach(loginInfoToken => {
609 610
            this.authToken = loginInfoToken.auth_token;
            this.authRole = loginInfoToken.auth_role;
Open Source Developer's avatar
Open Source Developer committed
611 612
        });
        let headers = new Headers({
613
            "Content-Type": "application/json",
Open Source Developer's avatar
Open Source Developer committed
614 615 616 617
        });
        this.createAuthorizationHeader(headers);
        let options = new RequestOptions({ headers: headers });
        return new Promise((resolve, reject) => {
618 619 620 621 622 623 624 625 626 627
            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
628 629
        });

630
    }
Open Source Developer's avatar
Open Source Developer committed
631

632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
    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(""));
        });

    }

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
    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(""));
        });

    }

683

684
    makeReport(username, userpassword, routepath, regionsel, adminsel, schsel) {
685 686 687 688 689 690 691 692

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

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

693 694 695 696
        console.log("Testing..");
        console.log(`${AppSettings.API_ENDPOINT}` + routepath + regionsel);

        return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath + regionsel + "/" + adminsel + "/"  + schsel, options)
697 698 699 700
            .map(response => response.json());

    }

701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
    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
725

Open Source Developer's avatar
trans  
Open Source Developer committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
    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
742
        return this.http.get(`${AppSettings.API_ENDPOINT}/epal/ScoolperPerf/` + PerfectureIdNew , options)
Open Source Developer's avatar
trans  
Open Source Developer committed
743 744 745
            .map(response => response.json());
    }

Open Source Developer's avatar
trans  
Open Source Developer committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
    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());
}

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
getRegions(username, userpassword)  {

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

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

  //return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath , options)
  //    .map(response => response.json());
  return this.http.get(`${AppSettings.API_ENDPOINT}/regionfields/list`  , options)
      .map(response => response.json());

}

getAdminAreas(username, userpassword, regionid)  {

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

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

  //return this.http.get(`${AppSettings.API_ENDPOINT}` + routepath , options)
  //    .map(response => response.json());

  console.log("Test");
  console.log(`${AppSettings.API_ENDPOINT}/adminfields/list/?region=` + regionid);
  return this.http.get(`${AppSettings.API_ENDPOINT}/adminfields/list/?region=` + regionid  , options)
      .map(response => response.json());
}

getSchoolsPerRegion(username, userpassword, regionid)  {

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

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

  console.log("Test2");
  console.log(`${AppSettings.API_ENDPOINT}/schoolfields_per_region/list/?region=` + regionid);
  return this.http.get(`${AppSettings.API_ENDPOINT}/schoolfields_per_region/list/?region=` + regionid  , options)
      .map(response => response.json());
}

getSchoolsPerAdminArea(username, userpassword, adminid)  {

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

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

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

Open Source Developer's avatar
trans  
Open Source Developer committed
831

Open Source Developer's avatar
Open Source Developer committed
832

Open Source Developer's avatar
Open Source Developer committed
833

834
}