Skip to content

Commit

Permalink
feat: edit Option For Daily Journal (#6759)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexis Saettler <alexis@saettler.org>
  • Loading branch information
khalilJayab and asbiin authored Nov 6, 2023
1 parent bdffa9b commit e4a41d8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/Http/Controllers/JournalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ public function edit(Entry $entry)
return view('journal.edit')
->withEntry($entry);
}

/**
* Method updateDay
*
* @param Request $request
* @param Day $day
*
*/
public function updateDay(Request $request, Day $day)
{
$validatedData = $request->validate([
'comment' => 'required|string',
]);

$day->update($validatedData);

return response()->json(['message' => 'Day updated successfully']);
}

/**
* Update a journal entry.
Expand Down
36 changes: 35 additions & 1 deletion resources/js/components/journal/partials/JournalContentRate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@
</div>

<!-- Log content -->
<div v-if="isEditingComment" class="pt2 w-100 pr-4">
<form-textarea
:id="'comment'"
v-model="day.comment"
:required="false"
:rows="4"
/>
<div class="pv3">
<div class="flex-ns justify-between">
<button v-cy-name="'save-entry-button'" class="btn btn-primary w-auto-ns w-100 mb2 pb0-ns" @click="saveComment()">
{{ $t('app.save') }}
</button>
</div>
</div>
</div>

<div class="flex-auto flex items-center">
<p v-if="day.comment" class="mb2">
<p v-if="!isEditingComment && day.comment" class="mb2">
{{ day.comment }}
</p>
<p v-if="!day.comment" class="mb2">
Expand Down Expand Up @@ -95,6 +111,11 @@
<li class="di">
{{ $t('journal.journal_entry_rate') }}
</li>
<li class="di">
<a v-cy-name="'entry-edit-button-' + journalEntry.id" class="pointer" :href="'journal/day/' + journalEntry.id + '/edit'" @click.prevent="editingComment">
{{ $t('app.edit') }}
</a>
</li>
<li class="di">
<a v-cy-name="'entry-delete-button-' + journalEntry.id" class="pointer" href="" @click.prevent="destroy()">
{{ $t('app.delete') }}
Expand All @@ -121,6 +142,8 @@ export default {
data() {
return {
day: [],
isEditingComment: false,
};
},
Expand All @@ -138,6 +161,17 @@ export default {
prepareComponent() {
this.day = this.journalEntry.object;
},
editingComment() {
this.isEditingComment = !this.isEditingComment;
},
saveComment() {
axios.put('journal/day/' + this.day.id + '/update', {
comment: this.day.comment,
})
.then(response => {
this.editingComment();
});
},
destroy() {
axios.delete('journal/day/' + this.day.id)
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
Route::get('/journal/hasRated', 'JournalController@hasRated');
Route::post('/journal/day', 'JournalController@storeDay');
Route::delete('/journal/day/{day}', 'JournalController@trashDay');
Route::put('/journal/day/{day}/update', 'JournalController@updateDay');

Route::get('/journal/add', 'JournalController@create')->name('create');
Route::post('/journal/create', 'JournalController@save')->name('save');
Expand Down

0 comments on commit e4a41d8

Please sign in to comment.