Skip to content

Commit 6b1feda

Browse files
committed
Some more linking to DAV APIs
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent bf83443 commit 6b1feda

7 files changed

Lines changed: 197 additions & 64 deletions

File tree

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
-
2121
-->
2222
<template>
23-
<form v-if="!showCollaboratorView" class="album-creation-form">
23+
<form v-if="!showCollaboratorView" class="album-form">
2424
<div class="form-inputs">
2525
<input ref="nameInput"
2626
v-model="albumName"
2727
type="text"
2828
name="name"
2929
required
3030
autofocus="true"
31-
:placeholder="t('photos', 'Name of the new album')">
32-
<label>
31+
:placeholder="t('photos', 'Name of the album')">
32+
<label v-if="!editMode">
3333
<MapMarker /><input v-model="albumLocation"
34-
type="text"
3534
name="location"
36-
:placeholder="t('photos', 'Add location')">
35+
type="text"
36+
:placeholder="t('photos', 'Location of the album')">
3737
</label>
3838
</div>
3939
<div class="form-buttons">
@@ -47,7 +47,8 @@
4747
</span>
4848
<span class="right-buttons">
4949

50-
<Button :aria-label="t('photo', 'Go to the add collaborators view.')"
50+
<Button v-if="!editMode"
51+
:aria-label="t('photo', 'Go to the add collaborators view.')"
5152
type="secondary"
5253
:disabled="albumName.trim() === '' || loading"
5354
@click="showCollaboratorView = true">
@@ -56,23 +57,22 @@
5657
</template>
5758
{{ t('photo', 'Add collaborators') }}
5859
</Button>
59-
<Button :aria-label="t('photo', 'Create the album.')"
60+
<Button :aria-label="editMode ? t('photo', 'Save.') : t('photo', 'Create the album.')"
6061
type="primary"
6162
:disabled="albumName.trim() === '' || loading"
62-
@click="createAlbum">
63+
@click="submit()">
6364
<template #icon>
6465
<Loader v-if="loading" />
6566
<Send v-else />
6667
</template>
67-
{{ t('photo', 'Create album') }}
68+
{{ editMode ? t('photo', 'Save') : t('photo', 'Create album') }}
6869
</Button>
6970
</span>
7071
</div>
7172
</form>
7273
<CollaboratorsSelectionForm v-else
7374
class="add-collaborators-form"
74-
@cancel="showCollaboratorView = true"
75-
@submit="createAlbum">
75+
@cancel="showCollaboratorView = true">
7676
<template slot-scope="{collaborators}">
7777
<span class="left-buttons">
7878
<Button :aria-label="t('photo', 'Back to the new album form.')"
@@ -82,32 +82,34 @@
8282
</Button>
8383
</span>
8484
<span class="right-buttons">
85-
<Button :aria-label="t('photo', 'Create the album.')"
85+
<Button :aria-label="editMode ? t('photo', 'Save.') : t('photo', 'Create the album.')"
8686
type="primary"
8787
:disabled="albumName.trim() === '' || loading"
88-
@click="createAlbum(collaborators)">
88+
@click="submit(collaborators)">
8989
<template #icon>
9090
<Loader v-if="loading" />
9191
<Send v-else />
9292
</template>
93-
{{ t('photo', 'Create album') }}
93+
{{ editMode ? t('photo', 'Save') : t('photo', 'Create album') }}
9494
</Button>
9595
</span>
9696
</template>
9797
</CollaboratorsSelectionForm>
9898
</template>
9999
<script>
100+
import { mapActions } from 'vuex'
100101
import MapMarker from 'vue-material-design-icons/MapMarker'
101102
import AccountMultiplePlus from 'vue-material-design-icons/AccountMultiplePlus'
102103
import Send from 'vue-material-design-icons/Send'
103104
104105
import { Button } from '@nextcloud/vue'
106+
import moment from '@nextcloud/moment'
105107
106-
import Loader from '../components/Loader.vue'
107-
import CollaboratorsSelectionForm from '../components/CollaboratorsSelectionForm.vue'
108+
import Loader from './Loader.vue'
109+
import CollaboratorsSelectionForm from './CollaboratorsSelectionForm.vue'
108110
109111
export default {
110-
name: 'AlbumCreationForm',
112+
name: 'AlbumForm',
111113
112114
components: {
113115
Button,
@@ -119,6 +121,10 @@ export default {
119121
},
120122
121123
props: {
124+
album: {
125+
type: Object,
126+
default: null,
127+
},
122128
displayBackButton: {
123129
type: Boolean,
124130
default: false,
@@ -134,24 +140,57 @@ export default {
134140
}
135141
},
136142
143+
computed: {
144+
editMode() {
145+
return this.album !== null
146+
},
147+
},
148+
137149
mounted() {
150+
if (this.editMode) {
151+
this.albumName = this.album.basename
152+
this.albumLocation = this.album.location
153+
}
154+
138155
this.$nextTick(() => {
139156
this.$refs.nameInput.focus()
140157
})
141158
},
142159
143160
methods: {
144-
async createAlbum(collaborators = []) {
161+
...mapActions(['createAlbum', 'renameAlbum']),
162+
163+
submit(collaborators = []) {
164+
if (this.editMode) {
165+
this.handleUpdateAlbum(collaborators)
166+
} else {
167+
this.handleCreateAlbum(collaborators)
168+
}
169+
},
170+
171+
async handleCreateAlbum(collaborators = []) {
145172
try {
146173
this.loading = true
147-
const album = await this.$store.dispatch('createAlbum', {
174+
const album = await this.createAlbum({
148175
album: {
149-
name: this.albumName,
176+
basename: this.albumName,
177+
size: 0,
178+
lastmod: moment().unix(),
150179
location: this.albumLocation,
151180
collaborators,
152181
},
153182
})
154-
this.$emit('album-created', { album })
183+
this.$emit('done', { album })
184+
} finally {
185+
this.loading = false
186+
}
187+
},
188+
189+
async handleUpdateAlbum(collaborators = []) {
190+
try {
191+
this.loading = true
192+
const album = await this.renameAlbum({ currentAlbumName: this.album.basename, newAlbumName: this.albumName })
193+
this.$emit('done', { album })
155194
} finally {
156195
this.loading = false
157196
}
@@ -164,7 +203,7 @@ export default {
164203
}
165204
</script>
166205
<style lang="scss" scoped>
167-
.album-creation-form {
206+
.album-form {
168207
display: flex;
169208
flex-direction: column;
170209
height: 350px;

src/components/AlbumPicker.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
</Button>
5858
</div>
5959

60-
<AlbumCreationForm v-else
60+
<AlbumForm v-else
6161
:display-back-button="true"
6262
:title="t('photos', 'New album')"
6363
@back="showAlbumCreationForm = false"
64-
@album-created="albumCreatedHandler" />
64+
@done="albumCreatedHandler" />
6565
</template>
6666

6767
<script>
@@ -71,15 +71,15 @@ import { Button } from '@nextcloud/vue'
7171
import { generateUrl } from '@nextcloud/router'
7272
7373
import FetchAlbumsMixin from '../mixins/FetchAlbumsMixin.js'
74-
import AlbumCreationForm from '../components/AlbumCreationForm.vue'
74+
import AlbumForm from './AlbumForm.vue'
7575
import Loader from '../components/Loader.vue'
7676
7777
export default {
7878
name: 'AlbumPicker',
7979
8080
components: {
8181
Button,
82-
AlbumCreationForm,
82+
AlbumForm,
8383
Loader,
8484
Plus,
8585
},

src/components/CollaboratorsSelectionForm.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export default {
5353
loading: false,
5454
}
5555
},
56-
57-
methods: {
58-
},
5956
}
6057
</script>
6158
<style lang="scss" scoped>

src/store/albums.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ const actions = {
196196
*/
197197
async createAlbum(context, { album }) {
198198
try {
199-
await client.createDirectory(`/photos/${getCurrentUser()?.uid}/albums/${album.name}`)
199+
await client.createDirectory(`/photos/${getCurrentUser()?.uid}/albums/${album.basename}`)
200200
context.commit('addAlbums', { albums: [album] })
201201
} catch (error) {
202-
logger.error(t('photos', 'Failed to create {albumName}.', { albumName: album.name }), error)
203-
showError(t('photos', 'Failed to create {albumName}.', { albumName: album.name }))
202+
logger.error(t('photos', 'Failed to create {albumName}.', { albumName: album.basename }), error)
203+
showError(t('photos', 'Failed to create {albumName}.', { albumName: album.basename }))
204204
}
205205
},
206206

@@ -220,7 +220,7 @@ const actions = {
220220

221221
album = await client.moveFile(
222222
`/photos/${getCurrentUser()?.uid}/albums/${currentAlbumName}`,
223-
{ destinationFilename: newAlbumName }
223+
`/photos/${getCurrentUser()?.uid}/albums/${newAlbumName}`,
224224
)
225225
} catch (error) {
226226
logger.error(t('photos', 'Failed to rename {currentAlbumName} to {newAlbumName}.', { currentAlbumName, newAlbumName }), error)
@@ -239,7 +239,7 @@ const actions = {
239239
*/
240240
async deleteAlbum(context, { albumName }) {
241241
try {
242-
await client.deleteFile(`/files/${getCurrentUser()?.uid}/${albumName}`)
242+
await client.deleteFile(`/photos/${getCurrentUser()?.uid}/albums/${albumName}`)
243243
context.commit('removeAlbums', { albumNames: [albumName] })
244244
} catch (error) {
245245
logger.error(t('photos', 'Failed to delete {albumName}.', { albumName }), error)

0 commit comments

Comments
 (0)