From 80e38d26d074d37865aba488a7b458cffce06c3f Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 4 Sep 2020 17:09:29 +0200 Subject: [PATCH 01/35] Define Model & Relationsships --- .../ObservationOrderController.php | 85 +++++++++++++++++++ app/Models/Block.php | 8 ++ app/Models/ObservationOrder.php | 36 ++++++++ app/Models/Participant.php | 8 ++ app/Models/User.php | 8 ++ .../Import/Blocks/BlockListImporter.php | 0 .../Import/Blocks/BlockListParser.php | 0 .../ECamp2/ECamp2BlockOverviewImporter.php | 0 .../ECamp2/ECamp2BlockOverviewParser.php | 0 .../MiData/MiDataParticipantListImporter.php | 0 .../MiData/MiDataParticipantListParser.php | 0 .../Participants/ParticipantListImporter.php | 0 .../Participants/ParticipantListParser.php | 0 app/Services/Translator.php | 0 .../factories/ObservationOrderFactory.php | 12 +++ ...145745_create_observation_orders_table.php | 31 +++++++ database/seeds/ObservationOrderSeeder.php | 16 ++++ 17 files changed, 204 insertions(+) create mode 100644 app/Http/Controllers/ObservationOrderController.php create mode 100644 app/Models/ObservationOrder.php mode change 100755 => 100644 app/Services/Import/Blocks/BlockListImporter.php mode change 100755 => 100644 app/Services/Import/Blocks/BlockListParser.php mode change 100755 => 100644 app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewImporter.php mode change 100755 => 100644 app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewParser.php mode change 100755 => 100644 app/Services/Import/Participants/MiData/MiDataParticipantListImporter.php mode change 100755 => 100644 app/Services/Import/Participants/MiData/MiDataParticipantListParser.php mode change 100755 => 100644 app/Services/Import/Participants/ParticipantListImporter.php mode change 100755 => 100644 app/Services/Import/Participants/ParticipantListParser.php mode change 100755 => 100644 app/Services/Translator.php create mode 100755 database/factories/ObservationOrderFactory.php create mode 100644 database/migrations/2020_09_04_145745_create_observation_orders_table.php create mode 100755 database/seeds/ObservationOrderSeeder.php diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php new file mode 100644 index 00000000..61b142ba --- /dev/null +++ b/app/Http/Controllers/ObservationOrderController.php @@ -0,0 +1,85 @@ +hasMany('App\Models\Observation'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function observationsOrders() { + return $this->hasMany('App\Models\ObservationOrder'); + } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationOrder.php new file mode 100644 index 00000000..02db9b5e --- /dev/null +++ b/app/Models/ObservationOrder.php @@ -0,0 +1,36 @@ +belongsTo('App\Models\Block'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function participant() + { + return $this->belongsTo('App\Models\Participant', 'observations_participants'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user() + { + return $this->belongsTo('App\Models\User'); + } +} diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 771b06b2..2308e06e 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -66,6 +66,14 @@ public function qualis() { return $this->hasMany(Quali::class); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function observationOrders() + { + return $this->hasMany('App\Models\ObservationOrder'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ diff --git a/app/Models/User.php b/app/Models/User.php index cf6cff9a..fb3bfb54 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -70,6 +70,14 @@ public function observations() return $this->hasMany('App\Models\Observation'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function observationOrders() + { + return $this->hasMany('App\Models\ObservationOrder'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ diff --git a/app/Services/Import/Blocks/BlockListImporter.php b/app/Services/Import/Blocks/BlockListImporter.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Blocks/BlockListParser.php b/app/Services/Import/Blocks/BlockListParser.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewImporter.php b/app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewImporter.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewParser.php b/app/Services/Import/Blocks/ECamp2/ECamp2BlockOverviewParser.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Participants/MiData/MiDataParticipantListImporter.php b/app/Services/Import/Participants/MiData/MiDataParticipantListImporter.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Participants/MiData/MiDataParticipantListParser.php b/app/Services/Import/Participants/MiData/MiDataParticipantListParser.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Participants/ParticipantListImporter.php b/app/Services/Import/Participants/ParticipantListImporter.php old mode 100755 new mode 100644 diff --git a/app/Services/Import/Participants/ParticipantListParser.php b/app/Services/Import/Participants/ParticipantListParser.php old mode 100755 new mode 100644 diff --git a/app/Services/Translator.php b/app/Services/Translator.php old mode 100755 new mode 100644 diff --git a/database/factories/ObservationOrderFactory.php b/database/factories/ObservationOrderFactory.php new file mode 100755 index 00000000..3c520219 --- /dev/null +++ b/database/factories/ObservationOrderFactory.php @@ -0,0 +1,12 @@ +define(ObservationOrder::class, function (Faker $faker) { + return [ + // + ]; +}); diff --git a/database/migrations/2020_09_04_145745_create_observation_orders_table.php b/database/migrations/2020_09_04_145745_create_observation_orders_table.php new file mode 100644 index 00000000..5881ec32 --- /dev/null +++ b/database/migrations/2020_09_04_145745_create_observation_orders_table.php @@ -0,0 +1,31 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('observation_orders'); + } +} diff --git a/database/seeds/ObservationOrderSeeder.php b/database/seeds/ObservationOrderSeeder.php new file mode 100755 index 00000000..7aa75c14 --- /dev/null +++ b/database/seeds/ObservationOrderSeeder.php @@ -0,0 +1,16 @@ + Date: Fri, 4 Sep 2020 17:24:59 +0200 Subject: [PATCH 02/35] migration: table and foreign keys --- database/factories/ObservationOrderFactory.php | 12 ------------ ...04_145745_create_observation_orders_table.php | 16 ++++++++++++++++ database/seeds/ObservationOrderSeeder.php | 16 ---------------- 3 files changed, 16 insertions(+), 28 deletions(-) delete mode 100755 database/factories/ObservationOrderFactory.php delete mode 100755 database/seeds/ObservationOrderSeeder.php diff --git a/database/factories/ObservationOrderFactory.php b/database/factories/ObservationOrderFactory.php deleted file mode 100755 index 3c520219..00000000 --- a/database/factories/ObservationOrderFactory.php +++ /dev/null @@ -1,12 +0,0 @@ -define(ObservationOrder::class, function (Faker $faker) { - return [ - // - ]; -}); diff --git a/database/migrations/2020_09_04_145745_create_observation_orders_table.php b/database/migrations/2020_09_04_145745_create_observation_orders_table.php index 5881ec32..ac0d5b05 100644 --- a/database/migrations/2020_09_04_145745_create_observation_orders_table.php +++ b/database/migrations/2020_09_04_145745_create_observation_orders_table.php @@ -15,8 +15,18 @@ public function up() { Schema::create('observation_orders', function (Blueprint $table) { $table->id(); + $table->integer('user_id')->nullable(false); + $table->integer('block_id')->nullable(false); + $table->integer('participant_id')->nullable(false); $table->timestamps(); }); + Schema::table('observation_orders', function(Blueprint $table) + { + $table->foreign('user_id', 'fk_user_observation_orders')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('block_id', 'fk_block_observation_orders')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('participant_id', 'fk_participants_observation_orders')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); } /** @@ -26,6 +36,12 @@ public function up() */ public function down() { + Schema::table('observation_orders', function(Blueprint $table) + { + $table->dropForeign('fk_user_observation_orders'); + $table->dropForeign('fk_block_observation_orders'); + $table->dropForeign('fk_participants_observation_orders'); + }); Schema::dropIfExists('observation_orders'); } } diff --git a/database/seeds/ObservationOrderSeeder.php b/database/seeds/ObservationOrderSeeder.php deleted file mode 100755 index 7aa75c14..00000000 --- a/database/seeds/ObservationOrderSeeder.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Fri, 4 Sep 2020 17:35:19 +0200 Subject: [PATCH 03/35] prepare controller with index, edit & destroy --- .../ObservationOrderController.php | 50 ++++++++----------- app/Models/ObservationOrder.php | 1 + 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index 61b142ba..8c2163ed 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -2,30 +2,26 @@ namespace App\Http\Controllers; -use App\ObservationOrder; +use App\Models\Course; +use App\Models\ObservationOrder; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\DB; + class ObservationOrderController extends Controller { /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index() { - // + return view('admin.observationOrders.index'); } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ - public function create() - { - // - } /** * Store a newly created resource in storage. @@ -38,33 +34,23 @@ public function store(Request $request) // } - /** - * Display the specified resource. - * - * @param \App\ObservationOrder $observationOrder - * @return \Illuminate\Http\Response - */ - public function show(ObservationOrder $observationOrder) - { - // - } /** * Show the form for editing the specified resource. * - * @param \App\ObservationOrder $observationOrder + * @param \App\Models\ObservationOrder $observationOrder * @return \Illuminate\Http\Response */ public function edit(ObservationOrder $observationOrder) { - // + return view('admin.observationOrders.edit', ['observationOrder' => $observationOrder]); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\ObservationOrder $observationOrder + * @param \App\Models\ObservationOrder $observationOrder * @return \Illuminate\Http\Response */ public function update(Request $request, ObservationOrder $observationOrder) @@ -75,11 +61,17 @@ public function update(Request $request, ObservationOrder $observationOrder) /** * Remove the specified resource from storage. * - * @param \App\ObservationOrder $observationOrder - * @return \Illuminate\Http\Response + * @param Request $request + * @param Course $course + * @param ObservationOrder $observationOrder + * @return RedirectResponse + * */ - public function destroy(ObservationOrder $observationOrder) + public function destroy(Request $request, Course $course, ObservationOrder $observationOrder) { - // + $observationOrder->delete(); + $request->session()->flash('alert-success', __('t.views.admin.observation_orders.delete_success')); + return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + } } diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationOrder.php index 02db9b5e..ed75035e 100644 --- a/app/Models/ObservationOrder.php +++ b/app/Models/ObservationOrder.php @@ -6,6 +6,7 @@ class ObservationOrder extends Model { + protected $table = 'observation_orders'; protected $fillable = ['user_id', 'block_id', 'participant_id']; From 5f50be5399514cbcd06afd68bb73539b6128e2d7 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 4 Sep 2020 17:36:06 +0200 Subject: [PATCH 04/35] prepare routes --- app/Http/Controllers/ObservationOrderController.php | 4 ++-- routes/web.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index 8c2163ed..f6f481b7 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -19,7 +19,7 @@ class ObservationOrderController extends Controller */ public function index() { - return view('admin.observationOrders.index'); + return view('admin.observationOrders'); } @@ -71,7 +71,7 @@ public function destroy(Request $request, Course $course, ObservationOrder $obse { $observationOrder->delete(); $request->session()->flash('alert-success', __('t.views.admin.observation_orders.delete_success')); - return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + return Redirect::route('admin.observationOrders', ['course' => $course->id]); } } diff --git a/routes/web.php b/routes/web.php index b5e61cdc..b5b1ac5e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -72,10 +72,13 @@ Route::post('/course/{course}/admin/participantGroups/{participantGroup}', 'ParticipantGroupController@update')->name('admin.participantGroups.update'); Route::delete('/course/{course}/admin/participantGroups/{participantGroup}', 'ParticipantGroupController@destroy')->name('admin.participantGroups.delete'); + Route::get('/course/{course}/admin/observationOrders', 'ObservationOrderController@index')->name('admin.observationOrders'); + Route::post('/course/{course}/admin/observationOrders', 'ObservationOrderController@store')->name('admin.observationOrders.store'); + Route::get('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@edit')->name('admin.observationOrders.edit'); + Route::post('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@update')->name('admin.observationOrders.update'); + Route::delete('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@destroy')->name('admin.observationOrders.delete'); }); - - Route::get('/course/{course}/admin/blocks', 'BlockController@index')->name('admin.blocks'); Route::post('/course/{course}/admin/blocks', 'BlockController@store')->name('admin.block.store'); Route::get('/course/{course}/admin/blocks/import', 'BlockController@upload')->name('admin.block.upload'); From ae0ec53e88e28d7cca7fcc80850a1f765588bf5d Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 4 Sep 2020 18:21:26 +0200 Subject: [PATCH 05/35] view:index new part and translations --- resources/lang/de/t.php | 25 +++++ .../admin/observationOrders/index.blade.php | 96 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100755 resources/views/admin/observationOrders/index.blade.php diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 083ea8fc..59b0f869 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -93,6 +93,12 @@ "requirements" => "Anforderungen", "user" => "Beobachter", ), + "observation_order" => array( + "trainer" => "Equipenmitglied", + "participant" => "TN", + "participants" => "TN", + "block" => "Block", + ), "participant" => array( "group" => "Abteilung", "image" => "Bild", @@ -230,6 +236,25 @@ "menu_name" => "Neuen Kurs erstellen", "title" => "Neuen Kurs erstellen", ), + "observation_orders" => array( + "are_observation_orders_required" => array( + "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-') Prozess", + "question" => "Muss ich Beobachtungsaufträge für meinen Kurs erfassen?", + ), + "create_success" => "Beobachtungsauftrag wurde erfolgreich erstellt.", + "delete_success" => "Beobachtungsauftrag wurde erfolgreich gelöscht.", + "edit" => "Beobachtungsauftrag bearbeiten", + "edit_success" => "Beobachtungsauftrag wurde erfolgreich gespeichert.", + "existing" => "Beobachtungsaufträge :courseName", + "menu_name" => "Beobachtungsaufträge", + "new" => "Neuer Beobachtungsauftrag", + "no_participant_group" => "Bisher sind keine Beobachtungsaufträge erfasst.", + "really_delete" => "Willst du den Beobachtungsauftrag wirklich löschen?", + "what_are_observation_orders" => array( + "answer" => "Viele Equipen definieren, wer wann wen beobachten sollte. Diese Aufträge könnt ihr hier definieren und seht diese (und ob sie schon erfüllt sind) z.Bsp. beim Spick.", + "question" => "Was sind Beobachtungsaufträge?", + ), + ), "participants" => array( "add_success" => "TN \":name\" erfolgreich erfasst.", "edit" => "TN ändern", diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php new file mode 100755 index 00000000..bf29aacb --- /dev/null +++ b/resources/views/admin/observationOrders/index.blade.php @@ -0,0 +1,96 @@ +@extends('layouts.default') + +@section('content') + + + + + @component('components.form', ['route' => ['admin.observationOrders.store', ['course' => $course->id]]]) + + + + + + + + + @component('components.help-text', ['id' => 'requirementsHelp', 'key' => 't.views.admin.observation_orders.what_are_observation_orders'])@endcomponent + + + + @endcomponent + + + + + + + @if (count($course->participantGroups)) + + @php + $fields = [ + __('t.models.participant_group.group_name') => function(\App\Models\ParticipantGroup $participantGroup) { return $participantGroup->group_name; }, + __('t.models.participant_group.participants') => function(\App\Models\ParticipantGroup $participantGroup) { + return $participantGroup->participants->map(function ($item){ + $scout_name = $item['scout_name']; + $group = $item['group']; + return $group ? "$scout_name ($group)" : $scout_name; + })->implode(', '); + }, + ]; + + @endphp + @component('components.responsive-table', [ + 'data' => $course->participantGroups, + 'fields' => $fields, + 'actions' => [ + 'edit' => function(\App\Models\ParticipantGroup $participantGroup) use ($course) { return route('admin.participantGroups.edit', ['course' => $course->id, 'participantGroup' => $participantGroup->id]); }, + 'delete' => function(\App\Models\ParticipantGroup $participantGroup) use ($course) { return [ + 'text' => __('t.views.admin.participant_groups.really_delete', [ 'name' => $participantGroup->group_name]), + 'route' => ['admin.participantGroups.destroy', ['course' => $course->id, 'participantGroup' => $participantGroup->id]], + ];}, + ] + ])@endcomponent + + + + @else + + {{__('t.views.admin.participant_groups.no_participant_group')}} + + @component('components.help-text', ['id' => 'noGroupsHelp', 'key' => 't.views.admin.participant_groups.are_participant_groups_required'])@endcomponent + + @endif + + + +@endsection From 7968bd8362e4f626daf535caca7ffd2909efeb74 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 4 Sep 2020 21:45:55 +0200 Subject: [PATCH 06/35] add order_desc and change to entity --- app/Models/ObservationOrder.php | 4 +- ...145745_create_observation_orders_table.php | 16 +++---- ...93813_create_observation_order_details.php | 45 +++++++++++++++++++ 3 files changed, 53 insertions(+), 12 deletions(-) create mode 100755 database/migrations/2020_09_04_193813_create_observation_order_details.php diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationOrder.php index ed75035e..6d8a0e26 100644 --- a/app/Models/ObservationOrder.php +++ b/app/Models/ObservationOrder.php @@ -8,7 +8,7 @@ class ObservationOrder extends Model { protected $table = 'observation_orders'; - protected $fillable = ['user_id', 'block_id', 'participant_id']; + protected $fillable = ['order_name']; /** @@ -24,7 +24,7 @@ public function block() */ public function participant() { - return $this->belongsTo('App\Models\Participant', 'observations_participants'); + return $this->belongsTo('App\Models\Participant'); } /** diff --git a/database/migrations/2020_09_04_145745_create_observation_orders_table.php b/database/migrations/2020_09_04_145745_create_observation_orders_table.php index ac0d5b05..79400fa6 100644 --- a/database/migrations/2020_09_04_145745_create_observation_orders_table.php +++ b/database/migrations/2020_09_04_145745_create_observation_orders_table.php @@ -14,17 +14,14 @@ class CreateObservationOrdersTable extends Migration public function up() { Schema::create('observation_orders', function (Blueprint $table) { - $table->id(); - $table->integer('user_id')->nullable(false); - $table->integer('block_id')->nullable(false); - $table->integer('participant_id')->nullable(false); + $table->integer('id', true); + $table->integer('course_id')->nullable(false); + $table->string('order_name')->nullable(false); $table->timestamps(); }); Schema::table('observation_orders', function(Blueprint $table) { - $table->foreign('user_id', 'fk_user_observation_orders')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('block_id', 'fk_block_observation_orders')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('participant_id', 'fk_participants_observation_orders')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('course_id', 'fk_course_observation_order')->references('id')->on('courses')->onUpdate('CASCADE')->onDelete('CASCADE'); }); } @@ -38,9 +35,8 @@ public function down() { Schema::table('observation_orders', function(Blueprint $table) { - $table->dropForeign('fk_user_observation_orders'); - $table->dropForeign('fk_block_observation_orders'); - $table->dropForeign('fk_participants_observation_orders'); + $table->dropForeign('fk_course_observation_order'); + }); Schema::dropIfExists('observation_orders'); } diff --git a/database/migrations/2020_09_04_193813_create_observation_order_details.php b/database/migrations/2020_09_04_193813_create_observation_order_details.php new file mode 100755 index 00000000..4aecb983 --- /dev/null +++ b/database/migrations/2020_09_04_193813_create_observation_order_details.php @@ -0,0 +1,45 @@ +integer('user_id')->nullable(false); + $table->integer('block_id')->nullable(false); + $table->integer('participant_id')->nullable(false); + }); + + Schema::table('observation_order_details', function (Blueprint $table) { + $table->foreign('user_id', 'fk_user_observation_order_details')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('block_id', 'fk_block_observation_order_details')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('participant_id', 'fk_participants_observation_order_details')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_order_details', function(Blueprint $table) + { + $table->dropForeign('fk_user_observation_order_details'); + $table->dropForeign('fk_block_observation_order_details'); + $table->dropForeign('fk_participants_observation_order_details'); + }); + Schema::dropIfExists('observation_order_details'); + } +} From 0d497d5af3d639d67613368c93c962a86017f757 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 4 Sep 2020 22:41:15 +0200 Subject: [PATCH 07/35] adjusted view --- resources/lang/de/t.php | 6 ++++-- resources/views/admin/observationOrders/index.blade.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 59b0f869..b2ae1cc4 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -94,10 +94,12 @@ "user" => "Beobachter", ), "observation_order" => array( - "trainer" => "Equipenmitglied", + "block" => "Block", + "order_name" => "Beobachtungsauftrag", "participant" => "TN", "participants" => "TN", - "block" => "Block", + "trainer" => "Equipenmitglied", + ), "participant" => array( "group" => "Abteilung", diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php index bf29aacb..f1d8ddb8 100755 --- a/resources/views/admin/observationOrders/index.blade.php +++ b/resources/views/admin/observationOrders/index.blade.php @@ -6,6 +6,7 @@ @component('components.form', ['route' => ['admin.observationOrders.store', ['course' => $course->id]]]) + Date: Sat, 5 Sep 2020 00:46:34 +0200 Subject: [PATCH 08/35] controller rules --- app/Http/Requests/ObservationOrderRequest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 app/Http/Requests/ObservationOrderRequest.php diff --git a/app/Http/Requests/ObservationOrderRequest.php b/app/Http/Requests/ObservationOrderRequest.php new file mode 100755 index 00000000..53b2ba09 --- /dev/null +++ b/app/Http/Requests/ObservationOrderRequest.php @@ -0,0 +1,34 @@ + 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', + 'group_name' => 'required|max:1023' + ]; + } + + + public function attributes() { + return Lang::get('t.models.participant_group'); + } +} From ff3d4427346fbda5aad683cb31ea6a0c38ecdc9b Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Sat, 5 Sep 2020 02:20:31 +0200 Subject: [PATCH 09/35] rechanged models but still not working --- .../ObservationOrderController.php | 23 ++++++++-- app/Http/Requests/ObservationOrderRequest.php | 11 +++-- app/Models/ObservationOrder.php | 23 +++++++--- ...193813_create_observation_order_blocks.php | 42 +++++++++++++++++ ...93813_create_observation_order_details.php | 45 ------------------- ..._193818_create_observation_order_users.php | 42 +++++++++++++++++ ..._create_observation_order_participants.php | 42 +++++++++++++++++ resources/lang/de/t.php | 2 +- .../admin/observationOrders/index.blade.php | 5 ++- 9 files changed, 172 insertions(+), 63 deletions(-) create mode 100755 database/migrations/2020_09_04_193813_create_observation_order_blocks.php delete mode 100755 database/migrations/2020_09_04_193813_create_observation_order_details.php create mode 100755 database/migrations/2020_09_04_193818_create_observation_order_users.php create mode 100755 database/migrations/2020_09_04_193823_create_observation_order_participants.php diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index f6f481b7..b68007a4 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -4,6 +4,7 @@ use App\Models\Course; use App\Models\ObservationOrder; +use App\Http\Requests\ObservationOrderRequest; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Redirect; @@ -26,12 +27,26 @@ public function index() /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @param ObservationOrderRequest $request + * @param Course $course + + * @return RedirectResponse */ - public function store(Request $request) + public function store(ObservationOrderRequest $request, Course $course) { - // + $data = $request->validated(); + + $completeData = (array_merge($data, ['course_id' => $course->id])); + DB::transaction(function() use ($request, $completeData, $data){ + + $observationOrder = ObservationOrder::create($completeData); + dd($observationOrder); + + $request->session()->flash('alert-success', __('t.views.admin.observation_orders.create_success')); + }); + + return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + } diff --git a/app/Http/Requests/ObservationOrderRequest.php b/app/Http/Requests/ObservationOrderRequest.php index 53b2ba09..22c8d394 100755 --- a/app/Http/Requests/ObservationOrderRequest.php +++ b/app/Http/Requests/ObservationOrderRequest.php @@ -4,8 +4,10 @@ use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Lang; +use App\Models\Trainer; -class ParticipantGroupRequest extends FormRequest { + +class ObservationOrderRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * @@ -22,13 +24,14 @@ public function authorize() { */ public function rules() { return [ + 'order_name' => 'required|max:1023', + 'block' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', 'participants' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', - 'group_name' => 'required|max:1023' - ]; + 'user' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse:' . Trainer::class . ',user_id' ]; } public function attributes() { - return Lang::get('t.models.participant_group'); + return Lang::get('t.models.observation_order'); } } diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationOrder.php index 6d8a0e26..4f4560d6 100644 --- a/app/Models/ObservationOrder.php +++ b/app/Models/ObservationOrder.php @@ -2,13 +2,22 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; + class ObservationOrder extends Model { + /** + * The table associated with the model. + * + * @var string + */ protected $table = 'observation_orders'; - protected $fillable = ['order_name']; + + /** + * @var array + */ + protected $fillable = ['order_name, course_id']; /** @@ -16,22 +25,22 @@ class ObservationOrder extends Model */ public function block() { - return $this->belongsTo('App\Models\Block'); + return $this->belongsTo('App\Models\Block', 'fk_block_observation_order_block'); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function participant() + public function participants() { - return $this->belongsTo('App\Models\Participant'); + return $this->belongsTo('App\Models\Participant', 'fk_participant_observation_order_participant'); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function user() + public function users() { - return $this->belongsTo('App\Models\User'); + return $this->belongsTo('App\Models\User', 'fk_user_observation_order_user'); } } diff --git a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php new file mode 100755 index 00000000..c42315cf --- /dev/null +++ b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php @@ -0,0 +1,42 @@ +integer('order_id')->nullable(false); + $table->integer('block_id')->nullable(false); + }); + + Schema::table('observation_order_blocks', function (Blueprint $table) { + $table->foreign('order_id', 'fk_order_observation_order_block')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('block_id', 'fk_block_observation_order_block')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_order_blocks', function(Blueprint $table) + { + $table->dropForeign('fk_block_observation_order_block'); + $table->dropForeign('fk_order_observation_order_block'); + }); + Schema::dropIfExists('observation_order_blocks'); + } +} diff --git a/database/migrations/2020_09_04_193813_create_observation_order_details.php b/database/migrations/2020_09_04_193813_create_observation_order_details.php deleted file mode 100755 index 4aecb983..00000000 --- a/database/migrations/2020_09_04_193813_create_observation_order_details.php +++ /dev/null @@ -1,45 +0,0 @@ -integer('user_id')->nullable(false); - $table->integer('block_id')->nullable(false); - $table->integer('participant_id')->nullable(false); - }); - - Schema::table('observation_order_details', function (Blueprint $table) { - $table->foreign('user_id', 'fk_user_observation_order_details')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('block_id', 'fk_block_observation_order_details')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('participant_id', 'fk_participants_observation_order_details')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('observation_order_details', function(Blueprint $table) - { - $table->dropForeign('fk_user_observation_order_details'); - $table->dropForeign('fk_block_observation_order_details'); - $table->dropForeign('fk_participants_observation_order_details'); - }); - Schema::dropIfExists('observation_order_details'); - } -} diff --git a/database/migrations/2020_09_04_193818_create_observation_order_users.php b/database/migrations/2020_09_04_193818_create_observation_order_users.php new file mode 100755 index 00000000..2318a821 --- /dev/null +++ b/database/migrations/2020_09_04_193818_create_observation_order_users.php @@ -0,0 +1,42 @@ +integer('order_id')->nullable(false); + $table->integer('user_id')->nullable(false); + }); + + Schema::table('observation_order_users', function (Blueprint $table) { + $table->foreign('order_id', 'fk_order_observation_order_user')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('user_id', 'fk_user_observation_order_user')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_order_users', function(Blueprint $table) + { + $table->dropForeign('fk_user_observation_order_user'); + $table->dropForeign('fk_order_observation_order_user'); + }); + Schema::dropIfExists('observation_order_users'); + } +} diff --git a/database/migrations/2020_09_04_193823_create_observation_order_participants.php b/database/migrations/2020_09_04_193823_create_observation_order_participants.php new file mode 100755 index 00000000..c938333a --- /dev/null +++ b/database/migrations/2020_09_04_193823_create_observation_order_participants.php @@ -0,0 +1,42 @@ +integer('order_id')->nullable(false); + $table->integer('participant_id')->nullable(false); + }); + + Schema::table('observation_order_participants', function (Blueprint $table) { + $table->foreign('order_id', 'fk_order_observation_order_participant')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('participant_id', 'fk_participant_observation_order_participant')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_order_participants', function(Blueprint $table) + { + $table->dropForeign('fk_participant_observation_order_participant'); + $table->dropForeign('fk_order_observation_order_participant'); + }); + Schema::dropIfExists('observation_order_participants'); + } +} diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index b2ae1cc4..066905b3 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -98,7 +98,7 @@ "order_name" => "Beobachtungsauftrag", "participant" => "TN", "participants" => "TN", - "trainer" => "Equipenmitglied", + "user" => "Equipenmitglied", ), "participant" => array( diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php index f1d8ddb8..228530c2 100755 --- a/resources/views/admin/observationOrders/index.blade.php +++ b/resources/views/admin/observationOrders/index.blade.php @@ -6,11 +6,11 @@ @component('components.form', ['route' => ['admin.observationOrders.store', ['course' => $course->id]]]) - + From 6aca8742ecfe5a1ee380c4c79147087aaf6d2d5c Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Tue, 15 Sep 2020 11:36:44 +0200 Subject: [PATCH 10/35] navigation linking --- resources/views/includes/header.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/includes/header.blade.php b/resources/views/includes/header.blade.php index 0fcc7b85..c92cbb46 100644 --- a/resources/views/includes/header.blade.php +++ b/resources/views/includes/header.blade.php @@ -58,6 +58,8 @@ @if(!$course->archived) {{__('t.views.admin.participant_groups.menu_name')}} + {{__('t.views.admin.observation_orders.menu_name')}} @endif {{__('t.views.admin.qualis.menu_name')}} From 35fcacdb375ad14d9a027a4f1bdebc38dd769676 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Tue, 15 Sep 2020 12:14:22 +0200 Subject: [PATCH 11/35] fix column naming, create orders --- .../Controllers/ObservationOrderController.php | 10 ++++++---- app/Models/ObservationOrder.php | 16 ++++++++-------- ...04_193813_create_observation_order_blocks.php | 4 ++-- ..._04_193818_create_observation_order_users.php | 4 ++-- ...823_create_observation_order_participants.php | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index b68007a4..ec01d50c 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -36,11 +36,13 @@ public function store(ObservationOrderRequest $request, Course $course) { $data = $request->validated(); - $completeData = (array_merge($data, ['course_id' => $course->id])); - DB::transaction(function() use ($request, $completeData, $data){ + DB::transaction(function() use ($request,$course, $data){ - $observationOrder = ObservationOrder::create($completeData); - dd($observationOrder); + $observationOrder = ObservationOrder::create(array_merge($data, ['course_id' => $course->id])); + + $observationOrder->participants()->attach(array_filter(explode(',', $data['participants']))); + $observationOrder->blocks()->attach(array_filter(explode(',', $data['block']))); + $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); $request->session()->flash('alert-success', __('t.views.admin.observation_orders.create_success')); }); diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationOrder.php index 4f4560d6..a6a9eb49 100644 --- a/app/Models/ObservationOrder.php +++ b/app/Models/ObservationOrder.php @@ -17,30 +17,30 @@ class ObservationOrder extends Model /** * @var array */ - protected $fillable = ['order_name, course_id']; + protected $fillable = ['order_name', 'course_id']; /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function block() + public function blocks() { - return $this->belongsTo('App\Models\Block', 'fk_block_observation_order_block'); + return $this->belongsToMany('App\Models\Block', 'observation_order_blocks'); } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function participants() { - return $this->belongsTo('App\Models\Participant', 'fk_participant_observation_order_participant'); + return $this->belongsToMany('App\Models\Participant', 'observation_order_participants'); } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function users() { - return $this->belongsTo('App\Models\User', 'fk_user_observation_order_user'); + return $this->belongsToMany('App\Models\User', 'observation_order_users'); } } diff --git a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php index c42315cf..f2e0fba4 100755 --- a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php +++ b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php @@ -14,12 +14,12 @@ class CreateObservationOrderBlocks extends Migration public function up() { Schema::create('observation_order_blocks', function (Blueprint $table) { - $table->integer('order_id')->nullable(false); + $table->integer('observation_order_id')->nullable(false); $table->integer('block_id')->nullable(false); }); Schema::table('observation_order_blocks', function (Blueprint $table) { - $table->foreign('order_id', 'fk_order_observation_order_block')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('observation_order_id', 'fk_order_observation_order_block')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); $table->foreign('block_id', 'fk_block_observation_order_block')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); }); diff --git a/database/migrations/2020_09_04_193818_create_observation_order_users.php b/database/migrations/2020_09_04_193818_create_observation_order_users.php index 2318a821..9b44ba26 100755 --- a/database/migrations/2020_09_04_193818_create_observation_order_users.php +++ b/database/migrations/2020_09_04_193818_create_observation_order_users.php @@ -14,12 +14,12 @@ class CreateObservationOrderUsers extends Migration public function up() { Schema::create('observation_order_users', function (Blueprint $table) { - $table->integer('order_id')->nullable(false); + $table->integer('observation_order_id')->nullable(false); $table->integer('user_id')->nullable(false); }); Schema::table('observation_order_users', function (Blueprint $table) { - $table->foreign('order_id', 'fk_order_observation_order_user')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('observation_order_id', 'fk_order_observation_order_user')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); $table->foreign('user_id', 'fk_user_observation_order_user')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); }); diff --git a/database/migrations/2020_09_04_193823_create_observation_order_participants.php b/database/migrations/2020_09_04_193823_create_observation_order_participants.php index c938333a..3cb4cd9c 100755 --- a/database/migrations/2020_09_04_193823_create_observation_order_participants.php +++ b/database/migrations/2020_09_04_193823_create_observation_order_participants.php @@ -14,12 +14,12 @@ class CreateObservationOrderparticipants extends Migration public function up() { Schema::create('observation_order_participants', function (Blueprint $table) { - $table->integer('order_id')->nullable(false); + $table->integer('observation_order_id')->nullable(false); $table->integer('participant_id')->nullable(false); }); Schema::table('observation_order_participants', function (Blueprint $table) { - $table->foreign('order_id', 'fk_order_observation_order_participant')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('observation_order_id', 'fk_order_observation_order_participant')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); $table->foreign('participant_id', 'fk_participant_observation_order_participant')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); }); From beae5f91be08589b31ad569f1062e75a52187d56 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Tue, 15 Sep 2020 13:07:58 +0200 Subject: [PATCH 12/35] overwiev and create observation_group --- app/Models/Course.php | 7 ++++ resources/lang/de/t.php | 6 +-- .../admin/observationOrders/index.blade.php | 41 +++++++++++++------ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/app/Models/Course.php b/app/Models/Course.php index 9e0c7264..1af95bc2 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -60,6 +60,13 @@ public function participantGroups() { return $this->hasMany('App\Models\ParticipantGroup', 'course_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function observationOrders() + { + return $this->hasMany('App\Models\ObservationOrder', 'course_id'); + } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 066905b3..ff44cfd5 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -98,7 +98,7 @@ "order_name" => "Beobachtungsauftrag", "participant" => "TN", "participants" => "TN", - "user" => "Equipenmitglied", + "user" => "Equipe", ), "participant" => array( @@ -240,7 +240,7 @@ ), "observation_orders" => array( "are_observation_orders_required" => array( - "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-') Prozess", + "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-') Prozess.", "question" => "Muss ich Beobachtungsaufträge für meinen Kurs erfassen?", ), "create_success" => "Beobachtungsauftrag wurde erfolgreich erstellt.", @@ -250,7 +250,7 @@ "existing" => "Beobachtungsaufträge :courseName", "menu_name" => "Beobachtungsaufträge", "new" => "Neuer Beobachtungsauftrag", - "no_participant_group" => "Bisher sind keine Beobachtungsaufträge erfasst.", + "no_observation_order" => "Bisher sind keine Beobachtungsaufträge erfasst.", "really_delete" => "Willst du den Beobachtungsauftrag wirklich löschen?", "what_are_observation_orders" => array( "answer" => "Viele Equipen definieren, wer wann wen beobachten sollte. Diese Aufträge könnt ihr hier definieren und seht diese (und ob sie schon erfüllt sind) z.Bsp. beim Spick.", diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php index 228530c2..a8658b47 100755 --- a/resources/views/admin/observationOrders/index.blade.php +++ b/resources/views/admin/observationOrders/index.blade.php @@ -54,31 +54,46 @@ - - - @if (count($course->participantGroups)) + + @if (count($course->observationOrders)) @php $fields = [ - __('t.models.participant_group.group_name') => function(\App\Models\ParticipantGroup $participantGroup) { return $participantGroup->group_name; }, - __('t.models.participant_group.participants') => function(\App\Models\ParticipantGroup $participantGroup) { - return $participantGroup->participants->map(function ($item){ + __('t.models.observation_order.order_name') => function(\App\Models\ObservationOrder $observationOrder) { return $observationOrder->order_name; }, + __('t.models.observation_order.user') => function(\App\Models\ObservationOrder $observationOrder) { + return $observationOrder->users->map(function ($item){ return $item['name']; + })->implode(', '); + + }, + __('t.models.observation_order.participants') => function(\App\Models\ObservationOrder $observationOrder) { + return $observationOrder->participants->map(function ($item){ $scout_name = $item['scout_name']; $group = $item['group']; return $group ? "$scout_name ($group)" : $scout_name; })->implode(', '); + + }, + __('t.models.observation_order.block') => function(\App\Models\ObservationOrder $observationOrder) { + return $observationOrder->blocks->map(function ($item){ + $block_name = $item['name']; + $block_number = $item['block_number']; + $day_number = $item['day_number']; + $number = "$day_number.$block_number"; + return $number ? "($number) $block_name" : $block_name; + })->implode(', '); + }, ]; @endphp @component('components.responsive-table', [ - 'data' => $course->participantGroups, + 'data' => $course->observationOrders, 'fields' => $fields, 'actions' => [ - 'edit' => function(\App\Models\ParticipantGroup $participantGroup) use ($course) { return route('admin.participantGroups.edit', ['course' => $course->id, 'participantGroup' => $participantGroup->id]); }, - 'delete' => function(\App\Models\ParticipantGroup $participantGroup) use ($course) { return [ - 'text' => __('t.views.admin.participant_groups.really_delete', [ 'name' => $participantGroup->group_name]), - 'route' => ['admin.participantGroups.destroy', ['course' => $course->id, 'participantGroup' => $participantGroup->id]], + 'edit' => function(\App\Models\ObservationOrder $observationOrder) use ($course) { return route('admin.observationOrders.edit', ['course' => $course->id, 'observationOrder' => $observationOrder->id]); }, + 'delete' => function(\App\Models\ObservationOrder $observationOrder) use ($course) { return [ + 'text' => __('t.views.admin.observation_orders.really_delete', [ 'name' => $observationOrder->order_name]), + 'route' => ['admin.observationOrders.destroy', ['course' => $course->id, 'observationOrder' => $observationOrder->id]], ];}, ] ])@endcomponent @@ -87,9 +102,9 @@ @else - {{__('t.views.admin.participant_groups.no_participant_group')}} + {{__('t.views.admin.observation_orders.no_observation_order')}} - @component('components.help-text', ['id' => 'noGroupsHelp', 'key' => 't.views.admin.participant_groups.are_participant_groups_required'])@endcomponent + @component('components.help-text', ['id' => 'noGroupsHelp', 'key' => 't.views.admin.observation_orders.are_observation_orders_required'])@endcomponent @endif From 5d883dde64d258a52ec9180abaf6c498d54d42fd Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Tue, 15 Sep 2020 16:09:57 +0200 Subject: [PATCH 13/35] edit observation order view --- .../ObservationOrderController.php | 28 ++++++++++--- resources/lang/de/t.php | 2 +- .../admin/observationOrders/edit.blade.php | 40 +++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100755 resources/views/admin/observationOrders/edit.blade.php diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index ec01d50c..2ccf1bc3 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -54,11 +54,11 @@ public function store(ObservationOrderRequest $request, Course $course) /** * Show the form for editing the specified resource. - * + * @param Course $course * @param \App\Models\ObservationOrder $observationOrder * @return \Illuminate\Http\Response */ - public function edit(ObservationOrder $observationOrder) + public function edit(Course $course ,ObservationOrder $observationOrder) { return view('admin.observationOrders.edit', ['observationOrder' => $observationOrder]); } @@ -66,13 +66,29 @@ public function edit(ObservationOrder $observationOrder) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request + * + * @param ObservationOrderRequest $request + * @param Course $course * @param \App\Models\ObservationOrder $observationOrder - * @return \Illuminate\Http\Response + * @return RedirectResponse */ - public function update(Request $request, ObservationOrder $observationOrder) + public function update(ObservationOrderRequest $request, Course $course, ObservationOrder $observationOrder) { - // + DB::transaction(function () use ($request, $course, $observationOrder) { + $data = $request->validated(); + dd($observationOrder); + + $observationOrder->update($data); + $observationOrder->participants()->detach(null); + $observationOrder->participants()->attach(array_filter(explode(',', $data['participants']))); + $observationOrder->blocks()->detach(null); + $observationOrder->blocks()->attach(array_filter(explode(',', $data['block']))); + $observationOrder->users()->detach(null); + $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); + $request->session()->flash('alert-success', __('t.views.admin.observation_order.edit_success')); + }); + return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + } /** diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index ff44cfd5..42bbf6ef 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -94,7 +94,7 @@ "user" => "Beobachter", ), "observation_order" => array( - "block" => "Block", + "block" => "Blöcke", "order_name" => "Beobachtungsauftrag", "participant" => "TN", "participants" => "TN", diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationOrders/edit.blade.php new file mode 100755 index 00000000..4c732011 --- /dev/null +++ b/resources/views/admin/observationOrders/edit.blade.php @@ -0,0 +1,40 @@ +@extends('layouts.default') + +@section('content') + + + + + @component('components.form', ['route' => ['admin.observationOrders.update', ['course' => $course->id, 'observationOrder' => $observationOrder->id]]]) + + order_name) label="{{__('t.models.observation_order.order_name')}}" required autofocus> + + users->pluck('id')->join(',')) + label="{{__('t.models.observation_order.user')}}" + required + :options="{{ json_encode($course->users->map->only('id', 'name')) }}" + display-field="name" + multiple> + participants->pluck('id')->join(',')) + label="{{__('t.models.observation_order.participants')}}" + required + :options="{{ json_encode($course->participants->map->only('id', 'scout_name')) }}" + display-field="scout_name" + multiple> + blocks->pluck('id')->join(',')) + label="{{__('t.models.observation_order.block')}}" + required + :options="{{ json_encode($course->blocks->map->only('id', 'blockname_and_number')) }}" + display-field="blockname_and_number" + multiple> + + + + @endcomponent + + + +@endsection From aa33f2fe655386c6c4adcbc5d37e97ac04e15702 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Tue, 15 Sep 2020 17:10:44 +0200 Subject: [PATCH 14/35] edit and save observation order finished --- app/Http/Controllers/ObservationOrderController.php | 3 +-- resources/lang/de/t.php | 2 +- resources/views/admin/observationOrders/edit.blade.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index 2ccf1bc3..e1da9ebd 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -76,7 +76,6 @@ public function update(ObservationOrderRequest $request, Course $course, Observa { DB::transaction(function () use ($request, $course, $observationOrder) { $data = $request->validated(); - dd($observationOrder); $observationOrder->update($data); $observationOrder->participants()->detach(null); @@ -85,7 +84,7 @@ public function update(ObservationOrderRequest $request, Course $course, Observa $observationOrder->blocks()->attach(array_filter(explode(',', $data['block']))); $observationOrder->users()->detach(null); $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); - $request->session()->flash('alert-success', __('t.views.admin.observation_order.edit_success')); + $request->session()->flash('alert-success', __('t.views.admin.observation_orders.edit_success')); }); return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 42bbf6ef..2e2a38d6 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -246,7 +246,7 @@ "create_success" => "Beobachtungsauftrag wurde erfolgreich erstellt.", "delete_success" => "Beobachtungsauftrag wurde erfolgreich gelöscht.", "edit" => "Beobachtungsauftrag bearbeiten", - "edit_success" => "Beobachtungsauftrag wurde erfolgreich gespeichert.", + "edit_success" => "Beobachtungsauftrag wurde erfolgreich geändert.", "existing" => "Beobachtungsaufträge :courseName", "menu_name" => "Beobachtungsaufträge", "new" => "Neuer Beobachtungsauftrag", diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationOrders/edit.blade.php index 4c732011..0aae7236 100755 --- a/resources/views/admin/observationOrders/edit.blade.php +++ b/resources/views/admin/observationOrders/edit.blade.php @@ -24,7 +24,7 @@ display-field="scout_name" multiple> blocks->pluck('id')->join(',')) + @forminput('block', $observationOrder->blocks->pluck('id')->join(',')) label="{{__('t.models.observation_order.block')}}" required :options="{{ json_encode($course->blocks->map->only('id', 'blockname_and_number')) }}" From 36f2b581efdc3746e520877b646c74223ccf00fb Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Wed, 23 Sep 2020 14:22:23 +0200 Subject: [PATCH 15/35] for cosinus, don't mind about test --- app/Models/Block.php | 62 +++- app/Models/Course.php | 1 + app/Models/User.php | 6 +- resources/views/crib.blade.php | 17 ++ .../CreateObservationOrderTest.php | 272 ++++++++++++++++++ 5 files changed, 352 insertions(+), 6 deletions(-) create mode 100755 tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php diff --git a/app/Models/Block.php b/app/Models/Block.php index 7eecf0ef..a39cd149 100644 --- a/app/Models/Block.php +++ b/app/Models/Block.php @@ -5,6 +5,7 @@ use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Database\Eloquent\Collection; +use PhpParser\Node\Expr\Cast\Object_; /** * @property int $id @@ -18,7 +19,7 @@ * @property Collection $requirement_ids * @property Course $course * @property Observation[] $observations - * @property ObservationOrder[] $obsersationOrders + * @property ObservationOrder[] $observationOrders * @property Collection $requirements * @property Collection $requirementIds * @property int $num_observations @@ -64,10 +65,63 @@ public function observations() { return $this->hasMany('App\Models\Observation'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function observationsOrders() { - return $this->hasMany('App\Models\ObservationOrder'); + public function observationOrders() { + return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_blocks')->with('users', 'participants'); + } + + public function observationOrdersUser(){ + $block = $this; + return $this->course->users()->mapWithKeys(function (User $user) use($block) { + return [ $user->id => + $user->observationOrders()->whereIn('id', $block->observationOrders()->pluck('id'))->get()->participants + ]; + }); + + $obj = $this->observationOrders->map( + function ($order){ + return (object) $order->users->pluck('id', 'name'); + })->collapse(); + $trainers= ""; + $users = $this->observationOrders->map( + function ($observationOrder){ + $users = array(); + foreach ($observationOrder->users as $user){ + $users[]= ['id' => $user->id]; + } + return $users; + + })->collapse()->unique(); + + $obj = $this->observationOrders->map( + function ( $observationOrder){ + $users = array(); + foreach ($observationOrder->users as $user){ + $users[]= ['id' => $user->id, 'name' => $user->name, 'participants' => $observationOrder->participants->pluck('id')]; + } + return $users; + /* + $test = ['id' => $observationOrder->users->pluck('id'), 'name' =>$observationOrder->users->pluck('name') + ]; + return $test; + */ + + })->collapse(); + + + + + + return $this->observationOrders; + //$trainers = array_unique (array_merge ($array1, $array2)); + + } + public function observationOrdersperUser(){ + $user = $this->observationOrdersUser(); + + + return $user; } /** diff --git a/app/Models/Course.php b/app/Models/Course.php index 1af95bc2..6189552c 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -68,6 +68,7 @@ public function observationOrders() return $this->hasMany('App\Models\ObservationOrder', 'course_id'); } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/User.php b/app/Models/User.php index fb3bfb54..53d984bf 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -71,13 +71,14 @@ public function observations() } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function observationOrders() { - return $this->hasMany('App\Models\ObservationOrder'); + return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_users'); } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -129,4 +130,5 @@ public function getLastUsedBlockDate(Course $course) { public function setLastUsedBlockDate($value, Course $course) { $this->courses()->updateExistingPivot($course->id, ['last_used_block_date' => Carbon::parse($value)]); } + } diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index d9d06015..ffe093c5 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -12,6 +12,11 @@ foreach($course->blocks as $block) { $days[$block->block_date->timestamp][] = $block; } + + /* + use this to change the crib for other trainers + */ + $trainerId = Auth::id(); @endphp @foreach($days as $day) @@ -41,6 +46,18 @@ {{$requirement->content}} @endforeach @endif + + {{"----------"}} + {{$block->observationOrdersPerUser()}} + {{"----------"}} + + @foreach($block->observationOrders as $orders) + @if(in_array($trainerId, [$orders->users->pluck('id')->join(',')])) + {{$orders->participants->pluck('id', 'scout_name')}} + @endif + @endforeach + + @endforeach diff --git a/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php b/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php new file mode 100755 index 00000000..3acecd73 --- /dev/null +++ b/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php @@ -0,0 +1,272 @@ +participantId = $this->createParticipant('Pflock'); + $this->blockId = $this->createBlock('Einstieg', '1.1'); + $this->userId = $this->createUser('') + $this->payload = ['group_name' => 'Unternehmungsgruppe 1', 'participants' => '' . $this->participantId]; + } + + public function test_shouldRequireLogin() + { + // given + auth()->logout(); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/login'); + } + + public function test_shouldRequireNonArchivedCourse() + { + // given + Course::find($this->courseId)->update(['archived' => true]); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect(route('admin.course', ['course' => $this->courseId])); + } + + public function test_shouldCreateAndDisplayParticipantGroup() + { + // given + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/participantGroups'); + /** @var TestResponse $response */ + $response = $response->followRedirects(); + $response->assertSee('Teilnehmergruppe wurde erfolgreich erstellt.'); + } + + public function test_shouldValidateNewParticipantGroup_noParticipantIds() + { + // given + $payload = $this->payload; + unset($payload['participants']); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Teilnehmer muss ausgefüllt sein.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewParticipantGroup_invalidParticipantIds() + { + // given + $payload = $this->payload; + $payload['participants'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Teilnehmer Format ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewParticipantGroup_oneValidParticipantId() + { + // given + $payload = $this->payload; + $participantId = $this->createParticipant(); + $payload['participants'] = $participantId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/participantGroups'); + $this->assertEquals([$participantId], ParticipantGroup::latest()->first()->participants->pluck('id')->all()); + } + + public function test_shouldValidateNewParticipantGroup_multipleValidParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/participantGroups'); + $this->assertEquals($participantIds, ParticipantGroup::latest()->first()->participants->pluck('id')->all()); + } + + public function test_shouldValidateNewParticipantGroup_someNonexistentParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), '999999', $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Teilnehmer ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewParticipantGroup_someInvalidParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), 'abc', $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Teilnehmer Format ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewParticipantGroup_multipleValidParticipantIds_shouldWork() + { + // given + $participantId2 = $this->createParticipant('Pfnörch'); + $participantIds = $this->participantId . ',' . $participantId2; + $payload = $this->payload; + $payload['participants'] = $participantIds; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/participantGroups'); + /** @var TestResponse $response */ + $response = $response->followRedirects(); + $response->assertSee('Teilnehmergruppe wurde erfolgreich erstellt.'); + } + + public function test_createParticipantGroupWitMultipleParticipantIds_shouldLinkTheParticipantGroup() + { + // given + $participantId2 = $this->createParticipant('Pfnörch'); + $participantIds = $this->participantId . ',' . $participantId2; + $payload = $this->payload; + $payload['participants'] = $participantIds; + $payload['group_name'] = 'visible on both participants'; + + // when + $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $response = $this->get('/course/' . $this->courseId . '/participants/' . $this->participantId); + $response->assertSee('visible on both participants'); + $response = $this->get('/course/' . $this->courseId . '/participants/' . $participantId2); + $response->assertSee('visible on both participants'); + } + + public function test_shouldValidateNewParticipantGroup_noGroupName() + { + // given + $payload = $this->payload; + unset($payload['group_name']); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Gruppe muss ausgefüllt sein.', $exception->validator->errors()->first('group_name')); + } + + public function test_shouldValidateNewParticipantGroup_longContent() + { + // given + $payload = $this->payload; + $payload['group_name'] = 'Unglaublich langer Gruppenname. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr.'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Gruppe darf maximal 1023 Zeichen haben.', $exception->validator->errors()->first('group_name')); + } + + + public function test_shouldShowEscapedNotice_afterCreatingParticipantGroup() + { + // given + $participantName = 'Participant name with \'some" formatting'; + $payload = $this->payload; + $payload['participants'] = $this->createParticipant($participantName); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload)->followRedirects(); + + // then + $response->assertDontSee($participantName, false); + $response->assertSee(htmlspecialchars($participantName, ENT_QUOTES), false); + } + + public function test_shouldNotAllowCreatingParticipantGroup_withParticipantFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $participantFromDifferentCourse = $this->createParticipant('Foreign', $differentCourse); + $payload = $this->payload; + $payload['participants'] = $this->participantId . ',' . $participantFromDifferentCourse; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Teilnehmer ist ungültig.', $exception->validator->errors()->first('participants')); + } + +} From e7278ff313eff4bbe53f65a768fa55163aee4d2a Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 25 Sep 2020 16:06:42 +0200 Subject: [PATCH 16/35] cosinus commit to peerfix --- app/Models/Block.php | 77 ++++++++++++++-------------------- app/Models/Course.php | 13 ++++++ resources/sass/app.scss | 6 +++ resources/views/crib.blade.php | 71 ++++++++++++++++++------------- 4 files changed, 94 insertions(+), 73 deletions(-) diff --git a/app/Models/Block.php b/app/Models/Block.php index a39cd149..b82f273a 100644 --- a/app/Models/Block.php +++ b/app/Models/Block.php @@ -65,63 +65,50 @@ public function observations() { return $this->hasMany('App\Models\Observation'); } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function observationOrders() { - return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_blocks')->with('users', 'participants'); - } + public function observationsWithParticipants(){ - public function observationOrdersUser(){ - $block = $this; - return $this->course->users()->mapWithKeys(function (User $user) use($block) { - return [ $user->id => - $user->observationOrders()->whereIn('id', $block->observationOrders()->pluck('id'))->get()->participants - ]; - }); + return $this->hasMany('App\Models\Observation')->with('participants'); - $obj = $this->observationOrders->map( - function ($order){ - return (object) $order->users->pluck('id', 'name'); - })->collapse(); - $trainers= ""; - $users = $this->observationOrders->map( - function ($observationOrder){ - $users = array(); - foreach ($observationOrder->users as $user){ - $users[]= ['id' => $user->id]; - } - return $users; - - })->collapse()->unique(); - - $obj = $this->observationOrders->map( - function ( $observationOrder){ - $users = array(); - foreach ($observationOrder->users as $user){ - $users[]= ['id' => $user->id, 'name' => $user->name, 'participants' => $observationOrder->participants->pluck('id')]; - } - return $users; - /* - $test = ['id' => $observationOrder->users->pluck('id'), 'name' =>$observationOrder->users->pluck('name') - ]; - return $test; - */ - - })->collapse(); + } + public function observationsMultipleParticipantsId(){ + return $this->hasMany('App\Models\Observation')->with('participants:id'); - return $this->observationOrders; - //$trainers = array_unique (array_merge ($array1, $array2)); + } + public function observationsMultipleParticipants(){ + return $this->observationsMultipleParticipantsId(); + foreach ($o as $obs){ + $obj=array_push($obs->participants->map(function ($o){ + return $o->pluck('id'); + })); + } + return $obj; + $obj->participants->map(function ($participant){return $participant->pluck('id');}); + } + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function observationOrders() { + return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_blocks')->with('users', 'participants'); } - public function observationOrdersperUser(){ - $user = $this->observationOrdersUser(); - return $user; + public function observationOrdersPerUser() { + return $this->course->participants()->select(['users.id as user_id', 'participants.*'])->distinct() + ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') + ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') + ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') + ->join('users', 'users.id', 'observation_order_users.user_id') + ->join('trainers', 'users.id', 'trainers.user_id') + ->mergeConstraintsFrom($this->course->users()->getQuery()) + ->where('observation_order_blocks.block_id', $this->id)->get() + ->groupBy('user_id'); } /** diff --git a/app/Models/Course.php b/app/Models/Course.php index 6189552c..9d9b00a7 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\DB; /** * @property int $id @@ -68,6 +69,18 @@ public function observationOrders() return $this->hasMany('App\Models\ObservationOrder', 'course_id'); } + public function observationOrdersPerUserAndPerBlock() { + return $this->participants()->select(['users.id as user_id', 'observation_order_blocks.block_id as block_id', DB::raw('COUNT(observations_participants.id) as observation_count'), 'participants.*'])->distinct() + ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') + ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') + ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') + ->join('users', 'users.id', 'observation_order_users.user_id') + ->join('trainers', 'users.id', 'trainers.user_id') + ->join('observations_participants', 'participants.id', 'observations_participants.participant_id') + ->mergeConstraintsFrom($this->users()->getQuery())->get() + ->groupBy('user_id') + ->map->groupBy('block_id'); + } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany diff --git a/resources/sass/app.scss b/resources/sass/app.scss index ff6af33b..24f6f62e 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -98,6 +98,12 @@ } } +.text-overflow-ellipsis{ + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + .bg-success-light { background-color: #d7f3e3; } diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index ffe093c5..01a2882d 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -14,7 +14,7 @@ } /* - use this to change the crib for other trainers + use $trainerId to change the crib for other trainers */ $trainerId = Auth::id(); @endphp @@ -30,33 +30,48 @@ archived || $day[0]->block_date->gt(\Carbon\Carbon::now()->subDays(2))) ? 'visible' : '' }}> @foreach ($day as $block) - - {{ $block->blockname_and_number }} - @if(count($block->mandatory_requirements)) -
- {{__('t.views.crib.mandatory_requirements')}}: - @foreach($block->mandatory_requirements as $requirement) - {{$requirement->content}} - @endforeach - @endif - @if(count($block->non_mandatory_requirements)) -
- {{__('t.views.crib.non_mandatory_requirements')}}: - @foreach($block->non_mandatory_requirements as $requirement) - {{$requirement->content}} - @endforeach - @endif - - {{"----------"}} - {{$block->observationOrdersPerUser()}} - {{"----------"}} - - @foreach($block->observationOrders as $orders) - @if(in_array($trainerId, [$orders->users->pluck('id')->join(',')])) - {{$orders->participants->pluck('id', 'scout_name')}} - @endif - @endforeach - + + + + {{ $block->blockname_and_number }} + @if(count($block->mandatory_requirements)) +
+ {{__('t.views.crib.mandatory_requirements')}}: + @foreach($block->mandatory_requirements as $requirement) + {{$requirement->content}} + @endforeach + @endif + @if(count($block->non_mandatory_requirements)) +
+ {{__('t.views.crib.non_mandatory_requirements')}}: + @foreach($block->non_mandatory_requirements as $requirement) + {{$requirement->content}} + @endforeach + @endif +
+ + @if($block->observationOrdersPerUser()[$trainerId]) +
+ @foreach($block->observationOrdersPerUser()[$trainerId] as $participant) + + @endforeach + {{$course->observationOrdersPerUserAndPerBlock()}} +
+ @endif +
+ +
From 5dbd53bf7036c34bb4948bf92d2abe06d6de8931 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 25 Sep 2020 16:33:43 +0200 Subject: [PATCH 17/35] fix blocknumber bug in observationassignment table --- resources/views/admin/observationOrders/edit.blade.php | 4 ++++ resources/views/admin/observationOrders/index.blade.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationOrders/edit.blade.php index 0aae7236..60bd4711 100755 --- a/resources/views/admin/observationOrders/edit.blade.php +++ b/resources/views/admin/observationOrders/edit.blade.php @@ -21,6 +21,10 @@ label="{{__('t.models.observation_order.participants')}}" required :options="{{ json_encode($course->participants->map->only('id', 'scout_name')) }}" + :groups="{{json_encode( + $course->participantGroups->mapWithKeys(function ($group) { + return [$group['group_name'] => $group->participants->pluck('id')->join(',')]; + }))}}" display-field="scout_name" multiple>
implode(', '); }, From 1646c0241c9830aceb08605dbca0fe70c7853e75 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 25 Sep 2020 17:27:41 +0200 Subject: [PATCH 18/35] base on course --- app/Models/Course.php | 43 +++++++++++++++++++++++++--------- resources/views/crib.blade.php | 7 +++--- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/Models/Course.php b/app/Models/Course.php index 9d9b00a7..6e48ebc7 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; @@ -26,6 +27,8 @@ class Course extends Model { * @var array */ protected $fillable = ['name', 'course_number', 'archived']; + protected $observationAssignments; + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany @@ -70,18 +73,36 @@ public function observationOrders() } public function observationOrdersPerUserAndPerBlock() { - return $this->participants()->select(['users.id as user_id', 'observation_order_blocks.block_id as block_id', DB::raw('COUNT(observations_participants.id) as observation_count'), 'participants.*'])->distinct() - ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') - ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') - ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') - ->join('users', 'users.id', 'observation_order_users.user_id') - ->join('trainers', 'users.id', 'trainers.user_id') - ->join('observations_participants', 'participants.id', 'observations_participants.participant_id') - ->mergeConstraintsFrom($this->users()->getQuery())->get() - ->groupBy('user_id') - ->map->groupBy('block_id'); - } + if (!$this->observationAssignments) { + $query = $this->participants()->select([ + 'users.id as user_id', + 'observation_order_blocks.block_id as block_id', + DB::raw('COUNT(observations_participants.observation_id) as observation_count'), + 'participants.id as participant_id' + ])->distinct() + ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') + ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') + ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') + ->join('users', 'users.id', 'observation_order_users.user_id') + ->join('trainers', 'users.id', 'trainers.user_id') + ->leftJoin('observations_participants', 'participants.id', 'observations_participants.participant_id') + ->mergeConstraintsFrom($this->users()->getQuery()) + ->groupBy('user_id', 'block_id', 'participants.id'); + $this->observationAssignments = $this->participants()->select([ + 'query.user_id as user_id', + 'query.block_id as block_id', + 'query.observation_count as observation_count', + 'participants.*' + ])->joinSub($query, 'query', function (JoinClause $join) { + $join->on('participants.id', 'query.participant_id'); + })->get() + ->groupBy('user_id') + ->map->groupBy('block_id'); + } + + return $this->observationAssignments; + } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index 01a2882d..09f3d1da 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -17,6 +17,7 @@ use $trainerId to change the crib for other trainers */ $trainerId = Auth::id(); + $trainerObservationOrders = $course->observationOrdersPerUserAndPerBlock()[$trainerId]; @endphp @foreach($days as $day) @@ -50,9 +51,9 @@ @endif - @if($block->observationOrdersPerUser()[$trainerId]) + @if($trainerObservationOrders[$block->id])
- @foreach($block->observationOrdersPerUser()[$trainerId] as $participant) + @foreach($trainerObservationOrders[$block->id] as $participant)
+ {{$participant->observation_count}} @endforeach - {{$course->observationOrdersPerUserAndPerBlock()}}
@endif From 92db07c25283e8d828199564c8e75b06049fe4df Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Fri, 25 Sep 2020 17:35:10 +0200 Subject: [PATCH 19/35] button success logic, but obs count wrong --- resources/views/crib.blade.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index 09f3d1da..a8a26a8d 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -18,6 +18,7 @@ */ $trainerId = Auth::id(); $trainerObservationOrders = $course->observationOrdersPerUserAndPerBlock()[$trainerId]; + $neededObs =1; @endphp @foreach($days as $day) @@ -59,7 +60,7 @@
{{ $participant->scout_name }}
-
{{$participant->scout_name }}
+
{{$participant->scout_name }}
From 05e6f7381723e1e01385f52a31aaa71ff15c53d9 Mon Sep 17 00:00:00 2001 From: Allan Benelli Date: Sat, 26 Sep 2020 19:06:14 +0200 Subject: [PATCH 20/35] course model return view for crib --- .../Controllers/ObservationController.php | 2 ++ app/Models/Course.php | 22 ++++++++++++------- resources/views/crib.blade.php | 3 +-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ObservationController.php b/app/Http/Controllers/ObservationController.php index 330dd176..94f0d453 100644 --- a/app/Http/Controllers/ObservationController.php +++ b/app/Http/Controllers/ObservationController.php @@ -54,6 +54,8 @@ public function store(ObservationRequest $request, Course $course) { ->__('t.views.observations.back_to_participant', ['name' => $participant->scout_name]) ->s(' '); } + + $request->session()->flash('alert-success', $flash); }); diff --git a/app/Models/Course.php b/app/Models/Course.php index 6e48ebc7..80c8bb51 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -74,27 +74,33 @@ public function observationOrders() public function observationOrdersPerUserAndPerBlock() { if (!$this->observationAssignments) { - $query = $this->participants()->select([ + $observationAssignmentsQuery = ObservationOrder::select([ 'users.id as user_id', 'observation_order_blocks.block_id as block_id', - DB::raw('COUNT(observations_participants.observation_id) as observation_count'), + DB::raw('COUNT(DISTINCT observations.id) as observation_count'), 'participants.id as participant_id' ])->distinct() - ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') - ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') - ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') + ->join('observation_order_participants', 'observation_orders.id', 'observation_order_participants.observation_order_id') + ->join('observation_order_users', 'observation_orders.id', 'observation_order_users.observation_order_id') + ->join('observation_order_blocks', 'observation_orders.id', 'observation_order_blocks.observation_order_id') ->join('users', 'users.id', 'observation_order_users.user_id') - ->join('trainers', 'users.id', 'trainers.user_id') + ->join('participants', 'participants.id', 'observation_order_participants.participant_id') ->leftJoin('observations_participants', 'participants.id', 'observations_participants.participant_id') + ->leftJoin('observations', function($join) { + $join->on('observations.id', 'observations_participants.observation_id'); + $join->on('observations.block_id', 'observation_order_blocks.block_id'); + $join->on('observations.user_id', 'users.id'); + }) + ->join('trainers', 'users.id', 'trainers.course_id') ->mergeConstraintsFrom($this->users()->getQuery()) - ->groupBy('user_id', 'block_id', 'participants.id'); + ->groupBy('user_id', 'block_id', 'participant_id'); $this->observationAssignments = $this->participants()->select([ 'query.user_id as user_id', 'query.block_id as block_id', 'query.observation_count as observation_count', 'participants.*' - ])->joinSub($query, 'query', function (JoinClause $join) { + ])->joinSub($observationAssignmentsQuery, 'query', function ($join) { $join->on('participants.id', 'query.participant_id'); })->get() ->groupBy('user_id') diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index a8a26a8d..de6094b6 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -52,7 +52,7 @@ @endif - @if($trainerObservationOrders[$block->id]) + @if(isset($trainerObservationOrders[$block->id]))
@foreach($trainerObservationOrders[$block->id] as $participant)
@@ -67,7 +67,6 @@
- {{$participant->observation_count}} @endforeach
@endif From 13a43681ccb99fb776a30b4aca9e8d0131d3e577 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 08:44:39 +0200 Subject: [PATCH 21/35] Revert file permissions --- app/Http/Requests/ObservationOrderRequest.php | 0 .../2020_09_04_193813_create_observation_order_blocks.php | 0 .../2020_09_04_193818_create_observation_order_users.php | 0 .../2020_09_04_193823_create_observation_order_participants.php | 0 resources/views/admin/observationOrders/edit.blade.php | 0 resources/views/admin/observationOrders/index.blade.php | 0 .../Feature/Admin/ObservationOrder/CreateObservationOrderTest.php | 0 7 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 app/Http/Requests/ObservationOrderRequest.php mode change 100755 => 100644 database/migrations/2020_09_04_193813_create_observation_order_blocks.php mode change 100755 => 100644 database/migrations/2020_09_04_193818_create_observation_order_users.php mode change 100755 => 100644 database/migrations/2020_09_04_193823_create_observation_order_participants.php mode change 100755 => 100644 resources/views/admin/observationOrders/edit.blade.php mode change 100755 => 100644 resources/views/admin/observationOrders/index.blade.php mode change 100755 => 100644 tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php diff --git a/app/Http/Requests/ObservationOrderRequest.php b/app/Http/Requests/ObservationOrderRequest.php old mode 100755 new mode 100644 diff --git a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php old mode 100755 new mode 100644 diff --git a/database/migrations/2020_09_04_193818_create_observation_order_users.php b/database/migrations/2020_09_04_193818_create_observation_order_users.php old mode 100755 new mode 100644 diff --git a/database/migrations/2020_09_04_193823_create_observation_order_participants.php b/database/migrations/2020_09_04_193823_create_observation_order_participants.php old mode 100755 new mode 100644 diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationOrders/edit.blade.php old mode 100755 new mode 100644 diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php old mode 100755 new mode 100644 diff --git a/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php b/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php old mode 100755 new mode 100644 From e83ea1b662eb603e72cef1302a976af8ec3f0d1b Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 10:06:22 +0200 Subject: [PATCH 22/35] Get it running with the latest Vue components updates --- .../ObservationOrderController.php | 6 +- app/Models/Course.php | 2 +- app/Models/Participant.php | 6 +- resources/lang/de/t.php | 5 +- .../admin/observationOrders/edit.blade.php | 51 ++++---- .../admin/observationOrders/index.blade.php | 116 +++++++----------- .../admin/participantGroups/index.blade.php | 2 +- resources/views/crib.blade.php | 2 +- 8 files changed, 85 insertions(+), 105 deletions(-) diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php index e1da9ebd..664ab16f 100644 --- a/app/Http/Controllers/ObservationOrderController.php +++ b/app/Http/Controllers/ObservationOrderController.php @@ -20,7 +20,7 @@ class ObservationOrderController extends Controller */ public function index() { - return view('admin.observationOrders'); + return view('admin.observationOrders.index'); } @@ -47,7 +47,7 @@ public function store(ObservationOrderRequest $request, Course $course) $request->session()->flash('alert-success', __('t.views.admin.observation_orders.create_success')); }); - return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + return Redirect::route('admin.observationOrders', ['course' => $course->id]); } @@ -86,7 +86,7 @@ public function update(ObservationOrderRequest $request, Course $course, Observa $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); $request->session()->flash('alert-success', __('t.views.admin.observation_orders.edit_success')); }); - return Redirect::route('admin.observationOrders.index', ['course' => $course->id]); + return Redirect::route('admin.observationOrders', ['course' => $course->id]); } diff --git a/app/Models/Course.php b/app/Models/Course.php index 80c8bb51..64d28162 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -91,7 +91,7 @@ public function observationOrdersPerUserAndPerBlock() { $join->on('observations.block_id', 'observation_order_blocks.block_id'); $join->on('observations.user_id', 'users.id'); }) - ->join('trainers', 'users.id', 'trainers.course_id') + ->join('trainers', 'users.id', 'trainers.user_id') ->mergeConstraintsFrom($this->users()->getQuery()) ->groupBy('user_id', 'block_id', 'participant_id'); diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 2308e06e..02a1cda3 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -36,7 +36,7 @@ class Participant extends Model { * * @var array */ - protected $appends = ['num_observations', 'image_path']; + protected $appends = ['num_observations', 'image_path', 'name_and_group']; /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo @@ -94,6 +94,10 @@ public function getNegativeAttribute() { return $this->observations()->where('impression', '=', '0'); } + public function getNameAndGroupAttribute() { + return $this->group ? $this->scout_name . ' (' . $this->group . ')' : $this->scout_name; + } + /** * Get the number of observations grouped by the users that created the observation. * diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 2e2a38d6..71e5522c 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -99,7 +99,6 @@ "participant" => "TN", "participants" => "TN", "user" => "Equipe", - ), "participant" => array( "group" => "Abteilung", @@ -240,7 +239,7 @@ ), "observation_orders" => array( "are_observation_orders_required" => array( - "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-') Prozess.", + "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-) Prozess.", "question" => "Muss ich Beobachtungsaufträge für meinen Kurs erfassen?", ), "create_success" => "Beobachtungsauftrag wurde erfolgreich erstellt.", @@ -251,7 +250,7 @@ "menu_name" => "Beobachtungsaufträge", "new" => "Neuer Beobachtungsauftrag", "no_observation_order" => "Bisher sind keine Beobachtungsaufträge erfasst.", - "really_delete" => "Willst du den Beobachtungsauftrag wirklich löschen?", + "really_delete" => "Willst du den Beobachtungsauftrag \":order_name\" wirklich löschen?", "what_are_observation_orders" => array( "answer" => "Viele Equipen definieren, wer wann wen beobachten sollte. Diese Aufträge könnt ihr hier definieren und seht diese (und ob sie schon erfüllt sind) z.Bsp. beim Spick.", "question" => "Was sind Beobachtungsaufträge?", diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationOrders/edit.blade.php index 60bd4711..62769db1 100644 --- a/resources/views/admin/observationOrders/edit.blade.php +++ b/resources/views/admin/observationOrders/edit.blade.php @@ -5,39 +5,44 @@ - @component('components.form', ['route' => ['admin.observationOrders.update', ['course' => $course->id, 'observationOrder' => $observationOrder->id]]]) + - order_name) label="{{__('t.models.observation_order.order_name')}}" required autofocus> + users->pluck('id')->join(',')) - label="{{__('t.models.observation_order.user')}}" - required - :options="{{ json_encode($course->users->map->only('id', 'name')) }}" - display-field="name" - multiple> + name="user" + value="{{ $observationOrder->users->pluck('id')->join(',') }}" + label="{{__('t.models.observation_order.user')}}" + required + :options="{{ json_encode($course->users->map->only('id', 'name')) }}" + display-field="name" + multiple> + participants->pluck('id')->join(',')) - label="{{__('t.models.observation_order.participants')}}" - required - :options="{{ json_encode($course->participants->map->only('id', 'scout_name')) }}" - :groups="{{json_encode( + name="participants" + value="{{ $observationOrder->participants->pluck('id')->join(',') }}" + label="{{__('t.models.observation_order.participants')}}" + required + :options="{{ json_encode($course->participants->map->only('id', 'scout_name')) }}" + :groups="{{json_encode( $course->participantGroups->mapWithKeys(function ($group) { return [$group['group_name'] => $group->participants->pluck('id')->join(',')]; - }))}}" - display-field="scout_name" - multiple> + }), JSON_FORCE_OBJECT)}}" + display-field="scout_name" + multiple> + blocks->pluck('id')->join(',')) - label="{{__('t.models.observation_order.block')}}" - required - :options="{{ json_encode($course->blocks->map->only('id', 'blockname_and_number')) }}" - display-field="blockname_and_number" - multiple> + name="block" + value="{{ $observationOrder->blocks->pluck('id')->join(',') }}" + label="{{__('t.models.observation_order.block')}}" + required + :options="{{ json_encode($course->blocks->map->only('id', 'blockname_and_number')) }}" + display-field="blockname_and_number" + multiple> - @endcomponent + diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php index ba75aea8..1b68d27f 100644 --- a/resources/views/admin/observationOrders/index.blade.php +++ b/resources/views/admin/observationOrders/index.blade.php @@ -5,43 +5,41 @@ - @component('components.form', ['route' => ['admin.observationOrders.store', ['course' => $course->id]]]) - + + - - :groups="{{json_encode( + + }), JSON_FORCE_OBJECT)}}" + display-field="scout_name" + multiple + required + :autofocus="true"> + name="block" + label="{{__('t.models.observation_order.block')}}" + required + :options="{{ json_encode($course->blocks->map->only('id', 'blockname_and_number')) }}" + :autofocus="true" + display-field="blockname_and_number" + multiple + :autofocus="true" + > @@ -49,7 +47,7 @@ - @endcomponent + @@ -57,48 +55,22 @@ @if (count($course->observationOrders)) - @php - $fields = [ - __('t.models.observation_order.order_name') => function(\App\Models\ObservationOrder $observationOrder) { return $observationOrder->order_name; }, - __('t.models.observation_order.user') => function(\App\Models\ObservationOrder $observationOrder) { - return $observationOrder->users->map(function ($item){ return $item['name']; - })->implode(', '); - - }, - __('t.models.observation_order.participants') => function(\App\Models\ObservationOrder $observationOrder) { - return $observationOrder->participants->map(function ($item){ - $scout_name = $item['scout_name']; - $group = $item['group']; - return $group ? "$scout_name ($group)" : $scout_name; - })->implode(', '); - - }, - __('t.models.observation_order.block') => function(\App\Models\ObservationOrder $observationOrder) { - return $observationOrder->blocks->map(function ($item){ - $block_name = $item['name']; - $block_number = $item['block_number']; - $day_number = $item['day_number']; - $number = ($day_number && $block_number) ? "($day_number.$block_number) " : ""; - return $number.$block_name; - })->implode(', '); - - }, - ]; - - @endphp - @component('components.responsive-table', [ - 'data' => $course->observationOrders, - 'fields' => $fields, - 'actions' => [ - 'edit' => function(\App\Models\ObservationOrder $observationOrder) use ($course) { return route('admin.observationOrders.edit', ['course' => $course->id, 'observationOrder' => $observationOrder->id]); }, - 'delete' => function(\App\Models\ObservationOrder $observationOrder) use ($course) { return [ - 'text' => __('t.views.admin.observation_orders.really_delete', [ 'name' => $observationOrder->order_name]), - 'route' => ['admin.observationOrders.destroy', ['course' => $course->id, 'observationOrder' => $observationOrder->id]], - ];}, - ] - ])@endcomponent - + @else diff --git a/resources/views/admin/participantGroups/index.blade.php b/resources/views/admin/participantGroups/index.blade.php index 337f2188..cf4b89e0 100644 --- a/resources/views/admin/participantGroups/index.blade.php +++ b/resources/views/admin/participantGroups/index.blade.php @@ -37,7 +37,7 @@ :data="{{ json_encode($course->participantGroups) }}" :fields="[ { label: $t('t.models.participant_group.group_name'), value: participantGroup => participantGroup.group_name }, - { label: $t('t.models.participant_group.group_name'), value: participantGroup => participantGroup.participant_names }, + { label: $t('t.models.participant_group.participants'), value: participantGroup => participantGroup.participant_names }, ]" :actions="{ edit: participantGroup => routeUri('admin.participantGroups.edit', {course: {{ $course->id }}, participantGroup: participantGroup.id}), diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index de6094b6..7b2e2484 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -17,7 +17,7 @@ use $trainerId to change the crib for other trainers */ $trainerId = Auth::id(); - $trainerObservationOrders = $course->observationOrdersPerUserAndPerBlock()[$trainerId]; + $trainerObservationOrders = $course->observationOrdersPerUserAndPerBlock()[$trainerId] ?? []; $neededObs =1; @endphp From 4eeb83fbb2edc271a68649b97d0d8c30d49231d5 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 11:14:59 +0200 Subject: [PATCH 23/35] Make trainer perspective selectable on crib view --- app/Http/Controllers/BlockListController.php | 15 ++++++++++--- resources/js/components/FormBasic.vue | 9 +++++--- resources/lang/de/t.php | 1 + resources/sass/app.scss | 8 +++++++ resources/views/crib.blade.php | 22 ++++++++++++-------- routes/web.php | 2 +- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/BlockListController.php b/app/Http/Controllers/BlockListController.php index 3f30aa5f..0bba6a90 100644 --- a/app/Http/Controllers/BlockListController.php +++ b/app/Http/Controllers/BlockListController.php @@ -3,8 +3,10 @@ namespace App\Http\Controllers; use App\Models\Course; +use App\Models\User; use App\Util\HtmlString; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Auth; class BlockListController extends Controller { @@ -20,14 +22,21 @@ public function index(Course $course) } /** - * Display the crib page which visualizes connections between blocks and requirements. + * Display the crib page which visualizes connections between blocks and requirements, as well as observation assignments. * * @param Course $course + * @param User $user * @return Response */ - public function crib(Course $course) + public function crib(Course $course, User $user) { - return view('crib', ['blockManagementLink' => $this->blockManagementLink($course, 't.views.crib.here')]); + $userId = $user->id ?? Auth::id(); + return view('crib', [ + 'blockManagementLink' => $this->blockManagementLink($course, 't.views.crib.here'), + 'userId' => $userId, + 'trainerObservationOrders' => $course->observationOrdersPerUserAndPerBlock()[$userId] ?? [], + 'neededObservations' => 1, + ]); } /** diff --git a/resources/js/components/FormBasic.vue b/resources/js/components/FormBasic.vue index f8710526..271f3f4f 100644 --- a/resources/js/components/FormBasic.vue +++ b/resources/js/components/FormBasic.vue @@ -1,7 +1,7 @@ @@ -27,8 +27,11 @@ export default { method() { return this.routeMethod(...this.arrayAction) }, + methodIsNotGet() { + return this.method !== 'GET' + }, formMethod() { - return (this.method && this.method === 'GET') ? 'GET' : 'POST' + return this.methodIsNotGet ? 'POST' : 'GET' }, } } diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index 71e5522c..dfc55061 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -374,6 +374,7 @@ "question" => "Siehst du nur leere Blöcke ohne Anforderungen?", ), "title" => "Welche Anforderungen können in welchen Blöcken beobachtet werden", + "view_as" => "Aus Sicht von", ), "error_form" => array( "back" => "Zurück zu wo ich gerade noch war...", diff --git a/resources/sass/app.scss b/resources/sass/app.scss index 24f6f62e..ff5f3e01 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -112,6 +112,14 @@ background-color: #f9d6d5; } +.btn-outline-danger.bg-white:hover { + background-color: $danger !important; +} + +.btn-outline-success.bg-white:hover { + background-color: $success !important; +} + .hr-label { width: 100%; text-align: center; diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index 7b2e2484..ffbc0b0f 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -12,15 +12,20 @@ foreach($course->blocks as $block) { $days[$block->block_date->timestamp][] = $block; } - - /* - use $trainerId to change the crib for other trainers - */ - $trainerId = Auth::id(); - $trainerObservationOrders = $course->observationOrdersPerUserAndPerBlock()[$trainerId] ?? []; - $neededObs =1; @endphp +
+ + +
+ @foreach($days as $day) block_date->timestamp }}> @@ -60,8 +65,7 @@
{{ $participant->scout_name }}
-
{{$participant->scout_name }}
- + {{$participant->scout_name}}
diff --git a/routes/web.php b/routes/web.php index b5b1ac5e..2cf8889c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,7 +24,7 @@ Route::get('/course/{course}', 'HomeController@index')->name('index'); Route::get('/course/{course}/blocks', 'BlockListController@index')->name('blocks'); - Route::get('/course/{course}/crib', 'BlockListController@crib')->name('crib'); + Route::get('/course/{course}/crib/{user?}', 'BlockListController@crib')->name('crib'); Route::middleware('courseNotArchived')->group(function () { Route::get('/course/{course}/participants', 'ParticipantListController@index')->name('participants'); From 5cdff43342d96f7ee602c26f490c0e3f0afd0201 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 11:25:50 +0200 Subject: [PATCH 24/35] Rename observation orders to observation assignments --- app/Http/Controllers/BlockListController.php | 2 +- .../ObservationAssignmentController.php | 109 ++++++++++++++++++ .../ObservationOrderController.php | 109 ------------------ ...t.php => ObservationAssignmentRequest.php} | 6 +- app/Models/Block.php | 19 ++- app/Models/Course.php | 23 ++-- ...ionOrder.php => ObservationAssignment.php} | 10 +- app/Models/Participant.php | 4 +- app/Models/User.php | 4 +- ..._create_observation_assignments_table.php} | 14 +-- ...3_create_observation_assignment_blocks.php | 42 +++++++ ...193813_create_observation_order_blocks.php | 42 ------- ...18_create_observation_assignment_users.php | 42 +++++++ ..._193818_create_observation_order_users.php | 42 ------- ...te_observation_assignment_participants.php | 42 +++++++ ..._create_observation_order_participants.php | 42 ------- resources/lang/de/t.php | 10 +- .../edit.blade.php | 18 +-- .../observationAssignments/index.blade.php | 85 ++++++++++++++ .../admin/observationOrders/index.blade.php | 85 -------------- resources/views/crib.blade.php | 4 +- resources/views/includes/header.blade.php | 4 +- routes/web.php | 10 +- .../CreateObservationAssignmentTest.php} | 8 +- 24 files changed, 387 insertions(+), 389 deletions(-) create mode 100644 app/Http/Controllers/ObservationAssignmentController.php delete mode 100644 app/Http/Controllers/ObservationOrderController.php rename app/Http/Requests/{ObservationOrderRequest.php => ObservationAssignmentRequest.php} (87%) rename app/Models/{ObservationOrder.php => ObservationAssignment.php} (81%) rename database/migrations/{2020_09_04_145745_create_observation_orders_table.php => 2020_09_04_145745_create_observation_assignments_table.php} (57%) create mode 100644 database/migrations/2020_09_04_193813_create_observation_assignment_blocks.php delete mode 100644 database/migrations/2020_09_04_193813_create_observation_order_blocks.php create mode 100644 database/migrations/2020_09_04_193818_create_observation_assignment_users.php delete mode 100644 database/migrations/2020_09_04_193818_create_observation_order_users.php create mode 100644 database/migrations/2020_09_04_193823_create_observation_assignment_participants.php delete mode 100644 database/migrations/2020_09_04_193823_create_observation_order_participants.php rename resources/views/admin/{observationOrders => observationAssignments}/edit.blade.php (60%) create mode 100644 resources/views/admin/observationAssignments/index.blade.php delete mode 100644 resources/views/admin/observationOrders/index.blade.php rename tests/Feature/Admin/{ObservationOrder/CreateObservationOrderTest.php => ObservationAssignment/CreateObservationAssignmentTest.php} (98%) diff --git a/app/Http/Controllers/BlockListController.php b/app/Http/Controllers/BlockListController.php index 0bba6a90..7da3f497 100644 --- a/app/Http/Controllers/BlockListController.php +++ b/app/Http/Controllers/BlockListController.php @@ -34,7 +34,7 @@ public function crib(Course $course, User $user) return view('crib', [ 'blockManagementLink' => $this->blockManagementLink($course, 't.views.crib.here'), 'userId' => $userId, - 'trainerObservationOrders' => $course->observationOrdersPerUserAndPerBlock()[$userId] ?? [], + 'trainerObservationAssignments' => $course->observationAssignmentsPerUserAndPerBlock()[$userId] ?? [], 'neededObservations' => 1, ]); } diff --git a/app/Http/Controllers/ObservationAssignmentController.php b/app/Http/Controllers/ObservationAssignmentController.php new file mode 100644 index 00000000..dc25c6a4 --- /dev/null +++ b/app/Http/Controllers/ObservationAssignmentController.php @@ -0,0 +1,109 @@ +validated(); + + DB::transaction(function() use ($request,$course, $data){ + + $observationAssignment = ObservationAssignment::create(array_merge($data, ['course_id' => $course->id])); + + $observationAssignment->participants()->attach(array_filter(explode(',', $data['participants']))); + $observationAssignment->blocks()->attach(array_filter(explode(',', $data['block']))); + $observationAssignment->users()->attach(array_filter(explode(',', $data['user']))); + + $request->session()->flash('alert-success', __('t.views.admin.observation_assignments.create_success')); + }); + + return Redirect::route('admin.observationAssignments', ['course' => $course->id]); + + } + + + /** + * Show the form for editing the specified resource. + * @param Course $course + * @param \App\Models\ObservationAssignment $observationAssignment + * @return \Illuminate\Http\Response + */ + public function edit(Course $course ,ObservationAssignment $observationAssignment) + { + return view('admin.observationAssignments.edit', ['observationAssignment' => $observationAssignment]); + } + + /** + * Update the specified resource in storage. + * + * + * @param ObservationAssignmentRequest $request + * @param Course $course + * @param \App\Models\ObservationAssignment $observationAssignment + * @return RedirectResponse + */ + public function update(ObservationAssignmentRequest $request, Course $course, ObservationAssignment $observationAssignment) + { + DB::transaction(function () use ($request, $course, $observationAssignment) { + $data = $request->validated(); + + $observationAssignment->update($data); + $observationAssignment->participants()->detach(null); + $observationAssignment->participants()->attach(array_filter(explode(',', $data['participants']))); + $observationAssignment->blocks()->detach(null); + $observationAssignment->blocks()->attach(array_filter(explode(',', $data['block']))); + $observationAssignment->users()->detach(null); + $observationAssignment->users()->attach(array_filter(explode(',', $data['user']))); + $request->session()->flash('alert-success', __('t.views.admin.observation_assignments.edit_success')); + }); + return Redirect::route('admin.observationAssignments', ['course' => $course->id]); + + } + + /** + * Remove the specified resource from storage. + * + * @param Request $request + * @param Course $course + * @param ObservationAssignment $observationAssignment + * @return RedirectResponse + * + */ + public function destroy(Request $request, Course $course, ObservationAssignment $observationAssignment) + { + $observationAssignment->delete(); + $request->session()->flash('alert-success', __('t.views.admin.observation_assignments.delete_success')); + return Redirect::route('admin.observationAssignments', ['course' => $course->id]); + + } +} diff --git a/app/Http/Controllers/ObservationOrderController.php b/app/Http/Controllers/ObservationOrderController.php deleted file mode 100644 index 664ab16f..00000000 --- a/app/Http/Controllers/ObservationOrderController.php +++ /dev/null @@ -1,109 +0,0 @@ -validated(); - - DB::transaction(function() use ($request,$course, $data){ - - $observationOrder = ObservationOrder::create(array_merge($data, ['course_id' => $course->id])); - - $observationOrder->participants()->attach(array_filter(explode(',', $data['participants']))); - $observationOrder->blocks()->attach(array_filter(explode(',', $data['block']))); - $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); - - $request->session()->flash('alert-success', __('t.views.admin.observation_orders.create_success')); - }); - - return Redirect::route('admin.observationOrders', ['course' => $course->id]); - - } - - - /** - * Show the form for editing the specified resource. - * @param Course $course - * @param \App\Models\ObservationOrder $observationOrder - * @return \Illuminate\Http\Response - */ - public function edit(Course $course ,ObservationOrder $observationOrder) - { - return view('admin.observationOrders.edit', ['observationOrder' => $observationOrder]); - } - - /** - * Update the specified resource in storage. - * - * - * @param ObservationOrderRequest $request - * @param Course $course - * @param \App\Models\ObservationOrder $observationOrder - * @return RedirectResponse - */ - public function update(ObservationOrderRequest $request, Course $course, ObservationOrder $observationOrder) - { - DB::transaction(function () use ($request, $course, $observationOrder) { - $data = $request->validated(); - - $observationOrder->update($data); - $observationOrder->participants()->detach(null); - $observationOrder->participants()->attach(array_filter(explode(',', $data['participants']))); - $observationOrder->blocks()->detach(null); - $observationOrder->blocks()->attach(array_filter(explode(',', $data['block']))); - $observationOrder->users()->detach(null); - $observationOrder->users()->attach(array_filter(explode(',', $data['user']))); - $request->session()->flash('alert-success', __('t.views.admin.observation_orders.edit_success')); - }); - return Redirect::route('admin.observationOrders', ['course' => $course->id]); - - } - - /** - * Remove the specified resource from storage. - * - * @param Request $request - * @param Course $course - * @param ObservationOrder $observationOrder - * @return RedirectResponse - * - */ - public function destroy(Request $request, Course $course, ObservationOrder $observationOrder) - { - $observationOrder->delete(); - $request->session()->flash('alert-success', __('t.views.admin.observation_orders.delete_success')); - return Redirect::route('admin.observationOrders', ['course' => $course->id]); - - } -} diff --git a/app/Http/Requests/ObservationOrderRequest.php b/app/Http/Requests/ObservationAssignmentRequest.php similarity index 87% rename from app/Http/Requests/ObservationOrderRequest.php rename to app/Http/Requests/ObservationAssignmentRequest.php index 22c8d394..4385e328 100644 --- a/app/Http/Requests/ObservationOrderRequest.php +++ b/app/Http/Requests/ObservationAssignmentRequest.php @@ -2,12 +2,12 @@ namespace App\Http\Requests; +use App\Models\Trainer; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Lang; -use App\Models\Trainer; -class ObservationOrderRequest extends FormRequest { +class ObservationAssignmentRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * @@ -32,6 +32,6 @@ public function rules() { public function attributes() { - return Lang::get('t.models.observation_order'); + return Lang::get('t.models.observation_assignment'); } } diff --git a/app/Models/Block.php b/app/Models/Block.php index b82f273a..38eff96f 100644 --- a/app/Models/Block.php +++ b/app/Models/Block.php @@ -5,7 +5,6 @@ use Carbon\Carbon; use Carbon\CarbonInterface; use Illuminate\Database\Eloquent\Collection; -use PhpParser\Node\Expr\Cast\Object_; /** * @property int $id @@ -19,7 +18,7 @@ * @property Collection $requirement_ids * @property Course $course * @property Observation[] $observations - * @property ObservationOrder[] $observationOrders + * @property ObservationAssignment[] $observationAssignments * @property Collection $requirements * @property Collection $requirementIds * @property int $num_observations @@ -94,20 +93,20 @@ public function observationsMultipleParticipants(){ /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function observationOrders() { - return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_blocks')->with('users', 'participants'); + public function observationAssignments() { + return $this->belongsToMany('App\Models\ObservationAssignment', 'observation_assignment_blocks')->with('users', 'participants'); } - public function observationOrdersPerUser() { + public function observationAssignmentsPerUser() { return $this->course->participants()->select(['users.id as user_id', 'participants.*'])->distinct() - ->join('observation_order_participants', 'participants.id', 'observation_order_participants.participant_id') - ->join('observation_order_users', 'observation_order_participants.observation_order_id', 'observation_order_users.observation_order_id') - ->join('observation_order_blocks', 'observation_order_participants.observation_order_id', 'observation_order_blocks.observation_order_id') - ->join('users', 'users.id', 'observation_order_users.user_id') + ->join('observation_assignment_participants', 'participants.id', 'observation_assignment_participants.participant_id') + ->join('observation_assignment_users', 'observation_assignment_participants.observation_assignment_id', 'observation_assignment_users.observation_assignment_id') + ->join('observation_assignment_blocks', 'observation_assignment_participants.observation_assignment_id', 'observation_assignment_blocks.observation_assignment_id') + ->join('users', 'users.id', 'observation_assignment_users.user_id') ->join('trainers', 'users.id', 'trainers.user_id') ->mergeConstraintsFrom($this->course->users()->getQuery()) - ->where('observation_order_blocks.block_id', $this->id)->get() + ->where('observation_assignment_blocks.block_id', $this->id)->get() ->groupBy('user_id'); } diff --git a/app/Models/Course.php b/app/Models/Course.php index 64d28162..29b82429 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -2,7 +2,6 @@ namespace App\Models; -use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; @@ -67,28 +66,28 @@ public function participantGroups() /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function observationOrders() + public function observationAssignments() { - return $this->hasMany('App\Models\ObservationOrder', 'course_id'); + return $this->hasMany('App\Models\ObservationAssignment', 'course_id'); } - public function observationOrdersPerUserAndPerBlock() { + public function observationAssignmentsPerUserAndPerBlock() { if (!$this->observationAssignments) { - $observationAssignmentsQuery = ObservationOrder::select([ + $observationAssignmentsQuery = ObservationAssignment::select([ 'users.id as user_id', - 'observation_order_blocks.block_id as block_id', + 'observation_assignment_blocks.block_id as block_id', DB::raw('COUNT(DISTINCT observations.id) as observation_count'), 'participants.id as participant_id' ])->distinct() - ->join('observation_order_participants', 'observation_orders.id', 'observation_order_participants.observation_order_id') - ->join('observation_order_users', 'observation_orders.id', 'observation_order_users.observation_order_id') - ->join('observation_order_blocks', 'observation_orders.id', 'observation_order_blocks.observation_order_id') - ->join('users', 'users.id', 'observation_order_users.user_id') - ->join('participants', 'participants.id', 'observation_order_participants.participant_id') + ->join('observation_assignment_participants', 'observation_assignments.id', 'observation_assignment_participants.observation_assignment_id') + ->join('observation_assignment_users', 'observation_assignments.id', 'observation_assignment_users.observation_assignment_id') + ->join('observation_assignment_blocks', 'observation_assignments.id', 'observation_assignment_blocks.observation_assignment_id') + ->join('users', 'users.id', 'observation_assignment_users.user_id') + ->join('participants', 'participants.id', 'observation_assignment_participants.participant_id') ->leftJoin('observations_participants', 'participants.id', 'observations_participants.participant_id') ->leftJoin('observations', function($join) { $join->on('observations.id', 'observations_participants.observation_id'); - $join->on('observations.block_id', 'observation_order_blocks.block_id'); + $join->on('observations.block_id', 'observation_assignment_blocks.block_id'); $join->on('observations.user_id', 'users.id'); }) ->join('trainers', 'users.id', 'trainers.user_id') diff --git a/app/Models/ObservationOrder.php b/app/Models/ObservationAssignment.php similarity index 81% rename from app/Models/ObservationOrder.php rename to app/Models/ObservationAssignment.php index a6a9eb49..2558cf7f 100644 --- a/app/Models/ObservationOrder.php +++ b/app/Models/ObservationAssignment.php @@ -4,14 +4,14 @@ -class ObservationOrder extends Model +class ObservationAssignment extends Model { /** * The table associated with the model. * * @var string */ - protected $table = 'observation_orders'; + protected $table = 'observation_assignments'; /** @@ -25,7 +25,7 @@ class ObservationOrder extends Model */ public function blocks() { - return $this->belongsToMany('App\Models\Block', 'observation_order_blocks'); + return $this->belongsToMany('App\Models\Block', 'observation_assignment_blocks'); } /** @@ -33,7 +33,7 @@ public function blocks() */ public function participants() { - return $this->belongsToMany('App\Models\Participant', 'observation_order_participants'); + return $this->belongsToMany('App\Models\Participant', 'observation_assignment_participants'); } /** @@ -41,6 +41,6 @@ public function participants() */ public function users() { - return $this->belongsToMany('App\Models\User', 'observation_order_users'); + return $this->belongsToMany('App\Models\User', 'observation_assignment_users'); } } diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 02a1cda3..5103e5cf 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -69,9 +69,9 @@ public function qualis() { /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ - public function observationOrders() + public function observationAssignments() { - return $this->hasMany('App\Models\ObservationOrder'); + return $this->hasMany('App\Models\ObservationAssignment'); } /** diff --git a/app/Models/User.php b/app/Models/User.php index 53d984bf..b36a552e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -73,9 +73,9 @@ public function observations() /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ - public function observationOrders() + public function observationAssignments() { - return $this->belongsToMany('App\Models\ObservationOrder', 'observation_order_users'); + return $this->belongsToMany('App\Models\ObservationAssignment', 'observation_assignment_users'); } diff --git a/database/migrations/2020_09_04_145745_create_observation_orders_table.php b/database/migrations/2020_09_04_145745_create_observation_assignments_table.php similarity index 57% rename from database/migrations/2020_09_04_145745_create_observation_orders_table.php rename to database/migrations/2020_09_04_145745_create_observation_assignments_table.php index 79400fa6..d7f00c9e 100644 --- a/database/migrations/2020_09_04_145745_create_observation_orders_table.php +++ b/database/migrations/2020_09_04_145745_create_observation_assignments_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateObservationOrdersTable extends Migration +class CreateObservationAssignmentsTable extends Migration { /** * Run the migrations. @@ -13,15 +13,15 @@ class CreateObservationOrdersTable extends Migration */ public function up() { - Schema::create('observation_orders', function (Blueprint $table) { + Schema::create('observation_assignments', function (Blueprint $table) { $table->integer('id', true); $table->integer('course_id')->nullable(false); $table->string('order_name')->nullable(false); $table->timestamps(); }); - Schema::table('observation_orders', function(Blueprint $table) + Schema::table('observation_assignments', function(Blueprint $table) { - $table->foreign('course_id', 'fk_course_observation_order')->references('id')->on('courses')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('course_id', 'fk_course_observation_assignment')->references('id')->on('courses')->onUpdate('CASCADE')->onDelete('CASCADE'); }); } @@ -33,11 +33,11 @@ public function up() */ public function down() { - Schema::table('observation_orders', function(Blueprint $table) + Schema::table('observation_assignments', function(Blueprint $table) { - $table->dropForeign('fk_course_observation_order'); + $table->dropForeign('fk_course_observation_assignment'); }); - Schema::dropIfExists('observation_orders'); + Schema::dropIfExists('observation_assignments'); } } diff --git a/database/migrations/2020_09_04_193813_create_observation_assignment_blocks.php b/database/migrations/2020_09_04_193813_create_observation_assignment_blocks.php new file mode 100644 index 00000000..356ef7ed --- /dev/null +++ b/database/migrations/2020_09_04_193813_create_observation_assignment_blocks.php @@ -0,0 +1,42 @@ +integer('observation_assignment_id')->nullable(false); + $table->integer('block_id')->nullable(false); + }); + + Schema::table('observation_assignment_blocks', function (Blueprint $table) { + $table->foreign('observation_assignment_id', 'fk_order_observation_assignment_block')->references('id')->on('observation_assignments')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('block_id', 'fk_block_observation_assignment_block')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_assignment_blocks', function(Blueprint $table) + { + $table->dropForeign('fk_block_observation_assignment_block'); + $table->dropForeign('fk_order_observation_assignment_block'); + }); + Schema::dropIfExists('observation_assignment_blocks'); + } +} diff --git a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php b/database/migrations/2020_09_04_193813_create_observation_order_blocks.php deleted file mode 100644 index f2e0fba4..00000000 --- a/database/migrations/2020_09_04_193813_create_observation_order_blocks.php +++ /dev/null @@ -1,42 +0,0 @@ -integer('observation_order_id')->nullable(false); - $table->integer('block_id')->nullable(false); - }); - - Schema::table('observation_order_blocks', function (Blueprint $table) { - $table->foreign('observation_order_id', 'fk_order_observation_order_block')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('block_id', 'fk_block_observation_order_block')->references('id')->on('blocks')->onUpdate('CASCADE')->onDelete('CASCADE'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('observation_order_blocks', function(Blueprint $table) - { - $table->dropForeign('fk_block_observation_order_block'); - $table->dropForeign('fk_order_observation_order_block'); - }); - Schema::dropIfExists('observation_order_blocks'); - } -} diff --git a/database/migrations/2020_09_04_193818_create_observation_assignment_users.php b/database/migrations/2020_09_04_193818_create_observation_assignment_users.php new file mode 100644 index 00000000..c304dcda --- /dev/null +++ b/database/migrations/2020_09_04_193818_create_observation_assignment_users.php @@ -0,0 +1,42 @@ +integer('observation_assignment_id')->nullable(false); + $table->integer('user_id')->nullable(false); + }); + + Schema::table('observation_assignment_users', function (Blueprint $table) { + $table->foreign('observation_assignment_id', 'fk_order_observation_assignment_user')->references('id')->on('observation_assignments')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('user_id', 'fk_user_observation_assignment_user')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_assignment_users', function(Blueprint $table) + { + $table->dropForeign('fk_user_observation_assignment_user'); + $table->dropForeign('fk_order_observation_assignment_user'); + }); + Schema::dropIfExists('observation_assignment_users'); + } +} diff --git a/database/migrations/2020_09_04_193818_create_observation_order_users.php b/database/migrations/2020_09_04_193818_create_observation_order_users.php deleted file mode 100644 index 9b44ba26..00000000 --- a/database/migrations/2020_09_04_193818_create_observation_order_users.php +++ /dev/null @@ -1,42 +0,0 @@ -integer('observation_order_id')->nullable(false); - $table->integer('user_id')->nullable(false); - }); - - Schema::table('observation_order_users', function (Blueprint $table) { - $table->foreign('observation_order_id', 'fk_order_observation_order_user')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('user_id', 'fk_user_observation_order_user')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('observation_order_users', function(Blueprint $table) - { - $table->dropForeign('fk_user_observation_order_user'); - $table->dropForeign('fk_order_observation_order_user'); - }); - Schema::dropIfExists('observation_order_users'); - } -} diff --git a/database/migrations/2020_09_04_193823_create_observation_assignment_participants.php b/database/migrations/2020_09_04_193823_create_observation_assignment_participants.php new file mode 100644 index 00000000..facdacee --- /dev/null +++ b/database/migrations/2020_09_04_193823_create_observation_assignment_participants.php @@ -0,0 +1,42 @@ +integer('observation_assignment_id')->nullable(false); + $table->integer('participant_id')->nullable(false); + }); + + Schema::table('observation_assignment_participants', function (Blueprint $table) { + $table->foreign('observation_assignment_id', 'fk_order_observation_assignment_participant')->references('id')->on('observation_assignments')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('participant_id', 'fk_participant_observation_assignment_participant')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('observation_assignment_participants', function(Blueprint $table) + { + $table->dropForeign('fk_participant_observation_assignment_participant'); + $table->dropForeign('fk_order_observation_assignment_participant'); + }); + Schema::dropIfExists('observation_assignment_participants'); + } +} diff --git a/database/migrations/2020_09_04_193823_create_observation_order_participants.php b/database/migrations/2020_09_04_193823_create_observation_order_participants.php deleted file mode 100644 index 3cb4cd9c..00000000 --- a/database/migrations/2020_09_04_193823_create_observation_order_participants.php +++ /dev/null @@ -1,42 +0,0 @@ -integer('observation_order_id')->nullable(false); - $table->integer('participant_id')->nullable(false); - }); - - Schema::table('observation_order_participants', function (Blueprint $table) { - $table->foreign('observation_order_id', 'fk_order_observation_order_participant')->references('id')->on('observation_orders')->onUpdate('CASCADE')->onDelete('CASCADE'); - $table->foreign('participant_id', 'fk_participant_observation_order_participant')->references('id')->on('participants')->onUpdate('CASCADE')->onDelete('CASCADE'); - - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('observation_order_participants', function(Blueprint $table) - { - $table->dropForeign('fk_participant_observation_order_participant'); - $table->dropForeign('fk_order_observation_order_participant'); - }); - Schema::dropIfExists('observation_order_participants'); - } -} diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index dfc55061..a25fe724 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -93,7 +93,7 @@ "requirements" => "Anforderungen", "user" => "Beobachter", ), - "observation_order" => array( + "observation_assignment" => array( "block" => "Blöcke", "order_name" => "Beobachtungsauftrag", "participant" => "TN", @@ -237,8 +237,8 @@ "menu_name" => "Neuen Kurs erstellen", "title" => "Neuen Kurs erstellen", ), - "observation_orders" => array( - "are_observation_orders_required" => array( + "observation_assignments" => array( + "are_observation_assignments_required" => array( "answer" => "Nein, aber sie sind ein nützliches Tool beim RQF (Rückmelde-, Qualifizierungs-, Förderungs-) Prozess.", "question" => "Muss ich Beobachtungsaufträge für meinen Kurs erfassen?", ), @@ -249,9 +249,9 @@ "existing" => "Beobachtungsaufträge :courseName", "menu_name" => "Beobachtungsaufträge", "new" => "Neuer Beobachtungsauftrag", - "no_observation_order" => "Bisher sind keine Beobachtungsaufträge erfasst.", + "no_observation_assignment" => "Bisher sind keine Beobachtungsaufträge erfasst.", "really_delete" => "Willst du den Beobachtungsauftrag \":order_name\" wirklich löschen?", - "what_are_observation_orders" => array( + "what_are_observation_assignments" => array( "answer" => "Viele Equipen definieren, wer wann wen beobachten sollte. Diese Aufträge könnt ihr hier definieren und seht diese (und ob sie schon erfüllt sind) z.Bsp. beim Spick.", "question" => "Was sind Beobachtungsaufträge?", ), diff --git a/resources/views/admin/observationOrders/edit.blade.php b/resources/views/admin/observationAssignments/edit.blade.php similarity index 60% rename from resources/views/admin/observationOrders/edit.blade.php rename to resources/views/admin/observationAssignments/edit.blade.php index 62769db1..a7112b30 100644 --- a/resources/views/admin/observationOrders/edit.blade.php +++ b/resources/views/admin/observationAssignments/edit.blade.php @@ -3,16 +3,16 @@ @section('content') - + - + - + + + + + + + + + + + + + + + @component('components.help-text', ['id' => 'requirementsHelp', 'key' => 't.views.admin.observation_assignments.what_are_observation_assignments'])@endcomponent + + + + + + + + + + + @if (count($course->observationAssignments)) + + + + @else + + {{__('t.views.admin.observation_assignments.no_observation_assignment')}} + + @component('components.help-text', ['id' => 'noGroupsHelp', 'key' => 't.views.admin.observation_assignments.are_observation_assignments_required'])@endcomponent + + @endif + + + +@endsection diff --git a/resources/views/admin/observationOrders/index.blade.php b/resources/views/admin/observationOrders/index.blade.php deleted file mode 100644 index 1b68d27f..00000000 --- a/resources/views/admin/observationOrders/index.blade.php +++ /dev/null @@ -1,85 +0,0 @@ -@extends('layouts.default') - -@section('content') - - - - - - - - - - - - - - - - @component('components.help-text', ['id' => 'requirementsHelp', 'key' => 't.views.admin.observation_orders.what_are_observation_orders'])@endcomponent - - - - - - - - - - - @if (count($course->observationOrders)) - - - - @else - - {{__('t.views.admin.observation_orders.no_observation_order')}} - - @component('components.help-text', ['id' => 'noGroupsHelp', 'key' => 't.views.admin.observation_orders.are_observation_orders_required'])@endcomponent - - @endif - - - -@endsection diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index ffbc0b0f..c03e4a13 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -57,9 +57,9 @@ class="" @endif
- @if(isset($trainerObservationOrders[$block->id])) + @if(isset($trainerObservationAssignments[$block->id]))
- @foreach($trainerObservationOrders[$block->id] as $participant) + @foreach($trainerObservationAssignments[$block->id] as $participant)
diff --git a/resources/views/includes/header.blade.php b/resources/views/includes/header.blade.php index c92cbb46..c11a1150 100644 --- a/resources/views/includes/header.blade.php +++ b/resources/views/includes/header.blade.php @@ -58,8 +58,8 @@ @if(!$course->archived) {{__('t.views.admin.participant_groups.menu_name')}} - {{__('t.views.admin.observation_orders.menu_name')}} + {{__('t.views.admin.observation_assignments.menu_name')}} @endif {{__('t.views.admin.qualis.menu_name')}} diff --git a/routes/web.php b/routes/web.php index 2cf8889c..c5cae5da 100644 --- a/routes/web.php +++ b/routes/web.php @@ -72,11 +72,11 @@ Route::post('/course/{course}/admin/participantGroups/{participantGroup}', 'ParticipantGroupController@update')->name('admin.participantGroups.update'); Route::delete('/course/{course}/admin/participantGroups/{participantGroup}', 'ParticipantGroupController@destroy')->name('admin.participantGroups.delete'); - Route::get('/course/{course}/admin/observationOrders', 'ObservationOrderController@index')->name('admin.observationOrders'); - Route::post('/course/{course}/admin/observationOrders', 'ObservationOrderController@store')->name('admin.observationOrders.store'); - Route::get('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@edit')->name('admin.observationOrders.edit'); - Route::post('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@update')->name('admin.observationOrders.update'); - Route::delete('/course/{course}/admin/observationOrders/{observationOrder}', 'ObservationOrderController@destroy')->name('admin.observationOrders.delete'); + Route::get('/course/{course}/admin/observationAssignments', 'ObservationAssignmentController@index')->name('admin.observationAssignments'); + Route::post('/course/{course}/admin/observationAssignments', 'ObservationAssignmentController@store')->name('admin.observationAssignments.store'); + Route::get('/course/{course}/admin/observationAssignments/{observationAssignment}', 'ObservationAssignmentController@edit')->name('admin.observationAssignments.edit'); + Route::post('/course/{course}/admin/observationAssignments/{observationAssignment}', 'ObservationAssignmentController@update')->name('admin.observationAssignments.update'); + Route::delete('/course/{course}/admin/observationAssignments/{observationAssignment}', 'ObservationAssignmentController@destroy')->name('admin.observationAssignments.delete'); }); Route::get('/course/{course}/admin/blocks', 'BlockController@index')->name('admin.blocks'); diff --git a/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php b/tests/Feature/Admin/ObservationAssignment/CreateObservationAssignmentTest.php similarity index 98% rename from tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php rename to tests/Feature/Admin/ObservationAssignment/CreateObservationAssignmentTest.php index 3acecd73..2bf842ec 100644 --- a/tests/Feature/Admin/ObservationOrder/CreateObservationOrderTest.php +++ b/tests/Feature/Admin/ObservationAssignment/CreateObservationAssignmentTest.php @@ -1,14 +1,14 @@ participantId = $this->createParticipant('Pflock'); $this->blockId = $this->createBlock('Einstieg', '1.1'); - $this->userId = $this->createUser('') + $this->userId = $this->createUser(''); $this->payload = ['group_name' => 'Unternehmungsgruppe 1', 'participants' => '' . $this->participantId]; } From 05a2937f8f89ca3a93d63c1a390994438e394b26 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 11:34:31 +0200 Subject: [PATCH 25/35] Fix plural names of fields --- .../Controllers/ObservationAssignmentController.php | 8 ++++---- app/Http/Requests/ObservationAssignmentRequest.php | 5 +++-- resources/lang/de/t.php | 5 ++--- .../admin/observationAssignments/edit.blade.php | 8 ++++---- .../admin/observationAssignments/index.blade.php | 12 ++++++------ 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/ObservationAssignmentController.php b/app/Http/Controllers/ObservationAssignmentController.php index dc25c6a4..28a8386b 100644 --- a/app/Http/Controllers/ObservationAssignmentController.php +++ b/app/Http/Controllers/ObservationAssignmentController.php @@ -41,8 +41,8 @@ public function store(ObservationAssignmentRequest $request, Course $course) $observationAssignment = ObservationAssignment::create(array_merge($data, ['course_id' => $course->id])); $observationAssignment->participants()->attach(array_filter(explode(',', $data['participants']))); - $observationAssignment->blocks()->attach(array_filter(explode(',', $data['block']))); - $observationAssignment->users()->attach(array_filter(explode(',', $data['user']))); + $observationAssignment->blocks()->attach(array_filter(explode(',', $data['blocks']))); + $observationAssignment->users()->attach(array_filter(explode(',', $data['users']))); $request->session()->flash('alert-success', __('t.views.admin.observation_assignments.create_success')); }); @@ -81,9 +81,9 @@ public function update(ObservationAssignmentRequest $request, Course $course, Ob $observationAssignment->participants()->detach(null); $observationAssignment->participants()->attach(array_filter(explode(',', $data['participants']))); $observationAssignment->blocks()->detach(null); - $observationAssignment->blocks()->attach(array_filter(explode(',', $data['block']))); + $observationAssignment->blocks()->attach(array_filter(explode(',', $data['blocks']))); $observationAssignment->users()->detach(null); - $observationAssignment->users()->attach(array_filter(explode(',', $data['user']))); + $observationAssignment->users()->attach(array_filter(explode(',', $data['users']))); $request->session()->flash('alert-success', __('t.views.admin.observation_assignments.edit_success')); }); return Redirect::route('admin.observationAssignments', ['course' => $course->id]); diff --git a/app/Http/Requests/ObservationAssignmentRequest.php b/app/Http/Requests/ObservationAssignmentRequest.php index 4385e328..895bff91 100644 --- a/app/Http/Requests/ObservationAssignmentRequest.php +++ b/app/Http/Requests/ObservationAssignmentRequest.php @@ -25,9 +25,10 @@ public function authorize() { public function rules() { return [ 'order_name' => 'required|max:1023', - 'block' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', + 'blocks' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', 'participants' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse', - 'user' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse:' . Trainer::class . ',user_id' ]; + 'users' => 'required|regex:/^\d+(,\d+)*$/|allExistInCourse:' . Trainer::class . ',user_id' + ]; } diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index a25fe724..9d2c5f80 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -94,11 +94,10 @@ "user" => "Beobachter", ), "observation_assignment" => array( - "block" => "Blöcke", + "blocks" => "Blöcke", "order_name" => "Beobachtungsauftrag", - "participant" => "TN", "participants" => "TN", - "user" => "Equipe", + "users" => "Equipe", ), "participant" => array( "group" => "Abteilung", diff --git a/resources/views/admin/observationAssignments/edit.blade.php b/resources/views/admin/observationAssignments/edit.blade.php index a7112b30..fea330d7 100644 --- a/resources/views/admin/observationAssignments/edit.blade.php +++ b/resources/views/admin/observationAssignments/edit.blade.php @@ -10,9 +10,9 @@ array( "blocks" => "Blöcke", - "order_name" => "Beobachtungsauftrag", + "name" => "Beobachtungsauftrag", "participants" => "TN", "users" => "Equipe", ), @@ -249,7 +249,7 @@ "menu_name" => "Beobachtungsaufträge", "new" => "Neuer Beobachtungsauftrag", "no_observation_assignment" => "Bisher sind keine Beobachtungsaufträge erfasst.", - "really_delete" => "Willst du den Beobachtungsauftrag \":order_name\" wirklich löschen?", + "really_delete" => "Willst du den Beobachtungsauftrag \":name\" wirklich löschen?", "what_are_observation_assignments" => array( "answer" => "Viele Equipen definieren, wer wann wen beobachten sollte. Diese Aufträge könnt ihr hier definieren und seht diese (und ob sie schon erfüllt sind) z.Bsp. beim Spick.", "question" => "Was sind Beobachtungsaufträge?", diff --git a/resources/views/admin/observationAssignments/edit.blade.php b/resources/views/admin/observationAssignments/edit.blade.php index fea330d7..249c656f 100644 --- a/resources/views/admin/observationAssignments/edit.blade.php +++ b/resources/views/admin/observationAssignments/edit.blade.php @@ -7,7 +7,7 @@ - + {{__('t.views.admin.observation_assignments.new')}} - + payload; - $payload['participants'] = $participantIds; + $payload['participants'] = $this->createParticipant($participantName); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload)->followRedirects(); + + // then + $response->assertDontSee($participantName, false); + $response->assertSee('<b>Participant name<\/b> with 'some\" formatting', false); + } + + public function test_shouldNotAllowCreatingObservationAssignment_withParticipantFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $participantFromDifferentCourse = $this->createParticipant('Foreign', $differentCourse); + $payload = $this->payload; + $payload['participants'] = $this->participantId . ',' . $participantFromDifferentCourse; // when - $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für TN ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewObservationAssignment_noUserIds() + { + // given + $payload = $this->payload; + unset($payload['users']); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Equipe muss ausgefüllt sein.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateNewObservationAssignment_invalidUserIds() + { + // given + $payload = $this->payload; + $payload['users'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Equipe Format ist ungültig.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateNewObservationAssignment_oneValidUserId() + { + // given + $payload = $this->payload; + $userId = $this->createUser()->id; + Course::find($this->courseId)->users()->attach($userId); + $payload['users'] = $userId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then $response->assertStatus(302); - $response->assertRedirect('/course/' . $this->courseId . '/admin/participantGroups'); - /** @var TestResponse $response */ - $response = $response->followRedirects(); - $response->assertSee('Teilnehmergruppe wurde erfolgreich erstellt.'); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments'); + $this->assertEquals([$userId], ObservationAssignment::latest()->first()->users->pluck('id')->all()); } - public function test_createParticipantGroupWitMultipleParticipantIds_shouldLinkTheParticipantGroup() + public function test_shouldValidateNewObservationAssignment_multipleValidUserIds() { // given - $participantId2 = $this->createParticipant('Pfnörch'); - $participantIds = $this->participantId . ',' . $participantId2; $payload = $this->payload; - $payload['participants'] = $participantIds; - $payload['group_name'] = 'visible on both participants'; + $userIds = [$this->createUser()->id, $this->createUser()->id]; + Course::find($this->courseId)->users()->attach($userIds); + $payload['users'] = implode(',', $userIds); // when - $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then - $response = $this->get('/course/' . $this->courseId . '/participants/' . $this->participantId); - $response->assertSee('visible on both participants'); - $response = $this->get('/course/' . $this->courseId . '/participants/' . $participantId2); - $response->assertSee('visible on both participants'); + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments'); + $this->assertEquals($userIds, ObservationAssignment::latest()->first()->users->pluck('id')->all()); } - public function test_shouldValidateNewParticipantGroup_noGroupName() + public function test_shouldValidateNewObservationAssignment_someNonexistentUserIds() { // given $payload = $this->payload; - unset($payload['group_name']); + $userIds = [$this->createUser()->id, '999999', $this->createUser()->id]; + Course::find($this->courseId)->users()->attach([$userIds[0], $userIds[2]]); + $payload['users'] = implode(',', $userIds); // when - $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then $this->assertInstanceOf(ValidationException::class, $response->exception); /** @var ValidationException $exception */ $exception = $response->exception; - $this->assertEquals('Gruppe muss ausgefüllt sein.', $exception->validator->errors()->first('group_name')); + $this->assertEquals('Der gewählte Wert für Equipe ist ungültig.', $exception->validator->errors()->first('users')); } - public function test_shouldValidateNewParticipantGroup_longContent() + public function test_shouldValidateNewObservationAssignment_someInvalidUserIds() { // given $payload = $this->payload; - $payload['group_name'] = 'Unglaublich langer Gruppenname. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr.'; + $userIds = [$this->createUser()->id, 'abc', $this->createUser()->id]; + Course::find($this->courseId)->users()->attach([$userIds[0], $userIds[2]]); + $payload['users'] = implode(',', $userIds); // when - $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then $this->assertInstanceOf(ValidationException::class, $response->exception); /** @var ValidationException $exception */ $exception = $response->exception; - $this->assertEquals('Gruppe darf maximal 1023 Zeichen haben.', $exception->validator->errors()->first('group_name')); + $this->assertEquals('Equipe Format ist ungültig.', $exception->validator->errors()->first('users')); } + public function test_shouldNotAllowCreatingObservationAssignment_withUserFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $userFromDifferentCourse = $this->createUser(['name' => 'Foreign'])->id; + Course::find($differentCourse)->users()->attach($userFromDifferentCourse); + $payload = $this->payload; + $payload['users'] = Auth::id() . ',' . $userFromDifferentCourse; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Equipe ist ungültig.', $exception->validator->errors()->first('users')); + } - public function test_shouldShowEscapedNotice_afterCreatingParticipantGroup() + public function test_shouldValidateNewObservationAssignment_noBlockIds() { // given - $participantName = 'Participant name with \'some" formatting'; $payload = $this->payload; - $payload['participants'] = $this->createParticipant($participantName); + unset($payload['blocks']); // when - $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload)->followRedirects(); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then - $response->assertDontSee($participantName, false); - $response->assertSee(htmlspecialchars($participantName, ENT_QUOTES), false); + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke muss ausgefüllt sein.', $exception->validator->errors()->first('blocks')); } - public function test_shouldNotAllowCreatingParticipantGroup_withParticipantFromADifferentCourse() + public function test_shouldValidateNewObservationAssignment_invalidBlockIds() + { + // given + $payload = $this->payload; + $payload['blocks'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke Format ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldValidateNewObservationAssignment_oneValidBlockId() + { + // given + $payload = $this->payload; + $blockId = $this->createBlock(); + $payload['blocks'] = $blockId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments'); + $this->assertEquals([$blockId], ObservationAssignment::latest()->first()->blocks->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignment_multipleValidBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments'); + $this->assertEquals($blockIds, ObservationAssignment::latest()->first()->blocks->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignment_someNonexistentBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), '999999', $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Blöcke ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldValidateNewObservationAssignment_someInvalidBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), 'abc', $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke Format ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldNotAllowCreatingObservationAssignment_withBlockFromADifferentCourse() { // given $differentCourse = $this->createCourse('Other course', '', false); - $participantFromDifferentCourse = $this->createParticipant('Foreign', $differentCourse); + $blockFromDifferentCourse = $this->createBlock('Foreign', '1.1', '01.01.2019', null, $differentCourse); $payload = $this->payload; - $payload['participants'] = $this->participantId . ',' . $participantFromDifferentCourse; + $payload['blocks'] = $this->blockId . ',' . $blockFromDifferentCourse; // when - $response = $this->post('/course/' . $this->courseId . '/admin/participantGroups', $payload); + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments', $payload); // then $this->assertInstanceOf(ValidationException::class, $response->exception); /** @var ValidationException $exception */ $exception = $response->exception; - $this->assertEquals('Der gewählte Wert für Teilnehmer ist ungültig.', $exception->validator->errors()->first('participants')); + $this->assertEquals('Der gewählte Wert für Blöcke ist ungültig.', $exception->validator->errors()->first('blocks')); } } diff --git a/tests/Feature/Admin/ObservationAssignment/DeleteObservationAssignmentTest.php b/tests/Feature/Admin/ObservationAssignment/DeleteObservationAssignmentTest.php new file mode 100644 index 00000000..dceccf8d --- /dev/null +++ b/tests/Feature/Admin/ObservationAssignment/DeleteObservationAssignmentTest.php @@ -0,0 +1,65 @@ +observationAssignmentId = $this->createObservationAssignment('Beobachtungsauftrag 1'); + } + + public function test_shouldRequireLogin() { + // given + auth()->logout(); + + // when + $response = $this->delete('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertStatus(302); + $response->assertRedirect('/login'); + } + + public function test_shouldRequireNonArchivedCourse() { + // given + Course::find($this->courseId)->update(['archived' => true]); + + // when + $response = $this->delete('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertStatus(302); + $response->assertRedirect(route('admin.course', ['course' => $this->courseId])); + } + + public function test_shouldDeleteObservationAssignment() { + // given + + // when + $response = $this->delete('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + /** @var TestResponse $response */ + $response = $response->followRedirects(); + $response->assertDontSee('UN Gruppe 1'); + } + + public function test_shouldValidateDeletedObservationAssignmentUrl_wrongId() { + // given + + // when + $response = $this->delete('/course/' . $this->courseId . '/admin/observationAssignments/' . ($this->observationAssignmentId + 1)); + + // then + $response->assertStatus(404); + } +} diff --git a/tests/Feature/Admin/ObservationAssignment/ReadObservationAssignmentTest.php b/tests/Feature/Admin/ObservationAssignment/ReadObservationAssignmentTest.php new file mode 100644 index 00000000..98e46192 --- /dev/null +++ b/tests/Feature/Admin/ObservationAssignment/ReadObservationAssignmentTest.php @@ -0,0 +1,70 @@ +observationAssignmentId = $this->createObservationAssignment('Auftrag 1'); + } + + + public function test_shouldRequireLogin() + { + // given + auth()->logout(); + + // when + $response = $this->get('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertStatus(302); + $response->assertRedirect('/login'); + } + + public function test_shouldRequireNonArchivedCourse() + { + // given + Course::find($this->courseId)->update(['archived' => true]); + + // when + $response = $this->get('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertStatus(302); + $response->assertRedirect(route('admin.course', ['course' => $this->courseId])); + } + + public function test_shouldDisplayObservationAssignment() + { + // given + + // when + $response = $this->get('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $response->assertOk(); + $response->assertSee('Auftrag 1'); + } + + public function test_shouldNotDisplayObservationAssignment_fromOtherCourseOfSameUser() + { + // given + $otherKursId = $this->createCourse('Zweiter Kurs', ''); + + // when + $response = $this->get('/course/' . $otherKursId . '/admin/observationAssignments/' . $this->observationAssignmentId); + + // then + $this->assertInstanceOf(ModelNotFoundException::class, $response->exception); + } +} diff --git a/tests/Feature/Admin/ObservationAssignment/UpdateObservationAssignmentTest.php b/tests/Feature/Admin/ObservationAssignment/UpdateObservationAssignmentTest.php new file mode 100644 index 00000000..260a6522 --- /dev/null +++ b/tests/Feature/Admin/ObservationAssignment/UpdateObservationAssignmentTest.php @@ -0,0 +1,453 @@ +observationAssignmentId = $this->createObservationAssignment("Auftrag 1"); + + + $this->payload = ['name' => 'Besserer Auftrag', 'participants' => '' . $this->participantId, 'users' => '' . Auth::id(), 'blocks' => '' . $this->blockId]; + } + + public function test_shouldRequireLogin() + { + // given + auth()->logout(); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/login'); + } + + public function test_shouldRequireNonArchivedCourse() + { + // given + Course::find($this->courseId)->update(['archived' => true]); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect(route('admin.course', ['course' => $this->courseId])); + } + + public function test_shouldUpdateObservationAssignment() + { + // given + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $this->payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/' ); + /** @var TestResponse $response */ + $response = $response->followRedirects(); + $response->assertSee($this->payload['name']); + $response->assertDontSee('Auftrag 1'); + } + + public function test_shouldValidateNewObservationAssignmentData_noName() + { + // given + $payload = $this->payload; + unset($payload['name']); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Beobachtungsauftrag muss ausgefüllt sein.', $exception->validator->errors()->first('name')); + } + + public function test_shouldValidateNewObservationAssignmentData_longName() + { + // given + $payload = $this->payload; + $payload['name'] = 'Unglaublich langer Name. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr. Und noch etwas mehr.'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Beobachtungsauftrag darf maximal 1023 Zeichen haben.', $exception->validator->errors()->first('name')); + } + + public function test_shouldValidateObservationAssignmentData_noParticipantIds() + { + // given + $payload = $this->payload; + $payload['participants'] = ''; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('TN muss ausgefüllt sein.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewObservationAssignmentData_invalidParticipantIds() + { + // given + $payload = $this->payload; + $payload['participants'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('TN Format ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewObservationAssignmentData_oneValidParticipantId() + { + // given + $payload = $this->payload; + $participantId = $this->createParticipant(); + $payload['participants'] = $participantId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals([$participantId], ObservationAssignment::latest()->first()->participants()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_multipleValidParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals($participantIds, ObservationAssignment::latest()->first()->participants()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_someNonexistentParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), '999999', $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für TN ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateNewObservationAssignmentData_someInvalidParticipantIds() + { + // given + $payload = $this->payload; + $participantIds = [$this->createParticipant(), 'abc', $this->createParticipant()]; + $payload['participants'] = implode(',', $participantIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('TN Format ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldNotAllowChangingParticipantToSomeoneFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $participantFromDifferentCourse = $this->createParticipant('Foreign', $differentCourse); + $payload = $this->payload; + $payload['participants'] = $this->participantId . ',' . $participantFromDifferentCourse; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für TN ist ungültig.', $exception->validator->errors()->first('participants')); + } + + public function test_shouldValidateObservationAssignmentData_noUserIds() + { + // given + $payload = $this->payload; + $payload['users'] = ''; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Equipe muss ausgefüllt sein.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateNewObservationAssignmentData_invalidUserIds() + { + // given + $payload = $this->payload; + $payload['users'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Equipe Format ist ungültig.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateNewObservationAssignmentData_oneValidUserId() + { + // given + $payload = $this->payload; + $userId = $this->createUser()->id; + Course::find($this->courseId)->users()->attach($userId); + $payload['users'] = $userId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals([$userId], ObservationAssignment::latest()->first()->users()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_multipleValidUserIds() + { + // given + $payload = $this->payload; + $userIds = [$this->createUser()->id, $this->createUser()->id]; + Course::find($this->courseId)->users()->attach($userIds); + $payload['users'] = implode(',', $userIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals($userIds, ObservationAssignment::latest()->first()->users()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_someNonexistentUserIds() + { + // given + $payload = $this->payload; + $userIds = [$this->createUser()->id, '999999', $this->createUser()->id]; + Course::find($this->courseId)->users()->attach([$userIds[0], $userIds[2]]); + $payload['users'] = implode(',', $userIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Equipe ist ungültig.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateNewObservationAssignmentData_someInvalidUserIds() + { + // given + $payload = $this->payload; + $userIds = [$this->createUser()->id, 'abc', $this->createUser()->id]; + Course::find($this->courseId)->users()->attach([$userIds[0], $userIds[2]]); + $payload['users'] = implode(',', $userIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Equipe Format ist ungültig.', $exception->validator->errors()->first('users')); + } + + public function test_shouldNotAllowChangingUserToSomeoneFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $userFromDifferentCourse = $this->createUser(['name' => 'Foreign'])->id; + Course::find($differentCourse)->users()->attach($userFromDifferentCourse); + $payload = $this->payload; + $payload['users'] = Auth::id() . ',' . $userFromDifferentCourse; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Equipe ist ungültig.', $exception->validator->errors()->first('users')); + } + + public function test_shouldValidateObservationAssignmentData_noBlockIds() + { + // given + $payload = $this->payload; + $payload['blocks'] = ''; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke muss ausgefüllt sein.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldValidateNewObservationAssignmentData_invalidBlockIds() + { + // given + $payload = $this->payload; + $payload['blocks'] = 'a'; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke Format ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldValidateNewObservationAssignmentData_oneValidBlockId() + { + // given + $payload = $this->payload; + $blockId = $this->createBlock(); + $payload['blocks'] = $blockId; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals([$blockId], ObservationAssignment::latest()->first()->blocks()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_multipleValidBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/admin/observationAssignments/'); + $this->assertEquals($blockIds, ObservationAssignment::latest()->first()->blocks()->pluck('id')->all()); + } + + public function test_shouldValidateNewObservationAssignmentData_someNonexistentBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), '999999', $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Blöcke ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldValidateNewObservationAssignmentData_someInvalidBlockIds() + { + // given + $payload = $this->payload; + $blockIds = [$this->createBlock(), 'abc', $this->createBlock()]; + $payload['blocks'] = implode(',', $blockIds); + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Blöcke Format ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + public function test_shouldNotAllowChangingBlockToSomeoneFromADifferentCourse() + { + // given + $differentCourse = $this->createCourse('Other course', '', false); + $blockFromDifferentCourse = $this->createBlock('Foreign', '1.1', '01.01.2019', null, $differentCourse); + $payload = $this->payload; + $payload['blocks'] = $this->blockId . ',' . $blockFromDifferentCourse; + + // when + $response = $this->post('/course/' . $this->courseId . '/admin/observationAssignments/' . $this->observationAssignmentId, $payload); + + // then + $this->assertInstanceOf(ValidationException::class, $response->exception); + /** @var ValidationException $exception */ + $exception = $response->exception; + $this->assertEquals('Der gewählte Wert für Blöcke ist ungültig.', $exception->validator->errors()->first('blocks')); + } + + } diff --git a/tests/TestCaseWithBasicData.php b/tests/TestCaseWithBasicData.php index 70bbfc97..0303d60f 100644 --- a/tests/TestCaseWithBasicData.php +++ b/tests/TestCaseWithBasicData.php @@ -3,8 +3,10 @@ namespace Tests; use App\Models\Observation; +use App\Models\ObservationAssignment; use App\Models\ParticipantGroup; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Auth; abstract class TestCaseWithBasicData extends TestCaseWithCourse { @@ -30,6 +32,13 @@ protected function createParticipantGroup($group_name = "Test Gruppe", $particip $participant_group = ParticipantGroup::create(['course_id' => ($courseId !== null ? $courseId : $this->courseId), 'group_name' => $group_name]); $participant_group->participants()->attach(($participantIds !== null ? Arr::wrap($participantIds) : [$this->participantId])); return $participant_group->id; + } + protected function createObservationAssignment($name = "Test Auftrag", $participantIds = null, $blockIds = null, $userIds = null, $courseId = null) { + $observation_assignment = ObservationAssignment::create(['course_id' => ($courseId !== null ? $courseId : $this->courseId), 'name' => $name]); + $observation_assignment->participants()->attach(($participantIds !== null ? Arr::wrap($participantIds) : [$this->participantId])); + $observation_assignment->blocks()->attach(($blockIds !== null ? Arr::wrap($blockIds) : [$this->blockId])); + $observation_assignment->users()->attach(($userIds !== null ? Arr::wrap($userIds) : [Auth::id()])); + return $observation_assignment->id; } } From a646315d012ee557de8300f80685e0773f35c42c Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 16:28:09 +0200 Subject: [PATCH 28/35] Redesign a little with help from @manuelmeister --- resources/sass/app.scss | 8 -------- resources/views/crib.blade.php | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/resources/sass/app.scss b/resources/sass/app.scss index ff5f3e01..24f6f62e 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -112,14 +112,6 @@ background-color: #f9d6d5; } -.btn-outline-danger.bg-white:hover { - background-color: $danger !important; -} - -.btn-outline-success.bg-white:hover { - background-color: $success !important; -} - .hr-label { width: 100%; text-align: center; diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index c03e4a13..268d0d05 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -38,9 +38,9 @@ class="" @foreach ($day as $block) - - - {{ $block->blockname_and_number }} + + +
{{ $block->blockname_and_number }}
@if(count($block->mandatory_requirements))
{{__('t.views.crib.mandatory_requirements')}}: @@ -56,17 +56,19 @@ class="" @endforeach @endif
- + @if(isset($trainerObservationAssignments[$block->id]))
@foreach($trainerObservationAssignments[$block->id] as $participant) -
+
-
- {{ $participant->scout_name }} +
+ {{ $participant->scout_name }}
- {{$participant->scout_name}} + {{ $participant->observation_count }} + {{ $participant->observation_count }}
+

{{ $participant->scout_name }}

From cce590a8ffdaa0795dc969a69c20e2da2065d8ba Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 19:09:04 +0200 Subject: [PATCH 29/35] Add test for the mother of all queries --- tests/Feature/Crib/ReadCribTest.php | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/Feature/Crib/ReadCribTest.php b/tests/Feature/Crib/ReadCribTest.php index de49c57f..d20fe865 100644 --- a/tests/Feature/Crib/ReadCribTest.php +++ b/tests/Feature/Crib/ReadCribTest.php @@ -2,8 +2,11 @@ namespace Tests\Feature\Crib; +use App\Models\Observation; +use App\Models\ObservationAssignment; use App\Models\Participant; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Support\Facades\Auth; use Tests\TestCaseWithCourse; class ReadCribTest extends TestCaseWithCourse { @@ -110,4 +113,58 @@ public function test_shouldNotDisplayCrib_toOtherUser() { // then $this->assertInstanceOf(ModelNotFoundException::class, $response->exception); } + + public function test_shouldCalculateObservationAssignmentsCorrectly() { + // given + $block1 = $this->createBlock('Block 1', '1.1', '01.01.2019'); + $block2 = $this->createBlock('Block 2', '1.2', '01.01.2019'); + $participant1 = $this->createParticipant('One'); + $participant2 = $this->createParticipant('Two'); + $observation = Observation::create(['content' => 'test', 'block' => $block1, 'user_id' => Auth::id()]); + $observation->participants()->attach($participant1); + + $observationAssignment = ObservationAssignment::create(['name' => 'Assignment', 'course_id' => $this->courseId]); + $observationAssignment->blocks()->attach([$block1, $block2]); + $observationAssignment->participants()->attach([$participant1, $participant2]); + $observationAssignment->users()->attach(Auth::id()); + + $participant1Data = Participant::find($participant1)->attributesToArray(); + $participant2Data = Participant::find($participant2)->attributesToArray(); + $userId = Auth::id(); + $courseId = $this->courseId; + + // when + $response = $this->get('/course/' . $this->courseId . '/crib'); + + // then + $response->assertOk(); + $response->assertSee('Block 1'); + $response->assertSee('Block 2'); + $data = $response->getOriginalContent()->getData()['trainerObservationAssignments']; + $this->assertEquals([$block2, $block1], array_keys($data->all())); + $block1Participant1 = collect($data[$block1])->first(function ($entry) use($participant1) { return $entry['id'] === $participant1; }); + $this->assertEquals($block1Participant1['user_id'], $userId); + $this->assertEquals($block1Participant1['block_id'], $block1); + $this->assertEquals($block1Participant1['observation_count'], 1); + $this->assertEquals($block1Participant1['id'], $participant1); + $this->assertEquals($block1Participant1['scout_name'], 'One'); + $block1Participant2 = collect($data[$block1])->first(function ($entry) use($participant2) { return $entry['id'] === $participant2; }); + $this->assertEquals($block1Participant2['user_id'], $userId); + $this->assertEquals($block1Participant2['block_id'], $block1); + $this->assertEquals($block1Participant2['observation_count'], 0); + $this->assertEquals($block1Participant2['id'], $participant2); + $this->assertEquals($block1Participant2['scout_name'], 'Two'); + $block2Participant1 = collect($data[$block2])->first(function ($entry) use($participant1) { return $entry['id'] === $participant1; }); + $this->assertEquals($block2Participant1['user_id'], $userId); + $this->assertEquals($block2Participant1['block_id'], $block2); + $this->assertEquals($block2Participant1['observation_count'], 0); + $this->assertEquals($block2Participant1['id'], $participant1); + $this->assertEquals($block2Participant1['scout_name'], 'One'); + $block2Participant2 = collect($data[$block2])->first(function ($entry) use($participant2) { return $entry['id'] === $participant2; }); + $this->assertEquals($block2Participant2['user_id'], $userId); + $this->assertEquals($block2Participant2['block_id'], $block2); + $this->assertEquals($block2Participant2['observation_count'], 0); + $this->assertEquals($block2Participant2['id'], $participant2); + $this->assertEquals($block2Participant2['scout_name'], 'Two'); + } } From 689ff4ce7e4054fc79bbfd760e4967e932b4b3f2 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Fri, 2 Oct 2020 23:28:13 +0200 Subject: [PATCH 30/35] Load observation assignments only in the course that they belong to --- app/Http/Controllers/ObservationAssignmentController.php | 6 +++--- app/Providers/RouteServiceProvider.php | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ObservationAssignmentController.php b/app/Http/Controllers/ObservationAssignmentController.php index 28a8386b..3a419dd7 100644 --- a/app/Http/Controllers/ObservationAssignmentController.php +++ b/app/Http/Controllers/ObservationAssignmentController.php @@ -55,10 +55,10 @@ public function store(ObservationAssignmentRequest $request, Course $course) /** * Show the form for editing the specified resource. * @param Course $course - * @param \App\Models\ObservationAssignment $observationAssignment + * @param ObservationAssignment $observationAssignment * @return \Illuminate\Http\Response */ - public function edit(Course $course ,ObservationAssignment $observationAssignment) + public function edit(Course $course, ObservationAssignment $observationAssignment) { return view('admin.observationAssignments.edit', ['observationAssignment' => $observationAssignment]); } @@ -69,7 +69,7 @@ public function edit(Course $course ,ObservationAssignment $observationAssignmen * * @param ObservationAssignmentRequest $request * @param Course $course - * @param \App\Models\ObservationAssignment $observationAssignment + * @param ObservationAssignment $observationAssignment * @return RedirectResponse */ public function update(ObservationAssignmentRequest $request, Course $course, ObservationAssignment $observationAssignment) diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 58683d7d..179e9c64 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -67,6 +67,11 @@ public function boot() $course = $route->parameter('course'); return $course->participantGroups()->findOrFail($id); }); + Route::bind('observationAssignment', function($id, \Illuminate\Routing\Route $route) { + /** @var Course $course */ + $course = $route->parameter('course'); + return $course->observationAssignments()->findOrFail($id); + }); Route::bind('quali_data', function($id, \Illuminate\Routing\Route $route) { /** @var Course $course */ $course = $route->parameter('course'); From 107eff68c8a02d3626b5b35c5f0b94c5ff101dd4 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Mon, 5 Oct 2020 08:32:09 +0200 Subject: [PATCH 31/35] Improve layout and only show stuff related to observation assignments if there are any in the course --- app/Http/Controllers/BlockListController.php | 1 + resources/views/crib.blade.php | 67 ++++++++++---------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/BlockListController.php b/app/Http/Controllers/BlockListController.php index 7da3f497..ce622ec5 100644 --- a/app/Http/Controllers/BlockListController.php +++ b/app/Http/Controllers/BlockListController.php @@ -33,6 +33,7 @@ public function crib(Course $course, User $user) $userId = $user->id ?? Auth::id(); return view('crib', [ 'blockManagementLink' => $this->blockManagementLink($course, 't.views.crib.here'), + 'showObservationAssignments' => $course->observationAssignments()->count(), 'userId' => $userId, 'trainerObservationAssignments' => $course->observationAssignmentsPerUserAndPerBlock()[$userId] ?? [], 'neededObservations' => 1, diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index 268d0d05..74ffe75d 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -14,17 +14,19 @@ } @endphp -
- - -
+ @if($showObservationAssignments) +
+ + +
+ @endif @foreach($days as $day) @@ -39,10 +41,9 @@ class="" @foreach ($day as $block) - +
{{ $block->blockname_and_number }}
@if(count($block->mandatory_requirements)) -
{{__('t.views.crib.mandatory_requirements')}}: @foreach($block->mandatory_requirements as $requirement) {{$requirement->content}} @@ -56,27 +57,29 @@ class="" @endforeach @endif
- - @if(isset($trainerObservationAssignments[$block->id])) -
- @foreach($trainerObservationAssignments[$block->id] as $participant) - + @endif + + @endif From 3dd4c9478f772a0b27160fa42c50f39031040178 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Mon, 5 Oct 2020 08:34:20 +0200 Subject: [PATCH 32/35] Include a multi-participant observation in the test for the mother query --- tests/Feature/Crib/ReadCribTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Crib/ReadCribTest.php b/tests/Feature/Crib/ReadCribTest.php index d20fe865..cf360fc9 100644 --- a/tests/Feature/Crib/ReadCribTest.php +++ b/tests/Feature/Crib/ReadCribTest.php @@ -122,6 +122,8 @@ public function test_shouldCalculateObservationAssignmentsCorrectly() { $participant2 = $this->createParticipant('Two'); $observation = Observation::create(['content' => 'test', 'block' => $block1, 'user_id' => Auth::id()]); $observation->participants()->attach($participant1); + $multiObservation = Observation::create(['content' => 'haben die ganze Zeit nur geschnädert', 'block' => $block1, 'user_id' => Auth::id()]); + $multiObservation->participants()->attach([$participant1, $participant2]); $observationAssignment = ObservationAssignment::create(['name' => 'Assignment', 'course_id' => $this->courseId]); $observationAssignment->blocks()->attach([$block1, $block2]); @@ -145,13 +147,13 @@ public function test_shouldCalculateObservationAssignmentsCorrectly() { $block1Participant1 = collect($data[$block1])->first(function ($entry) use($participant1) { return $entry['id'] === $participant1; }); $this->assertEquals($block1Participant1['user_id'], $userId); $this->assertEquals($block1Participant1['block_id'], $block1); - $this->assertEquals($block1Participant1['observation_count'], 1); + $this->assertEquals($block1Participant1['observation_count'], 2); $this->assertEquals($block1Participant1['id'], $participant1); $this->assertEquals($block1Participant1['scout_name'], 'One'); $block1Participant2 = collect($data[$block1])->first(function ($entry) use($participant2) { return $entry['id'] === $participant2; }); $this->assertEquals($block1Participant2['user_id'], $userId); $this->assertEquals($block1Participant2['block_id'], $block1); - $this->assertEquals($block1Participant2['observation_count'], 0); + $this->assertEquals($block1Participant2['observation_count'], 1); $this->assertEquals($block1Participant2['id'], $participant2); $this->assertEquals($block1Participant2['scout_name'], 'Two'); $block2Participant1 = collect($data[$block2])->first(function ($entry) use($participant1) { return $entry['id'] === $participant1; }); From d6750f5149ef89967ed1d4bdcf2508420e9655a8 Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Mon, 5 Oct 2020 12:52:04 +0200 Subject: [PATCH 33/35] Automatically return to crib after creating an observation from there --- app/Http/Controllers/BlockListController.php | 5 +- .../Controllers/ObservationController.php | 15 +++-- resources/lang/de/t.php | 2 +- resources/lang/fr/t.php | 2 +- resources/views/crib.blade.php | 9 +-- tests/Feature/Crib/ReadCribTest.php | 56 ++++++++++++++++++- 6 files changed, 72 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/BlockListController.php b/app/Http/Controllers/BlockListController.php index ce622ec5..1faac287 100644 --- a/app/Http/Controllers/BlockListController.php +++ b/app/Http/Controllers/BlockListController.php @@ -5,6 +5,7 @@ use App\Models\Course; use App\Models\User; use App\Util\HtmlString; +use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Auth; @@ -24,13 +25,15 @@ public function index(Course $course) /** * Display the crib page which visualizes connections between blocks and requirements, as well as observation assignments. * + * @param Request $request * @param Course $course * @param User $user * @return Response */ - public function crib(Course $course, User $user) + public function crib(Request $request, Course $course, User $user) { $userId = $user->id ?? Auth::id(); + $request->session()->flash('return_url', $request->url()); return view('crib', [ 'blockManagementLink' => $this->blockManagementLink($course, 't.views.crib.here'), 'showObservationAssignments' => $course->observationAssignments()->count(), diff --git a/app/Http/Controllers/ObservationController.php b/app/Http/Controllers/ObservationController.php index 94f0d453..ac36ebcb 100644 --- a/app/Http/Controllers/ObservationController.php +++ b/app/Http/Controllers/ObservationController.php @@ -25,6 +25,7 @@ class ObservationController extends Controller { * @return Response */ public function create(Request $request) { + $this->rememberPreviouslyActiveView($request); return view('observation.new', ['participants' => $request->input('participant'), 'block' => $request->input('block')]); } @@ -51,15 +52,14 @@ public function store(ObservationRequest $request, Course $course) { $participant = $observation->participants()->first(); $route = route('participants.detail', ['course' => $course->id, 'participant' => $participant->id]); $flash->s(" ") - ->__('t.views.observations.back_to_participant', ['name' => $participant->scout_name]) + ->__('t.views.observations.go_to_participant', ['name' => $participant->scout_name]) ->s(' '); } - $request->session()->flash('alert-success', $flash); }); - return Redirect::route('observation.new', ['course' => $course->id, 'participant' => $data['participants'], 'block' => $data['block']]); + return $this->redirectToPreviouslyActiveView($request, $course, collect([]), route('observation.new', ['course' => $course->id, 'participant' => $data['participants'], 'block' => $data['block']])); } /** @@ -82,6 +82,7 @@ public function edit(Request $request, Course $course, Observation $observation) */ protected function rememberPreviouslyActiveView(Request $request) { $returnTo = $this->extractPathParameter(URL::previous(), 'participants.detail', 'participant'); + $request->session()->keep(['return_url']); $request->session()->flash('participant_before_edit', $request->session()->get('participant_before_edit', $returnTo)); } @@ -92,15 +93,19 @@ protected function rememberPreviouslyActiveView(Request $request) { * @param Request $request * @param Course $course * @param Collection $returnOptions a collection of participant ids that are legal to be viewed + * @param string|null $fallback * @return RedirectResponse */ - protected function redirectToPreviouslyActiveView(Request $request, Course $course, Collection $returnOptions) { + protected function redirectToPreviouslyActiveView(Request $request, Course $course, Collection $returnOptions, $fallback = null) { + if ($request->session()->has('return_url')) return Redirect::to($request->session()->get('return_url')); + $returnTo = $request->session()->get('participant_before_edit'); if (!$returnOptions->contains($returnTo)) { $returnTo = $returnOptions->first(); } - return Redirect::to(route('participants.detail', ['course' => $course->id, 'participant' => $returnTo])); + if ($returnTo) return Redirect::to(route('participants.detail', ['course' => $course->id, 'participant' => $returnTo])); + return Redirect::to($fallback ?? URL::previous()); } /** diff --git a/resources/lang/de/t.php b/resources/lang/de/t.php index b00cf3a4..ed94b9b9 100644 --- a/resources/lang/de/t.php +++ b/resources/lang/de/t.php @@ -407,7 +407,7 @@ ), "observations" => array( "add_success" => "Beobachtung erfasst. Mässi!", - "back_to_participant" => "Zurück zu :name", + "go_to_participant" => "Zu :name", "edit" => "Beobachtung bearbeiten", "edit_success" => "Beobachtung aktualisiert.", "new" => "Beobachtung erfassen", diff --git a/resources/lang/fr/t.php b/resources/lang/fr/t.php index 40324752..60ee481d 100644 --- a/resources/lang/fr/t.php +++ b/resources/lang/fr/t.php @@ -291,7 +291,7 @@ ), "observations" => array( "add_success" => "Observation saisie. Merci!", - "back_to_participant" => "Revenir à :name", + "go_to_participant" => "Venir à :name", "edit" => "Modifier l'observation", "edit_success" => "Observation actualisée", "new" => "Créer une observation", diff --git a/resources/views/crib.blade.php b/resources/views/crib.blade.php index 74ffe75d..036f918a 100644 --- a/resources/views/crib.blade.php +++ b/resources/views/crib.blade.php @@ -41,7 +41,7 @@ class="" @foreach ($day as $block) - +
{{ $block->blockname_and_number }}
@if(count($block->mandatory_requirements)) {{__('t.views.crib.mandatory_requirements')}}: @@ -57,13 +57,12 @@ class="" @endforeach @endif
- @if($showObservationAssignments) + @if($showObservationAssignments && isset($trainerObservationAssignments[$block->id])) - @if(isset($trainerObservationAssignments[$block->id]))
@foreach($trainerObservationAssignments[$block->id] as $participant) @endforeach
- @endif
@endif diff --git a/tests/Feature/Crib/ReadCribTest.php b/tests/Feature/Crib/ReadCribTest.php index cf360fc9..4e3055b1 100644 --- a/tests/Feature/Crib/ReadCribTest.php +++ b/tests/Feature/Crib/ReadCribTest.php @@ -130,10 +130,7 @@ public function test_shouldCalculateObservationAssignmentsCorrectly() { $observationAssignment->participants()->attach([$participant1, $participant2]); $observationAssignment->users()->attach(Auth::id()); - $participant1Data = Participant::find($participant1)->attributesToArray(); - $participant2Data = Participant::find($participant2)->attributesToArray(); $userId = Auth::id(); - $courseId = $this->courseId; // when $response = $this->get('/course/' . $this->courseId . '/crib'); @@ -169,4 +166,57 @@ public function test_shouldCalculateObservationAssignmentsCorrectly() { $this->assertEquals($block2Participant2['id'], $participant2); $this->assertEquals($block2Participant2['scout_name'], 'Two'); } + + public function test_shouldReturnToCrib_afterAddingObservationInAssignment() { + // given + $block1 = $this->createBlock('Block 1', '1.1', '01.01.2019'); + $block2 = $this->createBlock('Block 2', '1.2', '01.01.2019'); + $participant1 = $this->createParticipant('One'); + $participant2 = $this->createParticipant('Two'); + + $observationAssignment = ObservationAssignment::create(['name' => 'Assignment', 'course_id' => $this->courseId]); + $observationAssignment->blocks()->attach([$block1, $block2]); + $observationAssignment->participants()->attach([$participant1, $participant2]); + $observationAssignment->users()->attach(Auth::id()); + + $this->get('/course/' . $this->courseId . '/crib'); + + // when + $this->get('/course/' . $this->courseId . '/observation/new?participant=' . $participant1 . '&block=' . $block1); + $response = $this->post('/course/' . $this->courseId . '/observation/new', [ + 'participants' => '' . $participant1, + 'content' => 'hat gut mitgemacht', + 'impression' => '1', + 'block' => '' . $block1, + 'requirements' => '', + 'categories' => '' + ]); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/crib'); + } + + public function test_shouldReturnToCrib_afterAddingObservationInBlock() { + // given + $block1 = $this->createBlock('Block 1', '1.1', '01.01.2019'); + $participant1 = $this->createParticipant('One'); + + $this->get('/course/' . $this->courseId . '/crib'); + + // when + $this->get('/course/' . $this->courseId . '/observation/new'); + $response = $this->post('/course/' . $this->courseId . '/observation/new', [ + 'participants' => '' . $participant1, + 'content' => 'hat gut mitgemacht', + 'impression' => '1', + 'block' => '' . $block1, + 'requirements' => '', + 'categories' => '' + ]); + + // then + $response->assertStatus(302); + $response->assertRedirect('/course/' . $this->courseId . '/crib'); + } } From ec86cc88c9998f8dbf26fbdc7db47804fc445b2d Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Wed, 7 Oct 2020 12:16:51 +0200 Subject: [PATCH 34/35] Adapt E2E test to changed translation --- cypress/integration/observations.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/observations.spec.js b/cypress/integration/observations.spec.js index 23bcc44a..f02e76a7 100644 --- a/cypress/integration/observations.spec.js +++ b/cypress/integration/observations.spec.js @@ -36,7 +36,7 @@ describe('observation form', () => { cy.contains('Speichern').click() cy.contains('Beobachtung erfasst.') - cy.contains('Zurück zu').click() + cy.contains('Zu ').click() cy.contains('hat sich mehrmals gut eingebracht') }) From 4b9e5e13c80cfdb4b7906377805ee9f9fa2fa20e Mon Sep 17 00:00:00 2001 From: Carlo Beltrame Date: Wed, 7 Oct 2020 22:55:14 +0200 Subject: [PATCH 35/35] Allow to select entire days for observation assignments --- app/Http/Controllers/ParticipantDetailController.php | 3 --- .../views/admin/observationAssignments/edit.blade.php | 9 +++++++++ .../views/admin/observationAssignments/index.blade.php | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ParticipantDetailController.php b/app/Http/Controllers/ParticipantDetailController.php index 79633258..8e627eef 100644 --- a/app/Http/Controllers/ParticipantDetailController.php +++ b/app/Http/Controllers/ParticipantDetailController.php @@ -2,12 +2,9 @@ namespace App\Http\Controllers; -use App\Models\Category; use App\Models\Course; use App\Models\Observation; use App\Models\Participant; -use App\Models\Quali; -use App\Models\Requirement; use Illuminate\Http\Request; use Illuminate\Http\Response; diff --git a/resources/views/admin/observationAssignments/edit.blade.php b/resources/views/admin/observationAssignments/edit.blade.php index 249c656f..80bde370 100644 --- a/resources/views/admin/observationAssignments/edit.blade.php +++ b/resources/views/admin/observationAssignments/edit.blade.php @@ -31,12 +31,21 @@ display-field="scout_name" multiple> + @php + $days = $course->blocks->mapToGroups(function($block) { + return [$block->block_date->formatLocalized(__('t.global.date_format')) => $block->id]; + })->map(function($ids, $date) { + return implode(',', $ids->all()); + }); + @endphp + diff --git a/resources/views/admin/observationAssignments/index.blade.php b/resources/views/admin/observationAssignments/index.blade.php index 214e399f..5c888c74 100644 --- a/resources/views/admin/observationAssignments/index.blade.php +++ b/resources/views/admin/observationAssignments/index.blade.php @@ -30,11 +30,20 @@ required :autofocus="true"> + @php + $days = $course->blocks->mapToGroups(function($block) { + return [$block->block_date->formatLocalized(__('t.global.date_format')) => $block->id]; + })->map(function($ids, $date) { + return implode(',', $ids->all()); + }); + @endphp +