Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Oct 16, 2023
1 parent 079a675 commit adeeabb
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 17 deletions.
37 changes: 29 additions & 8 deletions app/Http/Controllers/Admin/Data/FaqController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ class FaqController extends Controller {
*/
public function getFaqIndex(Request $request) {
$query = Faq::query();
$data = $request->only(['faq_category_id', 'name']);
if (isset($data['faq_category_id']) && $data['faq_category_id'] != 'none') {
$query->where('faq_category_id', $data['faq_category_id']);
$data = $request->only(['content', 'tags']);
if (isset($data['content'])) {
$content = $data['content'];
$query->where(function ($query) use ($content) {
$query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%');
});
}
if (isset($data['name'])) {
$query->where('name', 'LIKE', '%'.$data['name'].'%');

if (isset($data['tags'])) {
foreach ($data['tags'] as $tag) {
// json decode the tag column
$query->whereJsonContains('tags', $tag);
}
}

$tags = Config::get('lorekeeper.faq');
// tags is an array of names, make it so their key is their name also
$tags = array_combine($tags, $tags);
$tags = array_map(function ($tag) {
return ucwords($tag);
}, $tags);
ksort($tags);
return view('admin.faq.faq', [
'faqs' => $query->paginate(20)->appends($request->query()),
'tags' => Config::get('lorekeeper.faq'),
Expand All @@ -49,10 +63,13 @@ public function getCreateFaqQuestion() {
$tags = Config::get('lorekeeper.faq');
// tags is an array of names, make it so their key is their name also
$tags = array_combine($tags, $tags);
$tags = array_map(function ($tag) {
return ucwords($tag);
}, $tags);
ksort($tags);
return view('admin.faq.create_edit_question', [
'faq' => new Faq,
'tags' => $tags,

]);
}

Expand All @@ -71,6 +88,10 @@ public function getEditFaqQuestion($id) {
$tags = Config::get('lorekeeper.faq');
// tags is an array of names, make it so their key is their name also
$tags = array_combine($tags, $tags);
$tags = array_map(function ($tag) {
return ucwords($tag);
}, $tags);
ksort($tags);
return view('admin.faq.create_edit_question', [
'faq' => $faq,
'tags' => $tags,
Expand Down Expand Up @@ -115,7 +136,7 @@ public function postCreateEditFaqQuestion(Request $request, FaqService $service,
public function getDeleteFaqQuestion($id) {
$faq = Faq::find($id);

return view('admin.faqs._delete_faq', [
return view('admin.faq._delete_question', [
'faq' => $faq,
]);
}
Expand All @@ -137,6 +158,6 @@ public function postDeleteFaqQuestion(Request $request, FaqService $service, $id
}
}

return redirect()->to('admin/data/faqs');
return redirect()->to('admin/data/faq');
}
}
8 changes: 6 additions & 2 deletions app/Http/Controllers/BrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,12 @@ public function getFaq(Request $request) {
$tags = Config::get('lorekeeper.faq');
// tags is an array of names, make it so their key is their name also
$tags = array_combine($tags, $tags);
$tags = array_map(function ($tag) {
return ucwords($tag);
}, $tags);
ksort($tags);
return view('browse.faq', [
'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->get(),
'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->orderBy('created_at', 'DESC')->get(),
'tags' => $tags,
]);
}
Expand All @@ -673,7 +677,7 @@ public function getFaqSearch(Request $request) {
$query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%');
});
}
})->get(),
})->orderBy('created_at', 'DESC')->get(),
]);
}
}
7 changes: 6 additions & 1 deletion config/lorekeeper/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
'lorekeeper',
'world',
'species',
'guidelines'
'guidelines',
'redesigns',
'myos',
'items',
'prompts',
'events'

];
20 changes: 20 additions & 0 deletions resources/views/admin/faq/_delete_question.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@if ($faq)
{!! Form::open(['url' => 'admin/data/faq/delete/' . $faq->id]) !!}

<p>
You are about to delete the question
<br>
<strong>{{ $faq->question }}</strong>
<br>
This is not reversible.
</p>
<p>Are you sure you want to delete it?</p>

<div class="text-right">
{!! Form::submit('Delete Question', ['class' => 'btn btn-danger']) !!}
</div>

{!! Form::close() !!}
@else
Invalid question selected.
@endif
13 changes: 10 additions & 3 deletions resources/views/admin/faq/faq.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
</div>

<div>
{!! Form::open(['method' => 'GET', 'class' => 'form-inline justify-content-end']) !!}
{!! Form::open(['method' => 'GET', 'class' => 'text-right justify-content-end']) !!}
<div class="form-group mr-3 mb-3">
{!! Form::text('name', Request::get('name'), ['class' => 'form-control', 'placeholder' => 'Name']) !!}
{!! Form::text('content', Request::get('content'), ['class' => 'form-control col-md-6 ml-auto', 'placeholder' => 'Question or Answer Content']) !!}
</div>
<div class="form-group mr-3 mb-3">
{!! Form::select('tags', $tags, Request::get('tags'), ['class' => 'form-control']) !!}
{!! Form::select('tags[]', $tags, Request::get('tags'), ['class' => 'form-control selectize col-md-6 ml-auto', 'multiple', 'placeholder' => 'Select Tags']) !!}
</div>
<div class="form-group mb-3">
{!! Form::submit('Search', ['class' => 'btn btn-primary']) !!}
Expand Down Expand Up @@ -82,3 +82,10 @@
{!! $faqs->render() !!}
@endif
@endsection
@section('scripts')
<script>
$(document).ready(function() {
$('.selectize').selectize();
});
</script>
@endsection
3 changes: 2 additions & 1 deletion resources/views/browse/_faq_question.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@endif
{{ $faq->question }}
@if ($faq->tags)
@foreach (json_decode($faq->tags) as $tag)
@php $question_tags = json_decode($faq->tags); ksort($question_tags); @endphp
@foreach ($question_tags as $tag)
<div class="badge badge-primary mx-1" style="float: right;">{{ $tag }}</div>
@endforeach
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/browse/faq.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script>
$(document).ready(function() {
$('#tags').selectize({
maxItems: 3
maxItems: 5
});
// search on keyword change
Expand Down
1 change: 0 additions & 1 deletion routes/lorekeeper/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,4 @@
Route::group(['prefix' => 'faq',], function () {
Route::get('/', 'BrowseController@getFaq');
Route::get('/search', 'BrowseController@getFaqSearch');
Route::get('{slug}', 'BrowseController@getFaqQuestion');
});

0 comments on commit adeeabb

Please sign in to comment.