application.preview.ts 8.95 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
trans    
Open Source Developer committed
33
34
35
36
37
38
39
40
                <li class="list-group-item" *ngIf="epalclass$.name === '1'">
                    Α’ Λυκείου                    
                </li>
                <li class="list-group-item" *ngIf="epalclass$.name === '2'">
                    Β’ Λυκείου                    
                </li>
                <li class="list-group-item" *ngIf="epalclass$.name === '3'">
                    Γ’ Λυκείου                    
Open Source Developer's avatar
Open Source Developer committed
41
                </li>
42

Open Source Developer's avatar
Open Source Developer committed
43
        </ul>
44
        </div>
Open Source Developer's avatar
Open Source Developer committed
45

46
47
48
49
50
51
        <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>
52
        </div>
53

54
55
56
57
58
    <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>
59
        <div *ngFor="let course$ of sector$.courses;" >
60

61
                <li class="list-group-item" *ngIf="course$.selected === true">
Open Source Developer's avatar
UI    
Open Source Developer committed
62
                    {{course$.course_name   }}
63
                </li>
64
65

        </div>
66
            </ul>
67
        </div>
68

69
70


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

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

75
                <li class="list-group-item" [class.oddout]="isOdd" [class.evenout]="isEven">
76
                    <span class="roundedNumber">{{(i+1)}}</span>&nbsp;&nbsp;{{epal$.epal_name}}
77
78
                </li>
              </div>
79
        </ul>
80

81
              <div *ngFor="let studentDataField$ of studentDataFields$ | async;">
82
83
84
85
              <ul class="list-group left-side-view" style="margin-bottom: 20px;">
              <li class="list-group-item active">
                  Στοιχεία μαθητή
              </li>
86
                <li class="list-group-item">
87
                    {{studentDataField$.name  }}
88
89
                </li>
                <li class="list-group-item">
90
                    {{studentDataField$.studentsurname  }}
91
                </li>
92
                </ul>
93
            </div>
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
    private sectorFields$: BehaviorSubject<ISectorFields>;
    private studentDataFields$: BehaviorSubject<IStudentDataFields>;
    private epalclasses$: BehaviorSubject<IEpalClasses>;
    private sectorsSub: Subscription;
    private regionsSub: Subscription;
    private sectorFieldsSub: Subscription;
    private studentDataFieldsSub: Subscription;
108
109
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
110
111
    private numSelectedOrder = <number>0;
    private classSelected = 0;
112
113

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

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

120
121
122
        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);
123
    };
124
125

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

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

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

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

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

178
        this._ngRedux.select(state => {
179
180
181
182
183
184
            state.epalclasses.reduce(({}, epalclass) => {
                if (epalclass.name === "Α' Λυκείου")
                    this.classSelected = 1;
                else if (epalclass.name === "Β' Λυκείου")
                    this.classSelected = 2;
                else if (epalclass.name === "Γ' Λυκείου")
185
                    this.classSelected = 3;
186
                return epalclass;
Open Source Developer's avatar
Open Source Developer committed
187
188
            }, {});
            return state.epalclasses;
189
        }).subscribe(this.epalclasses$);
Open Source Developer's avatar
Open Source Developer committed
190

191
192
    }

193
194
195
196
197
198
199
200
    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;
    }

201
    ngOnDestroy() {
202
203
204
205
206
207
208
209
        if (this.regionsSub)
            this.regionsSub.unsubscribe();
        if (this.sectorsSub)
            this.sectorsSub.unsubscribe();
        if (this.sectorFieldsSub)
            this.sectorFieldsSub.unsubscribe();
        if (this.studentDataFieldsSub)
            this.studentDataFieldsSub.unsubscribe();
210
211
212
213
214
        this.regions$.unsubscribe();
        this.epalclasses$.unsubscribe();
        this.sectors$.unsubscribe();
        this.sectorFields$.unsubscribe();
        this.studentDataFields$.unsubscribe();
215
    }
216

217
}