application.preview.ts 9.18 KB
Newer Older
1
import { Component, OnInit, OnDestroy } from '@angular/core';
2
import { Router } from '@angular/router';
3
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
4 5 6 7 8 9 10
import { Injectable } from "@angular/core";
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { SectorFieldsActions } from '../../actions/sectorfields.actions';
import { SectorCoursesActions } from '../../actions/sectorcourses.actions';
import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import { StudentDataFieldsActions } from '../../actions/studentdatafields.actions';
Open Source Developer's avatar
Open Source Developer committed
11
import { EpalClassesActions } from '../../actions/epalclass.actions';
12 13
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
14
import { IRegions, IRegionSchool } from '../../store/regionschools/regionschools.types';
15
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
Open Source Developer's avatar
Open Source Developer committed
16
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
17
import {AppSettings} from '../../app.settings';
18 19 20 21 22 23
import { REGION_SCHOOLS_INITIAL_STATE } from '../../store/regionschools/regionschools.initial-state';
import { EPALCLASSES_INITIAL_STATE } from '../../store/epalclasses/epalclasses.initial-state';
import { SECTOR_COURSES_INITIAL_STATE } from '../../store/sectorcourses/sectorcourses.initial-state';
import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfields.initial-state';
import { STUDENT_DATA_FIELDS_INITIAL_STATE } from '../../store/studentdatafields/studentdatafields.initial-state';

24 25 26
@Component({
    selector: 'application-preview-select',
    template: `
27
        <div *ngFor="let epalclass$ of epalclasses$ | async;">
28
        <h4 style="margin-top: 20px; line-height: 2em; ">Οι επιλογές μου</h4>
29 30 31 32
        <ul class="list-group left-side-view" style="margin-bottom: 20px;">
                <li class="list-group-item active">
                    Τάξη εισαγωγής
                </li>
Open Source Developer's avatar
Open Source Developer committed
33
                <li class="list-group-item">
34
                    {{epalclass$.name  }}
Open Source Developer's avatar
Open Source Developer committed
35
                </li>
36

Open Source Developer's avatar
Open Source Developer committed
37
        </ul>
38
        </div>
Open Source Developer's avatar
Open Source Developer committed
39

40 41 42 43 44 45
        <div *ngFor="let sectorField$ of sectorFields$ | async">
        <ul class="list-group left-side-view">
            <li class="list-group-item active" *ngIf="sectorField$.selected === true" >
                {{sectorField$.name}}
            </li>
            </ul>
46
        </div>
47

48 49 50 51 52
    <div *ngFor="let sector$ of sectors$  | async;">
            <ul class="list-group left-side-view" style="margin-bottom: 20px;" *ngIf="sector$.sector_selected === true">
                <li class="list-group-item active" *ngIf="sector$.sector_selected === true" >
                    {{sector$.sector_name }}
                </li>
53
        <div *ngFor="let course$ of sector$.courses;" >
54

55
                <li class="list-group-item" *ngIf="course$.selected === true">
Open Source Developer's avatar
UI  
Open Source Developer committed
56
                    {{course$.course_name   }}
57
                </li>
58 59

        </div>
60
            </ul>
61
        </div>
62

63 64


65
        <ul *ngIf="(regions$ | async).size > 0" class="list-group left-side-view" style="margin-bottom: 20px;">
66

67
                <div *ngFor="let epal$ of selectedSchools$ | async; let i=index; let isOdd=odd; let isEven=even" >
68

69
                <li class="list-group-item" [class.oddout]="isOdd" [class.evenout]="isEven">
70
                    <span class="roundedNumber">{{(i+1)}}</span>&nbsp;&nbsp;{{epal$.epal_name}}
71 72
                </li>
              </div>
73
        </ul>
74

75
              <div *ngFor="let studentDataField$ of studentDataFields$ | async;">
76 77 78 79
              <ul class="list-group left-side-view" style="margin-bottom: 20px;">
              <li class="list-group-item active">
                  Στοιχεία μαθητή
              </li>
80
                <li class="list-group-item">
81
                    {{studentDataField$.name  }}
82 83
                </li>
                <li class="list-group-item">
84
                    {{studentDataField$.studentsurname  }}
85
                </li>
86
                </ul>
87
            </div>
88
<!--            <div *ngFor="let selectedAmkaFill$ of selectedAmkaFills$ | async;">
89 90 91
              <li class="list-group-item">
                  AMKA μαθητή: {{selectedAmkaFill$.name}}
              </li>
92
          </div>  -->
93

94 95 96 97
  `
})

@Injectable() export default class ApplicationPreview implements OnInit {
98 99
    private sectors$: BehaviorSubject<ISectors>;
    private regions$: BehaviorSubject<IRegions>;
100
    private selectedSchools$: BehaviorSubject<Array<IRegionSchool>> = new BehaviorSubject(Array());
101 102 103 104 105 106 107 108
    private sectorFields$: BehaviorSubject<ISectorFields>;
    private studentDataFields$: BehaviorSubject<IStudentDataFields>;
    private epalclasses$: BehaviorSubject<IEpalClasses>;
    private sectorsSub: Subscription;
    private regionsSub: Subscription;
    private sectorFieldsSub: Subscription;
    private studentDataFieldsSub: Subscription;
    private epalclassesSub: Subscription;
109 110
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
111 112
    private numSelectedOrder = <number>0;
    private classSelected = 0;
113 114

    constructor(private _ngRedux: NgRedux<IAppState>,
115 116
        private router: Router
    ) {
117 118 119

        this.regions$ = new BehaviorSubject(REGION_SCHOOLS_INITIAL_STATE);
        this.epalclasses$ = new BehaviorSubject(EPALCLASSES_INITIAL_STATE);
120

121 122 123
        this.sectors$ = new BehaviorSubject(SECTOR_COURSES_INITIAL_STATE);
        this.sectorFields$ = new BehaviorSubject(SECTOR_FIELDS_INITIAL_STATE);
        this.studentDataFields$ = new BehaviorSubject(STUDENT_DATA_FIELDS_INITIAL_STATE);
124
    };
125 126

    ngOnInit() {
127
        this.sectorsSub = this._ngRedux.select(state => {
128 129
            state.sectors.reduce((prevSector, sector) => {
                sector.courses.reduce((prevCourse, course) => {
130 131 132 133
                    if (course.selected === true) {
                        this.courseActive = course.course_id;
                    }

134 135 136 137
                    return course;
                }, {});
                return sector;
            }, {});
138
            //this.numSelectedCourses = numsel;
139
            return state.sectors;
140
        }).subscribe(this.sectors$);
141

142
        this.regionsSub = this._ngRedux.select(state => {
143
            let numsel = 0, numsel2 = 0;
144
            let selectedSchools = Array<IRegionSchool>();
145 146
            state.regions.reduce((prevRegion, region) => {
                region.epals.reduce((prevEpal, epal) => {
147
                    if (epal.selected === true) {
148
                        numsel++;
149
                        selectedSchools.push(epal);
150 151 152 153
                    }
                    if (epal.order_id !== 0) {
                        numsel2++;
                    }
154
                    return epal;
155 156 157 158 159
                }, {});
                return region;
            }, {});
            this.numSelectedSchools = numsel;
            this.numSelectedOrder = numsel2;
160
            this.selectedSchools$.next(selectedSchools.sort(this.compareSchools));
161
//            this.selectedSchools$.next(selectedSchools);
162
            return state.regions;
163
        }).subscribe(this.regions$);
164

165
        this.sectorFieldsSub = this._ngRedux.select(state => {
166
            state.sectorFields.reduce(({}, sectorField) => {
167 168 169
                return sectorField;
            }, {});
            return state.sectorFields;
170
        }).subscribe(this.sectorFields$);
171

172
        this.studentDataFieldsSub = this._ngRedux.select(state => {
173
            state.studentDataFields.reduce(({}, studentDataField) => {
174 175 176
                return studentDataField;
            }, {});
            return state.studentDataFields;
177
        }).subscribe(this.studentDataFields$);
178

179
/*        this.selectedAmkaFills$ = this._ngRedux.select(state => {
180
            state.amkafills.reduce(({}, selectedAmkaFill) => {
181 182 183
                return selectedAmkaFill;
            }, {});
            return state.amkafills;
184
        }); */
Open Source Developer's avatar
Open Source Developer committed
185

186
        this._ngRedux.select(state => {
187 188 189 190 191 192
            state.epalclasses.reduce(({}, epalclass) => {
                if (epalclass.name === "Α' Λυκείου")
                    this.classSelected = 1;
                else if (epalclass.name === "Β' Λυκείου")
                    this.classSelected = 2;
                else if (epalclass.name === "Γ' Λυκείου")
193
                    this.classSelected = 3;
194
                return epalclass;
Open Source Developer's avatar
Open Source Developer committed
195 196
            }, {});
            return state.epalclasses;
197
        }).subscribe(this.epalclasses$);
Open Source Developer's avatar
Open Source Developer committed
198

199 200
    }

201 202 203 204 205 206 207 208
    compareSchools(a: IRegionSchool,b: IRegionSchool) {
        if (a.order_id < b.order_id)
            return -1;
        if (a.order_id > b.order_id)
            return 1;
        return 0;
    }

209 210 211 212 213 214
    ngOnDestroy() {
        this.regionsSub.unsubscribe();
        this.epalclassesSub.unsubscribe();
        this.sectorsSub.unsubscribe();
        this.sectorFieldsSub.unsubscribe();
        this.studentDataFieldsSub.unsubscribe();
215 216 217 218 219
        this.regions$.unsubscribe();
        this.epalclasses$.unsubscribe();
        this.sectors$.unsubscribe();
        this.sectorFields$.unsubscribe();
        this.studentDataFields$.unsubscribe();
220
    }
221

222
    showValues() {
223
/*        console.log(this.epalclasses$);
224 225
        console.log(this.studentDataFields$);
        console.log(this.regions$);
226
        console.log(this.sectors$); */
227
    }
228

229
}