application.preview.ts 8.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Rx';
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
import { AmkaFillsActions } from '../../actions/amkafill.actions';
13 14 15 16
import { ISectorFields } from '../../store/sectorfields/sectorfields.types';
import { ISectors } from '../../store/sectorcourses/sectorcourses.types';
import { IRegions } from '../../store/regionschools/regionschools.types';
import { IStudentDataFields } from '../../store/studentdatafields/studentdatafields.types';
Open Source Developer's avatar
Open Source Developer committed
17
import { IEpalClasses } from '../../store/epalclasses/epalclasses.types';
18
import { IAmkaFills } from '../../store/amkafill/amkafills.types';
19 20
import {AppSettings} from '../../app.settings';

Open Source Developer's avatar
UI  
Open Source Developer committed
21

22 23 24
@Component({
    selector: 'application-preview-select',
    template: `
25
        <div *ngFor="let epalclass$ of epalclasses$ | async;">
26
        <h4 style="margin-top: 20px; line-height: 2em; ">Οι επιλογές μου</h4>
27 28 29 30
        <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
31
                <li class="list-group-item">
32
                    {{epalclass$.name  }}
Open Source Developer's avatar
Open Source Developer committed
33
                </li>
34

Open Source Developer's avatar
Open Source Developer committed
35
        </ul>
36
        </div>
Open Source Developer's avatar
Open Source Developer committed
37

38 39 40 41 42 43 44

        <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>
45
        </div>
46

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 66 67




        <ul class="list-group left-side-view" style="margin-bottom: 20px;">
68
              <div *ngFor="let region$ of regions$ | async;">
69

70
                <div *ngFor="let epal$ of region$.epals; " >
71

72 73 74 75
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 1">
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name}}
                </li>
                  <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 0">
Open Source Developer's avatar
UI  
Open Source Developer committed
76
                      {{epal$.epal_name   }}
Open Source Developer's avatar
commit  
Open Source Developer committed
77
                  </li>
78 79

                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 2">
Open Source Developer's avatar
UI  
Open Source Developer committed
80
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
81
                </li>
82

83
                <li class="list-group-item" *ngIf="epal$.selected === true && epal$.order_id === 3">
Open Source Developer's avatar
UI  
Open Source Developer committed
84
                    Προτίμηση {{epal$.order_id}}: {{epal$.epal_name   }}
85 86 87
                </li>
              </div>
            </div>
88
<!--            <div class="btn-group inline pull-right">
89 90
              <button type="button" class="btn-primary btn-sm pull-right" (click)="defineOrder()"
              [hidden] = "numSelectedSchools <= 1 ">> Σειρά προτίμησης</button>
91
            </div> -->
92
        </ul>
93

94 95 96 97 98





99
              <div *ngFor="let studentDataField$ of studentDataFields$ | async;">
100 101 102 103
              <ul class="list-group left-side-view" style="margin-bottom: 20px;">
              <li class="list-group-item active">
                  Στοιχεία μαθητή
              </li>
104
                <li class="list-group-item">
105
                    {{studentDataField$.name  }}
106 107
                </li>
                <li class="list-group-item">
108
                    {{studentDataField$.studentsurname  }}
109
                </li>
110
                </ul>
111
            </div>
112
<!--            <div *ngFor="let selectedAmkaFill$ of selectedAmkaFills$ | async;">
113 114 115
              <li class="list-group-item">
                  AMKA μαθητή: {{selectedAmkaFill$.name}}
              </li>
116
          </div>  -->
117

118 119 120 121 122 123 124 125
  `
})

@Injectable() export default class ApplicationPreview implements OnInit {
    private sectors$: Observable<ISectors>;
    private regions$: Observable<IRegions>;
    private sectorFields$: Observable<ISectorFields>;
    private studentDataFields$: Observable<IStudentDataFields>;
126
    private selectedAmkaFills$: Observable<IAmkaFills>;
Open Source Developer's avatar
Open Source Developer committed
127
    private epalclasses$: Observable<IEpalClasses>;
128 129
    private courseActive = "-1";
    private numSelectedSchools = <number>0;
130 131
    private numSelectedOrder = <number>0;
    private classSelected = 0;
132 133

    constructor(private _ngRedux: NgRedux<IAppState>,
134 135
        private router: Router
    ) {
136
    };
137 138

    ngOnInit() {
139
        this.courseActive = this.getCourseActive();
140
        this.sectors$ = this._ngRedux.select(state => {
141
            //let numsel = 0;
142
            state.sectors.reduce((prevSector, sector) => {
143
                //if (sector.sector_selected)
144 145 146 147 148
                console.log("hello" + sector.sector_selected);
                sector.courses.reduce((prevCourse, course) => {
                    //if (course.selected === true)  {
                    //  numsel++;
                    //}
149 150 151 152
                    return course;
                }, {});
                return sector;
            }, {});
153
            //this.numSelectedCourses = numsel;
154 155 156 157
            return state.sectors;
        });

        this.regions$ = this._ngRedux.select(state => {
158 159 160 161
            let numsel = 0, numsel2 = 0;
            state.regions.reduce((prevRegion, region) => {
                region.epals.reduce((prevEpal, epal) => {
                    console.log("hello" + epal.selected);
162
                    if (epal.selected === true) {
163
                        numsel++;
164 165 166 167
                    }
                    if (epal.order_id !== 0) {
                        numsel2++;
                    }
168
                    return epal;
169 170 171 172 173 174 175
                }, {});
                return region;
            }, {});
            this.numSelectedSchools = numsel;
            this.numSelectedOrder = numsel2;
            return state.regions;
        });
176 177

        this.sectorFields$ = this._ngRedux.select(state => {
178
            state.sectorFields.reduce(({}, sectorField) => {
179 180 181 182 183 184
                return sectorField;
            }, {});
            return state.sectorFields;
        });

        this.studentDataFields$ = this._ngRedux.select(state => {
185
            state.studentDataFields.reduce(({}, studentDataField) => {
186 187 188 189 190
                return studentDataField;
            }, {});
            return state.studentDataFields;
        });

191
        this.selectedAmkaFills$ = this._ngRedux.select(state => {
192
            state.amkafills.reduce(({}, selectedAmkaFill) => {
193 194 195 196
                return selectedAmkaFill;
            }, {});
            return state.amkafills;
        });
Open Source Developer's avatar
Open Source Developer committed
197

198 199 200 201 202 203 204
        this.epalclasses$ = this._ngRedux.select(state => {
            state.epalclasses.reduce(({}, epalclass) => {
                if (epalclass.name === "Α' Λυκείου")
                    this.classSelected = 1;
                else if (epalclass.name === "Β' Λυκείου")
                    this.classSelected = 2;
                else if (epalclass.name === "Γ' Λυκείου")
205
                    this.classSelected = 3;
206
                return epalclass;
Open Source Developer's avatar
Open Source Developer committed
207 208 209 210
            }, {});
            return state.epalclasses;
        });

211 212 213 214 215
    }

    defineSector() {
        this.router.navigate(['/sector-fields-select']);
    }
216

217 218 219
    defineSchools() {
        this.router.navigate(['/region-schools-select']);
    }
220

221 222 223
    definePersonalData() {
        this.router.navigate(['/student-application-form-main']);
    }
224

Open Source Developer's avatar
Open Source Developer committed
225 226 227 228
    defineClass() {
        this.router.navigate(['/epal-class-select']);
    }

229 230
    getCourseActive() {
        const { sectors } = this._ngRedux.getState();
231 232 233 234 235 236
        let l, m;
        for (l = 0; l < sectors.size; l++)
            if (sectors["_tail"]["array"][l]["sector_selected"] === true)
                for (m = 0; m < sectors["_tail"]["array"][l]["courses"].length; m++)
                    if (sectors["_tail"]["array"][l]["courses"][m]["selected"] === true)
                        return sectors["_tail"]["array"][l]["courses"][m]["course_id"];
237 238
    }

239
    defineCourse() {
240
        this.router.navigate(['/sectorcourses-fields-select']);
241
    }
242

243
    defineOrder() {
244
        this.router.navigate(['/schools-order-select']);
245
    }
246

247
}