added ministerView component, added ministerReports component

parent 52fe44e2
export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal';
export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/drupal-8.2.6';
// export const API_ENDPOINT = 'http://eduslim2.minedu.gov.gr/angular/eepal-front/drupal';
export class AppSettings {
public static get API_ENDPOINT(): string {
return 'http://eduslim2.minedu.gov.gr/drupal';
return 'http://eduslim2.minedu.gov.gr/drupal-8.2.6';
// return 'http://eduslim2.minedu.gov.gr/angular/eepal-front/drupal';
}
}
import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/core";
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import { Observable} from "rxjs/Observable";
import { Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import {
FormBuilder,
FormGroup,
FormControl,
FormArray,
Validators,
} from '@angular/forms';
import { API_ENDPOINT } from '../../app.settings';
@Component({
selector: 'minister-reports',
template: `
<div>
<form [formGroup]="formGroup" #form>
<!--<button type="submit" class="btn-primary btn-md" (click)="form.submit()" >-->
<button type="submit" class="btn btn-default btn-block" (click)="reportGeneral()" >
Συγκεντρωτικά Αποτελέσματα Κατανομής
</button>
<div *ngFor="let generalReports$ of generalReport$ | async; let i=index">
<div *ngIf="showMessage">
<br>
Αριθμός Αιτήσεων: {{generalReports$.num_applications}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στην πρώτη τους προτίμηση: {{generalReports$.numchoice1}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στη δεύτερή τους προτίμηση: {{generalReports$.numchoice2}}<br>
Αριθμός μαθητών που τοποθετήθηκαν στην τρίτη τους προτίμηση: {{generalReports$.numchoice3}}<br>
Αριθμός μαθητών που δεν τοποθετήθηκαν σε καμμία τους προτίμηση: {{generalReports$.num_noallocated}}<br>
</div>
</div>
</form>
</div>
`
})
@Injectable() export default class MinisterReports implements OnInit, OnDestroy {
public formGroup: FormGroup;
loginInfo$: BehaviorSubject<ILoginInfo>;
loginInfoSub: Subscription;
private generalReport$: BehaviorSubject<any>;
private generalReportSub: Subscription;
private apiEndPoint = API_ENDPOINT;
private minedu_userName: string;
private minedu_userPassword: string;
private distStatus = "READY";
private data: string;
private showMessage: boolean;
constructor(private fb: FormBuilder,
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router) {
this.formGroup = this.fb.group({
});
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.generalReport$ = new BehaviorSubject([{}]);
this.showMessage = false;
}
ngOnDestroy() {
if (this.loginInfoSub)
this.loginInfoSub.unsubscribe();
this.loginInfo$.unsubscribe();
if (this.generalReportSub)
this.generalReportSub.unsubscribe();
this.generalReport$.unsubscribe();
}
ngOnInit() {
this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
}, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
}
reportGeneral() {
this.generalReportSub = this._hds.makeGeneralReport(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
this.generalReport$.next(data);
this.data = data;
},
error => {
this.generalReport$.next([{}]);
console.log("Error Getting generalReport");
},
() => {
console.log("Getting generalReport");
/*this.numChoice1 = this.data['numchoice1'];
console.log(this.numChoice1);*/
this.showMessage = true;
}
)
}
}
......@@ -2,13 +2,15 @@ import { Component, OnInit, OnDestroy, ElementRef, ViewChild} from "@angular/cor
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {Http, Headers, RequestOptions} from '@angular/http';
import { Observable} from "rxjs/Observable";
import { Http, Headers, RequestOptions} from '@angular/http';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial-state';
import {
FormBuilder,
......@@ -24,9 +26,27 @@ import { API_ENDPOINT } from '../../app.settings';
selector: 'minister-view',
template: `
<div
class = "loading" *ngIf=" distStatus === 'STARTED'" >
</div>
<div class="alert alert-info" *ngIf="distStatus === 'STARTED'">
Παρακαλώ περιμένετε...Η εκτέλεση της κατανομής ενδέχεται να διαρκέσει μερικά λεπτά. Παρακαλώ μην εκτελείται οποιαδήποτε ενέργεια μετακίνησης στον φυλλομετρητή σας, μέχρι να ολοκληρωθεί η κατανομή.
</div>
<div class="alert alert-info" *ngIf="distStatus === 'FINISHED'">
Η κατανομή ολοκληρώθηκε με επιτυχία!
</div>
<div class="alert alert-info" *ngIf="distStatus === 'ERROR'">
Αποτυχία κατανομής!
</div>
<div>
<!--
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/epal/distribution" #form>
<button type="submit" class="btn-primary btn-md" (click)="form.submit()" [disabled]="true">
-->
<form [formGroup]="formGroup" #form>
<!--<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>-->
<!--<button type="submit" class="btn-primary btn-md" (click)="form.submit()" >-->
<button type="submit" class="btn-primary btn-md" *ngIf="(loginInfo$ | async).size !== 0" (click)="runDistribution()" >
Εκτέλεση Κατανομής Μαθητών
</button>
</form>
......@@ -38,9 +58,17 @@ import { API_ENDPOINT } from '../../app.settings';
@Injectable() export default class MinisterView implements OnInit, OnDestroy {
public formGroup: FormGroup;
//private loginInfo$: Observable<ILoginInfo>;
loginInfo$: BehaviorSubject<ILoginInfo>;
loginInfoSub: Subscription;
private apiEndPoint = API_ENDPOINT;
private minedu_userName: string;
private minedu_userPassword: string;
private distStatus = "READY";
constructor(private fb: FormBuilder,
// private _ata: LoginInfoActions,
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router) {
......@@ -49,21 +77,44 @@ import { API_ENDPOINT } from '../../app.settings';
});
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
}
ngOnDestroy() {
if (this.loginInfoSub) this.loginInfoSub.unsubscribe();
this.loginInfo$.unsubscribe();
}
ngOnInit() {
this.loginInfoSub = this._ngRedux.select(state => {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.minedu_userName = loginInfoToken.minedu_username;
this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
}, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
}
runDistribution() {
this.distStatus = "STARTED";
this._hds.makeDistribution(this.minedu_userName, this.minedu_userPassword)
.catch(err => {console.log(err); this.distStatus = "ERROR"; })
.then(msg => {
console.log("KATANOMH TELEIOSE");
if (this.distStatus !== "ERROR")
this.distStatus = "FINISHED";
});
}
......
import {Router, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
import { Router, Params} from '@angular/router';
import { OnInit, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
import { ILoginInfo } from '../store/logininfo/logininfo.types';
import { NgRedux, select } from 'ng2-redux';
......@@ -36,16 +36,20 @@ import { API_ENDPOINT } from '../app.settings';
<div class="alert alert-danger" *ngIf="userDataGroup.get('minedu_userpassword').touched && userDataGroup.get('minedu_userpassword').hasError('required')">
Το πεδίο δεν μπορεί να αφεθεί κενό!
</div>
<div class="alert alert-danger" *ngIf="!validLogin">
Λάθος όνομα χρήστη / κωδικός. Παρακαλώ προσπαθήστε ξανά.
</div>
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<div class="row" style="min-height: 300px; margin-top: 100px;">
<div *ngIf="!mineduUsername" class="col-md-8 offset-md-4">
<!--<div *ngIf="!mineduUsername" class="col-md-8 offset-md-4">-->
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn-primary btn-lg" (click)="submitCredentials()" [disabled]="userDataGroup.invalid">
Είσοδος<span class="glyphicon glyphicon-menu-right"></span>
</button>
</div>
</div>
</form>
</div>
`
......@@ -55,7 +59,9 @@ export default class MinistryHome implements OnInit {
public userDataGroup: FormGroup;
private authRole: string;
private mineduUsername: string;
private mineduPassword: string;
//private mineduPassword: string;
//private cuName: string;
private validLogin: boolean;
private loginInfo$: Observable<ILoginInfo>;
private apiEndPoint = API_ENDPOINT;
......@@ -68,12 +74,16 @@ export default class MinistryHome implements OnInit {
) {
this.mineduUsername = '';
this.mineduPassword = '';
//this.mineduPassword = '';
this.authRole = '';
//this.cuName = '';
this.validLogin = true;
this.userDataGroup = this.fb.group({
minedu_username: ['minedu01', [Validators.required]],
minedu_userpassword: ['12345678', [Validators.required]],
cu_name: [''],
auth_role: [''],
});
};
......@@ -82,7 +92,7 @@ export default class MinistryHome implements OnInit {
if (state.loginInfo.size > 0) {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.mineduUsername = loginInfoToken.minedu_username;
this.mineduPassword = loginInfoToken.minedu_userpassword;
//this.mineduPassword = loginInfoToken.minedu_userpassword;
if (this.mineduUsername && this.mineduUsername.length > 0)
this.router.navigate(['/ministry/minister-view']);
return loginInfoToken;
......@@ -96,11 +106,15 @@ export default class MinistryHome implements OnInit {
submitCredentials() {
let success = true;
this._hds.sendMinisrtyCredentials(this.userDataGroup.value['minedu_username'],this.userDataGroup.value['minedu_userpassword'])
.catch(err => {console.log(err); success = false;})
.catch(err => {console.log(err); success = false; this.validLogin = false; })
.then(msg => {
if (success) {
this.authRole = 'supervisor';
this._hds.setMineduCurrentUser(this.userDataGroup.value['minedu_username'], this.userDataGroup.value['minedu_userpassword'], this.authRole);
console.log("MPHKA");
this.validLogin = true;
this.userDataGroup.value['cu_name'] = this.userDataGroup.value['minedu_username'];
this.userDataGroup.value['auth_role'] = 'supervisor';
this._ata.saveMinEduloginInfo([this.userDataGroup.value]);
}
});
......
......@@ -37,6 +37,18 @@
<a class="nav-link" [routerLink]="['/school/director-classcapacity']" [routerLinkActive]="['active']"><b>Δυναμική Σχολείου</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item" >
<li *ngIf="authRole=='supervisor'" class="nav-item" >
<a class="nav-link" [routerLink]="['/ministry/minister-view']" [routerLinkActive]="['active']"><b>Κατανομή</b></a>
</li>
</div>
<div *ngIf="(loginInfo$ | async).size > 0" class="nav-item" >
<li *ngIf="authRole=='supervisor'" class="nav-item" >
<a class="nav-link" [routerLink]="['/ministry/minister-reports']" [routerLinkActive]="['active']"><b>Αναφορές</b></a>
</li>
</div>
</div>
</ul>
......@@ -46,7 +58,3 @@
</nav>
</div>
</div>
\ No newline at end of file
......@@ -67,6 +67,9 @@ import { LOGININFO_INITIAL_STATE } from '../../store/logininfo/logininfo.initial
else if (this.authRole === 'student') {
this.router.navigate(['']);
}
else if (this.authRole === 'supervisor') {
this.router.navigate(['/ministry']);
}
this.authToken = '';
this.authRole = '';
});
......
......@@ -24,6 +24,7 @@ import SubmitedPerson from '../components/student-application-form/submitedstude
import DirectorView from '../components/director/director-view';
import DirectorClassCapacity from '../components/director/director-classcapacity';
import MinisterView from '../components/minister/minister-view';
import MinisterReports from '../components/minister/minister-reports';
import SchoolAuthGuard from '../guards/school.auth.guard';
import StudentAuthGuard from '../guards/student.auth.guard';
......@@ -47,6 +48,7 @@ export const MainRoutes: Routes = [
{ path: 'school/director-view', component: DirectorView, canActivate: [SchoolAuthGuard] },
{ path: 'school/director-classcapacity', component: DirectorClassCapacity, canActivate: [SchoolAuthGuard] },
{ path: 'ministry/minister-view', component: MinisterView },
{ path: 'ministry/minister-reports', component: MinisterReports },
];
export const MainDeclarations = [
......@@ -70,5 +72,6 @@ export const MainDeclarations = [
SubmitedPerson,
DirectorView,
DirectorClassCapacity,
MinisterView
MinisterView,
MinisterReports
];
......@@ -21,6 +21,8 @@ export class HelperDataService implements OnInit, OnDestroy {
private authToken: string;
private authRole: string;
private minedu_userName: string;
private minedu_userPassword: string;
private loginInfo$: BehaviorSubject<ILoginInfo>;
constructor(
......@@ -36,11 +38,14 @@ export class HelperDataService implements OnInit, OnDestroy {
state.loginInfo.reduce(({}, loginInfoToken) => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
//this.minedu_userName = loginInfoToken.minedu_username;
//this.minedu_userPassword = loginInfoToken.minedu_userpassword;
return loginInfoToken;
}, {});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
}
ngOnDestroy() {
......@@ -360,6 +365,9 @@ export class HelperDataService implements OnInit, OnDestroy {
this.authToken = oauthtoken;
this.authRole = oauthrole;
//console.log("MIPOS");
let headers = new Headers({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
......@@ -387,6 +395,12 @@ export class HelperDataService implements OnInit, OnDestroy {
});
}
setMineduCurrentUser(minedu_username, minedu_pwd, role) {
this.minedu_userName = minedu_username;
this.minedu_userPassword = minedu_pwd;
this.authRole = role;
}
transformUserSchema(userlogin: any, oauthtoken: string, oauthrole: string) {
let rsa = Array<ILoginInfoToken>();
......@@ -397,31 +411,33 @@ export class HelperDataService implements OnInit, OnDestroy {
}
signOut() {
//loginInfo$ take values only in case getCurrentUser (epal module) has been used ...WHY? TO BE CHECKED..
this.loginInfo$.getValue().forEach(loginInfoToken => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
});
let headers = new Headers({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"Content-Type": "application/json",
"Accept": "*/*",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": "*",
// "Content-Type": "text/plain", // try to skip preflight
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
//"X-CSRF-Token": "EoAZ0APpIbbewK5MNzRrCFkvEeZZoGQsBslWFTrZ8bI",
// "X-oauth-enabled": "true",
// "X-Auth-Token": this.authToken
});
if (this.authRole === "supervisor")
this.createMinistryAuthorizationHeader(headers, this.minedu_userName, this.minedu_userPassword);
else
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers, withCredentials: true });
let logoutRoute = '/oauth/logout';
if (this.authRole === 'director')
logoutRoute = '/cas/logout';
else if (this.authRole === 'supervisor')
logoutRoute = '/ministry/logout';
return new Promise((resolve, reject) => {
this.http.post(`${AppSettings.API_ENDPOINT}${logoutRoute}`, {}, options)
......@@ -622,6 +638,60 @@ export class HelperDataService implements OnInit, OnDestroy {
}
makeDistribution(username, userpassword) {
let headers = new Headers({
"Content-Type": "application/json",
});
this.createMinistryAuthorizationHeader(headers, username, userpassword );
let options = new RequestOptions({ headers: headers });
//return this.http.get(`${AppSettings.API_ENDPOINT}/epal/distribution/` , options)
// .map(response => response.json());
return new Promise((resolve, reject) => {
this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution`, {username: username, userpassword: userpassword}, options)
.map(response => response.json())
.subscribe(data => {
resolve(data);
},
error => {
reject("Error POST in makeDistribution");
},
() => console.log(""));
});
}
makeGeneralReport(username, userpassword) {
let headers = new Headers({
"Content-Type": "application/json",
});
this.createMinistryAuthorizationHeader(headers, username, userpassword );
let options = new RequestOptions({ headers: headers });
return this.http.get(`${AppSettings.API_ENDPOINT}/ministry/general-report/` , options)
.map(response => response.json());
/*
return new Promise((resolve, reject) => {
this.http.post(`${AppSettings.API_ENDPOINT}/epal/distribution`, {username: username, userpassword: userpassword}, options)
.map(response => response.json())
.subscribe(data => {
resolve(data);
},
error => {
reject("Error POST in makeDistribution");
},
() => console.log(""));
});
*/
}
......
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