Commit a5e2f4fb authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

Merge branch 'applicationpdf' into 'develop'

Applicationpdf

See merge request !40
parents 5fb7ded0 62b74b7c
......@@ -14,6 +14,30 @@ current_user:
_controller: '\Drupal\epal\Controller\CurrentUser::getLoginInfo'
requirements:
_user_is_logged_in: 'TRUE'
submitedapplications:
path: '/epal/subapplic'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getSubmittedApplications'
requirements:
_user_is_logged_in: 'TRUE'
studentapplication:
path: '/epal/student/{studentId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getStudentApplications'
requirements:
_user_is_logged_in: 'TRUE'
epalchosen:
path: '/epal/epalchosen/{studentId}'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\epal\Controller\SubmitedApplications::getEpalChosen'
requirements:
_user_is_logged_in: 'TRUE'
epal.application_submit:
path: '/epal/appsubmit'
options:
......
<?php
namespace Drupal\epal\Controller;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class SubmitedApplications extends ControllerBase
{
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager)
{
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container)
{
return new static(
$container->get('entity_type.manager')
);
}
public function getSubmittedApplications(Request $request)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> id();
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid));
$i = 0;
if ($epalStudents) {
$list = array();
foreach ($epalStudents as $object) {
$list[] = array(
'id' => $object -> id(),
'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value);
$i++;
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
}
public function getStudentApplications(Request $request, $studentId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> id();
$studentIdNew = intval($studentId) ;
$epalStudents = $this->entityTypeManager->getStorage('epal_student')->loadByProperties(array('epaluser_id' => $userid, 'id'=> $studentIdNew));
$i = 0;
if ($epalStudents) {
$list = array();
foreach ($epalStudents as $object) {
$list[] = array(
'name' => $object -> name ->value,
'studentsurname' => $object -> studentsurname ->value,
'fatherfirstname' => $object -> fatherfirstname ->value,
'fathersurname' =>$object -> fathersurtname ->value,
'motherfirstname' => $object -> motherfirstname ->value,
'mothersurname' =>$object -> mothersurname ->value,
'birthdate' =>$object -> birthdate ->value,
);
$i++;
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("EPAL user not found"),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
}
public function getEpalChosen(Request $request, $studentId)
{
$authToken = $request->headers->get('PHP_AUTH_USER');
$epalUsers = $this->entityTypeManager->getStorage('epal_users')->loadByProperties(array('authtoken' => $authToken));
$epalUser = reset($epalUsers);
if ($epalUser) {
$userid = $epalUser -> user_id -> entity -> id();
$studentIdNew = intval($studentId) ;
$epalChosen = $this->entityTypeManager->getStorage('epal_student_epal_chosen')->loadByProperties(array( 'user_id'=>$userid,'student_id'=> $studentIdNew));
$i = 0;
if ($epalChosen) {
$list = array();
foreach ($epalChosen as $object) {
$list[] = array(
'epal_id' => $object -> epal_id ->entity->get('name')->value ,
'choice_no' => $object -> choice_no ->value,
);
$i++;
}
return $this->respondWithStatus(
$list
, Response::HTTP_OK);
}
else {
return $this->respondWithStatus([
'message' => t("EPAL chosen not found!!!"),
], Response::HTTP_FORBIDDEN);
}
} else {
return $this->respondWithStatus([
'message' => t("User not found"),
], Response::HTTP_FORBIDDEN);
}
}
private function respondWithStatus($arr, $s) {
$res = new JsonResponse($arr);
$res->setStatusCode($s);
return $res;
}
}
......@@ -60,6 +60,23 @@
.main-content{
.submited{
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
}
.btn {
background-color:#fd9665;
......
......@@ -3,4 +3,4 @@ export class AppSettings {
public static get API_ENDPOINT(): string {
return 'http://localhost/drupal-8.2.6';
}
}
}
\ No newline at end of file
......@@ -19,6 +19,8 @@ import { API_ENDPOINT } from '../app.settings';
template: `
<div>
<form [formGroup]="formGroup" method = "POST" action="{{apiEndPoint}}/oauth/login" #form>
<!-- <input type="hidden" name="X-oauth-enabled" value="true"> -->
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<div class="row" style="min-height: 300px; margin-top: 100px;">
......@@ -86,4 +88,4 @@ export default class Home implements OnInit {
checkvalidation() {
}
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
<img src="../myschool/assets/images/myschool_logo.png" alt="Αρχική" />
</a>
<div class="collapse navbar-collapse flex-row-reverse" id="navbarNav">
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index"></div>
<div *ngFor="let loginInfoToken$ of loginInfo$ | async; let i=index "></div>
<ul class="navbar-nav">
<div *ngFor="let username$ of loginInfo$ | async;">
......@@ -21,39 +21,17 @@
<i class="fa fa-sign-out"></i>
</button>
</div>
</div>
<!--
<li class="nav-item" [ngClass]="{active: path=='application-preview'}">
<a class="nav-link" [routerLink]="['/application-preview']" [routerLinkActive]="['active']">Προεπισκόπηση</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='amka-fill'}">
<a class="nav-link" [routerLink]="['/amka-fill']" [routerLinkActive]="['active']">ΑΜΚΑ ΜΑΘΗΤΗ</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='epal-class-select'}">
<a class="nav-link" [routerLink]="['/epal-class-select']" [routerLinkActive]="['active']">Τάξη</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='sector-fields-select'}">
<a class="nav-link" [routerLink]="['/sector-fields-select']" [routerLinkActive]="['active']">Τομεας</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='sectorcourses-fields-select'}">
<a class="nav-link" [routerLink]="['/sectorcourses-fields-select']" [routerLinkActive]="['active']">Ειδικοτητα</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='region-schools-select'}">
<a class="nav-link" [routerLink]="['/region-schools-select']" [routerLinkActive]="['active']">Σχολειο</a>
</li>
<li class="nav-item" [ngClass]="{active: path=='student-application-form-main'}">
<a class="nav-link" [routerLink]="['/student-application-form-main']" [routerLinkActive]="['active']">Αιτηση</a>
</li>
-->
<!--
<li class="nav-item" [ngClass]="{active: path=='schools-order-select'}">
<a class="nav-link" [routerLink]="['/schools-order-select']" [routerLinkActive]="['active']">Σειρά επιλογής</a>
</li>
-->
</div>
</ul>
</div>
<div class="pull-right" class="nav-item" [ngClass]="{active: path=='submited-preview'}">
<a class="nav-link" [routerLink]="['/submited-preview']" [routerLinkActive]="['active']"><b>Υποβληθείσες αιτήσεις</b></a>
</div>
</nav>
</div>
</div>
import { Component, OnInit, OnDestroy,ElementRef, ViewChild} from "@angular/core";
let jsPDF = require('jspdf');
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {IStudentDataFields, IStudentDataField} from '../../store/studentdatafields';
import {Http, Headers, RequestOptions} from '@angular/http';
import {Removetags} from '../../pipes/removehtmltags';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
@Component({
selector: 'submited-preview',
template: `
Έχει υποβληθεί αίτηση για εγγραφή στην Επαγγελματική Εκπαίδευση των παρακάτω ατόμων:
<table class = "submited">
<tr>
<th>Όνομα</th>
<th>Επώνυμο</th>
<th></th>
</tr>
<tr *ngFor="let UserData$ of SubmitedApplic$ | async">
<td>{{UserData$.name}} </td>
<td>{{UserData$.studentsurname}} </td>
<td> <button type="button" (click)="studentpreview(UserData$.id)"> <i class="fa fa-eye" aria-hidden="true"></i> </button> </td>
</tr>
`
})
@Injectable() export default class SubmitedPreview implements OnInit , OnDestroy{
private SubmitedApplic$: BehaviorSubject<any>;
private SubmitedUsersSub: Subscription;
public StudentId;
constructor(private _hds: HelperDataService,
private activatedRoute: ActivatedRoute,
private router: Router )
{
this.SubmitedApplic$ = new BehaviorSubject([{}]);
}
ngOnDestroy()
{
if (this.SubmitedUsersSub)
this.SubmitedUsersSub.unsubscribe();
}
ngOnInit() {
this.SubmitedUsersSub = this._hds.getSubmittedPreviw().subscribe(this.SubmitedApplic$);
console.log(this.SubmitedApplic$);
}
studentpreview(StudentId)
{
this.router.navigate(['/submited-person', {'id':StudentId}]);
}
}
\ No newline at end of file
import { Component, OnInit, OnDestroy,ElementRef, ViewChild} from "@angular/core";
let jsPDF = require('jspdf');
import { Injectable } from "@angular/core";
import { AppSettings } from '../../app.settings';
import { HelperDataService } from '../../services/helper-data-service';
import {Observable} from "rxjs/Observable";
import {IStudentDataFields, IStudentDataField} from '../../store/studentdatafields';
import {Http, Headers, RequestOptions} from '@angular/http';
import {Removetags} from '../../pipes/removehtmltags';
import { NgRedux, select } from 'ng2-redux';
import { IAppState } from '../../store/store';
import { ILoginInfo } from '../../store/logininfo/logininfo.types';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs/Rx';
import * as html2canvas from "html2canvas"
@Component({
selector: 'submited-student',
template: `
<div id = "target">
<div *ngFor="let StudentDetails$ of SubmitedDetails$ | async">
Όνομα: {{StudentDetails$.name}} <br>
Επώνυμο: {{StudentDetails$.studentsurname}}<br>
Όνομα Πατέρα: {{StudentDetails$.fatherfirstname}}<br>
Επώνυμο Πατέρα:{{StudentDetails$.fathersurname}}<br>
Όνομα Μητέρας: {{StudentDetails$.motherfirstname}}<br>
Επώνυμο Μητέρας:{{StudentDetails$.mothersurname}}<br>
Ημερομηνία Γέννησης: {{StudentDetails$.birthdate}}<br>
</div>
<b>Επιλογές ΕΠΑΛ</b>
<div *ngFor="let epalChoices$ of EpalChosen$ | async">
Σχολείο: {{epalChoices$.epal_id}}
Σειρά Προτίμισης:{{epalChoices$.choice_no}}
</div>
</div>
<button type="button" (click)="createPdf()">Εξαγωγή σε PDF</button>
`
})
@Injectable() export default class SubmitedStudentDetails implements OnInit , OnDestroy{
private SubmitedDetails$: BehaviorSubject<any>;
private SubmitedDetailsSub: Subscription;
private EpalChosen$: BehaviorSubject<any>;
private EpalChosenSub: Subscription;
public StudentId: Number;
constructor(private _hds: HelperDataService,
private route: ActivatedRoute,
private router: Router )
{
this.SubmitedDetails$ = new BehaviorSubject([{}]);
this.EpalChosen$ = new BehaviorSubject([{}]);
}
ngOnDestroy()
{
if (this.SubmitedDetailsSub)
this.SubmitedDetailsSub.unsubscribe();
if (this.EpalChosenSub)
this.EpalChosenSub.unsubscribe();
}
ngOnInit() {
this.getApplicationId();
this.SubmitedDetailsSub = this._hds.getStudentDetails(this.StudentId).subscribe(this.SubmitedDetails$);
this.EpalChosenSub = this._hds.getEpalchosen(this.StudentId).subscribe(this.EpalChosen$);
}
getApplicationId()
{
this.route.params.subscribe(params => {this.StudentId = params['id'];});
}
createPdf()
{
html2canvas(document.getElementById("target")).then(function(canvas)
{
var img = canvas.toDataURL();
var doc = new jsPDF('p', 'mm');
doc.addImage(img, 'PNG', 10, 10);
doc.save('applications.pdf');
});
}
}
\ No newline at end of file
......@@ -17,6 +17,8 @@ import SectorCoursesSelect from '../components/student-application-form/sector.c
import ApplicationPreview from '../components/student-application-form/application.preview';
import SchoolsOrderSelect from '../components/student-application-form/schools-order-select';
import ApplicationSubmit from '../components/student-application-form/application.submit';
import SubmitedPreview from '../components/student-application-form/submited.aplication.preview';
import SubmitedPerson from '../components/student-application-form/submitedstudent.preview';
export const MainRoutes: Routes = [
{ path: '', component: Home },
......@@ -30,7 +32,9 @@ export const MainRoutes: Routes = [
{ path: 'sectorcourses-fields-select', component: SectorCoursesSelect },
{ path: 'application-preview', component: ApplicationPreview },
{ path: 'schools-order-select', component: SchoolsOrderSelect },
{ path: 'application-submit', component: ApplicationSubmit }
{ path: 'application-submit', component: ApplicationSubmit },
{ path: 'submited-preview', component: SubmitedPreview },
{ path: 'submited-person', component: SubmitedPerson },
];
export const MainDeclarations = [
......@@ -47,5 +51,7 @@ export const MainDeclarations = [
StudentApplicationMain,
ApplicationPreview,
SchoolsOrderSelect,
ApplicationSubmit
ApplicationSubmit,
SubmitedPreview,
SubmitedPerson
];
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'removetags'})
export class Removetags implements PipeTransform {
transform(text: string) : any {
return text ? String(text).replace(/<[^>]+>/gm, '') : ''
}
}
......@@ -331,4 +331,56 @@ transformUserSchema(userlogin:any,oauthtoken:string, oauthrole:string){
}
getSubmittedPreviw() {
this.loginInfo$.forEach(loginInfoToken => {
this.authToken = loginInfoToken.get(0).auth_token;
});
let headers = new Headers({
"Content-Type": "application/json",
"id": ""
});
this.createAuthorizationHeader(headers);
let options = new RequestOptions({ headers: headers });
return this.http.get(`${AppSettings.API_ENDPOINT}/epal/subapplic`, options )
.map(response => response.json());
}
getStudentDetails(headerid)
{
let headerIdNew = headerid.toString();
this.loginInfo$.forEach(loginInfoToken => {
this.authToken = loginInfoToken.get(0).auth_token;
});
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/student/`+headerIdNew, options )
.map(response => response.json());
}
getEpalchosen(headerid)
{
let headerIdNew = headerid.toString();
this.loginInfo$.forEach(loginInfoToken => {
this.authToken = loginInfoToken.get(0).auth_token;
});
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/epalchosen/`+headerIdNew, options )
.map(response