Angularjs v4 migration. WIP: Fixing region.schools.select. Restructuring redux...

Angularjs v4 migration. WIP: Fixing region.schools.select. Restructuring redux store for deep immutability. DirectorView bug fix.
parent 887da2d0
......@@ -50,7 +50,7 @@ class DirectorView extends ControllerBase
"error_code" => 3001
], Response::HTTP_FORBIDDEN);
}
if ($epalConfig->lock_students->value) {
if ($epalConfig->lock_school_students_view->value) {
return $this->respondWithStatus([
"error_code" => 3002
], Response::HTTP_FORBIDDEN);
......@@ -555,7 +555,7 @@ class DirectorView extends ControllerBase
$specialityid = $object->specialty_id->entity->id();
$studentPerSchool = $this->entityTypeManager->getStorage('epal_student_class')
->loadByProperties(array('epal_id' => $schoolid, 'specialization_id' => $specialityid, 'currentclass' => 4));
$capacity_class_d = ($object -> capacity_class_specialty_d ->value) *25;
$capacity_class_d = ($object -> capacity_class_specialty_d ->value) *25;
$list[] = array(
'id' => $object->specialty_id->entity->id(),
'name' => 'Δ Λυκείου '.$object->specialty_id->entity->get('name')->value,
......
......@@ -436,9 +436,9 @@ class SubmitedApplications extends ControllerBase
'name' => $name_decoded,
'studentsurname' => $studentsurname_decoded,
'fatherfirstname' => $fatherfirstname_decoded,
'fathersurname' => $epalStudent->fathersurname,
'fathersurname' => '',
'motherfirstname' => $motherfirstname_decoded,
'mothersurname' => $epalStudent->mothersurname,
'mothersurname' => '',
'guardian_name' => $guardian_name_decoded,
'guardian_surname' => $guardian_surname_decoded,
'guardian_fathername' => $guardian_fathername_decoded,
......@@ -720,7 +720,7 @@ class SubmitedApplications extends ControllerBase
}
$transaction = $this->connection->startTransaction();
try {
//ανάκτηση τιμής από ρυθμίσεις διαχειριστή για lock_school_students_view
......@@ -749,7 +749,7 @@ class SubmitedApplications extends ControllerBase
if ($epalStudent) {
$epalStudentClasses = $this->entityTypeManager->getStorage('epal_student_class')->loadByProperties(array('student_id' => $applicationId));
$epalStudentClass = reset($epalStudentClasses);
if ($epalStudentClass) {
if ($epalStudentClass->directorconfirm->value === "1") {
return $this->respondWithStatus([
......@@ -801,4 +801,4 @@ class SubmitedApplications extends ControllerBase
return $res;
}
}
\ No newline at end of file
}
......@@ -304,14 +304,14 @@ class CBController extends ControllerBase
public function getXMLElements($doc){
$webUserDetails = $doc->getElementsByTagName( "WebUserDetails" );
if (!$webUserDetails || $webUserDetails->length === 0)
return false;
/* return array( // to be changed to empty array
// return false;
return array( // to be changed to empty array
'firstName' => '',
'surname' => '',
'fathersName' => '',
'comments' => '',
'tin' => '12345'
); */
);
foreach( $webUserDetails as $element )
{
......@@ -331,14 +331,14 @@ class CBController extends ControllerBase
$tin = $tins->item(0)->nodeValue;
if (!$tin || $tin === '')
return false;
/* return array( // to be changed to empty array
// return false;
return array( // to be changed to empty array
'firstName' => '',
'surname' => '',
'fathersName' => '',
'comments' => '',
'tin' => '12345'
); */
);
return array(
'firstName' => $firstName,
'surname' => $surname,
......
......@@ -40,6 +40,7 @@ import RegionEduAuthGuard from './guards/regionedu.auth.guard';
import EduAdminAuthGuard from './guards/eduadmin.auth.guard';
import MinistryAuthGuard from './guards/ministry.auth.guard';
import * as $ from 'jquery';
import { ACTION_PROVIDERS } from './actions';
import Home from './components/home';
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';
......@@ -101,5 +102,5 @@ class MyLocalization extends NgLocalization {
})
class AppModule {}
enableProdMode();
// enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
......@@ -82,7 +82,7 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this.TotalStudentsSub = this._hds.findTotalStudents().subscribe(x => {
this.TotalStudents$.next(x);
this.showLoader.next(false);
this.hasvalue = true;
this.hasvalue = true;
},
error => {
this.TotalStudents$.next([{}]);
......
......@@ -66,12 +66,12 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
</ul>
</div>
<ul *ngIf="(regions$ | async).size > 0" class="list-group left-side-view" style="margin-bottom: 20px;">
<ul *ngIf="(regions$ | async)" class="list-group left-side-view" style="margin-bottom: 20px;">
<div *ngFor="let epal$ of selectedSchools$ | async; let i=index; let isOdd=odd; let isEven=even" >
<li class="list-group-item" [class.oddout]="isOdd" [class.evenout]="isEven">
<span class="roundedNumber">{{(i+1)}}</span>&nbsp;&nbsp;{{epal$.epal_name}}
<span class="roundedNumber">{{(i+1)}}</span>&nbsp;&nbsp;{{epal$.get("epal_name")}}
</li>
</div>
</ul>
......@@ -124,13 +124,17 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
this.regionsSub = this._ngRedux.select(state => {
let numsel = 0, numsel2 = 0;
let selectedSchools = Array<IRegionSchool>();
if (state.regions.size === 0)
return;
console.log(state.regions);
state.regions.reduce((prevRegion, region) => {
region.epals.reduce((prevEpal, epal) => {
if (epal.selected === true) {
console.log(region);
region.get("epals").reduce((prevEpal, epal) => {
if (epal.get("selected") === true) {
numsel++;
selectedSchools.push(epal);
}
if (epal.order_id !== 0) {
if (epal.get("order_id") !== 0) {
numsel2++;
}
return epal;
......
......@@ -32,7 +32,7 @@ import {AppSettings} from '../../app.settings';
<breadcrumbs></breadcrumbs>
</div>
<div class = "loading" *ngIf="(regions$ | async).size === 0">
<div class = "loading" *ngIf="!(regions$ | async)">
</div>
<!-- <div class="row equal">
<div class="col-md-12"> -->
......@@ -66,20 +66,20 @@ import {AppSettings} from '../../app.settings';
<ul class="list-group main-view">
<div *ngFor="let region$ of regions$ | async; let i=index; let isOdd=odd; let isEven=even" >
<li class="list-group-item isclickable" (click)="setActiveRegion(i)" [class.oddout]="isOdd" [class.evenout]="isEven" [class.selectedout]="regionActive === i">
<h5>{{region$.region_name}}</h5>
<h5>{{region$.get("region_name")}}</h5>
</li>
<div *ngFor="let epal$ of region$.epals; let j=index; let isOdd2=odd; let isEven2=even" [class.oddin]="isOdd2" [class.evenin]="isEven2" [hidden]="i !== regionActive">
<div *ngFor="let epal$ of region$.get('epals'); let j=index; let isOdd2=odd; let isEven2=even" [class.oddin]="isOdd2" [class.evenin]="isEven2" [hidden]="i !== regionActive">
<div class="row">
<div class="col-md-2 col-md-offset-1">
<input #cb type="checkbox" formControlName="{{ epal$.globalIndex }}"
<input #cb type="checkbox" formControlName="{{ epal$.get('globalIndex') }}"
(change)="saveSelected(cb.checked,i,j)"
[hidden] = "(numSelected | async) === 3 && cb.checked === false"
>
</div>
<div class="col-md-8 col-md-offset-1 isclickable">
{{epal$.epal_name | removeSpaces}}
{{epal$.get("epal_name") | removeSpaces}}
</div>
</div>
......@@ -88,7 +88,7 @@ import {AppSettings} from '../../app.settings';
</div>
</ul>
</div>
<div class="row" style="margin-top: 20px; margin-bottom: 20px;" *ngIf="(regions$ | async).size > 0">
<div class="row" style="margin-top: 20px; margin-bottom: 20px;" *ngIf="(regions$ | async)">
<div class="col-md-6">
<button type="button" class="btn-primary btn-lg pull-left isclickable" (click)="navigateBack()" >
<i class="fa fa-backward"></i>
......@@ -109,6 +109,7 @@ import {AppSettings} from '../../app.settings';
</div>
</div>
</form>
<!-- <pre>{{formGroup.value | json}}</pre> -->
</div>
`
})
......@@ -233,20 +234,28 @@ import {AppSettings} from '../../app.settings';
let numreg = 0; //count reduced regions in order to set activeRegion when user comes back to his choices
this.selectionLimitOptional.next(false);
console.log("numsel="+numsel);
console.log(state.regions);
console.log(state.regions.size);
console.log(this.regions$.getValue());
if (state.regions.size === 0)
return;
state.regions.reduce((prevRegion, region) =>{
numreg++;
region.epals.reduce((prevEpal, epal) =>{
this.rss.push( new FormControl(epal.selected, []));
if (epal.selected === true) {
region.get("epals").reduce((prevEpal, epal) =>{
this.rss.push( new FormControl(epal.get("selected"), []));
if (epal.get("selected") === true) {
numsel++;
if ( epal.epal_special_case === "1") {
console.log("numsel2="+numsel);
if ( epal.get("epal_special_case") === "1") {
this.selectionLimitOptional.next(true);
}
this.regionActiveId = Number(region.region_id);
this.regionActive = numreg - 1;
}
if (Number(region.region_id) === this.regionActiveId) {
if (region.epals.length < this.regionSizeLimit)
if (region.get("epals").length < this.regionSizeLimit)
this.selectionLimitOptional.next(true);
}
return epal;
......@@ -254,9 +263,12 @@ import {AppSettings} from '../../app.settings';
return region;
}, {});
console.log("numsel3="+numsel);
this.numSelected.next(numsel);
return state.regions;
}).subscribe(this.regions$);
}
setClassActive(className) {
......@@ -327,12 +339,12 @@ import {AppSettings} from '../../app.settings';
// if ( (this.selectionLimitOptional.value === false /*&& this.classNight.value === false */ && this.numSelected.value < this.selectionLimit.value )
// || (this.numSelected.value === 0) ) {
if ( this.numSelected.value === 0) {
if ( this.numSelected.getValue() === 0) {
//this.modalHeader = "modal-header-success";
this.modalHeader.next("modal-header-danger");
this.modalTitle.next("Επιλογή αριθμού σχολείων");
if (this.numSelected.value === 0)
if (this.numSelected.getValue() === 0)
this.modalText.next("Δεν έχετε επιλέξει κανένα σχολείο!");
/*
else
......
......@@ -272,8 +272,8 @@ import {Location} from '@angular/common';
}
ngOnDestroy() {
(<any>$('#applicationDeleteConfirm')).remove();
(<any>$('#applicationDeleteError')).remove();
(<any>jQuery('#applicationDeleteConfirm')).remove();
(<any>jQuery('#applicationDeleteError')).remove();
if (this.SubmitedUsersSub)
this.SubmitedUsersSub.unsubscribe();
if (this.SubmitedDetailsSub)
......@@ -284,8 +284,8 @@ import {Location} from '@angular/common';
ngOnInit() {
(<any>$('#applicationDeleteConfirm')).appendTo("body");
(<any>$('#applicationDeleteError')).appendTo("body");
(<any>jQuery('#applicationDeleteConfirm')).appendTo("body");
(<any>jQuery('#applicationDeleteError')).appendTo("body");
this.showLoader$.next(true);
this.SubmitedUsersSub = this._hds.getSubmittedPreviw().subscribe(
......@@ -356,18 +356,18 @@ import {Location} from '@angular/common';
}
public showConfirmModal(): void {
(<any>$('#applicationDeleteConfirm')).modal('show');
(<any>jQuery('#applicationDeleteConfirm')).modal('show');
}
public showErrorModal(): void {
(<any>$('#applicationDeleteError')).modal('show');
(<any>jQuery('#applicationDeleteError')).modal('show');
}
public hideConfirmModal(): void {
(<any>$('#applicationDeleteConfirm')).modal('hide');
(<any>jQuery('#applicationDeleteConfirm')).modal('hide');
}
public hideErrorModal(): void {
(<any>$('#applicationDeleteError')).modal('hide');
(<any>jQuery('#applicationDeleteError')).modal('hide');
}
public onHidden(): void {
......
......@@ -3,6 +3,7 @@ import { Component, Inject, OnInit, OnDestroy }
import {
Router,
ActivatedRoute,
NavigationStart
}
from '@angular/router';
import './globalstyles.css';
......@@ -34,10 +35,18 @@ export default class Main {
private _ngRedux: NgRedux<IAppState>,
private _devTools: DevToolsExtension
) {
router.events.subscribe((data) => {
/* router.events
.filter((e: Event) => e instanceof NavigationStart)
.subscribe((e: NavigationStart) => {
console.log(e.url);
console.log(e.toString());
this.path = e.url.substr(1);
this.pathSchool = e.url.substr(1);
}); */
/* router.events.subscribe((data) => {
this.path = data.url.substr(1);
this.pathSchool = data.url.substr(1);
});
}); */
const tools = _devTools.enhancer({
......@@ -46,9 +55,9 @@ export default class Main {
_ngRedux.configureStore(
rootReducer,
{},
// middleware,
middleware,
// tools ? [ ...enhancers, tools ] : enhancers);
// tools);
);
tools);
// );
}
}
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { STUDENT_ROLE } from '../constants';
import { Router } from '@angular/router';
......@@ -9,7 +9,8 @@ export default class StudentAuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate() {
canActivate(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot) {
return this.authService.isLoggedIn(STUDENT_ROLE).then(loggedIn => {
if (!loggedIn) {
this.router.navigate(['/logout']);
......
......@@ -17,7 +17,7 @@ export class AuthService {
};
isLoggedIn(role) {
return new Promise((resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
......@@ -38,13 +38,13 @@ export class AuthService {
},
error => {
console.log("Error Getting Auth Data");
reject("Error Getting Auth Data");
reject(false);
});
});
}
isLoggedInForReports(role1,role2,role3) {
return new Promise((resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
......@@ -71,7 +71,7 @@ export class AuthService {
}
isApplicationLocked(role) {
return new Promise((resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
......@@ -96,7 +96,7 @@ export class AuthService {
}
isStudentsLocked(role) {
return new Promise((resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
......@@ -121,7 +121,7 @@ export class AuthService {
}
isCapacityLocked(role) {
return new Promise((resolve, reject) => {
return new Promise<boolean>((resolve, reject) => {
this._ngRedux.select(state => {
return state.loginInfo;
}).subscribe(loginInfo => {
......
......@@ -3,7 +3,7 @@ import * as createLogger from 'redux-logger';
import { IAppState, rootReducer, deimmutify } from './store';
import { ICourseField, ICourseFields } from './coursefields/coursefields.types';
import { ISectorField, ISectorFields } from './sectorfields/sectorfields.types';
import { IRegions, IRegion, IRegionSchool } from './regionschools/regionschools.types';
import { IRegions, IRegion, RegionSchool } from './regionschools/regionschools.types';
import { ISectors, ISector, ISectorCourse } from './sectorcourses/sectorcourses.types';
import { IStudentDataField, IStudentDataFields } from './studentdatafields/studentdatafields.types';
import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types';
......@@ -19,7 +19,7 @@ export {
ISectorFields,
IRegions,
IRegion,
IRegionSchool,
RegionSchool,
ISectors,
ISector,
ISectorCourse,
......
import { IRegions, IRegion, IRegionSchool } from './regionschools.types';
import { IRegions, IRegion, IRegionM, RegionSchool } from './regionschools.types';
import { regionSchoolsReducer } from './regionschools.reducer';
import { deimmutifyRegionSchools } from './regionschools.transformers';
export {
IRegion,
IRegionM,
IRegions,
IRegionSchool,
RegionSchool,
regionSchoolsReducer,
deimmutifyRegionSchools,
};
import { List } from 'immutable';
import { IRegion } from './regionschools.types';
import { IRegion, IRegionM } from './regionschools.types';
// export const INITIAL_STATE = List<ICourseField>([new CourseFieldRecord({})]);
export const REGION_SCHOOLS_INITIAL_STATE = List<IRegion>();
export const REGION_SCHOOLS_INITIAL_STATE = List<IRegionM>();
import { IRegions, IRegion, IRegionSchool } from './regionschools.types';
import { IRegions, Region, IRegion, IRegionM, RegionSchool, IRegionSchools } from './regionschools.types';
import { REGION_SCHOOLS_INITIAL_STATE } from './regionschools.initial-state';
import { Seq } from 'immutable';
import { Seq, Map, fromJS } from 'immutable';
import {
REGIONSCHOOLS_RECEIVED,
......@@ -12,28 +12,42 @@ import {
export function regionSchoolsReducer(state: IRegions = REGION_SCHOOLS_INITIAL_STATE, action): IRegions {
switch (action.type) {
case REGIONSCHOOLS_RECEIVED:
let newRegions = Array<IRegion>();
let newRegions = Array<Region>();
let i=0;
action.payload.regions.forEach(region => {
newRegions.push(<IRegion>{region_id: region.region_id, region_name: region.region_name, epals: Array<IRegionSchool>() });
newRegions.push(<any>{region_id: region.region_id, region_name: region.region_name, epals: <any>[] });
region.epals.forEach(epal => {
newRegions[i].epals.push(<IRegionSchool>{epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id });
newRegions[i].epals.push(<any>{epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id });
})
i++;
});
return Seq(newRegions).map(n => n).toList();
return fromJS(newRegions);
case REGIONSCHOOLS_SELECTED_SAVE:
let ind=0;
state.forEach(region => {
// let ind=0;
let region: IRegionM;
let epals: IRegionSchools;
region = state.get(action.payload.rIndex);
console.log(region);
epals = region.get("epals").epals;
let epal = epals.get(action.payload.sIndex);
epal.set("selected", action.payload.checked);
region = region.set("epals", epals.set(action.payload.sIndex,
epal.set("selected", action.payload.checked)));
return state
.set(action.payload.rIndex, region);
/* state.forEach(region => {
if (ind === action.payload.rIndex) {
region.epals[action.payload.sIndex].selected = action.payload.checked;
let regionCopy = state.get(ind);
regionCopy.epals[action.payload.sIndex].selected = action.payload.checked;
return state.withMutations(function (list) {
list.set(ind++, region);
list.set(ind++, regionCopy);
});
}
ind++;
});
return state;
}); */
// return state;
case REGIONSCHOOLS_ORDER_SAVE:
let ind2=0;
......
import { IRegions, IRegion, IRegionSchool } from './regionschools.types';
import { IRegions, IRegion } from './regionschools.types';
export function deimmutifyRegionSchools(state: IRegions): IRegion[] {
let fetchedRegions = new Array<IRegion>();
let i = 0;
state.forEach(region => {
export function deimmutifyRegionSchools(state: IRegions): IRegions {
// let fetchedRegions = new Array<IRegion>();
// let i = 0;
/* state.forEach(region => {
fetchedRegions.push(<IRegion>{region_id: region.region_id, region_name: region.region_name, epals: Array<IRegionSchool>()});
region.epals.forEach(epal => {
fetchedRegions[i].epals.push(<IRegionSchool>{epal_id: epal.epal_id, epal_name: epal.epal_name, epal_special_case: epal.epal_special_case, globalIndex: epal.globalIndex, selected: epal.selected, order_id: epal.order_id })
});
i++;
});
return fetchedRegions;
}); */
// return state.toJS();
return state;
// return fetchedRegions;
};
import { List } from 'immutable';
import { List, Map } from 'immutable';
export interface IRegion {
export interface Region {
region_id: string;
region_name: string;
epals: IRegionSchool[];
epals: RegionSchool[];
}
export interface IRegionSchool {
export interface RegionSchool {
epal_id: string;
epal_name: string;
epal_special_case: string;
......@@ -15,4 +16,14 @@ export interface IRegionSchool {
order_id: number;
}
export type IRegions = List<IRegion>;
export interface IRegion {
region_id: string;
region_name: string;
epals: IRegionSchools;
}
export type IRegions = List<IRegionM>;
// export type IRegionM = Map<IRegion>;
export type IRegionM = Map<string, IRegion>;
export type IRegionSchoolM = Map<string, RegionSchool>;
export type IRegionSchools = Map<string, List<IRegionSchoolM>>;
declare var require: any;
......@@ -10,7 +10,8 @@
"sourceMap": false,
"inlineSourceMap": false,
"module": "commonjs",
"target": "ES5"
"target": "ES5",
"types": []
},
"exclude": [
......
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