perfecture-view.ts 4.8 KB
Newer Older
1
import { Component, OnInit, OnDestroy, ElementRef, ViewChild, Injectable} from "@angular/core";
Open Source Developer's avatar
trans  
Open Source Developer committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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: `
22 23
            <h3> Αριθμός Μαθητών ανα τμήμα σχολείου </h3>

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
Open Source Developer committed
26
                  <li class="list-group-item isclickable" (click)="setActiveRegion(SchoolNames$.id)" [class.changelistcolor]= "SchoolNames$.status === true" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="regionActive === SchoolNames$.id" >
Open Source Developer's avatar
trans  
Open Source Developer committed
27
                     <h5> {{SchoolNames$.name}}</h5>
Open Source Developer's avatar
trans  
Open Source Developer committed
28
                  </li>
Open Source Developer's avatar
Open Source Developer committed
29
                 <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$.size,CoursesNames$.limitdown)" [hidden]="SchoolNames$.id !== regionActive" >
30
                    <div> {{CoursesNames$.name}}</div> <div class= "aastyle"><strong>Αριθμός Μαθητών:</strong>{{CoursesNames$.size}} </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
31

32
                 </div>
Open Source Developer's avatar
Open Source Developer committed
33
             </div>
34 35 36

             </ul>

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

Open Source Developer's avatar
trans  
Open Source Developer committed
43 44 45 46 47 48 49 50 51

   `
})

@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
52 53
    private LimitPerCateg$: BehaviorSubject<any>;
    private LimitPerCategSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
54 55
    private CoursesPerPerf$: BehaviorSubject<any>;
    private CoursesPerPerfSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
56 57
    private StudentsSize$: BehaviorSubject<any>;
    private StudentsSizeSub: Subscription;
Open Source Developer's avatar
Open Source Developer committed
58
    public perfecture ;
Open Source Developer's avatar
trans  
Open Source Developer committed
59
    private regionActive = <number>-1;
Open Source Developer's avatar
Open Source Developer committed
60 61 62
    private School$: BehaviorSubject<any>;
    private SchoolSub: Subscription;

63

Open Source Developer's avatar
trans  
Open Source Developer committed
64 65 66 67 68 69

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

    }

    ngOnDestroy() {
      }

    ngOnInit() {

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

                  },
                  error => {
                      this.School$.next([{}]);
                      console.log("Error Getting School");
                  },
102
                  () => console.log("Getting School "));
Open Source Developer's avatar
trans  
Open Source Developer committed
103 104 105 106 107 108 109



    }


     setActiveRegion(ind) {
110

Open Source Developer's avatar
trans  
Open Source Developer committed
111 112
      if (ind === this.regionActive)
        ind = -1;
113

Open Source Developer's avatar
trans  
Open Source Developer committed
114
      this.regionActive = ind;
Open Source Developer's avatar
trans  
Open Source Developer committed
115 116 117 118 119 120 121 122 123 124 125
      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
126 127 128 129 130
    }


    navigateToApplication()
    {
131

Open Source Developer's avatar
trans  
Open Source Developer committed
132
     var id: string= String(this.regionActive);
133
     this.router.navigate(['', {ids:id}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
134 135 136

    }

Open Source Developer's avatar
Open Source Developer committed
137
    calccolor(size, limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
138 139
    {

Open Source Developer's avatar
Open Source Developer committed
140
      if (size < limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
141
        return true;
Open Source Developer's avatar
trans  
Open Source Developer committed
142 143
      else
        return false;
Open Source Developer's avatar
trans  
Open Source Developer committed
144 145
    }

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