perfecture-view.ts 4.46 KB
Newer Older
Open Source Developer's avatar
trans  
Open Source Developer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';

import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray,
    Validators,
} from '@angular/forms';
@Component({
    selector: 'perfecture-view',
    template: `
Open Source Developer's avatar
trans  
Open Source Developer committed
23
                 
Open Source Developer's avatar
trans  
Open Source Developer committed
24 25
            <ul class="list-group main-view">
              <div *ngFor="let SchoolNames$  of SchoolsPerPerf$  | async; let i=index; let isOdd=odd; let isEven=even"  >
Open Source Developer's avatar
trans  
Open Source Developer committed
26 27
                  <li class="list-group-item isclickable" (click)="setActiveRegion(SchoolNames$.id)"  [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="regionActive === SchoolNames$.id ">
                     <h5> {{SchoolNames$.name}}</h5>
Open Source Developer's avatar
trans  
Open Source Developer committed
28
                  </li>
Open Source Developer's avatar
trans  
Open Source Developer committed
29 30 31 32 33 34 35 36 37

                 <div *ngFor="let CoursesNames$  of CoursesPerPerf$  | async; let j=index; let isOdd2=odd; let isEven2=even" [class.oddin]="isOdd2" [class.evenin]="isEven2" [class.changecolor]="calccolor(CoursesNames$.id,CoursesNames$.categ,CoursesNames$.classes)" [hidden]="SchoolNames$.id !== regionActive" >
                    <div> {{CoursesNames$.name}} </div>
                 </div> 

               </div>
             
             </ul> 
             
Open Source Developer's avatar
trans  
Open Source Developer committed
38 39 40 41 42 43
             <div class="col-md-6">
                <button type="button" class="btn-primary btn-lg pull-right" (click)="navigateToApplication()" >
                <i class="fa fa-forward"></i>
                </button>
            </div>  

Open Source Developer's avatar
trans  
Open Source Developer committed
44
 
Open Source Developer's avatar
trans  
Open Source Developer committed
45 46 47 48 49 50 51 52
   `
})

@Injectable() export default class PerfectureView implements OnInit, OnDestroy {

    public formGroup: FormGroup;
    private SchoolsPerPerf$: BehaviorSubject<any>;
    private SchoolPerPerfSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
53 54 55 56
    private LimitPerCategSub: BehaviorSubject<any>;
    private LimitPerCateg$: Subscription;
    private CoursesPerPerf$: BehaviorSubject<any>;
    private CoursesPerPerfSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
57 58
    private StudentsSize$: BehaviorSubject<any>;
    private StudentsSizeSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
59 60 61 62 63 64 65 66 67
    public perfecture = 1;
    private regionActive = <number>-1;
    

    constructor(private fb: FormBuilder,
      private router: Router,
      private _hds: HelperDataService,
      ) {
        this.SchoolsPerPerf$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
68 69
        this.LimitPerCateg$ = new BehaviorSubject([{}]);
        this.CoursesPerPerf$ = new BehaviorSubject([{}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
70
        this.StudentsSize$ = new BehaviorSubject({});
Open Source Developer's avatar
trans  
Open Source Developer committed
71 72 73 74 75 76 77 78 79 80 81
        this.formGroup = this.fb.group({
        });

    }

    ngOnDestroy() {
      }

    ngOnInit() {


Open Source Developer's avatar
trans  
Open Source Developer committed
82
        this.SchoolPerPerfSub = this._hds.getSchoolPerPerfecture(this.perfecture).subscribe(data => {
Open Source Developer's avatar
trans  
Open Source Developer committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
            this.SchoolsPerPerf$.next(data);
        },
            error => {
                this.SchoolsPerPerf$.next([{}]);
                console.log("Error Getting Schools");
            },
            () => console.log("Getting Schools"));



    }


     setActiveRegion(ind) {
      console.log(ind,"ind");
      if (ind === this.regionActive)
        ind = -1;
Open Source Developer's avatar
trans  
Open Source Developer committed
100
      console.log(this.regionActive,"RA");
Open Source Developer's avatar
trans  
Open Source Developer committed
101
      this.regionActive = ind;
Open Source Developer's avatar
trans  
Open Source Developer committed
102 103 104 105 106 107 108 109 110 111 112
      this.CoursesPerPerfSub = this._hds.getCoursePerPerfecture(this.regionActive).subscribe(data => {
            this.CoursesPerPerf$.next(data);
        },
            error => {
                this.CoursesPerPerf$.next([{}]);
                console.log("Error Getting Courses");
            },
            () => console.log("Getting Courses Per Perf"));



Open Source Developer's avatar
trans  
Open Source Developer committed
113 114 115 116 117 118 119 120 121 122 123
    }


    navigateToApplication()
    {
     
     var id: string= String(this.regionActive);
     this.router.navigate(['', {ids:id}]); 

    }

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

Open Source Developer's avatar
trans  
Open Source Developer committed
125
    calccolor(id, categ, classes)
Open Source Developer's avatar
trans  
Open Source Developer committed
126 127
    {

Open Source Developer's avatar
trans  
Open Source Developer committed
128 129 130 131 132 133 134 135 136 137 138
      this.LimitPerCategSub = this._hds.getLimitPerCateg(categ, classes).subscribe(data => {
            this.LimitPerCateg$.next(data);
        },
            error => {
                this.LimitPerCateg$.next([{}]);
                console.log("Error Getting Limits");
            },
            () => console.log("Getting Limits"));

      var newid = +id;
      if (newid <= 5)
Open Source Developer's avatar
trans  
Open Source Developer committed
139
        return true;
Open Source Developer's avatar
trans  
Open Source Developer committed
140 141
      else
        return false;
Open Source Developer's avatar
trans  
Open Source Developer committed
142 143 144

    }

Open Source Developer's avatar
trans  
Open Source Developer committed
145
}