Commit 6651c207 authored by Open Source Developer's avatar Open Source Developer

counter

parent 8ec26d0e
......@@ -308,5 +308,13 @@ epal.applicant.showresults:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getResults'
requirements:
_user_is_logged_in: 'TRUE'
epal.totalstudents:
path: '/epal/totalstudent'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\HelpDesk::findTotalStudents'
requirements:
_user_is_logged_in: 'TRUE'
\ No newline at end of file
......@@ -24,28 +24,32 @@ use Drupal\Core\Language\LanguageManagerInterface;
class HelpDesk extends ControllerBase {
protected $entityTypeManager;
protected $entity_query;
protected $entityTypeManager;
protected $logger;
protected $connection;
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
LoggerChannelFactoryInterface $loggerChannel,
Connection $connection
) {
$this->entityTypeManager = $entityTypeManager;
$this->logger = $loggerChannel->get('epal-school');
$this->connection = $connection;
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('logger.factory'),
$container->get('database')
$container->get('entity.query'),
$container->get('database'),
$container->get('logger.factory')
);
}
......@@ -109,6 +113,50 @@ class HelpDesk extends ControllerBase {
return;
}
public function findTotalStudents(Request $request)
{
$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 === "applicant") {
$validRole = true;
break;
}
}
if (!$validRole) {
return $this->respondWithStatus([
'message' => t("User Invalid Role"),
], Response::HTTP_FORBIDDEN);
}
$list = array();
$sCon = $this->connection
->select('epal_student', 'eStudent')
->fields('eStudent', array('id'));
$numApplications = $sCon->countQuery()->execute()->fetchField();
array_push($list, (object) array('name' => "Αριθμός Αιτήσεων (συνολικά)", 'numStudents' => $numApplications));
return $this->respondWithStatus($list, Response::HTTP_OK);
}
}
......@@ -31,8 +31,16 @@
<div class="col-md-2">
<span *ngIf="loginInfoRow$.auth_role===studentRole" class="signout isclickable" (click)="gohelpDesk()" style="color:#CC3300;">Επικοινωνία</span>
</div>
<div class="col-md-4">
<span *ngIf="loginInfoRow$.auth_role===studentRole" class="signout" style="color:#CC3300;">
<div *ngFor="let TotalStudent$ of TotalStudents$ | async;">
Σύνολο Αιτήσεων:{{TotalStudent$.numStudents}}
</div>
</span>
</div>
<div class="col-md-4">&nbsp;</div>
<div class="col-md-4" style="text-align: right">
<span class="username" style="text-align: right">{{ cuName }}&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span class="signout isclickable" style="text-align: right" (click)="signOut()" style="color:#CC3300;">Αποσύνδεση&nbsp;&nbsp;</span>
......
......@@ -2,7 +2,7 @@ import {Component, OnInit, OnDestroy} from "@angular/core";
import {Router} from "@angular/router";
import { Injectable } from "@angular/core";
import { BehaviorSubject } from "rxjs/Rx";
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import { NgRedux, select } from "ng2-redux";
import { IAppState } from "../../store/store";
import { ILoginInfo, ILoginInfoToken } from "../../store/logininfo/logininfo.types";
......@@ -17,6 +17,7 @@ import { SectorCoursesActions } from "../../actions/sectorcourses.actions";
import { CriteriaActions } from "../../actions/criteria.actions";
import { StudentDataFieldsActions } from "../../actions/studentdatafields.actions";
@Component({
selector: "reg-header",
templateUrl: "header.component.html"
......@@ -33,6 +34,10 @@ export default class HeaderComponent implements OnInit, OnDestroy {
private modalText: BehaviorSubject<string>;
private modalHeader: BehaviorSubject<string>;
private TotalStudents$: BehaviorSubject<any>;
private TotalStudentsSub: Subscription;
private showLoader: BehaviorSubject<boolean>;
constructor(private _ata: LoginInfoActions,
private _hds: HelperDataService,
private _csa: SectorCoursesActions,
......@@ -53,6 +58,8 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this.modalTitle = new BehaviorSubject("");
this.modalText = new BehaviorSubject("");
this.modalHeader = new BehaviorSubject("");
this.TotalStudents$ = new BehaviorSubject([{}]);
this.showLoader = new BehaviorSubject(false);
};
......@@ -66,11 +73,29 @@ export default class HeaderComponent implements OnInit, OnDestroy {
this.cuName = loginInfoToken.cu_name;
return loginInfoToken;
}, {});
this.showLoader.next(true);
this.TotalStudentsSub = this._hds.findTotalStudents().subscribe(x => {
this.TotalStudents$.next(x);
this.showLoader.next(false);
},
error => {
this.TotalStudents$.next([{}]);
console.log("Error Getting courses perSchool");
this.showLoader.next(false);
});
}
return state.loginInfo;
}).subscribe(this.loginInfo$);
}
ngOnDestroy() {
......
......@@ -1010,4 +1010,22 @@ export class HelperDataService implements OnInit, OnDestroy {
}
findTotalStudents() {
this.loginInfo$.getValue().forEach(loginInfoToken => {
this.authToken = loginInfoToken.auth_token;
this.authRole = loginInfoToken.auth_role;
});
let headers = new Headers({
"Content-Type": "application/json",
});
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers });
return this.http.get(`${AppSettings.API_ENDPOINT}/epal/totalstudent`, options)
.map(response => response.json());
}
}
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