perfecture-view.ts 4.16 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
trans  
Open Source Developer committed
58 59
    public perfecture = 1;
    private regionActive = <number>-1;
60

Open Source Developer's avatar
trans  
Open Source Developer committed
61 62 63 64 65 66

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

    }

    ngOnDestroy() {
      }

    ngOnInit() {


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



    }


     setActiveRegion(ind) {
96

Open Source Developer's avatar
trans  
Open Source Developer committed
97 98
      if (ind === this.regionActive)
        ind = -1;
99

Open Source Developer's avatar
trans  
Open Source Developer committed
100
      this.regionActive = ind;
Open Source Developer's avatar
trans  
Open Source Developer committed
101 102 103 104 105 106 107 108 109 110 111
      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
112 113 114 115 116
    }


    navigateToApplication()
    {
117

Open Source Developer's avatar
trans  
Open Source Developer committed
118
     var id: string= String(this.regionActive);
119
     this.router.navigate(['', {ids:id}]);
Open Source Developer's avatar
trans  
Open Source Developer committed
120 121 122

    }

Open Source Developer's avatar
Open Source Developer committed
123
    calccolor(size, limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
124 125
    {

Open Source Developer's avatar
Open Source Developer committed
126
      if (size < limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
127
        return true;
Open Source Developer's avatar
trans  
Open Source Developer committed
128 129
      else
        return false;
Open Source Developer's avatar
trans  
Open Source Developer committed
130 131
    }

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