updated Criteria Component

parent 6456d772
import { CRITERIA_SAVE} from '../constants';
import { CRITERIA_RECEIVED, CRITERIA_SAVE} from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
import { HelperDataService } from '../services/helper-data-service';
@Injectable()
export class CriteriaActions {
constructor(
private _ngRedux: NgRedux<IAppState>) {}
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {}
getCriteria = (reload) => {
const { criter } = this._ngRedux.getState();
//if (sectorFields.size === 0) {
if (reload === true || (reload === false && criter.size === 0)) {
return this._hds.getCriteria().then(criteria => {
return this._ngRedux.dispatch({
type: CRITERIA_RECEIVED,
payload: {
criteria
}
});
});
}
};
saveCriteria = (criter) => {
return this._ngRedux.dispatch({
......
......@@ -112,31 +112,45 @@
<form novalidate (ngSubmit)="onSubmit(studentCriteriaGroup)" [formGroup]="studentCriteriaGroup">
<div *ngFor="let criter$ of criteria$ | async; let i=index"> </div>
<!--
<fieldset class="group">
-->
<legend>Εισοδηματικά κριτήρια</legend>
<select #cblsttest class="form-control" (change)="checkstatus(cblsttest)" formControlName="incometest">
<option *ngFor="let criter$ of criteria$ | async; let i=index" >
<div *ngIf="criter$.name === 'Εισόδημα' && criter$.name !== 'Απόσταση'">
{{criter$.name}} </div></option>
</select>
<div class="form-group">
<label for="income">Το κατά κεφαλήν εισόδημα στο προηγούμενο φορολογικό έτος είναι:</label><br/>
<select class="form-control" (change)="checkstatus()" formControlName="income">
<option value="noincomecriterio">Παρακαλώ επιλέξτε..</option>
<option value="<= 3000 Ευρώ">μικρότερο ή ίσο των 3000 Ευρώ</option>
<option value="<= 6000 Ευρώ">μικρότερο ή ίσο των 6000 Ευρώ</option>
<option value="<= 9000 Ευρώ">μικρότερο ή ίσο των 9000 Ευρώ</option>
<option value="> 9000 Ευρώ">μεγαλύτερο των 9000 Ευρώ</option>
<select #cblst class="form-control" (change)="checkstatus(cblst)" formControlName="income">
<option value="noincomecriterio" [selected] = "selectionIncomeId === 0" >Παρακαλώ επιλέξτε..</option>
<option value="<= 3000 Ευρώ" [selected] = "selectionIncomeId === 8" >μικρότερο ή ίσο των 3000 Ευρώ</option>
<option value="<= 6000 Ευρώ" [selected] = "selectionIncomeId === 9" >μικρότερο ή ίσο των 6000 Ευρώ</option>
<option value="<= 9000 Ευρώ" [selected] = "selectionIncomeId === 10" >μικρότερο ή ίσο των 9000 Ευρώ</option>
<option value="> 9000 Ευρώ" [selected] = "selectionIncomeId === 11" >μεγαλύτερο των 9000 Ευρώ</option>
</select>
<!-- studentCriteriaGroup.get('income').dirty && -->
<div class="alert alert-danger" *ngIf=" studentCriteriaGroup.get('income').hasError('status')">
Η επιλογή από αυτή τη λίστα είναι απαραίτητη!
</div>
</div>
<div formArrayName="formArray">
<div *ngFor="let criter$ of criteria$ | async; let i=index"> </div>
<legend>Κοινωνικά κριτήρια</legend>
<p style="margin-top: 15px; line-height: 1.5em;">Επιλέξτε όσα από τα παρακάτω κριτήρια πληρούνται για εσάς.
Οι επιλογές σας επέχουν θέση υπέυθυνης δήλωσης.
Θα πρέπει να προσκομίσετε τα αντίστοιχα δικαιολογητικά στο σχολείο εγγραφής σας, όταν σας ζητηθεί.
</p>
<!--
<div class="row">
<div class="col-md-1"> <input #cborphanmono type="checkbox" (change)="checkorphan('mono', cborphanmono)" formControlName="orphanmono" ></div>
<div class="col-md-11 pull-left">Ορφανός από τον ένα γονέα</div>
......@@ -165,7 +179,33 @@
<div class="col-md-1"> <input type="checkbox" (change)="checkstatus()" formControlName="studies"></div>
<div class="col-md-11 pull-left">Αδελφός,-ή που σπουδάζει σε άλλη πόλη</div>
</div>
-->
<div *ngFor="let criter$ of criteria$ | async; let i=index">
<div class="row" *ngIf="criter$.name !== 'Εισόδημα' && criter$.name !== 'Απόσταση'">
<div class="col-md-1">
<input #cb type="checkbox" (change)="checkcriteria(cb, criter$.mutual_disabled_id)" formControlName={{i}}>
</div>
<div class="col-md-11 pull-left">
{{criter$.name}}
</div>
</div>
</div>
<div class="row">
</div>
<!--
</fieldset>
-->
</div>
</form>
......
......@@ -14,6 +14,7 @@ import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from '@angular/forms';
......@@ -30,6 +31,9 @@ import {
public studentDataGroup: FormGroup;
public applicantDataGroup: FormGroup;
public studentCriteriaGroup: FormGroup;
private rss = new FormArray([]);
private selectionIncomeId = <number>0;
//public orphanmode = <number>0;
//public childrenmode = <number>0;
......@@ -45,8 +49,8 @@ import {
regionaddress: ['ΓΙΑΝΝΙΤΣΩΝ 5', [Validators.pattern(VALID_ADDRESS_PATTERN),Validators.required]],
regiontk: ['26334', [Validators.pattern(VALID_ADDRESSTK_PATTERN),Validators.required]],
regionarea: ['ΠΑΤΡΑ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
certificatetype: ['Απολυτήριο Λυκείου', this.checkChoice],
relationtostudent: ['Μαθητής', this.checkChoice],
certificatetype: ['Απολυτήριο Λυκείου', checkChoice],
relationtostudent: ['Μαθητής', checkChoice],
telnum: ['2610789789', [Validators.pattern(VALID_DIGITS_PATTERN),Validators.required]],
});
......@@ -55,6 +59,7 @@ import {
guardiansurname: ['ΚΑΤΣΑΟΥΝΟΣ', [Validators.pattern(VALID_NAMES_PATTERN),Validators.required]],
});
/*
this.studentCriteriaGroup = this.fb.group({
orphanmono: false,
orphantwice: false,
......@@ -63,7 +68,13 @@ import {
twins: false,
disability: false,
studies: false,
income: ['noincomecriterio', this.checkChoice ],
income: ['noincomecriterio', checkChoice ],
});
*/
this.studentCriteriaGroup = this.fb.group({
formArray: this.rss,
income: ['noincomecriterio', checkChoice ],
incometest: ['noincomecriterio', checkChoice ],
});
};
......@@ -80,10 +91,16 @@ import {
return state.studentDataFields;
});
this._sdfb.getCriteria(true);
this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => {
this.studentCriteriaGroup.setValue(criteria);
//this.studentCriteriaGroup.setValue(criteria);
if (criteria.selected === true && (criteria.id === "8" || criteria.id === "9" || criteria.id === "10" || criteria.id === "11" ))
this.selectionIncomeId = Number(criteria.id);
console.log("Yes");
console.log(this.selectionIncomeId);
this.rss.push( new FormControl(criteria.selected, []));
return criteria;
}, {});
}
......@@ -112,6 +129,13 @@ import {
submitSelected() {
this._sdfa.saveStudentDataFields([this.studentDataGroup.value]);
this.studentCriteriaGroup.controls['formArray']['controls'][7].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][8].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][9].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][10].setValue(false);
this.studentCriteriaGroup.controls['formArray']['controls'][this.selectionIncomeId-1].setValue(true);
this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
this.router.navigate(['/application-submit']);
}
......@@ -139,20 +163,52 @@ import {
//console.log(this.studentCriteriaGroup.value);
}
checkstatus() {
//this.studentCriteriaGroup.controls[name].setValue(cb.checked);
//console.log("after check");
//console.log(this.studentCriteriaGroup.value);
this._sdfb.saveCriteria([this.studentCriteriaGroup.value]);
checkcriteria(cb, mutual_disabled) {
if (mutual_disabled !== "-1" && cb.checked === true) {
this.studentCriteriaGroup.controls['formArray']['controls'][mutual_disabled-1].setValue(false);
}
//this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
}
checkstatus(cb) {
console.log("Hey");
console.log(this.studentCriteriaGroup.value.income);
//this._sdfb.saveCriteria([this.studentCriteriaGroup.value.income]);
console.log("OK");
console.log(cb.value);
checkChoice(c: FormControl) {
if (cb.value === "<= 3000 Ευρώ")
this.selectionIncomeId = 8;
else if (cb.value === "<= 6000 Ευρώ")
this.selectionIncomeId = 9;
else if (cb.value === "<= 9000 Ευρώ")
this.selectionIncomeId = 10;
else if (cb.value === "> 9000 Ευρώ")
this.selectionIncomeId = 11;
//this.studentCriteriaGroup.value[9] = true;
//this.studentCriteriaGroup.value[9] = false;
console.log(this.studentCriteriaGroup.value.formArray);
console.log(this.studentCriteriaGroup.value);
//this._sdfb.saveCriteria([this.studentCriteriaGroup.value.formArray]);
}
}
function checkChoice(c: FormControl) {
console.log(c.value);
if (c.value === "noincomecriterio")
return {status: true}
else
// Null means valid, believe it or not
return null;
}
}
......@@ -127,6 +127,21 @@ import {AppSettings} from '../../app.settings';
});
this.showLoaderSchools$ = this.regions$.map(regions => regions.size === 0);
this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => {
//code to be replaced in next version
if (criteria.selected === true && Number(criteria.id) !== 11)
this.studentCriteria.push(Number(criteria.id));
return criteria;
}, {});
}
return state.criter;
});
this.showLoaderCriteria$ = this.criteria$.map(criter => criter.size === 0);
/*
this.criteria$ = this._ngRedux.select(state => {
if (state.criter.size > 0) {
state.criter.reduce(({}, criteria) => {
......@@ -158,6 +173,7 @@ import {AppSettings} from '../../app.settings';
return state.criter;
});
this.showLoaderCriteria$ = this.criteria$.map(criter => criter.size === 0);
*/
this.sectors$ = this._ngRedux.select(state => {
state.sectors.reduce((prevSector, sector) =>{
......
......@@ -23,6 +23,7 @@ export const AMKAFILL_SAVE = 'AMKAFILL_SAVE';
export const LOGININFO_SAVE = 'LOGININFO_SAVE';
export const LOGININFO_INIT = 'LOGININFO_INIT';
export const CRITERIA_RECEIVED = 'CRITERIA_RECEIVED';
export const CRITERIA_SAVE = 'CRITERIA_SAVE';
//export const VALID_NAMES_PATTERN = '[Α-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
......
......@@ -229,7 +229,30 @@ export class HelperDataService {
return rsa;
}
getCriteria() {
this.loginInfo$.forEach(loginInfoToken => {
console.log(loginInfoToken.get(0));
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
"Content-Type": "application/json",
"X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
});
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers });
return new Promise((resolve, reject) => {
this.http.get(`${AppSettings.API_ENDPOINT}/criteria/list`, options)
.map(response => <ISectorField[]>response.json())
.subscribe(data => {
resolve(data);
}, // put the data returned from the server in our variable
error => {
console.log("Error HTTP GET Service"); // in case of failure show this message
reject("Error HTTP GET Service");
},
() => console.log("Sector Fields Received"));//run this code in all cases); */
});
};
getCurrentUser() {
return new Promise((resolve, reject) => {
......
......@@ -3,17 +3,26 @@ import { INITIAL_STATE } from './criteria.initial-state';
import { Seq } from 'immutable';
import {
CRITERIA_RECEIVED,
CRITERIA_SAVE
} from '../../constants';
export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter {
switch (action.type) {
case CRITERIA_RECEIVED:
let newCriter = Array<ICriteria>();
let i=0;
action.payload.criteria.forEach(criteria => {
newCriter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: false});
i++;
});
return Seq(newCriter).map(n => n).toList();
case CRITERIA_SAVE:
let criter = Array<ICriteria>();
let ind=0;
action.payload.criter.forEach(criteria => {
criter.push(<ICriteria>criteria);
state.forEach(criteria => {
criter.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: action.payload.criter[0][ind]});
ind++;
});
......@@ -21,3 +30,14 @@ export function criteriaReducer(state: ICriter = INITIAL_STATE, action): ICriter
default: return state;
}
};
/*
case COURSEFIELDS_SELECTED_SAVE:
let selectedCourseFields = Array<ICourseField>();
let ind=0;
state.forEach(courseField => {
selectedCourseFields.push(<ICourseField>{id: courseField.id, name: courseField.name, selected: action.payload.courseFieldsSelected[ind]});
ind++;
});
return Seq(selectedCourseFields).map(n => n).toList();
default: return state;
*/
......@@ -3,10 +3,16 @@ import { ICriteria, ICriter } from './criteria.types';
export function deimmutifyCriteria(state: ICriter): ICriteria[] {
let fetchedCriteria = new Array();
/*
state.forEach(criteria => {
fetchedCriteria.push(<ICriteria>{orphanmono: criteria.orphanmono, orphantwice: criteria.orphantwice, threechildren: criteria.threechildren,
manychildren: criteria.manychildren, twins: criteria.twins, disability: criteria.disability, studies: criteria.studies, income: criteria.income,
});
});
*/
state.forEach(criteria => {
fetchedCriteria.push(<ICriteria>{id: criteria.id, name: criteria.name, mutual_disabled_id: criteria.mutual_disabled_id, selected: criteria.selected,
});
});
return fetchedCriteria;
};
import { List } from 'immutable';
export interface ICriteria {
/*
orphanmono: boolean;
orphantwice: boolean;
threechildren: boolean;
......@@ -9,6 +10,13 @@ export interface ICriteria {
disability: boolean;
studies: boolean;
income: string;
*/
id: string;
name: string;
mutual_disabled_id: string,
//globalIndex: number;
selected: boolean;
}
export type ICriter = List<ICriteria>;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment