Skip to content

Commit

Permalink
Added index pages for Referenties
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamieljv committed Jul 18, 2024
1 parent e1a8d2c commit 350658c
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/Http/Controllers/ActieWijzerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Answer;
use App\Models\Question;
use App\Models\Dimension;
use App\Models\Referentie;
use App\Models\ReferentieType;
use App\Models\Theme;
use Artesaos\SEOTools\Facades\SEOTools;
Expand Down Expand Up @@ -139,4 +140,56 @@ public function result(Request $request) {

return view('actiewijzer.result', compact('themes', 'dimensions', 'referentie_types', 'routes'));
}

public function referentie_type($referentie_type)
{
$referentie_type = ReferentieType::where('title', $referentie_type)->firstOrFail();

// Definieer de routes waarmee de component evenementen kan ophalen
$routes = collect(Route::getRoutes()->getRoutesByName())->filter(function ($route) {
return strpos($route->uri, 'referenties') !== false && (strpos($route->uri, 'admin') === false);
})->map(function ($route) {
return [
'uri' => '/' . $route->uri,
'methods' => $route->methods,
];
});

$themes = Theme::orderBy('name', 'ASC')->get();

// SEO
SEOTools::setTitle($referentie_type->title);
SEOTools::setDescription($referentie_type->description);
SEOMeta::setKeywords($referentie_type->title);

return view('actiewijzer.referentie_type', compact('referentie_type', 'themes', 'routes'));
}

public function search(Request $request)
{
$referentie_type = ReferentieType::find($request->referentieTypeId);

$query = Referentie::query()->whereHas('referentie_types', function($q) use ($referentie_type) {
$q->where('referentie_type_id', $referentie_type->id);
});
if ($request->q) {
$query->where(function ($q) use ($request) {
$q->where('title', 'LIKE', '%' . $request->q . '%')
->orWhere('description', 'LIKE', '%' . $request->q . '%');
});
}
if ($request->themes) {
$requestThemes = $request->themes;
$query->whereHas('themes', function ($q) use ($requestThemes) {
$q->whereIn('theme_id', $requestThemes);
});
}
if ($request->limit) {
$referenties = $query->orderBy('title', 'ASC')->published()->limit($request->limit)->get();
} else {
$referenties = $query->orderBy('title', 'ASC')->published()->paginate(12);
}

return response()->json(['referenties' => $referenties]);
}
}
1 change: 1 addition & 0 deletions resources/lang/nl/actiewijzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
'results_summary_header' => 'Jouw actieprofiel',
'results_summary_body' => 'Dit zijn de voorkeuren die je hebt aangegeven. Op basis van deze scores stellen we jouw persoonlijke suggesties voor actie samen.',
'back_to_actiewijzer' => 'Terug naar ActieWijzer',
'back_to_actiewijzer_result' => 'Terug naar Resultaat ActieWijzer',
];
37 changes: 37 additions & 0 deletions resources/views/actiewijzer/referentie_type.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@extends('layouts.app')

@section('content')

<div class="max-w-6xl mx-auto mt-10 px-5 flex">
<a href="{{ url()->previous() }}" class="flex items-center text-sm font-bold cursor-pointer text-gray-700">
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
{{ __("actiewijzer.back_to_actiewijzer_result") }}
</a>
</div>

<div class="max-w-6xl mx-auto mt-6 px-5">
<h1>{{ $referentie_type->title }}</h1>
<p class="mt-4">
{!! $referentie_type->description !!}
</p>
</div>

<div class="max-w-6xl mx-auto mt-6 px-5">
<div id="app" class="mb-40">
<referenties
:routes="{{ $routes }}"
:themes="{{ $themes }}"
:referentie-type-id="{{ $referentie_type->id }}"
/>
</div>
</div>

@endsection

@push('scripts')
<script type="application/javascript">
var app = new Vue({
el: '#app',
});
</script>
@endpush
10 changes: 10 additions & 0 deletions resources/views/actiewijzer/result.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ class="relative self-start inline-block px-2 py-1 mr-1 mb-1 text-xs font-medium
@endforeach
</div>
@endif
<div class="flex items-center justify-center my-12">
<a href="{{ route('actiewijzer.referentie_type', strtolower($rt->title)) }}">
<button class="secondary flex items-center hover:translate-x-[0.250rem]">
<p class="text-lg">Bekijk alles van {{ $rt->title }}</p>
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mr-2 ml-1" style="transform: rotate(180deg);">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
</svg>
</button>
</a>
</div>
</div>
@endforeach
</div>
Expand Down
185 changes: 185 additions & 0 deletions resources/views/assets/js/components/apps/Referenties.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<template>
<div>
<div class="row mx-auto max-w-6xl">
<div id="filter-container" class="row my-3">
<h3 class="mt-8 mb-3 text-sm text-gray-900">Zoek & Filter</h3>
<div id="filter-wrapper" class="col grid gap-3" :class="{'grid-cols-2': themes.length > 0}">
<FormField
v-model="query"
:value="query"
name="query"
type="text"
placeholder="Zoeken..."
@input="processQuery"
:clearable="true"
autofocus
classes="block w-full h-full px-3 py-2 transition duration-100 ease-in-out border rounded shadow-sm focus:ring-2 focus:ring-blue-500 focus:outline-none focus:ring-opacity-50 disabled:opacity-50 disabled:cursor-not-allowed text-black placeholder-gray-400 bg-white border-gray-300 focus:border-blue-500"
/>
<t-rich-select
v-if="themes.length > 0"
id="theme-selector"
:options="themes"
textAttribute="name"
v-model="themesSelected"
:multiple="true"
:closeOnSelect="false"
placeholder="Thema..."
searchBoxPlaceholder="Zoeken..."
:minimumResultsForSearch="5"
noResultsText="Geen resultaten"
/>
</div>
</div>
</div>
<div class="row mx-auto max-w-6xl mb-8" >
<div class="col" style="width: 100%">
<div class="relative mx-auto w-full">
<div class="relative mx-auto max-w-7xl">
<div v-if="!isGeladen" class="grid gap-5 mx-auto mt-12 sm:grid-cols-2 lg:grid-cols-3">
<t-card
v-for="i in skeletonArray"
:key="i"
variant="skeleton"
class="rounded-lg shadow-md overflow-hidden"
>
<template v-slot:header>
<div class="h-6 w-20 inline-block bg-gray-100 rounded"/>
</template>
<div class="relative h-6 w-full inline-block bg-gray-200 rounded"></div>
<div class="relative h-3 w-full inline-block bg-gray-200 rounded"></div>
</t-card>
</div>
<div v-else-if="heeftReferenties" class="grid gap-5 mx-auto mt-12 sm:grid-cols-2 lg:grid-cols-3">
<Referentie
v-for="referentie in referentiesFormatted"
:key="referentie.id"
:referentie="referentie"
/>
</div>
<div v-else-if="isGeladen" class="flex justify-center items-center py-8">
<div class="text-gray-400">
<h3>{{__('general.no_results')}}</h3>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Pagination -->
<pagination
:v-show="showPagination"
:current="currentPage"
:total="total"
:per-page="perPage"
:baseLink="base_link"
@page-changed="getReferenties"
/>
</div>
</template>

<script>
import Pagination from "../partials/Pagination.vue"
export default {
name: "Referenties",
components: {Pagination},
props: {
referentieTypeId: {
type: Number,
required: true,
},
routes: {
type: Object,
required: true,
},
themes: {
type: Array,
default: () => [],
},
showThemes: {
type: Boolean,
default: true,
},
showPagination: {
type: Boolean,
default: true
},
max: {
type: Number,
default: null,
},
},
data() {
return {
referenties: [],
themesSelected: "",
query: "",
isGeladen: false,
heeftFout: false,
currentPage: null,
perPage: null,
total: null,
base_link: null,
}
},
computed: {
skeletonArray() {
return [...Array(9).keys()]
},
heeftReferenties() {
return (this.referenties.length > 0)
},
referentiesFormatted() {
this.referenties.forEach((referentie) => {
referentie.description = referentie.description ? referentie.description.replace(/(<([^>]+)>)/gi, "") : null
return referentie
})
return this.referenties
},
},
watch: {
query: function() {
this.getReferenties()
},
themesSelected: function() {
this.getReferenties()
},
},
mounted() {
this.getReferenties();
console.log(this.referentie_type)
},
methods: {
getReferenties: _.debounce(async function getReferenties(page = 1) {
this.isGeladen = false
this.heeftFout = false
axios.get(this.routes["referenties.search"].uri, {
params: {
referentieTypeId: this.referentieTypeId,
q: this.query,
themes: this.themesSelected,
page: page,
limit: this.max ?? null
}
}).then((response) => {
if ('per_page' in response.data.referenties) {
this.referenties = response.data.referenties.data
this.currentPage = response.data.referenties.current_page
this.perPage = response.data.referenties.per_page
this.total = response.data.referenties.total
this.base_link = response.data.referenties.first_page_url
} else {
this.referenties = response.data.referenties
}
}).catch((error) => {
this.heeftFout = true
}).finally(() => {
this.isGeladen = true
})
}, 500),
processQuery: _.debounce(function(input) {
this.query = input
}, 500)
}
}
</script>
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
// ActieWijzer
Route::get('actiewijzer', [ActieWijzerController::class, 'landing'])->name('actiewijzer.landing');
Route::get('actiewijzer/result', [ActieWijzerController::class, 'result'])->name('actiewijzer.result');
Route::get('type/{referentie_type}', [ActieWijzerController::class, 'referentie_type'])->name('actiewijzer.referentie_type');
Route::get('referenties/search', [ActieWijzerController::class, 'search'])->name('referenties.search');


// Newsletter (subscriber) routes
Route::get('nieuwsbrief', [SubscriberController::class, 'landing'])->name('subscribers.landing');
Expand Down

0 comments on commit 350658c

Please sign in to comment.