diff --git a/server/routes/self.js b/server/routes/self.js index 3f22a55..85938fb 100644 --- a/server/routes/self.js +++ b/server/routes/self.js @@ -158,6 +158,33 @@ router.post('/upload', upload.single('screenshot'), async (req, res, next) => { } }) +router.post('/albums', async (req, res, next) => { + try { + if (req.user) { + if (req.user.access !== bannedAccess) { + let createdDate = new Date() + let albumDocument = new albumModel({ + title: req.body.title, + title_lower: req.body.title.toLowerCase(), + description: req.body.description, + description_lower: req.body.description.toLowerCase(), + created_at: createdDate, + last_modified_at: createdDate, + user_id: req.user._id + }) + let album = await albumDocument.save() + res.status(201).send(album) + } else { + res.status(403).send({}) + } + } else { + res.status(401).send({}) + } + } catch (err) { + next(err) + } +}) + router.get('/albums', async (req, res, next) => { try { if (req.user) { @@ -836,6 +863,13 @@ router.put('/images/:imageId/edit', async (req, res, next) => { try { if (req.user) { if (req.user.access !== bannedAccess) { + let albumId + + if (req.params.albumId === '0') { + albumId = null + } else { + albumId = ObjectId(req.params.albumId) + } await imageModel.findOneAndUpdate({ _id: req.params.imageId, user_id: req.user._id @@ -843,7 +877,8 @@ router.put('/images/:imageId/edit', async (req, res, next) => { title: req.body.title, title_lower: req.body.title.toLowerCase(), description: req.body.description, - description_lower: req.body.description.toLowerCase() + description_lower: req.body.description.toLowerCase(), + album_id: albumId }) res.status(200).send({}) } else { diff --git a/src/components/AlbumGallery.vue b/src/components/AlbumGallery.vue index 216a679..e77900b 100644 --- a/src/components/AlbumGallery.vue +++ b/src/components/AlbumGallery.vue @@ -42,9 +42,39 @@ delete - + share + + + + + New Album + + + + + + + + + + + + + + + + + + Cancel + Confirm + + + @@ -80,7 +110,10 @@ export default { }, data () { return { - selectedAlbumIndex: null + selectedAlbumIndex: null, + newAlbumDialog: false, + newAlbumTitle: '', + newAlbumDescription: '' } }, computed: { @@ -98,6 +131,20 @@ export default { }, clickDelete (index) { this.$emit('albumDeleted', this.albumItems[index]) + }, + clickNewAlbumConfirm () { + this.newAlbumDialog = false + this.$emit('albumCreated', { + title: this.newAlbumTitle, + description: this.newAlbumDescription + }) + this.newAlbumTitle = '' + this.newAlbumDescription = '' + }, + clickNewAlbumCancel () { + this.newAlbumDialog = false + this.newAlbumTitle = '' + this.newAlbumDescription = '' } } } diff --git a/src/components/ImageItem.vue b/src/components/ImageItem.vue index 649c97d..331f423 100644 --- a/src/components/ImageItem.vue +++ b/src/components/ImageItem.vue @@ -26,7 +26,9 @@ @@ -159,11 +161,13 @@ export default { editDialog: false, editId: '', editTitle: '', - editDescription: '' + editDescription: '', + editAlbum: '' } }, computed: { ...mapState({ + albums: state => state.self.albums, authenticated: state => state.auth.authenticated, authUser: state => state.auth.user }), @@ -225,6 +229,7 @@ export default { }, async created () { this.$store.dispatch('checkAuthenticated') + this.$store.dispatch('fetchAlbums') await this.fetchUseImageDetail() this.$store.dispatch('triggerImageViewed', this.imageItem) }, @@ -290,6 +295,7 @@ export default { this.editId = this.imageItem._id this.editTitle = this.imageItem.title this.editDescription = this.imageItem.description + this.editAlbum = this.imageItem.album_id ? this.imageItem.album_id : '0' this.editDialog = true }, deleteImage () { @@ -304,12 +310,13 @@ export default { onEditCancel () { this.editDialog = false }, - onEditConfirm ({ title, description }) { + onEditConfirm ({ title, description, album }) { this.editDialog = false this.$store.dispatch('triggerSelfImageEdited', { imageId: this.editId, title, - description + description, + album }) }, onCancelled () { diff --git a/src/components/profile/AlbumImages.vue b/src/components/profile/AlbumImages.vue index a8b8148..ec4890b 100644 --- a/src/components/profile/AlbumImages.vue +++ b/src/components/profile/AlbumImages.vue @@ -20,7 +20,9 @@ state.self.albums, authenticated: state => state.auth.authenticated }) }, created () { this.$store.dispatch('checkAuthenticated') + this.$store.dispatch('fetchAlbums') }, methods: { onClickThumbnail (image) { @@ -86,6 +91,7 @@ export default { this.editId = image._id this.editTitle = image.title this.editDescription = image.description + this.editAlbum = image.album_id ? image.album_id : '0' this.editDialog = true }, onClickDelete (image) { @@ -100,12 +106,13 @@ export default { onEditCancel () { this.editDialog = false }, - onEditConfirm ({ title, description }) { + onEditConfirm ({ title, description, album }) { this.editDialog = false this.$store.dispatch('triggerSelfImageEdited', { imageId: this.editId, title, - description + description, + album }) }, async onFetchImages () { diff --git a/src/components/profile/Albums.vue b/src/components/profile/Albums.vue index b537d57..081fd3e 100644 --- a/src/components/profile/Albums.vue +++ b/src/components/profile/Albums.vue @@ -27,6 +27,7 @@ @albumOpened="onClickOpen" @albumDeleted="onClickDelete" @albumEdited="onClickEdit" + @albumCreated="onClickCreate" :authenticated="authenticated" deletable editable/> @@ -59,11 +60,8 @@ export default { }) }, created () { - if (this.$router.currentRoute.name === 'images-page') { - this.currentPage = parseInt(this.$router.currentRoute.params.pageNumber) - } this.$store.dispatch('checkAuthenticated') - this.$store.dispatch('fetchAlbums', this.currentPage) + this.$store.dispatch('fetchAlbums') }, methods: { onClickOpen (albumItem) { @@ -81,6 +79,9 @@ export default { this.editDescription = albumItem.description this.editDialog = true }, + onClickCreate ({ title, description }) { + this.$store.dispatch('createAlbum', { title, description }) + }, onClickDelete (albumItem) { this.$store.dispatch('deleteAlbum', albumItem._id) }, diff --git a/src/components/profile/ImageEdit.vue b/src/components/profile/ImageEdit.vue index 327f5cb..598c824 100644 --- a/src/components/profile/ImageEdit.vue +++ b/src/components/profile/ImageEdit.vue @@ -32,6 +32,16 @@ + + + + + @@ -61,28 +71,49 @@ export default { type: String, default: '' }, + editAlbum: { + type: String, + default: '' + }, editDialog: { type: Boolean, default: false + }, + allAlbums: { + type: Array, + default () { + return [] + } } }, data () { return { dialogState: false, editTitleNew: '', - editDescriptionNew: '' + editDescriptionNew: '', + editAlbumNew: '' } }, computed: { ...mapState({ authenticated: state => state.auth.authenticated - }) + }), + allAlbumsDefaulted () { + return this.allAlbums.map(album => { + if (album._id) { + return album + } else { + album._id = '0' + } + }) + } }, watch: { editDialog () { this.dialogState = this.editDialog this.editTitleNew = this.editTitle this.editDescriptionNew = this.editDescription + this.editAlbumNew = this.editAlbum } }, created () { @@ -90,21 +121,25 @@ export default { this.dialogState = this.editDialog this.editTitleNew = this.editTitle this.editDescriptionNew = this.editDescription + this.editAlbumNew = this.editAlbum }, methods: { clickEditCancel () { this.editTitleNew = '' this.editDescriptionNew = '' + this.editAlbumNew = '' this.$emit('cancel') this.dialogState = false }, clickEditConfirm () { this.$emit('confirm', { title: this.editTitleNew, - description: this.editDescriptionNew + description: this.editDescriptionNew, + album: this.editAlbumNew }) this.editTitleNew = '' this.editDescriptionNew = '' + this.editAlbumNew = '' this.dialogState = false } } diff --git a/src/components/profile/Images.vue b/src/components/profile/Images.vue index 303cf58..e0fae64 100644 --- a/src/components/profile/Images.vue +++ b/src/components/profile/Images.vue @@ -20,7 +20,9 @@ state.self.albums, myImages: state => state.self.images, authenticated: state => state.auth.authenticated }) }, created () { this.$store.dispatch('checkAuthenticated') + this.$store.dispatch('fetchAlbums') this.$store.commit('terminateImages') }, methods: { @@ -81,6 +86,7 @@ export default { this.editId = image._id this.editTitle = image.title this.editDescription = image.description + this.editAlbum = image.album_id ? image.album_id : '0' this.editDialog = true }, onClickDelete (image) { @@ -95,12 +101,13 @@ export default { onEditCancel () { this.editDialog = false }, - onEditConfirm ({ title, description }) { + onEditConfirm ({ title, description, album }) { this.editDialog = false this.$store.dispatch('triggerSelfImageEdited', { imageId: this.editId, title, - description + description, + album }) }, async onFetchImages () { diff --git a/src/store/modules/self.js b/src/store/modules/self.js index 791125f..86f3f3b 100644 --- a/src/store/modules/self.js +++ b/src/store/modules/self.js @@ -276,6 +276,10 @@ const actions = { } }) }, + async createAlbum ({ commit, dispatch }, { title, description }) { + await axios.post('/frontend/self/albums', { title, description }) + dispatch('fetchAlbums') + }, async fetchAlbums ({ commit }) { let response = await axios.get('/frontend/self/albums') let albums = response.data @@ -343,8 +347,8 @@ const actions = { await axios.put(`/frontend/public/images/${imageItem._id}/save`) commit('saveImage', { imageItem, authenticated: rootState.auth.authenticated }) }, - async triggerSelfImageEdited ({ commit, rootState }, { imageId, title, description }) { - await axios.put(`/frontend/self/images/${imageId}/edit`, { title, description }) + async triggerSelfImageEdited ({ commit, rootState }, { imageId, title, description, album }) { + await axios.put(`/frontend/self/images/${imageId}/edit`, { title, description, album }) commit('editImage', { imageId, title, description, authenticated: rootState.auth.authenticated }) }, async triggerSelfImageDeleted ({ commit, rootState }, imageItem) {