From a63eafb833fb81e700a6dae1f2102ceba7016ef9 Mon Sep 17 00:00:00 2001 From: Mathieu Lagace Date: Sat, 17 Aug 2019 18:02:09 -0400 Subject: [PATCH] Add Calendar in Admin --- app/Booking.php | 7 +- app/Http/Controllers/ConfigController.php | 4 +- app/Http/Controllers/ScheduleController.php | 37 ++- composer.json | 1 + composer.lock | 245 +++++++++++++++++- config/app.php | 3 + .../2019_08_17_102431_create_events_table.php | 2 + public/css/custom.css | 184 +++++++------ public/js/calendar.js | 3 +- resources/custom.css | 184 +++++++------ .../admin/calendar/calendar_display.blade.php | 2 +- .../views/admin/configs/general.blade.php | 4 +- .../views/admin/schedule/modal/show.blade.php | 102 +++++++- .../layouts/modal/schedule/show.blade.php | 4 +- .../views/layouts/public/header.blade.php | 8 +- resources/views/layouts/public/main.blade.php | 24 +- .../views/public/modal/schedule.blade.php | 43 ++- routes/api.php | 4 +- routes/web.php | 7 + 19 files changed, 649 insertions(+), 219 deletions(-) diff --git a/app/Booking.php b/app/Booking.php index bf30ebc7..86282d55 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -13,6 +13,11 @@ class Booking extends Model public function user() { - return $this->belongsTo('App\User'); + return $this->belongsTo('App\User'); + } + + public function item() + { + return $this->belongsTo('App\Item'); } } diff --git a/app/Http/Controllers/ConfigController.php b/app/Http/Controllers/ConfigController.php index 03597fc2..fba69b57 100644 --- a/app/Http/Controllers/ConfigController.php +++ b/app/Http/Controllers/ConfigController.php @@ -72,9 +72,9 @@ class ConfigController extends Controller $config = Config::all()->where('name',request('perm'))->first(); if (request('value') == "true") { - $config->state = 1; + $config->data = ["true"]; } else { - $config->state = 0; + $config->data = ["false"]; } $config->save(); diff --git a/app/Http/Controllers/ScheduleController.php b/app/Http/Controllers/ScheduleController.php index bb32771c..295b733f 100644 --- a/app/Http/Controllers/ScheduleController.php +++ b/app/Http/Controllers/ScheduleController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use \App\Schedule; use function GuzzleHttp\json_encode; +use PDF; class ScheduleController extends Controller { @@ -76,7 +77,7 @@ class ScheduleController extends Controller if($event->date_begin >= $start && $event->date_begin <= $end) { array_push($events,$event); } - if($event->date_end >= $start && $event->date_end <= $end) { + else if($event->date_end >= $start && $event->date_end <= $end) { array_push($events,$event); } } @@ -91,6 +92,7 @@ class ScheduleController extends Controller 'start' => $schedule->date.'T'.$schedule->data['event_begin_time'], 'end' => $schedule->date.'T'.$schedule->data['event_end_time'], 'color' => $color, + 'source' => 'schedule', 'id' => $schedule->id ]; array_push($jsonevents,$event); @@ -105,6 +107,8 @@ class ScheduleController extends Controller 'start' => $event->date_begin, 'end' => $event->date_end, 'color' => $color, + 'extraParams' => [ + 'db_type' => 'event'], 'id' => $event->id ]; array_push($jsonevents,$myevent); @@ -113,14 +117,30 @@ class ScheduleController extends Controller return json_encode($jsonevents); } - public function loadModal($id) + public function loadModal($id,$db_type) { - return view('public.modal.schedule',['event' => \App\Schedule::find($id)]); + if($db_type == "event") + { + $event = \App\Event::find($id); + } + else + { + $event = \App\Schedule::find($id); + } + return view('public.modal.schedule',['event' => $event]); } - public function loadModalFull($id) + public function loadModalFull($id,$db_type) { - return view('admin.schedule.modal.show',['event' => \App\Schedule::find($id)]); + if($db_type == "event") + { + $event = \App\Event::find($id); + } + else + { + $event = \App\Schedule::find($id); + } + return view('admin.schedule.modal.show',['event' => $event]); } public function getColor($type) @@ -172,4 +192,11 @@ class ScheduleController extends Controller }; return $color; } + + public function printtopdf($id) + { + $event = \App\Event::find($id); + $pdf = PDF::loadView('admin.schedule.modal.show',['event' => $event]); + return $pdf->download($event->date_begin.'.pdf'); + } } diff --git a/composer.json b/composer.json index 0d801e5b..0004d34c 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "type": "project", "require": { "php": "^7.1.3", + "barryvdh/laravel-dompdf": "^0.8.4", "fideloper/proxy": "^4.0", "guzzlehttp/guzzle": "^6.3", "laravel/framework": "5.6.*", diff --git a/composer.lock b/composer.lock index 5a9f8658..bd358bd1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,64 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b914f34bb5ca62a2b7d916629dc30d1a", + "content-hash": "a92d2a9579b7e0ef7e3c8b77e8c5dcde", "packages": [ + { + "name": "barryvdh/laravel-dompdf", + "version": "v0.8.4", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-dompdf.git", + "reference": "3fd817065e1c820b1ddace8b2bf65ca45088df4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/3fd817065e1c820b1ddace8b2bf65ca45088df4f", + "reference": "3fd817065e1c820b1ddace8b2bf65ca45088df4f", + "shasum": "" + }, + "require": { + "dompdf/dompdf": "^0.8", + "illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x", + "php": ">=7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.8-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\DomPDF\\ServiceProvider" + ], + "aliases": { + "PDF": "Barryvdh\\DomPDF\\Facade" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\DomPDF\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "A DOMPDF Wrapper for Laravel", + "keywords": [ + "dompdf", + "laravel", + "pdf" + ], + "time": "2019-02-26T18:07:43+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", @@ -168,6 +224,72 @@ ], "time": "2019-07-30T19:33:28+00:00" }, + { + "name": "dompdf/dompdf", + "version": "v0.8.3", + "source": { + "type": "git", + "url": "https://github.com/dompdf/dompdf.git", + "reference": "75f13c700009be21a1965dc2c5b68a8708c22ba2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/75f13c700009be21a1965dc2c5b68a8708c22ba2", + "reference": "75f13c700009be21a1965dc2c5b68a8708c22ba2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "phenx/php-font-lib": "0.5.*", + "phenx/php-svg-lib": "0.3.*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8|^5.5|^6.5", + "squizlabs/php_codesniffer": "2.*" + }, + "suggest": { + "ext-gd": "Needed to process images", + "ext-gmagick": "Improves image processing performance", + "ext-imagick": "Improves image processing performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.7-dev" + } + }, + "autoload": { + "psr-4": { + "Dompdf\\": "src/" + }, + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + }, + { + "name": "Brian Sweeney", + "email": "eclecticgeek@gmail.com" + }, + { + "name": "Gabriel Bull", + "email": "me@gabrielbull.com" + } + ], + "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", + "homepage": "https://github.com/dompdf/dompdf", + "time": "2018-12-14T02:40:31+00:00" + }, { "name": "dragonmantank/cron-expression", "version": "v2.3.0", @@ -1319,6 +1441,83 @@ ], "time": "2018-07-02T15:55:56+00:00" }, + { + "name": "phenx/php-font-lib", + "version": "0.5.1", + "source": { + "type": "git", + "url": "https://github.com/PhenX/php-font-lib.git", + "reference": "760148820110a1ae0936e5cc35851e25a938bc97" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/760148820110a1ae0936e5cc35851e25a938bc97", + "reference": "760148820110a1ae0936e5cc35851e25a938bc97", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "FontLib\\": "src/FontLib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse, export and make subsets of different types of font files.", + "homepage": "https://github.com/PhenX/php-font-lib", + "time": "2017-09-13T16:14:37+00:00" + }, + { + "name": "phenx/php-svg-lib", + "version": "v0.3.2", + "source": { + "type": "git", + "url": "https://github.com/PhenX/php-svg-lib.git", + "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/ccc46ef6340d4b8a4a68047e68d8501ea961442c", + "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c", + "shasum": "" + }, + "require": { + "sabberworm/php-css-parser": "8.1.*" + }, + "require-dev": { + "phpunit/phpunit": "~5.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Svg\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse and export to PDF SVG files.", + "homepage": "https://github.com/PhenX/php-svg-lib", + "time": "2018-06-03T10:10:03+00:00" + }, { "name": "php-http/guzzle6-adapter", "version": "v1.1.1", @@ -1927,6 +2126,50 @@ ], "time": "2018-07-19T23:38:55+00:00" }, + { + "name": "sabberworm/php-css-parser", + "version": "8.1.0", + "source": { + "type": "git", + "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", + "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/850cbbcbe7fbb155387a151ea562897a67e242ef", + "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "Sabberworm\\CSS": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Raphael Schweikert" + } + ], + "description": "Parser for CSS Files written in PHP", + "homepage": "http://www.sabberworm.com/blog/2010/6/10/php-css-parser", + "keywords": [ + "css", + "parser", + "stylesheet" + ], + "time": "2016-07-19T19:14:21+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.2.1", diff --git a/config/app.php b/config/app.php index 13b36021..bc2ac278 100644 --- a/config/app.php +++ b/config/app.php @@ -157,10 +157,12 @@ return [ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, + /* * Package Service Providers... */ + Barryvdh\DomPDF\ServiceProvider::class, /* * Application Service Providers... @@ -219,6 +221,7 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'PDF' => Barryvdh\DomPDF\Facade::class, ], diff --git a/database/migrations/2019_08_17_102431_create_events_table.php b/database/migrations/2019_08_17_102431_create_events_table.php index 6149cb20..ad681b15 100644 --- a/database/migrations/2019_08_17_102431_create_events_table.php +++ b/database/migrations/2019_08_17_102431_create_events_table.php @@ -21,6 +21,8 @@ class CreateEventsTable extends Migration $table->string('type'); $table->string('user_id'); $table->string('location'); + $table->boolean('is_mandatory'); + $table->text('desc'); $table->timestamps(); }); } diff --git a/public/css/custom.css b/public/css/custom.css index c158eb75..2ab92f9d 100644 --- a/public/css/custom.css +++ b/public/css/custom.css @@ -1,87 +1,107 @@ -.calendar{ - margin-top: 50px; +.calendar { + margin-top: 50px; +} + +.calendar-body-column { + display: flex; +} + +.calendar-container { + width: 14%; + height: 7.5rem; + text-align: center; + vertical-align: middle !important; + border: solid 1px #d9d9d9 !important; + padding: 0px !important; + background-color: white; +} + +.calendar-date { + float: left; + margin-left: 1rem; +} + +.calendar-text { + float: right; +} + +.calendar-text>div { + text-align: start; +} + +.calendar_event_name { + height: 3rem; + overflow: hidden; +} + +@media only screen and (max-width: 800px) { + .calendar-container { + width: 100%; } - - .calendar-body-column { - display: flex; + .calendar-head { + display: none; } - .calendar-container{ - width: 14%; - height: 7.5rem; - text-align: center; - vertical-align: middle !important; - border: solid 1px #d9d9d9 !important; - padding: 0px !important; - background-color: white; + .calendar-empty { + display: none; } - .calendar-date{ - float: left; - margin-left: 1rem; +} + +.btn-calendar { + padding: 36px 0; + height: 7.5rem; + margin: 0px; +} + +.btn-calendar:hover { + background-color: #f2f2f26e; +} + +.thead-dark { + color: #fff; + background-color: #212529; + border-color: #32383e; + text-align: center; +} + +.loader { + text-align: center; +} + +.loader-bg { + width: 70px; + margin-top: 50px; + margin-bottom: 50px; +} + +.loader-spinner { + position: absolute; + border: 16px solid #f3f3f3; + border-top: 16px solid #272c33; + border-radius: 50%; + width: 120px; + height: 120px; + animation: spin 2s linear infinite; + left: 0px; + right: 0px; + margin-left: auto; + margin-right: auto; + top: 44px; +} + +@keyframes spin { + 0% { + transform: rotate(0deg); } - .calendar-text{ - float: right; + 100% { + transform: rotate(360deg); } - .calendar-text > div { - text-align:start; - } - .calendar_event_name { - height: 3rem; - overflow: hidden; - } - @media only screen and (max-width: 800px) { - .calendar-container{ - width: 100%; - } - .calendar-head{ - display: none; - } - .calendar-empty{ - display: none; - } - } - - .btn-calendar{ - padding: 36px 0; - height: 7.5rem; - margin: 0px; - } - .btn-calendar:hover{ - background-color: #f2f2f26e; - } - .thead-dark { - color: #fff; - background-color: #212529; - border-color: #32383e; - text-align: center; - } - .loader{ - text-align: center; - } - .loader-bg{ - width: 70px; - margin-top: 50px; - margin-bottom: 50px; - } - .loader-spinner { - position: absolute; - border: 16px solid #f3f3f3; - border-top: 16px solid #272c33; - border-radius: 50%; - width: 120px; - height: 120px; - animation: spin 2s linear infinite; - left: 0px; - right: 0px; - margin-left: auto; - margin-right: auto; - top: 44px; - } - - @keyframes spin { - 0% { transform: rotate(0deg); } - 100% { transform: rotate(360deg); } - } - .cs-notification:hover { - background-color: #F2F2F2 !important; - color:white; - } \ No newline at end of file +} + +.cs-notification:hover { + background-color: #F2F2F2 !important; + color: white; +} + +.modal-lg { + max-width: 1150px !important; +} \ No newline at end of file diff --git a/public/js/calendar.js b/public/js/calendar.js index cb65f195..bf51cddd 100644 --- a/public/js/calendar.js +++ b/public/js/calendar.js @@ -12,8 +12,7 @@ function initFullCalendar(authToken) { }, events: '/api/schedule/events', eventClick: function (info) { - console.log(info.event.id) - $.get("/api/schedule/full/events/" + info.event.id + "/modal?api_token="+authToken, function (data) { + $.get("/api/schedule/full/events/" + info.event.id + "/"+ info.event.extendedProps.extraParams.db_type + "/modal?api_token="+authToken, function (data) { $("#modal-content").html(data); }); $('#schedulemodal').modal('toggle') diff --git a/resources/custom.css b/resources/custom.css index c158eb75..326af695 100644 --- a/resources/custom.css +++ b/resources/custom.css @@ -1,87 +1,107 @@ -.calendar{ - margin-top: 50px; +.calendar { + margin-top: 50px; +} + +.calendar-body-column { + display: flex; +} + +.calendar-container { + width: 14%; + height: 7.5rem; + text-align: center; + vertical-align: middle !important; + border: solid 1px #d9d9d9 !important; + padding: 0px !important; + background-color: white; +} + +.calendar-date { + float: left; + margin-left: 1rem; +} + +.calendar-text { + float: right; +} + +.calendar-text>div { + text-align: start; +} + +.calendar_event_name { + height: 3rem; + overflow: hidden; +} + +@media only screen and (max-width: 800px) { + .calendar-container { + width: 100%; } - - .calendar-body-column { - display: flex; + .calendar-head { + display: none; } - .calendar-container{ - width: 14%; - height: 7.5rem; - text-align: center; - vertical-align: middle !important; - border: solid 1px #d9d9d9 !important; - padding: 0px !important; - background-color: white; + .calendar-empty { + display: none; } - .calendar-date{ - float: left; - margin-left: 1rem; +} + +.btn-calendar { + padding: 36px 0; + height: 7.5rem; + margin: 0px; +} + +.btn-calendar:hover { + background-color: #f2f2f26e; +} + +.thead-dark { + color: #fff; + background-color: #212529; + border-color: #32383e; + text-align: center; +} + +.loader { + text-align: center; +} + +.loader-bg { + width: 70px; + margin-top: 50px; + margin-bottom: 50px; +} + +.loader-spinner { + position: absolute; + border: 16px solid #f3f3f3; + border-top: 16px solid #272c33; + border-radius: 50%; + width: 120px; + height: 120px; + animation: spin 2s linear infinite; + left: 0px; + right: 0px; + margin-left: auto; + margin-right: auto; + top: 44px; +} + +@keyframes spin { + 0% { + transform: rotate(0deg); } - .calendar-text{ - float: right; + 100% { + transform: rotate(360deg); } - .calendar-text > div { - text-align:start; - } - .calendar_event_name { - height: 3rem; - overflow: hidden; - } - @media only screen and (max-width: 800px) { - .calendar-container{ - width: 100%; - } - .calendar-head{ - display: none; - } - .calendar-empty{ - display: none; - } - } - - .btn-calendar{ - padding: 36px 0; - height: 7.5rem; - margin: 0px; - } - .btn-calendar:hover{ - background-color: #f2f2f26e; - } - .thead-dark { - color: #fff; - background-color: #212529; - border-color: #32383e; - text-align: center; - } - .loader{ - text-align: center; - } - .loader-bg{ - width: 70px; - margin-top: 50px; - margin-bottom: 50px; - } - .loader-spinner { - position: absolute; - border: 16px solid #f3f3f3; - border-top: 16px solid #272c33; - border-radius: 50%; - width: 120px; - height: 120px; - animation: spin 2s linear infinite; - left: 0px; - right: 0px; - margin-left: auto; - margin-right: auto; - top: 44px; - } - - @keyframes spin { - 0% { transform: rotate(0deg); } - 100% { transform: rotate(360deg); } - } - .cs-notification:hover { - background-color: #F2F2F2 !important; - color:white; - } \ No newline at end of file +} + +.cs-notification:hover { + background-color: #F2F2F2 !important; + color: white; +} + +.modal-lg { + width: 80%; +} \ No newline at end of file diff --git a/resources/views/admin/calendar/calendar_display.blade.php b/resources/views/admin/calendar/calendar_display.blade.php index 912f32ba..bcf02a9b 100644 --- a/resources/views/admin/calendar/calendar_display.blade.php +++ b/resources/views/admin/calendar/calendar_display.blade.php @@ -97,7 +97,7 @@ } diff --git a/resources/views/admin/schedule/modal/show.blade.php b/resources/views/admin/schedule/modal/show.blade.php index c07d4808..4751c115 100644 --- a/resources/views/admin/schedule/modal/show.blade.php +++ b/resources/views/admin/schedule/modal/show.blade.php @@ -1,5 +1,105 @@ @extends('layouts.modal.schedule.show') @section('content') -Test + +
+
+ Du {{$event->date_begin}} au {{$event->date_end}}
+ {{$event->location}} +
+
+ @if ($event->is_mandatory) + Obligatoire + @else + Optionnel + @endif + @if (is_int($event->type)) + {{$event->type}} + @else + {{\App\ComplementaryActivity::find($event->type)->name}} + @endif +
+
+
+
+ {{$event->desc}} +
+
+ @if (!$event->courses->isEmpty()) +
+
+

Horaire

+
+
+ @for ($p = 1; $p <= \App\Config::getData('admin_periode_nb'); $p++) +
+ Période {{$p}} {{\App\Config::all()->where('name','admin_periode_begin')->first()->data[$p]}} à {{\App\Config::all()->where('name','admin_periode_end')->first()->data[$p]}} +
+ @endfor +
+ @for ($l = 1; $l <= \App\Config::getData('admin_level_in_schedule_nb'); $l++) +
+
+ Niveau {{$l}} +
+ @for ($p = 1; $p <= \App\Config::getData('admin_periode_nb'); $p++) +
+ @foreach ($event->courses as $course) + @if ($course->periode == $p && $course->level == $l) +
+
+ {{$course->name}} +
+
+ {{\App\User::find($course->user_id)->fullname()}} +
+
+ {{$course->ocom}} +
+
+ {{$course->location}} +
+
+ +
+
+ @if (!$course->bookings->isEmpty()) +
+
+ Item +
+
+ Quantité +
+
+ @foreach ($course->bookings as $booking) + +
+ {{$booking->amount}} +
+ @endforeach +
+ @else +

+ Aucune réservation +

+ @endif +
+ Modifier les réservation +
+
+
+
+ @endif + @endforeach +
+ @endfor +
+ @endfor +
+
+ @endif + @endsection \ No newline at end of file diff --git a/resources/views/layouts/modal/schedule/show.blade.php b/resources/views/layouts/modal/schedule/show.blade.php index 5ab1d000..8a367fde 100644 --- a/resources/views/layouts/modal/schedule/show.blade.php +++ b/resources/views/layouts/modal/schedule/show.blade.php @@ -1,5 +1,5 @@ diff --git a/resources/views/layouts/public/header.blade.php b/resources/views/layouts/public/header.blade.php index cdf766d9..d67d6d91 100644 --- a/resources/views/layouts/public/header.blade.php +++ b/resources/views/layouts/public/header.blade.php @@ -22,16 +22,16 @@ airplanemode_active L'escadron