Skip to content

Commit

Permalink
Enable groups to have their own page
Browse files Browse the repository at this point in the history
  • Loading branch information
tobifra committed Mar 1, 2024
1 parent 9d1e733 commit 8a3ea36
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 106 deletions.
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private function storeFileAndCreateThumbnail($fileData, $filename, $newFile)

$newFile->thumbnail = Storage::url($thumbnailPath);
} elseif ($newFile->extension === 'svg') {
$newFile->thumbnail = $$newFile->path;
$newFile->thumbnail = $newFile->path;
}
}

Expand Down
11 changes: 5 additions & 6 deletions api/app/Http/Controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GroupController extends Controller
public function index(Request $request)
{
$user = Auth::user();
$groups = Group::with(['file', 'section', 'predecessors', 'successors', 'parent', 'headerImages', 'files']);
$groups = Group::with(['file', 'section', 'predecessors', 'successors', 'parent']);
if ($request->has('dashboard') && $user->hasRole('unitleader')) {
$groups = $groups->whereIn('id', $user->groups->pluck('id'));
}
Expand All @@ -27,8 +27,6 @@ public function index(Request $request)
public function store(StoreGroupRequest $request)
{
$group = Group::create($request->validated());
$group->headerImages()->sync(array_column($request->input('header_images', []), 'id'));
$group->files()->sync(array_column($request->input('files', []), 'id'));

$group->predecessors()->sync($request->input('predecessors', []));
$group->successors()->sync($request->input('successors', []));
Expand All @@ -38,7 +36,7 @@ public function store(StoreGroupRequest $request)

public function show($idOrRoute)
{
$query = Group::with(['section', 'file', 'predecessors', 'successors', 'parent', 'headerImages', 'files']);
$query = Group::with(['section', 'file', 'predecessors', 'successors', 'parent', 'page', 'page.files']);
if (is_numeric($idOrRoute)) {
$group = $query->find($idOrRoute);
} else {
Expand All @@ -49,6 +47,9 @@ public function show($idOrRoute)

$group = $filteredGroups->first();
}
if($group->page){
$group->page->page_items = $group->page->getAllItems();
}

if (!$group) {
return response()->json(['message' => 'Group not found'], 404);
Expand All @@ -70,8 +71,6 @@ public function update(UpdateGroupRequest $request, $id)
}

$group->update($request->validated());
$group->headerImages()->sync(array_column($request->input('header_images', []), 'id'));
$group->files()->sync(array_column($request->input('files', []), 'id'));

$group->predecessors()->sync($request->input('predecessors', []));
$group->successors()->sync($request->input('successors', []));
Expand Down
11 changes: 11 additions & 0 deletions api/app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\FilesItem;
use App\Models\FormItem;
use App\Models\GenericItem;
use App\Models\GroupEventsItem;
use App\Models\ImageItem;
use App\Models\LocationItem;
use App\Models\Page;
Expand Down Expand Up @@ -241,6 +242,16 @@ private function createPageItemsFromValidatedData(Page $page, $validatedData)
]
);
break;
case 'groupEventsItem':
GroupEventsItem::updateOrCreate(
['id' => $pageItemData['id'] ?? null],
[
'page_id' => $page->id,
'sort' => $sort_counter,
'group_id' => $pageItemData['group_id'] ?? null,
]
);
break;
default:
throw new \InvalidArgumentException("Unsupported field type: {$pageItemData['type']}");
}
Expand Down
4 changes: 3 additions & 1 deletion api/app/Http/Requests/StorePageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public function rules()
'route' => 'string|max:255|unique:pages|required',
'big_header' => 'boolean|nullable',
'files' => 'array|nullable',
'group_id' => 'nullable|unique:pages,group_id',
'page_items' => 'nullable|array',
'page_items.*.id' => 'nullable',
'page_items.*.sort' => 'required',
'page_items.*.type' => 'required|string|in:textItem,imageItem,formItem,filesItem,contactItem,groupsItem,sectionsItem,campsItem,locationItem,faqItem',
'page_items.*.type' => 'required|string|in:textItem,imageItem,formItem,filesItem,contactItem,groupsItem,sectionsItem,campsItem,locationItem,faqItem,groupEventsItem',
'page_items.*.title' => 'nullable',
'page_items.*.body' => 'nullable',
'page_items.*.show_fleur_de_lis' => 'nullable',
Expand All @@ -25,6 +26,7 @@ public function rules()
'page_items.*.form_id' => 'nullable',
'page_items.*.location_id' => 'nullable',
'page_items.*.faq_id' => 'nullable',
'page_items.*.group_id' => 'nullable',
];
}
}
6 changes: 4 additions & 2 deletions api/app/Http/Requests/UpdatePageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ public function rules()
{
return [
'title' => 'sometimes|required|string|max:255',
'route' => 'sometimes|required|string|max:255|unique:pages',
'route' => 'sometimes|required|string|max:255',
'big_header' => 'boolean|nullable',
'files' => 'nullable',
'group_id' => 'nullable',
'page_items' => 'nullable|array',
'page_items.*.id' => 'nullable',
'page_items.*.sort' => 'required',
'page_items.*.type' => 'required|string|in:textItem,imageItem,formItem,filesItem,contactItem,groupsItem,sectionsItem,campsItem,locationItem,faqItem',
'page_items.*.type' => 'required|string|in:textItem,imageItem,formItem,filesItem,contactItem,groupsItem,sectionsItem,campsItem,locationItem,faqItem,groupEventsItem',
'page_items.*.title' => 'nullable',
'page_items.*.body' => 'nullable',
'page_items.*.show_fleur_de_lis' => 'nullable',
'page_items.*.files' => 'nullable',
'page_items.*.form_id' => 'nullable',
'page_items.*.location_id' => 'nullable',
'page_items.*.faq_id' => 'nullable',
'page_items.*.group_id' => 'nullable',
];
}
}
18 changes: 9 additions & 9 deletions api/app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,20 @@ class Group extends Model
'enable_group_page',
];

protected $appends = ['route'];
protected $appends = ['route','has_page'];

public function getRouteAttribute()
{
return $this->toCamelCase($this->name);
}


public function headerImages()
public function getHasPageAttribute()
{
return $this->belongsToMany(File::class, 'group_headers');

return $this->page ? true : false;
}

public function files()
{
return $this->belongsToMany(File::class, 'group_files');

}


public function section()
{
Expand All @@ -68,4 +63,9 @@ public function successors()
{
return $this->belongsToMany(Group::class, 'group_successor', 'group_id', 'successor_id');
}

public function page()
{
return $this->hasOne(Page::class);
}
}
30 changes: 30 additions & 0 deletions api/app/Models/GroupEventsItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GroupEventsItem extends Model
{
use HasFactory;

protected $fillable = ['group_id', 'sort', 'page_id'];

protected $appends = ['type'];

public function getTypeAttribute()
{
return "groupEventsItem";
}

public function page()
{
return $this->belongsTo(Page::class);
}

public function group()
{
return $this->belongsTo(Group::class);
}
}
15 changes: 14 additions & 1 deletion api/app/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Page extends Model
{
protected $fillable = ['title', 'route', 'file_ids', 'big_header'];
protected $fillable = ['title', 'route', 'file_ids', 'big_header', 'group_id'];

protected $hidden = ['textItems', 'imageItems', 'formItems', 'filesItems', 'genericItems'];

Expand All @@ -17,6 +17,11 @@ public function files()

}

public function group()
{
return $this->belongsTo(Group::class);
}

public function textItems()
{

Expand Down Expand Up @@ -65,6 +70,12 @@ public function faqItems()
return $this->hasMany(FaqItem::class)->with('faq')->with('faq.questions');
}

public function groupEventsItems()
{

return $this->hasMany(GroupEventsItem::class)->with('group');
}

public function genericItems()
{

Expand All @@ -82,6 +93,7 @@ public function getAllItems()
$genericItems = $this->genericItems;
$locationItems = $this->locationItems;
$faqItems = $this->faqItems;
$groupEventsItems = $this->groupEventsItems;

$items = $items->concat($textItems);
$items = $items->concat($imageItems);
Expand All @@ -90,6 +102,7 @@ public function getAllItems()
$items = $items->concat($genericItems);
$items = $items->concat($locationItems);
$items = $items->concat($faqItems);
$items = $items->concat($groupEventsItems);

$items = $items->sortBy('sort')->values()->all();;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('pages', function (Blueprint $table) {
$table->unsignedBigInteger('group_id')->nullable()->after('id');
$table->foreign('group_id')->references('id')->on('groups')->onDelete('set null');
});
Schema::table('groups', function (Blueprint $table) {
$table->dropColumn('description');
$table->dropColumn('enable_group_page');
});

Schema::dropIfExists('group_headers');

Schema::dropIfExists('group_files');

Schema::create('group_events_items', function (Blueprint $table) {
$table->id();
$table->foreignId('group_id')->nullable()->constrained()->onDelete('cascade');
$table->integer('sort')->nullable();
$table->unsignedBigInteger('page_id');
$table->foreign('page_id')->references('id')->on('pages')->onDelete('cascade');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('group_events_items');
Schema::create('group_headers', function (Blueprint $table) {
$table->foreignId('group_id')->constrained()->onDelete('cascade');
$table->foreignId('file_id')->constrained()->onDelete('cascade');
$table->timestamps();
});

Schema::create('group_files', function (Blueprint $table) {
$table->foreignId('group_id')->constrained()->onDelete('cascade');
$table->foreignId('file_id')->constrained()->onDelete('cascade');
$table->timestamps();
});

Schema::table('groups', function (Blueprint $table) {
$table->text('description')->nullable();
$table->boolean('enable_group_page')->default(0);
});
Schema::table('pages', function (Blueprint $table) {
$table->dropForeign(['group_id']);
$table->dropColumn('group_id');
});
}
};
7 changes: 0 additions & 7 deletions api/database/seeders/GroupsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 1,
'file_id' => 1,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:00:24',
'updated_at' => '2023-12-19 21:52:51',
),
Expand All @@ -47,7 +46,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 2,
'file_id' => 2,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:04:00',
'updated_at' => '2023-12-19 21:52:56',
),
Expand All @@ -63,7 +61,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 2,
'file_id' => 3,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:04:44',
'updated_at' => '2023-12-19 21:53:09',
),
Expand All @@ -79,7 +76,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 3,
'file_id' => 4,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:19:05',
'updated_at' => '2023-12-19 21:53:19',
),
Expand All @@ -95,7 +91,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 3,
'file_id' => 5,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:19:38',
'updated_at' => '2023-12-19 21:53:30',
),
Expand All @@ -111,7 +106,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 4,
'file_id' => 6,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:20:21',
'updated_at' => '2023-12-19 21:53:36',
),
Expand All @@ -127,7 +121,6 @@ public function run()
'parent_id' => NULL,
'section_id' => 5,
'file_id' => 7,
'description' => '<p class="main-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>',
'created_at' => '2023-12-11 13:21:05',
'updated_at' => '2023-12-19 21:53:41',
),
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/admin/AddPageItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
{ name: this.$t("dashboard.camps"), type: "campsItem" },
{ name: this.$t("dashboard.location"), type: "locationItem" },
{ name: this.$t("dashboard.faq"), type: "faqItem" },
{ name: this.$t("dashboard.groupEvents"), type: "groupEventsItem" },
],
};
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/admin/CheckBox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="flex flex-col">
<FormLabel v-if="label">{{ label }}</FormLabel>
<div class="h-9 flex items-center">
<label class="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
Expand All @@ -13,6 +14,7 @@
></div>
</label>
</div>
</div>
</template>
<script>
import FormLabel from "./FormLabel.vue";
Expand Down
Loading

0 comments on commit 8a3ea36

Please sign in to comment.