perfecture-view.ts 4.26 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
Open Source Developer committed
23
            <h3> Αριθμός Μαθητών ανα τμήμα σχολείου </h3> 
Open Source Developer's avatar
trans  
Open Source Developer committed
24
                 
Open Source Developer's avatar
trans  
Open Source Developer committed
25 26
            <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
27
                  <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
28
                     <h5> {{SchoolNames$.name}}</h5>
Open Source Developer's avatar
trans  
Open Source Developer committed
29
                  </li>
Open Source Developer's avatar
Open Source Developer committed
30 31
                 <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" >
                    <div> {{CoursesNames$.name}}</div> <div class= "aastyle"><strong>Αριθμός Μαθητών:</strong>{{CoursesNames$.size}} </div> 
Open Source Developer's avatar
trans  
Open Source Developer committed
32 33

                 </div> 
Open Source Developer's avatar
Open Source Developer committed
34
             </div>
Open Source Developer's avatar
trans  
Open Source Developer committed
35 36 37
             
             </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
    private LimitPerCateg$: BehaviorSubject<any>;
    private LimitPerCategSub: Subscription;
Open Source Developer's avatar
trans  
Open Source Developer committed
55 56
    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
            this.SchoolsPerPerf$.next(data);
        },
            error => {
                this.SchoolsPerPerf$.next([{}]);
                console.log("Error Getting Schools");
            },
            () => console.log("Getting Schools"));



    }


     setActiveRegion(ind) {
Open Source Developer's avatar
styles  
Open Source Developer committed
97
    
Open Source Developer's avatar
trans  
Open Source Developer committed
98 99
      if (ind === this.regionActive)
        ind = -1;
Open Source Developer's avatar
styles  
Open Source Developer committed
100
      
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
Open Source Developer committed
124
    calccolor(size, limit)
Open Source Developer's avatar
trans  
Open Source Developer committed
125 126
    {

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

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