perfecture-view.ts 5.29 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

Open Source Developer's avatar
Open Source Developer committed
89 90 91 92 93 94

                  },
                  error => {
                      this.School$.next([{}]);
                      console.log("Error Getting School");
                  },
95 96 97 98 99 100 101 102 103 104 105 106 107 108
                  () => {
                          console.log("Getting School ");

                          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
109

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

111
        /*
Open Source Developer's avatar
trans  
Open Source Developer committed
112
        this.SchoolPerPerfSub = this._hds.getSchoolPerPerfecture(this.perfecture).subscribe(data => {
Open Source Developer's avatar
trans  
Open Source Developer committed
113 114 115 116 117 118 119
            this.SchoolsPerPerf$.next(data);
        },
            error => {
                this.SchoolsPerPerf$.next([{}]);
                console.log("Error Getting Schools");
            },
            () => console.log("Getting Schools"));
120
        */
Open Source Developer's avatar
trans  
Open Source Developer committed
121 122 123 124 125 126 127



    }


     setActiveRegion(ind) {
128

Open Source Developer's avatar
trans  
Open Source Developer committed
129 130
      if (ind === this.regionActive)
        ind = -1;
131

Open Source Developer's avatar
trans  
Open Source Developer committed
132
      this.regionActive = ind;
Open Source Developer's avatar
trans  
Open Source Developer committed
133 134 135 136 137 138 139 140 141 142 143
      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
144 145 146 147 148
    }


    navigateToApplication()
    {
149

Open Source Developer's avatar
trans  
Open Source Developer committed
150
     var id: string= String(this.regionActive);
151
     this.router.navigate(['', {ids:id}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
152 153 154

    }

Open Source Developer's avatar
Open Source Developer committed
155
    calccolor(size, limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
156 157
    {

Open Source Developer's avatar
Open Source Developer committed
158
      if (size < limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
159
        return true;
Open Source Developer's avatar
trans  
Open Source Developer committed
160 161
      else
        return false;
Open Source Developer's avatar
trans  
Open Source Developer committed
162 163
    }

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