From 4dc7fca3e3b3fafd660668fba8a93fa5f5fbb659 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Tue, 30 Jan 2018 17:54:48 +0100 Subject: [PATCH] FEAT #40 Reports front --- .../reports-administration.component.html | 16 +++------ .../basket-administration.component.js | 1 - .../basket-administration.component.ts | 1 - .../reports-administration.component.js | 24 +++++++++----- .../reports-administration.component.ts | 33 +++++++++++-------- rest/index.php | 1 + .../report/controllers/ReportController.php | 13 ++++++-- 7 files changed, 53 insertions(+), 36 deletions(-) diff --git a/apps/maarch_entreprise/Views/reports-administration.component.html b/apps/maarch_entreprise/Views/reports-administration.component.html index 65aec96f487..5fb9ce52fee 100644 --- a/apps/maarch_entreprise/Views/reports-administration.component.html +++ b/apps/maarch_entreprise/Views/reports-administration.component.html @@ -1,17 +1,10 @@ +<div class="page-header"> + <h1>{{lang.administration}} {{lang.reports}}</h1> +</div> <div *ngIf="loading"> - <i class="fa fa-spinner fa-spin fa-5x" style="margin-left: 50%;margin-top: 16%;font-size: 8em"></i> + <mat-spinner style="margin:auto;"></mat-spinner> </div> <div *ngIf="!loading" class="container-fluid"> - <h1 style="margin-top: 0"><i class="fa fa-area-chart fa-2x"></i> {{lang.reports}}</h1> - <nav class="navbar navbar-default" style="font-size:17px !important;" id="toolBox"> - <div class="container-fluid"> - <div class="navbar-header"> - <a class="navbar-brand" routerLink="/administration" style="cursor: pointer"> - <i class="fa fa-arrow-circle-left" title="{{lang.back}}"></i> - </a> - </div> - </div> - </nav> <div> <mat-select placeholder="{{lang.chooseGroup}}" [(ngModel)]="selectedGroup" (change)="loadReports()" name="group"> <mat-option *ngFor="let group of groups" [value]="group.group_id"> @@ -41,6 +34,7 @@ <div class="form-group"> <div style="text-align:center;"> <button type="submit" class="btn btn-success">{{lang.save}}</button> + <button mat-raised-button routerLink='/administration'>{{lang.cancel}}</button> </div> </div> </form> diff --git a/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.js b/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.js index 70fb9062c95..e2a7b8e080b 100644 --- a/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.js @@ -104,7 +104,6 @@ var BasketAdministrationComponent = /** @class */ (function () { BasketAdministrationComponent = __decorate([ core_1.Component({ templateUrl: angularGlobals["basket-administrationView"], - styleUrls: ['../../node_modules/bootstrap/dist/css/bootstrap.min.css'], providers: [notification_service_1.NotificationService] }), __metadata("design:paramtypes", [http_1.HttpClient, router_1.ActivatedRoute, router_1.Router, notification_service_1.NotificationService]) diff --git a/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.ts index 54522ddc930..682036e2416 100644 --- a/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/administration/basket-administration.component.ts @@ -11,7 +11,6 @@ declare var angularGlobals : any; @Component({ templateUrl : angularGlobals["basket-administrationView"], - styleUrls : ['../../node_modules/bootstrap/dist/css/bootstrap.min.css'], providers : [NotificationService] }) export class BasketAdministrationComponent implements OnInit { diff --git a/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.js b/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.js index f2a3cf210f0..44f6048efa8 100755 --- a/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.js +++ b/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.js @@ -12,13 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var http_1 = require("@angular/common/http"); var translate_component_1 = require("../translate.component"); +var notification_service_1 = require("../notification.service"); var ReportsAdministrationComponent = /** @class */ (function () { - function ReportsAdministrationComponent(http) { + function ReportsAdministrationComponent(http, notify) { this.http = http; + this.notify = notify; this.lang = translate_component_1.LANG; this.groups = []; this.reports = []; this.selectedGroup = ""; + this.loading = false; } ReportsAdministrationComponent.prototype.updateBreadcrumb = function (applicationName) { if ($j('#ariane')[0]) { @@ -29,9 +32,13 @@ var ReportsAdministrationComponent = /** @class */ (function () { var _this = this; this.updateBreadcrumb(angularGlobals.applicationName); this.coreUrl = angularGlobals.coreUrl; - this.http.get(this.coreUrl + 'rest/groups') + this.loading = true; + this.http.get(this.coreUrl + 'rest/reports/groups') .subscribe(function (data) { _this.groups = data['groups']; + _this.loading = false; + }, function () { + location.href = "index.php"; }); }; ReportsAdministrationComponent.prototype.loadReports = function () { @@ -40,23 +47,24 @@ var ReportsAdministrationComponent = /** @class */ (function () { .subscribe(function (data) { _this.reports = data['reports']; }, function (err) { - errorNotification(err.error.errors); + _this.notify.error(err.error.errors); }); }; ReportsAdministrationComponent.prototype.onSubmit = function () { + var _this = this; this.http.put(this.coreUrl + 'rest/reports/groups/' + this.selectedGroup, this.reports) - .subscribe(function (data) { - successNotification(data['success']); + .subscribe(function () { + _this.notify.success(_this.lang.modificationSaved); }, function (err) { - errorNotification(err.error.errors); + _this.notify.error(err.error.errors); }); }; ReportsAdministrationComponent = __decorate([ core_1.Component({ templateUrl: angularGlobals["reports-administrationView"], - styleUrls: ['../../node_modules/bootstrap/dist/css/bootstrap.min.css'] + providers: [notification_service_1.NotificationService] }), - __metadata("design:paramtypes", [http_1.HttpClient]) + __metadata("design:paramtypes", [http_1.HttpClient, notification_service_1.NotificationService]) ], ReportsAdministrationComponent); return ReportsAdministrationComponent; }()); diff --git a/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.ts index eddbf696f1c..e578dfe92f1 100755 --- a/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/administration/reports-administration.component.ts @@ -1,29 +1,30 @@ import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { LANG } from '../translate.component'; +import { NotificationService } from '../notification.service'; declare function $j (selector: any) : any; -declare function successNotification(message: string) : void; -declare function errorNotification(message: string) : void; -declare const angularGlobals : any; +declare var angularGlobals : any; @Component({ templateUrl : angularGlobals["reports-administrationView"], - styleUrls : ['../../node_modules/bootstrap/dist/css/bootstrap.min.css'] + providers : [NotificationService] }) export class ReportsAdministrationComponent implements OnInit { coreUrl : string; lang : any = LANG; + groups : any[] = []; reports : any[] = []; - selectedGroup : string = ""; + loading : boolean = false; + - constructor(public http: HttpClient) { + constructor(public http: HttpClient, private notify: NotificationService) { } updateBreadcrumb(applicationName: string) { @@ -36,27 +37,33 @@ export class ReportsAdministrationComponent implements OnInit { this.updateBreadcrumb(angularGlobals.applicationName); this.coreUrl = angularGlobals.coreUrl; - this.http.get(this.coreUrl + 'rest/groups') + this.loading = true; + + this.http.get(this.coreUrl + 'rest/reports/groups') .subscribe((data: any) => { this.groups = data['groups']; + + this.loading = false; + }, () => { + location.href = "index.php"; }); } loadReports() { - this.http.get(this.coreUrl + 'rest/reports/groups/'+ this.selectedGroup) + this.http.get(this.coreUrl + 'rest/reports/groups/' + this.selectedGroup) .subscribe((data: any) => { this.reports = data['reports']; }, (err) => { - errorNotification(err.error.errors); + this.notify.error(err.error.errors); }); } onSubmit() { - this.http.put(this.coreUrl + 'rest/reports/groups/'+ this.selectedGroup, this.reports) - .subscribe((data: any) => { - successNotification(data['success']); + this.http.put(this.coreUrl + 'rest/reports/groups/' + this.selectedGroup, this.reports) + .subscribe(() => { + this.notify.success(this.lang.modificationSaved); }, (err) => { - errorNotification(err.error.errors); + this.notify.error(err.error.errors); }); } } \ No newline at end of file diff --git a/rest/index.php b/rest/index.php index 7e9f4f5ce5f..5983a3607b9 100755 --- a/rest/index.php +++ b/rest/index.php @@ -242,6 +242,7 @@ $app->put('/notifications/{id}', \Notifications\Controllers\NotificationControll $app->delete('/notifications/{id}', \Notifications\Controllers\NotificationController::class . ':delete'); //Reports +$app->get('/reports/groups', \Report\controllers\ReportController::class . ':getGroups'); $app->get('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':getByGroupId'); $app->put('/reports/groups/{groupId}', \Report\controllers\ReportController::class . ':updateForGroupId'); diff --git a/src/app/report/controllers/ReportController.php b/src/app/report/controllers/ReportController.php index f14e59a563f..62bb064a975 100644 --- a/src/app/report/controllers/ReportController.php +++ b/src/app/report/controllers/ReportController.php @@ -23,9 +23,18 @@ use Slim\Http\Response; class ReportController { + public function getGroups(Request $request, Response $response) + { + if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); + } + + return $response->withJson(['groups' => GroupModel::get()]); + } + public function getByGroupId(Request $request, Response $response, array $aArgs) { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } @@ -41,7 +50,7 @@ class ReportController public function updateForGroupId(Request $request, Response $response, array $aArgs) { - if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { + if (!ServiceModel::hasService(['id' => 'admin_reports', 'userId' => $GLOBALS['userId'], 'location' => 'reports', 'type' => 'admin'])) { return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } -- GitLab