merrged updates

parents 8154ea6f 64f0a4b0
......@@ -182,6 +182,22 @@ epal.ministry.massive_mail:
_controller: '\Drupal\epal\Controller\InformUnlocatedStudents::sendMailToStudents'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.retrievesettings:
path: '/ministry/retrieve-settings'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::retrieveSettings'
requirements:
_user_is_logged_in: 'TRUE'
epal.ministry.storesettings:
path: '/ministry/store-settings/{capacityDisabled}/{directorViewDisabled}/{applicantsLoginDisabled}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\MinisterSettings::storeSettings'
requirements:
_user_is_logged_in: 'TRUE'
regionview:
path: '/epal/ScoolperPerf/{perfectureId}'
options:
......
......@@ -102,6 +102,29 @@ class Distribution extends ControllerBase {
], Response::HTTP_FORBIDDEN);
}
//check where distribution can be done now ($capacityDisabled / $directorViewDisabled settings)
$capacityDisabled = false;
$directorViewDisabled = false;
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
}
if ($capacityDisabled === "0" or $directorViewDisabled === "0") {
return $this->respondWithStatus([
'message' => t("capacityDisabled and / or directorViewDisabled settings are false"),
], Response::HTTP_FORBIDDEN);
}
$transaction = $this->connection->startTransaction();
......
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
class MinisterSettings extends ControllerBase {
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
QueryFactory $entity_query,
Connection $connection,
LoggerChannelFactoryInterface $loggerChannel)
{
$this->entityTypeManager = $entityTypeManager;
$this->entity_query = $entity_query;
$connection = Database::getConnection();
$this->connection = $connection;
$this->logger = $loggerChannel->get('epal');
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager'),
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
}
public function retrieveSettings(Request $request) {
try {
if (!$request->isMethod('GET')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
//user validation
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
//minister settings retrieve
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$capacityDisabled = $epalConfig->lock_school_capacity->getString();
$directorViewDisabled = $epalConfig->lock_school_students_view->getString();
$applicantsLoginDisabled = $epalConfig->lock_application->getString();
}
$config_storage->resetCache();
return $this->respondWithStatus([
//'message' => t("post successful"),
'capacityDisabled' => $capacityDisabled,
'directorViewDisabled' => $directorViewDisabled,
'applicantsLoginDisabled' => $applicantsLoginDisabled,
], Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during retrieveSettings Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
public function storeSettings(Request $request, $capacityDisabled, $directorViewDisabled, $applicantsLoginDisabled ) {
try {
if (!$request->isMethod('GET')) {
return $this->respondWithStatus([
"message" => t("Method Not Allowed")
], Response::HTTP_METHOD_NOT_ALLOWED);
}
//user validation
$authToken = $request->headers->get('PHP_AUTH_USER');
$users = $this->entityTypeManager->getStorage('user')->loadByProperties(array('name' => $authToken));
$user = reset($users);
if (!$user) {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
//user role validation
$roles = $user->getRoles();
$validRole = false;
foreach ($roles as $role)
if ($role === "ministry") {
$validRole = true;
break;
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
$config_storage = $this->entityTypeManager->getStorage('epal_config');
$epalConfigs = $config_storage->loadByProperties(array('id' => 1));
$epalConfig = reset($epalConfigs);
if (!$epalConfig) {
return $this->respondWithStatus([
'message' => t("EpalConfig Enity not found"),
], Response::HTTP_FORBIDDEN);
}
else {
$epalConfig->set('lock_school_capacity', $capacityDisabled);
$epalConfig->set('lock_school_students_view', $directorViewDisabled);
$epalConfig->set('lock_application', $applicantsLoginDisabled);
$epalConfig->save();
}
$config_storage->resetCache();
return $this->respondWithStatus([
//'message' => t("post successful"),
'capacityDisabled' => $capacityDisabled,
'directorViewDisabled' => $directorViewDisabled,
'applicantsLoginDisabled' => $applicantsLoginDisabled,
], Response::HTTP_OK);
} //end try
catch (\Exception $e) {
$this->logger->warning($e->getMessage());
return $this->respondWithStatus([
"message" => t("An unexpected problem occured during storeSettings Method ")
], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
......@@ -514,7 +514,7 @@ class ReportsCreator extends ControllerBase {
array_push($numClasses, $numClassCour);
array_push($numClasses, $numClassCour_D);
if ($sectorId === "0" && $courseId === 0) {
if ($sectorId === "0" && $courseId === "0") {
$clidstart = 1;
$clidend = 4;
......
......@@ -30,7 +30,7 @@ import {
<option value="1" >Α' Λυκείου</option>
<option value="2" >Β' Λυκείου</option>
<option value="3" >Γ' Λυκείου</option>
<option value="4" >Δ' Λυκείου</option>
<option *ngIf="(selectiontype | async)" value="4" >Δ' Λυκείου</option>
</select>
</div>
<div class="form-group">
......@@ -121,6 +121,7 @@ import {
<br>
<br>
<div *ngIf="(retrievedStudent | async)">
<div class="form-group" class="row">
Βρίσκεστε στη σελίδα:
<div class="col-1">
......@@ -144,6 +145,7 @@ import {
</ul>
</nav>
</div>
</form>
</div>
......@@ -169,6 +171,7 @@ import {
private SubmitedDetailsSub: Subscription;
private retrievedStudent: BehaviorSubject<boolean>;
private selectionBClass: BehaviorSubject<boolean>;
private selectiontype: BehaviorSubject<boolean>;
private selectionCClass: BehaviorSubject<boolean>;
private SchoolId ;
private currentclass: Number;
......@@ -196,6 +199,7 @@ import {
this.selectionBClass = new BehaviorSubject(false);
this.selectionCClass = new BehaviorSubject(false);
this.School$ = new BehaviorSubject([{}]);
this.selectiontype = new BehaviorSubject(true);
this.formGroup = this.fb.group({
......@@ -226,11 +230,14 @@ import {
ngOnInit() {
this.SchoolSub = this._hds.getSchoolId().subscribe(x => {
this.School$.next(x);
console.log(x[0].id, "schoolid!");
this.SchoolId = x[0].id;
this.SchoolSub = this._hds.gettypeofschool().subscribe(x => {
this.School$.next(x);
console.log(x[0].type, "schoolid!");
this.SchoolId = x[0].type;
if (this.SchoolId == 'ΗΜΕΡΗΣΙΟ'){
this.selectiontype.next(false);
}
},
error => {
......@@ -239,6 +246,7 @@ import {
},
() => console.log("Getting School "));
}
......@@ -315,7 +323,7 @@ import {
findstudent(txop, pageno) {
var tot_pages: Number;
var tot_pages: number;
var sectorint = +this.formGroup.value.tomeas;
if (txop.value === "1") {
this.currentclass = 1;
......@@ -339,6 +347,11 @@ import {
if (x.id % 5 > 0) {
tot_pages = (x.id - (x.id % 5)) / 5 + 1;
}
console.log(tot_pages,"totpages")
if (isNaN(tot_pages)){
this.retrievedStudent.next(false);
tot_pages = 0;
}
this.formGroup.get('maxpage').setValue(tot_pages);
});
......@@ -346,7 +359,15 @@ import {
this.StudentInfoSub = this._hds.getStudentPerSchool(sectorint, this.currentclass, this.limitdown, this.limitup).subscribe(data => {
this.StudentInfo$.next(data);
if (tot_pages === 0){
console.log("tot.pages", this.formGroup.value.maxpage);
this.retrievedStudent.next(false);
}
else
{
console.log("tot.pages", this.formGroup.value.maxpage, "max", tot_pages);
this.retrievedStudent.next(true);
}
},
error => {
this.StudentInfo$.next([{}]);
......@@ -379,8 +400,8 @@ import {
confirmStudent(txop) {
this._hds.saveConfirmStudents(this.saved, this.type);
this.findstudent(txop, this.pageno)
console.log(txop, this.pageno, "aaaaaaa");
this.findstudent(txop, this.pageno);
}
checkcclass() {
......
......@@ -39,6 +39,7 @@ import { API_ENDPOINT } from '../../app.settings';
</div>
</div>
<h5> >Αποστολή ειδοποιήσεων <br></h5>
<br><br>
<div class="col-md-12">
<button type="submit" class="btn btn-lg btn-block" *ngIf="(loginInfo$ | async).size !== 0" (click)="informUnlocatedStudents()" >
......
......@@ -29,7 +29,7 @@ import { API_ENDPOINT } from '../../app.settings';
<div>
<h5><br> >Επιλογή Αναφοράς<br><br></h5>
<h5> >Επιλογή Αναφοράς<br><br></h5>
<div class="col-md-1">
<button type="button" class="btn btn-alert" (click)="nav_to_reportpath(1)" [hidden]="minedu_userName == '' || userRole == 'pde' || userRole == 'dide'" >
......
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';
@Component({
selector: 'minister-settings',
template: `
<div
class = "loading" *ngIf="dataRetrieved == -1 " >
</div>
<div id="configNotice" (onHidden)="onHidden()" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header {{modalHeader | async}}" >
<h3 class="modal-title pull-left"><i class="fa fa-check-square-o"></i>&nbsp;&nbsp;{{ modalTitle | async }}</h3>
<button type="button" class="close pull-right" aria-label="Close" (click)="hideModal()">
<span aria-hidden="true"><i class="fa fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<p>{{ modalText | async }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Κλείσιμο</button>
</div>
</div>
</div>
</div>
<div *ngIf="(loginInfo$ | async).size !== 0">
<form [formGroup]="formGroup" #form>
<h5> >Ρυθμίσεις <br><br></h5>
<div class="row">
<div class="col-md-1 ">
<input type="checkbox" [checked]="capacityDisabled" formControlName="capacityDisabled"
(click)="toggleCapacityFilter()" >
</div>
<div class="col-md-9">
<label for="capacityDisabled">Απενεργοποίηση δυνατότητας τροποποίησης χωρητικότητας από τους Διευθυντές σχολείων</label>
</div>
</div>
<br>
<div class="row">
<div class="col-md-1 ">
<input type="checkbox" [checked]="directorViewDisabled" formControlName="directorViewDisabled"
(click)="toggleDirectorView()" >
</div>
<div class="col-md-9">
<label for="directorViewDisabled">Απενεργοποίηση δυνατότητας προβολής κατανομής μαθητών από τους Διευθυντές σχολείων</label>
</div>
</div>
<br>
<div class="row">
<div class="col-md-1 ">
<input type="checkbox" [checked]="applicantsLoginDisabled" formControlName="applicantsLoginDisabled"
(click)="toggleApplicantsLogin()" >
</div>
<div class="col-md-9">
<label for="applicantsLoginDisabled">Απενεργοποίηση δυνατότητας αίτησης μαθητών</label>
</div>
</div>
<br>
<button type="submit" class="btn btn-md pull-right" (click)="storeSettings()" >
Εφαρμογή
</button>
</form>
</div>
`
})
@Injectable() export default class MinisterSettings implements OnInit, OnDestroy {
public formGroup: FormGroup;
loginInfo$: BehaviorSubject<ILoginInfo>;
private modalTitle: BehaviorSubject<string>;
private modalText: BehaviorSubject<string>;
private modalHeader: BehaviorSubject<string>;
private settings$: BehaviorSubject<any>;
loginInfoSub: Subscription;
private settingsSub: Subscription;
//private data;
private capacityDisabled: boolean;
private directorViewDisabled: boolean;
private applicantsLoginDisabled: boolean;
private dataRetrieved: number;
private minedu_userName: string;
private minedu_userPassword: string;
constructor(private fb: FormBuilder,
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService,
private router: Router) {
this.formGroup = this.fb.group({
capacityDisabled: ['', []],
directorViewDisabled: ['', []],
applicantsLoginDisabled: ['', []],
});
this.loginInfo$ = new BehaviorSubject(LOGININFO_INITIAL_STATE);
this.settings$ = new BehaviorSubject([{}]);
this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject("");
}
public showModal():void {
console.log("about to show modal");
(<any>$('#configNotice')).modal('show');
}
public hideModal():void {
(<any>$('#configNotice')).modal('hide');
}
public onHidden():void {
//this.isModalShown.next(false);
}
ngOnDestroy() {
(<any>$('#configNotice')).remove();
if (this.loginInfoSub)
this.loginInfoSub.unsubscribe();
if (this.settingsSub)
this.settingsSub.unsubscribe();
}
ngOnInit() {
(<any>$('#configNotice')).appendTo("body");
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$);
this.retrieveSettings();
}
retrieveSettings() {
this.dataRetrieved = -1;
this.settingsSub = this._hds.retrieveAdminSettings(this.minedu_userName, this.minedu_userPassword).subscribe(data => {
this.settings$.next(data);
//this.data = data;
},
error => {
this.settings$.next([{}]);
this.dataRetrieved = 0;
console.log("Error Getting MinisterRetrieveSettings");
},
() => {
console.log("Success Getting MinisterRetrieveSettings");
this.capacityDisabled = Boolean(Number(this.settings$.value['capacityDisabled']));
this.directorViewDisabled = Boolean(Number(this.settings$.value['directorViewDisabled']));
this.applicantsLoginDisabled = Boolean(Number(this.settings$.value['applicantsLoginDisabled']));
this.dataRetrieved = 1;
}
)
}
storeSettings() {
this.dataRetrieved = -1;
this.settingsSub = this._hds.storeAdminSettings(this.minedu_userName, this.minedu_userPassword, this.capacityDisabled, this.directorViewDisabled, this.applicantsLoginDisabled )
.subscribe(data => {
this.settings$.next(data);
//this.data = data;
},
error => {
this.settings$.next([{}]);
this.dataRetrieved = 0;
console.log("Error Getting MinisterStoreSettings");
this.modalTitle.next("Ρύθμιση Παραμέτρων");
this.modalText.next("ΑΠΟΤΥΧΙΑ εφαρμογής των νέων σας ρυθμίσεων.");
this.modalHeader.next("modal-header-danger");
this.showModal();
},
() => {
console.log("Success Getting MinisterStoreSettings");
this.dataRetrieved = 1;
this.modalTitle.next("Ρύθμιση Παραμέτρων");
this.modalText.next("Έγινε εφαρμογή των νέων σας ρυθμίσεων.");
this.modalHeader.next("modal-header-success");
this.showModal();
//redundunt and has risk..Appear a modal!
//this.retrieveSettings();
}
)
}
toggleCapacityFilter() {
this.capacityDisabled = !this.capacityDisabled;
}
toggleDirectorView() {
this.directorViewDisabled = !this.directorViewDisabled;
}
toggleApplicantsLogin() {
this.applicantsLoginDisabled = !this.applicantsLoginDisabled;
}