Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add filter to journal #6758

Merged
merged 10 commits into from
Nov 6, 2023
20 changes: 18 additions & 2 deletions app/Http/Controllers/JournalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ public function index()
*
* @return array
*/
public function list()
public function list(Request $request)
{

$startDate = $request->input('start_date');
$endDate = $request->input('end_date');
$sortBy = $request->input('sort_by', 'created_at');
$sortOrder = $request->input('sort_order', 'desc');
$perPage = $request->input('per_page', 30);

$entries = collect([]);
$journalEntries = auth()->user()->account->journalEntries()->paginate(30);

$journalEntriesQuery = auth()->user()->account->journalEntries();

if ($startDate && $endDate) {
$journalEntriesQuery->whereDate('date', '>=', $startDate)
->whereDate('date', '<=', $endDate);
}
$journalEntries = $journalEntriesQuery->orderBy($sortBy, $sortOrder)
->paginate($perPage);


// this is needed to determine if we need to display the calendar
// (month + year) next to the journal entry
Expand Down
95 changes: 75 additions & 20 deletions resources/js/components/journal/JournalList.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
<style scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity .4s
transition: opacity .4s
}
</style>

<template>
<div class="mw9 center">
<!-- Left sidebar -->
<div :class="[ dirltr ? 'fl' : 'fr' ]" class="w-70-ns w-100 pa2">
<div :class="[dirltr ? 'fl' : 'fr']" class="w-70-ns w-100 pa2">

Check warning on line 11 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Expected 1 line break after opening tag (`<div>`), but 2 line breaks found

<!-- Filters -->
<div class="filter mb-4">
<div class="d-flex pb-2">
<div class="dt">
<label for="start-date">{{ $t('journal.start_date') }}:</label>
<input type="date" id="start-date" class="form-control" v-model="startDate">

Check failure on line 18 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Require self-closing on HTML void elements (<input>)

Check warning on line 18 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "id" should go before "type"

Check warning on line 18 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "v-model" should go before "class"
</div>
<div class="dt pl-2">
<label for="end-date py-2">{{ $t('journal.end_date') }}:</label>
<input type="date" id="end-date" class="form-control" v-model="endDate">

Check failure on line 22 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Require self-closing on HTML void elements (<input>)

Check warning on line 22 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "id" should go before "type"

Check warning on line 22 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "v-model" should go before "class"
</div>
<div class="dt pl-2">
<label for="per-page">{{ $t('journal.per_page') }}:</label>
<input type="number" id="per-page" class="form-control" v-model="perPage">

Check failure on line 26 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Require self-closing on HTML void elements (<input>)

Check warning on line 26 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "id" should go before "type"

Check warning on line 26 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "v-model" should go before "class"
</div>
<div class="dt pl-2">
<label for="sort-order">{{ $t('journal.sort_order') }} :</label>
<select id="sort-order" class="form-control" v-model="sortOrder">

Check warning on line 30 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Attribute "v-model" should go before "class"
<option value="asc">{{ $t('journal.ascending') }}</option>

Check warning on line 31 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Expected 1 line break after opening tag (`<option>`), but no line breaks found

Check warning on line 31 in resources/js/components/journal/JournalList.vue

View workflow job for this annotation

GitHub Actions / Build Assets

Expected 1 line break before closing tag (`</option>`), but no line breaks found
<option value="desc">{{ $t('journal.descending') }}</option>
</select>
</div>
</div>
<button @click="getEntries" class="btn btn-primary">{{ $t('journal.apply_filter') }}</button>
</div>


<!-- How was your day -->
<journal-rate-day @hasRated="hasRated" />

<!-- Logs -->
<div v-if="journalEntries.data" v-cy-name="'journal-entries-body'" v-cy-items="journalEntries.data.map(j => j.id)" :cy-object-items="journalEntries.data.map(j => j.object.id)">
<div v-for="journalEntry in journalEntries.data" :key="journalEntry.id" v-cy-name="'entry-body-' + journalEntry.id" class="cf">
<journal-content-rate v-if="journalEntry.journalable_type === 'App\\Models\\Journal\\Day'" :journal-entry="journalEntry" @deleteJournalEntry="deleteJournalEntry" />

<journal-content-activity v-else-if="journalEntry.journalable_type === 'App\\Models\\Account\\Activity'" :journal-entry="journalEntry" />

<journal-content-entry v-else-if="journalEntry.journalable_type === 'App\\Models\\Journal\\Entry'" :journal-entry="journalEntry" @deleteJournalEntry="deleteJournalEntry" />
<div v-if="journalEntries.data" v-cy-name="'journal-entries-body'" v-cy-items="journalEntries.data.map(j => j.id)"
:cy-object-items="journalEntries.data.map(j => j.object.id)">
<div v-for="journalEntry in journalEntries.data" :key="journalEntry.id"
v-cy-name="'entry-body-' + journalEntry.id" class="cf">
<journal-content-rate v-if="journalEntry.journalable_type === 'App\\Models\\Journal\\Day'"
:journal-entry="journalEntry" @deleteJournalEntry="deleteJournalEntry" />

<journal-content-activity v-else-if="journalEntry.journalable_type === 'App\\Models\\Account\\Activity'"
:journal-entry="journalEntry" />

<journal-content-entry v-else-if="journalEntry.journalable_type === 'App\\Models\\Journal\\Entry'"
:journal-entry="journalEntry" @deleteJournalEntry="deleteJournalEntry" />
</div>
</div>

<div v-if="(journalEntries.per_page * journalEntries.current_page) <= journalEntries.total" class="br3 ba b--gray-monica bg-white pr3 pb3 pt3 mb3 tc">
<div v-if="(journalEntries.per_page * journalEntries.current_page) <= journalEntries.total"
class="br3 ba b--gray-monica bg-white pr3 pb3 pt3 mb3 tc">
<p class="mb0 pointer" @click="loadMore()">
<span v-if="!loadingMore">
{{ $t('app.load_more') }}
Expand All @@ -34,7 +68,8 @@
</p>
</div>

<div v-if="journalEntries.total === 0" v-cy-name="'journal-blank-state'" class="br3 ba b--gray-monica bg-white pr3 pb3 pt3 mb3 tc">
<div v-if="journalEntries.total === 0" v-cy-name="'journal-blank-state'"
class="br3 ba b--gray-monica bg-white pr3 pb3 pt3 mb3 tc">
<div class="tc mb4">
<img src="img/journal/blank.svg" :alt="$t('journal.journal_empty')" />
</div>
Expand All @@ -46,7 +81,7 @@
</div>

<!-- Right sidebar -->
<div :class="[ dirltr ? 'fl' : 'fr' ]" class="w-30-ns w-100 pa2">
<div :class="[dirltr ? 'fl' : 'fr']" class="w-30-ns w-100 pa2">
<a v-cy-name="'add-entry-button'" href="journal/add" class="btn btn-primary w-100 mb4">
{{ $t('journal.journal_add') }}
</a>
Expand All @@ -68,15 +103,19 @@
showSadSmileyColor: false,
showHappySmileyColor: false,
loadingMore: false,

startDate: '',
endDate: '',
sortBy: 'created_at', // Specify the field to sort by (e.g., 'created_at', 'updated_at')
sortOrder: 'desc', // Specify the sort order ('asc' or 'desc')
perPage: 30, // Specify the number of entries per page
};
},

computed: {
dirltr() {
return this.$root.htmldir === 'ltr';
},
hasMorePage: function() {
hasMorePage: function () {
var total = this.journalEntries.per_page * this.journalEntries.current_page;

if (total >= this.journalEntries.total) {
Expand All @@ -97,7 +136,15 @@
},

getEntries() {
axios.get('journal/entries')
axios.get('journal/entries', {
params: {
start_date: this.startDate,
end_date: this.endDate,
per_page: this.perPage,
sort_order: this.sortOrder,
sort_by: this.sortBy,
},
})
.then(response => {
this.journalEntries = response.data;
this.journalEntries.current_page = response.data.current_page;
Expand All @@ -109,28 +156,36 @@
},

// This event is omited from the child component
deleteJournalEntry: function($journalEntryId) {
deleteJournalEntry: function ($journalEntryId) {
// check if the deleted entry date is today. If that's the case
// we need to put back the Rate box. This is only necessary if
// the user does all his actions on the same page without ever
// reloading the page.
this.journalEntries.data.filter(function(obj) {
this.journalEntries.data.filter(function (obj) {
return obj.id === $journalEntryId;
});

// Filter out the array without the deleted Journal Entry
this.journalEntries.data = this.journalEntries.data.filter(function(element) {
this.journalEntries.data = this.journalEntries.data.filter(function (element) {
return element.id !== $journalEntryId;
});
},

hasRated: function(journalObject) {
hasRated: function (journalObject) {
this.journalEntries.data.unshift(journalObject);
},

loadMore() {
this.loadingMore = true;
axios.get('journal/entries?page=' + (this.journalEntries.current_page + 1))
axios.get('journal/entries?page=' + (this.journalEntries.current_page + 1),{
params: {
start_date: this.startDate,
end_date: this.endDate,
per_page: this.perPage,
sort_order: this.sortOrder,
sort_by: this.sortBy,
},
})
.then(response => {
this.journalEntries.current_page = response.data.current_page;
this.journalEntries.next_page_url = response.data.next_page_url;
Expand Down
7 changes: 7 additions & 0 deletions resources/lang/ar/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'قم بتدوين مذكرتك الأولى',
'journal_blank_description' => 'المذكرة تدَعُك تدون الأحداث التي حصلت لك، لتتذكرها.',
'delete_confirmation' => 'هل أنت متأكد من حذف تدوين هذه المذكرة؟',
'apply_filter' => 'طبق الفلترة',
"start_date" => "تاريخ البدء" ,
"end_date" => "تاريخ الانتهاء" ,
"per_page" => "لكل صفحة" ,
'Sort_order' => 'فرز حسب تاريخ الإنشاء',
"ascending" => "تصاعدي" ,
"descending" => "تنازلي" ,
];
7 changes: 7 additions & 0 deletions resources/lang/cs/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Přidej svůj první deníkový záznam',
'journal_blank_description' => 'Deník umožňuje zaznamenávání událostí které se staly a ulehčuje jejich zapamatování.',
'delete_confirmation' => 'Opravdu chcete smazat tento deníkový záznam?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/da/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/de/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Schreibe deinen ersten Eintrag',
'journal_blank_description' => 'Im Tagebuch kannst du deine Erlebnisse festhalten und dich später an sie erinnern.',
'delete_confirmation' => 'Willst du diesen Eintrag wirklich löschen?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/el/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Προσθέστε την πρώτη καταχώρηση ημερολογίου',
'journal_blank_description' => 'Το ημερολόγιο σας επιτρέπει να γράφετε γεγονότα που σας συνέβησαν και να τα θυμάστε.',
'delete_confirmation' => 'Είστε βέβαιοι ότι θέλετε να διαγράψετε αυτή την καταχώρηση ημερολογίου;',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/en-GB/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/en/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/es/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Añade tu primera entrada de diario',
'journal_blank_description' => 'El diario te permite escribir eventos que te han pasado y recordarlos.',
'delete_confirmation' => '¿Seguro que deseas eliminar esta entrada de tu diario?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/fa/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/fi/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/fr/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Ajouter votre première entrée dans le journal',
'journal_blank_description' => 'Le journal vous permet de vous rappeler d’évènements passés, ou à venir.',
'delete_confirmation' => 'Êtes-vous sûr de vouloir supprimer cette entrée ?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/he/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'ניתן להוסיף את רשומת היומן הראשונה שלך',
'journal_blank_description' => 'היומן מאפשר לך לכתוב אירועים שעברו עליך ולזכור אותם.',
'delete_confirmation' => 'למחוק את הרשומה הזאת ביומן?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/hr/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/id/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Tambahkan entri jurnal pertama Anda',
'journal_blank_description' => 'Jurnal memungkinkan Anda menulis peristiwa yang terjadi pada Anda, dan mengingatnya.',
'delete_confirmation' => 'Apakah Anda yakin ingin menghapus entri jurnal ini?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/it/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Scrivi qualcosa nel diario',
'journal_blank_description' => 'Il diario ti permette di appuntare cose che ti succedono, e ricordarle.',
'delete_confirmation' => 'Sei sicuro di voler rimuovere questa pagina dal diario?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
7 changes: 7 additions & 0 deletions resources/lang/ja/journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@
'journal_blank_cta' => 'Add your first journal entry',
'journal_blank_description' => 'The journal lets you write events that happened to you, and remember them.',
'delete_confirmation' => 'Are you sure you want to delete this journal entry?',
'apply_filter' => 'Apply filter',
'start_date' => 'Start Date',
'end_date' => 'End Date',
'per_page' => 'Per Page',
'sort_order' => 'Sort By Created At',
'ascending' => 'Ascending',
'descending' => 'Descending',
];
Loading
Loading