Skip to content

Commit

Permalink
Merge pull request #120 from Kamieljv/wkid_tool
Browse files Browse the repository at this point in the history
More updates on ActieWijzer
  • Loading branch information
Kamieljv authored Nov 30, 2024
2 parents 28cc029 + 06b1c9d commit 7d53321
Show file tree
Hide file tree
Showing 19 changed files with 375 additions and 155 deletions.
9 changes: 6 additions & 3 deletions app/Http/Controllers/ActieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ActieController extends VoyagerBaseController
{
public function agenda()
public function agenda(Request $request)
{
// Definieer de routes waarmee de component evenementen kan ophalen
$routes = collect(Route::getRoutes()->getRoutesByName())->filter(function ($route) {
Expand All @@ -29,10 +29,13 @@ public function agenda()
$themes = Theme::orderBy('name', 'ASC')->get();
$categories = Category::orderBy('name', 'ASC')->get();

$themes_selected_ids = $request->themes ? array_map('intval', $request->themes) : [];
$categories_selected_ids = $request->categories ? array_map('intval', $request->categories) : [];

// SEO
SEOTools::setTitle('Acties');

return view('acties.agenda', compact('routes', 'themes', 'categories'));
return view('acties.agenda', compact('routes', 'themes', 'categories', 'themes_selected_ids', 'categories_selected_ids'));
}

public function actie($slug)
Expand Down Expand Up @@ -123,7 +126,7 @@ public function search(Request $request)
if ($request->limit) {
$acties = $query->limit($request->limit)->get();
} else {
$acties = $query->paginate(12);
$acties = $query->paginate(24);
}

return response()->json(['acties' => $acties]);
Expand Down
23 changes: 17 additions & 6 deletions app/Http/Controllers/ActieWijzerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function landing()
{
$questions = Question::active()->get()->toArray();
$dimensions = Dimension::all()->toArray();
$themes = Theme::all()->toArray();
$themes = Theme::orderBy('name', 'ASC')->all()->toArray();
$result_route = route('actiewijzer.result');

// SEO
Expand Down Expand Up @@ -126,22 +126,32 @@ public function result(Request $request) {
});

// Get referentie_types and calculate the similarity with the score_vector
$referentie_types = ReferentieType::published()->with(['referenties' => function (Builder $query) {
$referentie_types = ReferentieType::published()->with(['referenties' => function (Builder $query) use ($themes) {
$query->whereHas('themes', function (Builder $query) use ($themes) {
$query->whereIn('theme_id', $themes->pluck('id')->toArray());
})->with('referentie_types');
$query->inRandomOrder()->limit(3);
}])->get();

foreach ($referentie_types as $rt) {
// calculate percentage match
$dims_filtered = array_filter($dimensions->toArray(), function($d) use ($rt) {
return in_array($d['id'], array_keys($rt->score_vector));
});
$dim_scores = array_combine(array_column($dims_filtered, 'id'), array_column($dims_filtered, 'score'));
$rt->match_perc = round(percentageMatch($dim_scores, $rt->score_vector));

// if we get 0 referenties, get 3 referenties without filtering by theme
if ($rt->referenties->count() == 0) {
$rt->referenties = ReferentieType::find($rt->id)->referenties()->with('referentie_types')->inRandomOrder()->limit(3)->get();
}
}
$referentie_types = $referentie_types->sortByDesc('match_perc');

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

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

Expand All @@ -156,20 +166,21 @@ public function referentie_type($referentie_type)
});

$themes = Theme::orderBy('name', 'ASC')->get();
$themes_selected_ids = $request->themes ? array_map('intval', $request->themes) : [];

// 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'));
return view('actiewijzer.referentie_type', compact('referentie_type', 'themes', 'routes', 'themes_selected_ids'));
}

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

$query = Referentie::query()->whereHas('referentie_types', function($q) use ($referentie_type) {
$query = Referentie::query()->with('referentie_types')->whereHas('referentie_types', function($q) use ($referentie_type) {
$q->where('referentie_type_id', $referentie_type->id);
});
if ($request->q) {
Expand All @@ -187,7 +198,7 @@ public function search(Request $request)
if ($request->limit) {
$referenties = $query->orderBy('title', 'ASC')->published()->limit($request->limit)->get();
} else {
$referenties = $query->orderBy('title', 'ASC')->published()->paginate(12);
$referenties = $query->orderBy('title', 'ASC')->published()->paginate(24);
}

return response()->json(['referenties' => $referenties]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/OrganizerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function search(Request $request)
if ($request->limit) {
$organizers = $query->orderBy('name', 'ASC')->published()->limit($request->limit)->get();
} else {
$organizers = $query->orderBy('name', 'ASC')->published()->paginate(12);
$organizers = $query->orderBy('name', 'ASC')->published()->paginate(24);
}

return response()->json(['organizers' => $organizers]);
Expand Down
11 changes: 10 additions & 1 deletion app/Models/ReferentieType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ReferentieType extends Model

protected $table = 'referentie_types';

protected $appends = [
'link'
];

protected $fillable = [
'title',
'description',
Expand All @@ -24,7 +28,6 @@ class ReferentieType extends Model
* @var array
*/
protected $with = [
'referenties',
'dimensions'
];

Expand All @@ -50,6 +53,12 @@ public function getScoreVectorAttribute()
return $score_vec;
}

public function getLinkAttribute()
{
return url('/type/' . strtolower($this->title));

}

public function scopePublished($query)
{
return $query->where('status', 'PUBLISHED');
Expand Down
1 change: 1 addition & 0 deletions resources/lang/nl/actiewijzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
'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',
'no_results_suggestion_retry_or_later' => 'Vul de ActieWijzer in met meer thema\'s of probeer het later opnieuw.',
];
3 changes: 3 additions & 0 deletions resources/lang/nl/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'written_on' => 'Geschreven op ',
'read_more' => 'Meer lezen...',
'more_info' => 'Meer info',
'load_more' => 'Meer laden',
'about' => 'Over',
'about_us' => 'Over ons',
'mark_as_read' => 'Markeer als gelezen',
Expand All @@ -35,6 +36,8 @@
'position_and_resize_photo' => 'Pas de grootte en positie van je foto aan',
'send_form' => 'Verzenden',
'no_results' => 'Geen resultaten',
'no_results_suggestion_too_many_filters' => 'Heb je misschien te veel filters ingesteld?',
'clear_filters' => 'Filter(s) wissen',
'404_header' => 'Oeps! Pagina niet gevonden...',
'500_header' => 'Oeps! Er is iets misgegaan...',
'approve' => 'Goedkeuren',
Expand Down
4 changes: 4 additions & 0 deletions resources/svg/antdesign-link-o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion resources/views/VueTailwindSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const VueTailwindSettings = {
fixedClasses: {
overlay: "z-[1001] overflow-auto scrolling-touch left-0 top-0 bottom-0 right-0 w-full h-full fixed bg-black/50",
wrapper: "relative mx-auto mt-20 max-w-lg px-3 py-12",
modal: "overflow-visible relative rounded-lg overflow-hidden",
modal: "relative rounded-lg overflow-hidden",
body: "p-3",
header: "border-b rounded-t",
footer: " p-3 rounded-b",
Expand Down Expand Up @@ -143,6 +143,14 @@ const VueTailwindSettings = {
close: "bg-red-50 text-red-700 hover:bg-red-200 border-red-100 border",
modal: "bg-white shadow-lg",
footer: "bg-red-50"
},
card: {
overlay: "",
header: "p-0",
body: "",
close: "m-3",
modal: "bg-white shadow",
footer: "bg-gray-100"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/views/acties/agenda.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
:routes="{{ $routes }}"
:themes="{{ $themes }}"
:categories="{{ $categories }}"
:themes-selected-ids="{{ json_encode($themes_selected_ids) }}"
:categories-selected-ids="{{ json_encode($categories_selected_ids) }}"
>
</actie-agenda>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/actiewijzer/referentie_type.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:routes="{{ $routes }}"
:themes="{{ $themes }}"
:referentie-type-id="{{ $referentie_type->id }}"
:themes-selected-ids="{{ json_encode($themes_selected_ids) }}"
/>
</div>
</div>
Expand Down
51 changes: 34 additions & 17 deletions resources/views/actiewijzer/result.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,42 @@ class="relative self-start inline-block px-2 py-1 mr-1 mb-1 text-xs font-medium
:limit="4"
>
</actie-agenda>
@else
<div class="grid gap-5 mx-auto mt-12 sm:grid-cols-2 lg:grid-cols-3">
@foreach ($rt->referenties->toArray() as $ref)
<Referentie
:referentie="{{json_encode($ref)}}"
> </Referentie>
@endforeach
<div class="flex items-center justify-center my-12">
<a href="{{ route('acties.agenda') . '?' . http_build_query(['themes' => array_column($themes->toArray(), 'id')])}}">
<button class="secondary flex items-center hover:translate-x-[0.250rem]">
<p class="text-lg">Bekijk alle Acties</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>
@else
@if($rt->referenties->count() > 0)
<referenties
:referenties-fixed="{{ json_encode($rt->referenties) }}"
:filterable="false"
:max="3"
/>
<div class="flex items-center justify-center my-12">
<a href="{{ route('actiewijzer.referentie_type', strtolower($rt->title)) . '?' . http_build_query(['themes' => array_column($themes->toArray(), 'id')])}}">
<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>
@else
<div class="flex flex-col justify-center items-center py-12 text-gray-400">
<h3>{{__('general.no_results')}}</h3>
<div class="flex flex-col items-center">
<p>{{ __('actiewijzer.no_results_suggestion_retry_or_later') }}</p>
</div>
</div>
@endif
@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
Loading

0 comments on commit 7d53321

Please sign in to comment.