epal.class.select.ts 3.83 KB
Newer Older
Open Source Developer's avatar
Open Source Developer committed
1
import { Component, OnInit } from '@angular/core';
Open Source Developer's avatar
Open Source Developer committed
2 3 4 5 6 7
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { Injectable } from "@angular/core";
import { EpalClassesActions } from '../../actions/epalclass.actions';
import { NgRedux, select } from 'ng2-redux';
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
Open Source Developer's avatar
Open Source Developer committed
8 9 10
import { SectorFieldsActions } from '../../actions/sectorfields.actions';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
Open Source Developer's avatar
Open Source Developer committed
11 12 13 14 15 16 17 18 19 20 21 22
import { IAppState } from '../../store/store';
import {
    FormBuilder,
    FormGroup,
    FormControl,
    FormArray
} from '@angular/forms';
import {AppSettings} from '../../app.settings';

@Component({
    selector: 'epal-class-select',
    template: `
Open Source Developer's avatar
Open Source Developer committed
23 24
   
    <form [formGroup]="formGroup"> 
Open Source Developer's avatar
Open Source Developer committed
25 26 27
           <div *ngFor="let epalclass$ of epalclasses$ | async;"> </div>
            <div class="form-group">
              <label for="name">Παρακαλώ επιλέξτε την τάξη εισαγωγής του μαθητή στην Επαγγελματική Εκπαίδευση</label><br/>
Open Source Developer's avatar
Open Source Developer committed
28
                    <select class="form-control" formControlName="name" (change)="initializestore()">
29 30 31
                        <option value="Α' Λυκείου">Α' Λυκείου</option>
                        <option value="Β' Λυκείου">Β' Λυκείου</option>
                        <option value="Γ' Λυκείου">Γ' Λυκείου</option>
Open Source Developer's avatar
Open Source Developer committed
32 33
                    </select>

34
            </div>
Open Source Developer's avatar
Open Source Developer committed
35
        <div class="row">
Open Source Developer's avatar
UI  
Open Source Developer committed
36 37
            <div class="col-md-12 col-md-offset-5">
                <button type="button" class="btn-primary btn-lg pull-right" (click)="saveSelected()">
Open Source Developer's avatar
Open Source Developer committed
38
               <i class="fa fa-forward"></i>
Open Source Developer's avatar
Open Source Developer committed
39 40 41
                </button>
            </div>
        </div>
Open Source Developer's avatar
a  
Open Source Developer committed
42 43 44 45 46

        <div *ngIf="emptyselection==true">
             Παρακαλώ επιλέξτε μια τάξη
        </div>

Open Source Developer's avatar
Open Source Developer committed
47 48 49 50 51 52 53 54 55
    </form>
   `
})

@Injectable() export default class EpalClassesSelect implements OnInit {
    private epalclasses$: Observable<IEpalClasses>;

    public formGroup: FormGroup;

Open Source Developer's avatar
a  
Open Source Developer committed
56
       emptyselection = false;
Open Source Developer's avatar
Open Source Developer committed
57 58 59
       constructor(private fb: FormBuilder,
                private _cfa: EpalClassesActions,
                private _ngRedux: NgRedux<IAppState>,
Open Source Developer's avatar
Open Source Developer committed
60 61 62
                private _csa: SectorCoursesActions,
                private _sfa: SectorFieldsActions,
                private _rsa: RegionSchoolsActions,
Open Source Developer's avatar
Open Source Developer committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
                private router: Router) {
       this.formGroup = this.fb.group({
            name: []
            });
        };

    ngOnInit() {

          this.epalclasses$ = this._ngRedux.select(state => {
            if (state.epalclasses.size > 0) {
                state.epalclasses.reduce(({}, epalclass) => {
                    this.formGroup.setValue(epalclass);
                    return epalclass;
                }, {});
            }
            return state.epalclasses;
        });

    }

    saveSelected() {
Open Source Developer's avatar
a  
Open Source Developer committed
84

85
        if (this.formGroup.value.name == undefined) {
Open Source Developer's avatar
a  
Open Source Developer committed
86
                   this.emptyselection = true;
87
        }
Open Source Developer's avatar
a  
Open Source Developer committed
88 89 90
        else
        {
            this._cfa.saveEpalClassesSelected(this.formGroup.value);
91 92 93 94 95 96 97
            if (this.formGroup.value.name === "Α' Λυκείου")
              this.router.navigate(['/region-schools-select']);
            else if (this.formGroup.value.name === "Β' Λυκείου")
                this.router.navigate(['/sector-fields-select']);
            else if (this.formGroup.value.name === "Γ' Λυκείου")
                this.router.navigate(['/sectorcourses-fields-select']);

Open Source Developer's avatar
a  
Open Source Developer committed
98
        }
99

Open Source Developer's avatar
Open Source Developer committed
100
    }
Open Source Developer's avatar
Open Source Developer committed
101 102 103 104 105 106 107 108 109 110 111


    initializestore()
    {
       this._cfa.saveEpalClassesSelected(this.formGroup.value);
       this._sfa.getSectorFields(true);
       this._rsa.getRegionSchools(1,"-1", true);
       this._csa.getSectorCourses(true);

    }

Open Source Developer's avatar
a  
Open Source Developer committed
112
}