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

[Feature] Renaming of notes #1104

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/Icons/MarkdownPencil.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<span class="material-design-icon">
<svg-icon type="mdi" :path="path" :width="size" :height="size"></svg-icon>
</span>
</template>

<script>
import SvgIcon from '@jamescoyle/vue-icon';
import { mdiPencil } from '@mdi/js';
export default {
name: "MarkdownPencil",
components: {
SvgIcon
},
props: {
size: {
type: Number,
default: 24
},
},
data() {
return {
path: mdiPencil,
}
}
}
</script>
73 changes: 60 additions & 13 deletions src/components/NoteItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,58 @@
:size="20"
fill-color="var(--color-text-lighter)"
/>

</template>
<template #actions>
<NcActionButton :icon="actionFavoriteIcon" @click="onToggleFavorite">
{{ actionFavoriteText }}
</NcActionButton>

<NcActionButton v-if="!renaming" @click="startRenaming">
<MarkdownPencil slot="icon" :size="20"/>
{{ t('notes', 'Rename') }}
</NcActionButton>
<NcActionInput v-else
v-model.trim="newTitle"
@input="onInputChange($event)"
@submit="onRename"
:disabled="!renaming"
:placeholder="t('notes', 'Rename note')"
:show-trailing-button="true"
>
<MarkdownPencil slot="icon" :size="20"/>
</NcActionInput>

<NcActionButton @click="onToggleSidebar">
<SidebarIcon slot="icon" :size="20" />
<SidebarIcon slot="icon" :size="20"/>
{{ t('notes', 'Details') }}
</NcActionButton>

<NcActionButton v-if="!note.readonly" :icon="actionDeleteIcon" @click="onDeleteNote">
{{ t('notes', 'Delete note') }}
</NcActionButton>
<NcActionSeparator />

<NcActionSeparator/>

<NcActionButton icon="icon-files-dark" @click="onCategorySelected">
{{ actionCategoryText }}
</NcActionButton>

</template>
</NcListItem>
</template>

<script>
import { NcListItem, NcActionButton } from '@nextcloud/vue'
import {NcListItem, NcActionButton, NcActionInput} from '@nextcloud/vue'
import AlertOctagonIcon from 'vue-material-design-icons/AlertOctagon.vue'
import FileDocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
import StarIcon from 'vue-material-design-icons/Star.vue'
import SidebarIcon from 'vue-material-design-icons/PageLayoutSidebarRight.vue'
import { categoryLabel, routeIsNewNote } from '../Util.js'
import { showError } from '@nextcloud/dialogs'
import {categoryLabel, routeIsNewNote} from '../Util.js'
import {showError} from '@nextcloud/dialogs'
import store from '../store.js'
import { setFavorite, setTitle, fetchNote, deleteNote } from '../NotesService.js'

import {setFavorite, setTitle, fetchNote, deleteNote} from '../NotesService.js'
import MarkdownPencil from "./Icons/MarkdownPencil.vue";
export default {
name: 'NoteItem',

Expand All @@ -65,20 +86,26 @@ export default {
NcListItem,
SidebarIcon,
StarIcon,
NcActionInput,
MarkdownPencil,

},

props: {
note: {
type: Object,
required: true,
},

},

data() {
return {
loading: {
note: false,
},
newTitle: "",
renaming: false,
}
},

Expand Down Expand Up @@ -112,7 +139,6 @@ export default {
return 'icon-delete' + (this.loading.delete ? ' loading' : '')
},
},

methods: {
onNoteSelected(noteId) {
this.$emit('note-selected', noteId)
Expand All @@ -135,20 +161,41 @@ export default {
this.actionsOpen = false
store.commit('setSidebarOpen', !store.state.app.sidebarOpen)
},
startRenaming() {
this.renaming = true;
this.$emit('start-renaming', this.note.id);
},
onInputChange(event) {
this.newTitle = event.target.value.toString();
},
onRename(newTitle) {
this.loading.note = true
newTitle = this.newTitle.toString();
if (!newTitle) {
return;
}
this.loading.note = true;
setTitle(this.note.id, newTitle)
.then(() => {
this.note.title = newTitle;
this.newTitle = "";
})
.catch(() => {
console.log('error')
showError(this.t('notes', 'Error while renaming note.'));
})
.finally(() => {
this.loading.note = false
})
this.loading.note = false;
this.renaming = false;
});

if (routeIsNewNote(this.$route)) {
this.$router.replace({
name: 'note',
params: { noteId: this.note.id.toString() },
})
params: {noteId: this.note.id.toString()},
});
}
this.renaming = false;

},
async onDeleteNote() {
this.loading.delete = true
Expand Down
15 changes: 14 additions & 1 deletion src/components/NotesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
:key="note.id"
:note="note"
@note-selected="onNoteSelected"
:renaming="isRenaming(note.id)"
@start-renaming="onStartRenaming"
/>
</ul>
</template>
Expand All @@ -24,11 +26,22 @@ export default {
required: true,
},
},

data() {
return {
renamingNotes: [],
};
},
methods: {
onNoteSelected(noteId) {
this.$emit('note-selected', noteId)
},
onStartRenaming(noteId) {
this.renamingNotes.push(noteId);
},
isRenaming(noteId) {
return this.renamingNotes.includes(noteId);
},

},
}
</script>