Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
8074c820
Commit
8074c820
authored
Jul 20, 2017
by
Χάρης Παπαδόπουλος
Browse files
Restructured region schools. Rewrote reducers.
parent
286e72e6
Changes
14
Hide whitespace changes
Inline
Side-by-side
source/actions/regionschools.actions.ts
View file @
8074c820
...
...
@@ -12,7 +12,7 @@ export class RegionSchoolsActions {
getRegionSchools
=
(
classActive
,
courseActive
,
reload
)
=>
{
const
{
regions
}
=
this
.
_ngRedux
.
getState
();
if
(
reload
===
true
||
(
reload
===
false
&&
(
regions
.
length
===
0
||
regions
[
0
].
get
(
"
region_id
"
)
===
null
)
))
{
if
(
reload
===
true
||
(
reload
===
false
&&
regions
.
size
===
0
))
{
return
this
.
_hds
.
getRegionsWithSchools
(
classActive
,
courseActive
).
then
(
regions
=>
{
return
this
.
_ngRedux
.
dispatch
({
type
:
REGIONSCHOOLS_RECEIVED
,
...
...
source/app.ts
View file @
8074c820
import
'
reflect-metadata
'
;
import
'
babel-polyfill
'
;
import
'
core-js/es6
'
;
import
'
core-js/es7/reflect
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
NgReduxModule
,
DevToolsExtension
,
NgRedux
}
from
'
ng2-redux
'
;
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
CookieModule
}
from
'
ngx-cookie
'
;
import
{
MyDatePickerModule
}
from
'
mydatepicker
'
;
import
{
NguiAutoCompleteModule
}
from
'
@ngui/auto-complete
'
;
import
"
reflect-metadata
"
;
import
"
babel-polyfill
"
;
import
"
core-js/es6
"
;
import
"
core-js/es7/reflect
"
;
import
{
NgModule
}
from
"
@angular/core
"
;
import
{
NgReduxModule
,
DevToolsExtension
,
NgRedux
}
from
"
ng2-redux
"
;
import
{
BrowserModule
}
from
"
@angular/platform-browser
"
;
import
{
CookieModule
}
from
"
ngx-cookie
"
;
import
{
MyDatePickerModule
}
from
"
mydatepicker
"
;
import
{
NguiAutoCompleteModule
}
from
"
@ngui/auto-complete
"
;
import
{
FormsModule
,
ReactiveFormsModule
,
}
from
'
@angular/forms
'
;
}
from
"
@angular/forms
"
;
import
{
RouterModule
}
from
'
@angular/router
'
;
import
{
HttpModule
}
from
'
@angular/http
'
;
import
{
RouterModule
}
from
"
@angular/router
"
;
import
{
HttpModule
}
from
"
@angular/http
"
;
import
{
APP_BASE_HREF
,
HashLocationStrategy
,
LocationStrategy
,
NgLocalization
,
}
from
'
@angular/common
'
;
}
from
"
@angular/common
"
;
import
{
platformBrowserDynamic
}
from
'
@angular/platform-browser-dynamic
'
;
import
Main
from
'
./containers/main
'
;
import
{
APP_ROUTER_PROVIDERS
,
APP_DECLARATIONS
}
from
'
./app.routes
'
;
import
{
platformBrowserDynamic
}
from
"
@angular/platform-browser-dynamic
"
;
import
Main
from
"
./containers/main
"
;
import
{
APP_ROUTER_PROVIDERS
,
APP_DECLARATIONS
}
from
"
./app.routes
"
;
/* Here we import services */
import
{
HelperDataService
}
from
'
./services/helper-data-service
'
;
import
{
LoaderService
}
from
'
./services/Spinner.service
'
;
import
{
AuthService
}
from
'
./services/auth.service
'
;
import
SchoolAuthGuard
from
'
./guards/school.auth.guard
'
;
import
SchoolStudentsLockedGuard
from
'
./guards/school.students.locked.guard
'
;
import
SchoolCapacityLockedGuard
from
'
./guards/school.capacity.locked.guard
'
;
import
StudentAuthGuard
from
'
./guards/student.auth.guard
'
;
import
ReportsAuthGuard
from
'
./guards/reports.auth.guard
'
;
import
StudentLockGuard
from
'
./guards/student.lock.guard
'
;
import
RegionEduAuthGuard
from
'
./guards/regionedu.auth.guard
'
;
import
EduAdminAuthGuard
from
'
./guards/eduadmin.auth.guard
'
;
import
MinistryAuthGuard
from
'
./guards/ministry.auth.guard
'
;
import
{
HelperDataService
}
from
"
./services/helper-data-service
"
;
import
{
LoaderService
}
from
"
./services/Spinner.service
"
;
import
{
AuthService
}
from
"
./services/auth.service
"
;
import
SchoolAuthGuard
from
"
./guards/school.auth.guard
"
;
import
SchoolStudentsLockedGuard
from
"
./guards/school.students.locked.guard
"
;
import
SchoolCapacityLockedGuard
from
"
./guards/school.capacity.locked.guard
"
;
import
StudentAuthGuard
from
"
./guards/student.auth.guard
"
;
import
ReportsAuthGuard
from
"
./guards/reports.auth.guard
"
;
import
StudentLockGuard
from
"
./guards/student.lock.guard
"
;
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
'
;
import
*
as
$
from
"
jquery
"
;
import
{
ACTION_PROVIDERS
}
from
"
./actions
"
;
import
Home
from
"
./components/home
"
;
import
{
Ng2SmartTableModule
,
LocalDataSource
}
from
"
ng2-smart-table
"
;
import
HeaderComponent
from
'
./components/header/header.component
'
;
import
NavbarComponent
from
'
./components/navbar/navbar.component
'
;
import
MainComponent
from
'
./components/main/main.component
'
;
import
FooterComponent
from
'
./components/footer/footer.component
'
;
import
HeaderComponent
from
"
./components/header/header.component
"
;
import
NavbarComponent
from
"
./components/navbar/navbar.component
"
;
import
MainComponent
from
"
./components/main/main.component
"
;
import
FooterComponent
from
"
./components/footer/footer.component
"
;
import
{
enableProdMode
}
from
'
@angular/core
'
;
import
{
enableProdMode
}
from
"
@angular/core
"
;
class
MyLocalization
extends
NgLocalization
{
getPluralCategory
(
value
:
any
)
{
if
(
value
<
5
)
{
return
'
few
'
;
return
"
few
"
;
}
}
}
...
...
@@ -80,12 +80,12 @@ class MyLocalization extends NgLocalization {
],
bootstrap
:
[
Main
],
providers
:
[
{
provide
:
APP_BASE_HREF
,
useValue
:
'
/
'
},
{
provide
:
APP_BASE_HREF
,
useValue
:
"
/
"
},
{
provide
:
LocationStrategy
,
useClass
:
HashLocationStrategy
},
{
provide
:
NgLocalization
,
useClass
:
MyLocalization
},
DevToolsExtension
,
ACTION_PROVIDERS
,
//Service1, again services here
//
Service1, again services here
HelperDataService
,
LoaderService
,
AuthService
,
...
...
source/components/student-application-form/application.preview.ts
View file @
8074c820
...
...
@@ -10,7 +10,7 @@ import { RegionSchoolsActions } from '../../actions/regionschools.actions';
import
{
EpalClassesActions
}
from
'
../../actions/epalclass.actions
'
;
import
{
ISectorFields
}
from
'
../../store/sectorfields/sectorfields.types
'
;
import
{
ISectors
}
from
'
../../store/sectorcourses/sectorcourses.types
'
;
import
{
IRegionRecord
,
IRegionSchoolRecord
}
from
'
../../store/regionschools/regionschools.types
'
;
import
{
IRegionRecord
,
IRegionRecords
,
IRegionSchoolRecord
}
from
'
../../store/regionschools/regionschools.types
'
;
import
{
IEpalClasses
}
from
'
../../store/epalclasses/epalclasses.types
'
;
import
{
AppSettings
}
from
'
../../app.settings
'
;
import
{
REGION_SCHOOLS_INITIAL_STATE
}
from
'
../../store/regionschools/regionschools.initial-state
'
;
...
...
@@ -80,7 +80,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
@
Injectable
()
export
default
class
ApplicationPreview
implements
OnInit
{
private
sectors$
:
BehaviorSubject
<
ISectors
>
;
private
regions$
:
BehaviorSubject
<
Array
<
IRegionRecord
>
>
;
private
regions$
:
BehaviorSubject
<
IRegionRecord
s
>
;
private
selectedSchools$
:
BehaviorSubject
<
Array
<
IRegionSchoolRecord
>>
=
new
BehaviorSubject
(
Array
());
private
sectorFields$
:
BehaviorSubject
<
ISectorFields
>
;
private
epalclasses$
:
BehaviorSubject
<
IEpalClasses
>
;
...
...
@@ -124,7 +124,7 @@ import { SECTOR_FIELDS_INITIAL_STATE } from '../../store/sectorfields/sectorfiel
this
.
regionsSub
=
this
.
_ngRedux
.
select
(
state
=>
{
let
numsel
=
0
,
numsel2
=
0
;
let
selectedSchools
=
Array
<
IRegionSchoolRecord
>
();
if
(
state
.
regions
.
length
===
0
||
state
.
regions
[
0
].
get
(
"
region_id
"
)
===
null
)
if
(
state
.
regions
.
size
===
0
)
return
;
state
.
regions
.
reduce
((
prevRegion
,
region
)
=>
{
region
.
get
(
"
epals
"
).
reduce
((
prevEpal
,
epal
)
=>
{
...
...
source/components/student-application-form/application.submit.ts
View file @
8074c820
...
...
@@ -6,7 +6,7 @@ import { Injectable } from "@angular/core";
import
{
NgRedux
,
select
}
from
"
ng2-redux
"
;
import
{
IAppState
}
from
"
../../store/store
"
;
import
{
IStudentDataFields
}
from
"
../../store/studentdatafields/studentdatafields.types
"
;
import
{
IRegionRecord
,
IRegionSchoolRecord
}
from
"
../../store/regionschools/regionschools.types
"
;
import
{
IRegionRecord
,
IRegionRecords
,
IRegionSchoolRecord
}
from
"
../../store/regionschools/regionschools.types
"
;
import
{
ISectors
}
from
"
../../store/sectorcourses/sectorcourses.types
"
;
import
{
ISectorFields
}
from
"
../../store/sectorfields/sectorfields.types
"
;
import
{
IEpalClasses
}
from
"
../../store/epalclasses/epalclasses.types
"
;
...
...
@@ -106,7 +106,7 @@ import { HelperDataService } from "../../services/helper-data-service";
</button>
</div>
<div class="col-md-6">
<button type="button" *ngIf="(studentDataFields$ | async).size > 0 && (regions$ | async) && (regions$ | async).
length > 0 && (regions$ | async)[0].region_id !== null
&& (epalclasses$ | async).size > 0 && (loginInfo$ | async).size > 0" class="btn-primary btn-lg pull-right isclickable" style="width: 9em;" (click)="submitNow()">
<button type="button" *ngIf="(studentDataFields$ | async).size > 0 && (regions$ | async) && (regions$ | async).
size > 0
&& (epalclasses$ | async).size > 0 && (loginInfo$ | async).size > 0" class="btn-primary btn-lg pull-right isclickable" style="width: 9em;" (click)="submitNow()">
<span style="font-size: 0.9em; font-weight: bold;">Υποβολή </span><i class="fa fa-forward"></i>
</button>
</div>
...
...
@@ -124,7 +124,7 @@ import { HelperDataService } from "../../services/helper-data-service";
private
classSelected
;
private
totalPoints
=
<
number
>
0
;
private
studentDataFields$
:
BehaviorSubject
<
IStudentDataFields
>
;
private
regions$
:
BehaviorSubject
<
Array
<
IRegionRecord
>
>
;
private
regions$
:
BehaviorSubject
<
IRegionRecord
s
>
;
private
sectors$
:
BehaviorSubject
<
ISectors
>
;
private
sectorFields$
:
BehaviorSubject
<
ISectorFields
>
;
private
epalclasses$
:
BehaviorSubject
<
IEpalClasses
>
;
...
...
source/components/student-application-form/region.schools.select.ts
View file @
8074c820
...
...
@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
RegionSchoolsActions
}
from
'
../../actions/regionschools.actions
'
;
import
{
NgRedux
,
select
}
from
'
ng2-redux
'
;
import
{
IRegionRecord
}
from
'
../../store/regionschools/regionschools.types
'
;
import
{
IRegionRecord
,
IRegionRecords
}
from
'
../../store/regionschools/regionschools.types
'
;
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
'
;
...
...
@@ -32,7 +32,7 @@ import {AppSettings} from '../../app.settings';
<breadcrumbs></breadcrumbs>
</div>
<div class = "loading" *ngIf="!(regions$ | async) || (regions$ | async)
[0].region_id===null
">
<div class = "loading" *ngIf="!(regions$ | async) || (regions$ | async)
.size===0
">
</div>
<!-- <div class="row equal">
<div class="col-md-12"> -->
...
...
@@ -115,7 +115,7 @@ import {AppSettings} from '../../app.settings';
})
@
Injectable
()
export
default
class
RegionSchoolsSelect
implements
OnInit
,
OnDestroy
{
private
epalclasses$
:
BehaviorSubject
<
IEpalClasses
>
;
private
regions$
:
BehaviorSubject
<
IRegionRecord
[]
>
;
private
regions$
:
BehaviorSubject
<
IRegionRecord
s
>
;
private
sectors$
:
BehaviorSubject
<
ISectors
>
;
private
sectorFields$
:
BehaviorSubject
<
ISectorFields
>
;
private
epalclassesSub
:
Subscription
;
...
...
@@ -234,7 +234,7 @@ 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
);
if
(
state
.
regions
.
length
===
0
||
state
.
regions
[
0
].
get
(
"
region_id
"
)
===
null
)
if
(
state
.
regions
.
size
===
0
)
return
;
state
.
regions
.
reduce
((
prevRegion
,
region
)
=>
{
...
...
source/components/student-application-form/schools-order-select.ts
View file @
8074c820
...
...
@@ -4,7 +4,7 @@ import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import
{
Injectable
}
from
"
@angular/core
"
;
import
{
NgRedux
,
select
}
from
'
ng2-redux
'
;
import
{
RegionSchoolsActions
}
from
'
../../actions/regionschools.actions
'
;
import
{
IRegionRecord
,
IRegionSchoolRecord
}
from
'
../../store/regionschools/regionschools.types
'
;
import
{
IRegionRecord
,
IRegionRecords
,
IRegionSchoolRecord
}
from
'
../../store/regionschools/regionschools.types
'
;
import
{
REGION_SCHOOLS_INITIAL_STATE
}
from
'
../../store/regionschools/regionschools.initial-state
'
;
import
{
IAppState
}
from
'
../../store/store
'
;
import
{
AppSettings
}
from
'
../../app.settings
'
;
...
...
@@ -15,7 +15,7 @@ import {AppSettings} from '../../app.settings';
<div class="row">
<breadcrumbs></breadcrumbs>
</div>
<div class = "loading" *ngIf="(selectedSchools$ | async).length === 0 || !(regions$ | async) ||
(
(regions$ | async).
length === 1 && (regions$ | async)[0].region_id === null)
">
<div class = "loading" *ngIf="(selectedSchools$ | async).length === 0 || !(regions$ | async) || (regions$ | async).
size === 0
">
</div>
<h4> Σειρά προτίμησης</h4>
...
...
@@ -51,7 +51,7 @@ import {AppSettings} from '../../app.settings';
})
@
Injectable
()
export
default
class
SchoolsOrderSelect
implements
OnInit
,
OnDestroy
{
// public formGroup: FormGroup;
private
regions$
:
BehaviorSubject
<
Array
<
IRegionRecord
>
>
;
private
regions$
:
BehaviorSubject
<
IRegionRecord
s
>
;
private
regionsSub
:
Subscription
;
private
selectedSchools$
:
BehaviorSubject
<
Array
<
IRegionSchoolRecord
>>
=
new
BehaviorSubject
(
Array
());
...
...
source/services/helper-data-service.ts
View file @
8074c820
...
...
@@ -32,8 +32,6 @@ export class HelperDataService implements OnInit, OnDestroy {
private
_ngRedux
:
NgRedux
<
IAppState
>
,
private
_cookieService
:
CookieService
)
{
this
.
loginInfo$
=
new
BehaviorSubject
(
LOGININFO_INITIAL_STATE
);
};
ngOnInit
()
{
...
...
@@ -278,7 +276,7 @@ export class HelperDataService implements OnInit, OnDestroy {
};
transformRegionSchoolsSchema
(
regionSchools
:
any
)
{
let
rsa
=
Array
<
IRRegion
>
();
let
rsa
=
Array
<
any
>
();
let
trackRegionId
:
string
;
let
trackIndex
:
number
;
...
...
@@ -289,7 +287,7 @@ export class HelperDataService implements OnInit, OnDestroy {
regionSchools
.
forEach
(
regionSchool
=>
{
if
(
trackRegionId
!==
regionSchool
.
region_id
)
{
trackIndex
++
;
rsa
.
push
(
<
IRRegion
>
{
"
region_id
"
:
regionSchool
.
region_id
,
"
region_name
"
:
regionSchool
.
region_name
,
"
epals
"
:
Array
<
IRRegionSchool
>
()
});
rsa
.
push
(
<
any
>
{
"
region_id
"
:
regionSchool
.
region_id
,
"
region_name
"
:
regionSchool
.
region_name
,
"
epals
"
:
Array
<
any
>
()
});
trackRegionId
=
regionSchool
.
region_id
;
}
rsa
[
trackIndex
].
epals
.
push
(
<
IRRegionSchool
>
{
"
epal_id
"
:
regionSchool
.
epal_id
,
"
epal_name
"
:
regionSchool
.
epal_name
,
"
epal_special_case
"
:
regionSchool
.
epal_special_case
,
"
globalIndex
"
:
j
,
"
selected
"
:
false
,
"
order_id
"
:
0
});
...
...
source/store/index.ts
View file @
8074c820
...
...
@@ -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
{
IRRegion
,
IRRegionSchool
,
IRegionRecord
,
IRegion
School
Record
}
from
'
./regionschools/regionschools.types
'
;
import
{
IRRegion
,
IRRegionSchool
,
IRegionRecord
,
IRegionRecord
s
,
IRegionSchoolRecord
,
IRegionSchoolRecords
}
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,9 @@ export {
ISectorFields
,
IRRegion
,
IRegionRecord
,
IRegionRecords
,
IRegionSchoolRecord
,
IRegionSchoolRecords
,
IRRegionSchool
,
ISectors
,
ISector
,
...
...
source/store/regionschools/index.ts
View file @
8074c820
import
{
IRegionRecord
,
IRRegion
,
IRRegionSchool
,
IRegionSchoolRecord
}
from
'
./regionschools.types
'
;
import
{
IRegionRecord
,
IRegionRecords
,
IRRegion
,
IRRegionSchool
,
IRegionSchoolRecord
,
IRegionSchoolRecords
}
from
'
./regionschools.types
'
;
import
{
regionSchoolsReducer
}
from
'
./regionschools.reducer
'
;
import
{
deimmutifyRegionSchools
}
from
'
./regionschools.transformers
'
;
export
{
IRRegion
,
IRegionRecord
,
IRegionRecords
,
IRegionSchoolRecord
,
IRegionSchoolRecords
,
IRRegionSchool
,
regionSchoolsReducer
,
deimmutifyRegionSchools
,
...
...
source/store/regionschools/regionschools.initial-state.ts
View file @
8074c820
import
{
List
}
from
'
immutable
'
;
import
{
IRegion
,
IRegionM
,
IRegionRecord
,
IRRegion
,
IRRegionSchool
,
IRegionSchoolRecord
}
from
'
./regionschools.types
'
;
import
{
IRegionRecord
,
IRRegion
,
IRRegionSchool
,
IRegionSchoolRecord
,
IRegionSchoolRecords
}
from
'
./regionschools.types
'
;
import
{
recordify
}
from
'
typed-immutable-record
'
;
// export const INITIAL_STATE = List<ICourseField>([new CourseFieldRecord({})]);
//
export const REGION_SCHOOLS_INITIAL_STATE = List<IRegion
M
>();
export
const
REGION_SCHOOLS_INITIAL_STATE
=
new
Array
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
null
,
region_name
:
null
,
epals
:
new
Array
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
epal_id
:
null
,
epal_name
:
null
,
epal_special_case
:
null
,
globalIndex
:
-
1
,
selected
:
false
,
order_id
:
-
1
}))
}));
export
const
REGION_SCHOOLS_INITIAL_STATE
=
List
<
IRegion
Record
>
();
//
export const REGION_SCHOOLS_INITIAL_STATE = new Array(recordify<IRRegion, IRegionRecord>({region_id: null, region_name: null, epals: new Array(recordify<IRRegionSchool, IRegionSchoolRecord>({epal_id: null, epal_name: null, epal_special_case: null, globalIndex: -1, selected: false, order_id: -1 })) }));
source/store/regionschools/regionschools.reducer.ts
View file @
8074c820
import
{
IR
egions
,
Region
,
IRegion
,
IRRegion
,
IRegionM
,
RegionSchool
,
IRRegionSchool
,
IRegionSchools
,
IRegionSchoolRecord
,
IRegionSchoolRecords
,
IRegionRecord
}
from
'
./regionschools.types
'
;
import
{
IR
Region
,
IRRegionSchool
,
IRegionSchoolRecord
,
IRegionSchoolRecords
,
IRegionRecord
,
IRegionRecords
}
from
'
./regionschools.types
'
;
import
{
REGION_SCHOOLS_INITIAL_STATE
}
from
'
./regionschools.initial-state
'
;
import
{
Seq
,
Map
,
fromJS
}
from
'
immutable
'
;
import
{
Seq
,
Map
,
fromJS
,
List
}
from
'
immutable
'
;
import
{
recordify
}
from
'
typed-immutable-record
'
;
import
{
...
...
@@ -10,79 +10,40 @@ import {
REGIONSCHOOLS_INIT
}
from
'
../../constants
'
;
export
function
regionSchoolsReducer
(
state
:
IRegionRecord
[]
=
REGION_SCHOOLS_INITIAL_STATE
,
action
):
IRegionRecord
[]
{
export
function
regionSchoolsReducer
(
state
:
IRegionRecord
s
=
REGION_SCHOOLS_INITIAL_STATE
,
action
):
IRegionRecord
s
{
switch
(
action
.
type
)
{
case
REGIONSCHOOLS_RECEIVED
:
let
newRegions
=
Array
<
IRegionRecord
>
();
let
newEpals
=
Array
<
IRegionSchoolRecord
>
();
let
i
=
0
,
j
=
0
;
let
ii
=
0
;
action
.
payload
.
regions
.
forEach
(
region
=>
{
region
.
epals
.
forEach
(
epal
=>
{
if
(
j
!==
i
||
(
i
===
0
&&
ii
===
0
))
{
newRegions
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
new
Array
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
}))
}));
j
=
i
;
}
else
newRegions
[
i
].
epals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
}));
newEpals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
}));
ii
++
;
})
newRegions
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
List
(
newEpals
)
}));
newEpals
=
Array
<
IRegionSchoolRecord
>
();
i
++
;
});
return
newRegions
;
return
List
(
newRegions
)
;
case
REGIONSCHOOLS_SELECTED_SAVE
:
// let ind=0;
let
region
:
IRegionRecord
;
region
=
state
[
action
.
payload
.
rIndex
];
let
newState
=
Array
<
IRegionRecord
>
();
i
=
0
,
j
=
0
;
ii
=
0
;
state
.
forEach
(
region
=>
{
let
epals
:
IRegionSchoolRecords
;
epals
=
region
.
get
(
"
epals
"
);
ii
=
0
;
epals
.
forEach
(
epal
=>
{
if
(
j
!==
i
||
(
i
===
0
&&
ii
===
0
))
{
if
(
i
===
action
.
payload
.
rIndex
&&
ii
===
action
.
payload
.
sIndex
)
newState
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
new
Array
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
epal_id
:
epal
.
epal_id
,
epal_name
:
epal
.
epal_name
,
epal_special_case
:
epal
.
epal_special_case
,
globalIndex
:
epal
.
globalIndex
,
selected
:
action
.
payload
.
checked
,
order_id
:
epal
.
order_id
}))
}));
else
newState
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
new
Array
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
}))
}));
j
=
i
;
}
else
{
if
(
i
===
action
.
payload
.
rIndex
&&
ii
===
action
.
payload
.
sIndex
)
newState
[
i
].
epals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
epal_id
:
epal
.
epal_id
,
epal_name
:
epal
.
epal_name
,
epal_special_case
:
epal
.
epal_special_case
,
globalIndex
:
epal
.
globalIndex
,
selected
:
action
.
payload
.
checked
,
order_id
:
epal
.
order_id
}));
else
newState
[
i
].
epals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
}));
}
ii
++
;
})
i
++
;
})
return
newState
;
/* state.forEach(region => {
if (ind === action.payload.rIndex) {
let regionCopy = state.get(ind);
regionCopy.epals[action.payload.sIndex].selected = action.payload.checked;
return state.withMutations(function (list) {
list.set(ind++, regionCopy);
let
ind
=
0
;
return
state
.
withMutations
(
function
(
list
)
{
list
.
setIn
([
action
.
payload
.
rIndex
,
"
epals
"
],
state
.
get
(
action
.
payload
.
rIndex
).
get
(
"
epals
"
).
setIn
([
action
.
payload
.
sIndex
,
"
selected
"
],
action
.
payload
.
checked
));
});
}
ind++;
}); */
// return state;
case
REGIONSCHOOLS_ORDER_SAVE
:
region
=
state
[
action
.
payload
.
rIndex
];
let
newState2
=
Array
<
IRegionRecord
>
();
newEpals
=
Array
<
IRegionSchoolRecord
>
();
i
=
0
,
j
=
0
;
let
ind2
=
0
;
state
.
forEach
(
region
=>
{
let
epals
:
IRegionSchoolRecords
;
epals
=
region
.
get
(
"
epals
"
);
epals
.
forEach
(
epal
=>
{
let
newOrderId
=
epal
.
order_id
;
...
...
@@ -93,18 +54,15 @@ export function regionSchoolsReducer(state: IRegionRecord[] = REGION_SCHOOLS_INI
break
;
}
}
if
(
j
!==
i
||
i
===
0
)
{
newState2
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
new
Array
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
:
newOrderId
}))
}));
j
=
i
;
}
else
{
newState2
[
i
].
epals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
:
newOrderId
}));
}
newEpals
.
push
(
recordify
<
IRRegionSchool
,
IRegionSchoolRecord
>
({
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
:
newOrderId
}));
});
newState2
.
push
(
recordify
<
IRRegion
,
IRegionRecord
>
({
region_id
:
region
.
region_id
,
region_name
:
region
.
region_name
,
epals
:
List
(
newEpals
)
}));
newEpals
=
Array
<
IRegionSchoolRecord
>
();
i
++
;
});
return
newState2
;
return
List
(
newState2
)
;
case
REGIONSCHOOLS_INIT
:
return
REGION_SCHOOLS_INITIAL_STATE
;
default
:
return
state
;
...
...
source/store/regionschools/regionschools.transformers.ts
View file @
8074c820
import
{
IRegionRecord
}
from
'
./regionschools.types
'
;
import
{
IRegionRecord
,
IRegionRecords
}
from
'
./regionschools.types
'
;
export
function
deimmutifyRegionSchools
(
state
:
IRegionRecord
[]
):
IRegionRecord
[]
{
export
function
deimmutifyRegionSchools
(
state
:
IRegionRecord
s
):
IRegionRecord
s
{
// let fetchedRegions = new Array<IRegion>();
// let i = 0;
...
...
source/store/regionschools/regionschools.types.ts
View file @
8074c820
...
...
@@ -4,7 +4,7 @@ import {TypedRecord} from 'typed-immutable-record';
export
interface
IRRegion
{
region_id
:
string
;
region_name
:
string
;
epals
:
IRRegionSchool
[]
;
epals
:
List
<
IRRegionSchool
>
;
}
export
interface
IRRegionSchool
{
...
...
@@ -17,33 +17,6 @@ export interface IRRegionSchool {
}
export
interface
IRegionRecord
extends
TypedRecord
<
IRegionRecord
>
,
IRRegion
{};
export
type
IRegionRecords
=
List
<
IRegionRecord
>
;
export
interface
IRegionSchoolRecord
extends
TypedRecord
<
IRegionSchoolRecord
>
,
IRRegionSchool
{};
export
type
IRegionSchoolRecords
=
IRegionSchoolRecord
[];
export
interface
Region
{
region_id
:
string
;
region_name
:
string
;
epals
:
RegionSchool
[];
}
export
interface
RegionSchool
{
epal_id
:
string
;
epal_name
:
string
;
epal_special_case
:
string
;
globalIndex
:
number
;
selected
:
boolean
;
order_id
:
number
;
}
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
=
List
<
RegionSchool
>
;
export
type
IRegionSchoolRecords
=
List
<
IRegionSchoolRecord
>
;
source/store/store.ts
View file @
8074c820
...
...
@@ -15,7 +15,7 @@ import * as criter from './criteria';
export
interface
IAppState
{
courseFields
?:
courseFields
.
ICourseFields
;
sectorFields
?:
sectorFields
.
ISectorFields
;
regions
?:
regions
.
IRegionRecord
[]
;
regions
?:
regions
.
IRegionRecord
s
;
sectors
?:
sectors
.
ISectors
;
studentDataFields
?:
studentDataFields
.
IStudentDataFields
;
epalclasses
?:
epalclasses
.
IEpalClasses
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment