diff --git a/app/EventType.php b/app/EventType.php new file mode 100644 index 00000000..9d98e112 --- /dev/null +++ b/app/EventType.php @@ -0,0 +1,12 @@ + 'array', + ]; +} diff --git a/app/Http/Controllers/EventTypeController.php b/app/Http/Controllers/EventTypeController.php new file mode 100644 index 00000000..231cb37e --- /dev/null +++ b/app/Http/Controllers/EventTypeController.php @@ -0,0 +1,85 @@ + $periode, 'niveau' => $niveau]); } - public function getTemplate() + public function getTemplate(int $id) { - return view('admin.schedule.editor.template'); + return view('admin.schedule.editor.template',["eventType" => \App\EventType::find($id)]); + } + + public function getEventTemplate(int $id) + { + $eventType = \App\EventType::find($id); + + return json_encode($eventType); + } + + public function test() + { + $evenType = new \App\EventType(); + + $evenType->name = "Soirée d'instruction régulière"; + $evenType->admin_desc = "Veuillez modifier la description admin par défaut"; + $evenType->calendar_color = "orange"; + $evenType->calendar_icon = "fas fa-book"; + $evenType->begin_time = "12:00"; + $evenType->end_time = "18:00"; + $evenType->location = "Escadron"; + $evenType->is_mandatory = true; + $evenType->use_weekly_msg = true; + $evenType->weekly_msg_publication_time = "-5days"; + $evenType->use_schedule = true; + $evenType->schedule_model = [ + "periodes" => [ + 0 => [ + "name" => "Periode 1", + "begin_time" => "19:00", + "end_time" => "20:10" + ], + 1 => [ + "name" => "Pause", + "begin_time" => "20:10", + "end_time" => "20:30" + ], + 2 => [ + "name" => "Periode 1", + "begin_time" => "20:30", + "end_time" => "21:20" + ] + ], + "niveaux" => [ + 0 => [ + "name" => "Niveau 1" + ], + 1 => [ + "name" => "Niveau 2" + ], + 2 => [ + "name" => "Niveau 3" + ] + ] + ]; + $evenType->is_promoted = true; + //$evenType->save(); } } diff --git a/database/migrations/2019_12_22_145445_create_event_types_table.php b/database/migrations/2019_12_22_145445_create_event_types_table.php new file mode 100644 index 00000000..210d134d --- /dev/null +++ b/database/migrations/2019_12_22_145445_create_event_types_table.php @@ -0,0 +1,44 @@ +bigIncrements('id'); + $table->string('name'); + $table->text('admin_desc'); + $table->string('calendar_color')->default('blue'); + $table->string('calendar_icon')->default(''); + $table->string('begin_time')->default('12:00'); + $table->string('end_time')->default('13:00'); + $table->string('location')->default('Escadron'); + $table->boolean('is_mandatory')->default(false); + $table->boolean('use_weekly_msg')->default(false); + $table->string('weekly_msg_publication_time')->default('-5day'); + $table->boolean('use_schedule')->default(false); + $table->text('schedule_model'); + $table->boolean('is_promoted')->default(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('event_types'); + } +} diff --git a/public/js/plugins/schedule/editor.js b/public/js/plugins/schedule/editor.js index 31a7ba25..7289e417 100644 --- a/public/js/plugins/schedule/editor.js +++ b/public/js/plugins/schedule/editor.js @@ -1,8 +1,8 @@ -function initScheduleEditor(id, periode, niveau) +function initScheduleEditor(id, eventType) { $.ajax({ type: 'GET', - url: '/api/schedule/editor/init?api_token='+api_token, + url: '/api/schedule/editor/init/'+eventType+'?api_token='+api_token, success: function (template) { $("#"+id).html(template); for (let pniveau = 1; pniveau <= 3; pniveau++) { @@ -16,11 +16,49 @@ function initScheduleEditor(id, periode, niveau) showNotification('error','Impossible d\'initialiser l\'éditeur d\'horaire ...','top', 'center') } }) + $('.datetimepicker').datetimepicker({ + icons: { + time: "fa fa-clock-o", + date: "fa fa-calendar", + up: "fa fa-chevron-up", + down: "fa fa-chevron-down", + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-screenshot', + clear: 'fa fa-trash', + close: 'fa fa-remove' + } + }); + $('.richeditor').trumbowyg({ + lang: 'fr' + }); + $('select').selectpicker(); } -function loadTemplate(id) +function switchUseWeeklyMsg() { - $.get('/api/schedule/editor/init?api_token='+api_token, function ( data ) {$("#"+id).html(data);}); + + if($('#use_weekly_msg').is(":checked")) + { + $('#collmessagedelasemaine').removeClass('d-none'); + } + else + { + $('#collmessagedelasemaine').addClass('d-none'); + } + +} + +function switchUseSchedule() +{ + if($('#use_schedule').is(":checked")) + { + $('#collschedule').removeClass('d-none'); + } + else + { + $('#collschedule').addClass('d-none'); + } } function loadCourse(periode,niveau) @@ -35,4 +73,89 @@ function loadCourse(periode,niveau) showNotification('error','Impossible de charger les cours ...','top', 'center') } }) +} + +function loadEventType(date) +{ + var selectInput = $('#type'); + var id = selectInput.val(); + $.ajax({ + type: 'GET', + url: '/api/schedule/editor/template/'+id+'?api_token='+api_token, + success: function (data) { + var result = JSON.parse(data); + initScheduleEditor("scheduleEditor",id) + $.each(result, function (i, val) { + if(i == "is_mandatory" || i == "use_schedule" || i == "use_weekly_msg") + { + if(val == 1) + { + $('#'+i).prop( "checked", true ); + } + else + { + $('#'+i).prop( "checked", false ); + } + switchUseSchedule(); + switchUseWeeklyMsg(); + } + else if(i == "begin_time" || i == "end_time") + { + var foo = $('#'+i); + var mdate = moment(date+" "+val); + foo.data("DateTimePicker").destroy(); + foo.datetimepicker({ + icons: { + time: "fa fa-clock-o", + date: "fa fa-calendar", + up: "fa fa-chevron-up", + down: "fa fa-chevron-down", + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-screenshot', + clear: 'fa fa-trash', + close: 'fa fa-remove' + }, + date: new Date(mdate) + }); + + } + else if(i == "weekly_msg_publication_time") + { + var foo = $('#'+i); + var mdate = moment(date+" "+result["begin_time"]); + mdate.subtract(5, 'days'); + foo.data("DateTimePicker").destroy(); + foo.datetimepicker({ + icons: { + time: "fa fa-clock-o", + date: "fa fa-calendar", + up: "fa fa-chevron-up", + down: "fa fa-chevron-down", + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-screenshot', + clear: 'fa fa-trash', + close: 'fa fa-remove' + }, + date: new Date(mdate) + }); + + } + else if(i == "location" || i == "name") + { + var foo = $('#'+i); + foo.val(val); + } + else if(i == "admin_desc") + { + var foo = $('#'+i); + foo.trumbowyg('html', val); + } + }); + }, + error: function () { + showNotification('error','Impossible de charger le type d\'évenement ...','top', 'center') + } + }) } \ No newline at end of file diff --git a/resources/views/admin/schedule/editor/template.blade.php b/resources/views/admin/schedule/editor/template.blade.php index 6ef641b3..cd64c21d 100644 --- a/resources/views/admin/schedule/editor/template.blade.php +++ b/resources/views/admin/schedule/editor/template.blade.php @@ -4,27 +4,27 @@ Niveau/Periode - @for($i = 1; $i <= 3; $i++) + @foreach($eventType->schedule_model['niveaux'] as $niveau)
- +
- @endfor + @endforeach
-@for($j = 1; $j <= 3; $j++) +@foreach($eventType->schedule_model['periodes'] as $periode)
- + @@ -32,28 +32,28 @@
- +
- +
- @for($i = 1; $i <= 3; $i++) -
+ @foreach($eventType->schedule_model['niveaux'] as $niveau) +
@loaderDot
- @endfor + @endforeach
-@endfor +@endforeach
@@ -37,12 +116,21 @@

Options

+
+ + Choisir le type d'activité supprimera vos modification actuel + +
L'activité est-elle obligatoire pour tout les cadets ?
@@ -53,7 +141,7 @@ Inclure des messages de la semaine avec l'activité ?
@@ -64,7 +152,7 @@ Inclure un horaire avec l'activité ?
@@ -81,49 +169,9 @@ - - @endsection \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 3d3df645..d7bb23ff 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,8 +19,9 @@ Route::middleware('auth:api')->group(function () { Route::get('/schedule/events/modal/full/{id}/{db_type}','ScheduleController@loadModalFull')->middleware('perm:schedule_see'); Route::get('/schedule/events/add/modal/{type}/{date}','ScheduleController@loadModalDefautType')->middleware('perm:schedule_add'); - Route::get('/schedule/editor/init','ScheduleEditorController@getTemplate')->middleware('perm:schedule_edit'); + Route::get('/schedule/editor/init/{id}','ScheduleEditorController@getTemplate')->middleware('perm:schedule_edit'); Route::get('/schedule/editor/course/{niveau}/{periode}','ScheduleEditorController@getCourseEmpty')->middleware('perm:schedule_edit'); + Route::get('/schedule/editor/template/{id}','ScheduleEditorController@getEventTemplate')->middleware('perm:schedule_add'); Route::post('/schedule/event/delete/{id}','ScheduleController@delete')->middleware('perm:schedule_delete'); /** Booking */ diff --git a/routes/web.php b/routes/web.php index 8f4d3fd9..093884cd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Storage; /* Basic Auth Route */ Auth::routes(); Route::get('logout', 'Auth\LoginController@logout')->name('logout'); -Route::get("/test",'OCOMController@create'); +Route::get("/test/{id}",'ScheduleEditorController@getEventTemplate'); /** Public Route */