List shared albums in album picker

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2023-05-24 16:34:08 +02:00
Родитель 1abc322c08
Коммит 7e8666fcfc
5 изменённых файлов: 68 добавлений и 30 удалений

Просмотреть файл

@ -23,16 +23,16 @@
<div v-if="!showAlbumCreationForm" class="album-picker"> <div v-if="!showAlbumCreationForm" class="album-picker">
<h2> <h2>
{{ t('photos', 'Add to Album') }} {{ t('photos', 'Add to Album') }}
<NcLoadingIcon v-if="loadingAlbums" class="loading-icon" /> <NcLoadingIcon v-if="loadingAlbums || loadingSharedAlbums" class="loading-icon" />
</h2> </h2>
<ul class="albums-container"> <ul class="albums-container">
<NcListItem v-for="album in albums" <NcListItem v-for="album in allAlbums"
:key="album.basename" :key="album.filename"
class="album" class="album"
:title="album.basename" :title="originalName(album)"
:aria-label="t('photos', 'Add selection to album {albumName}', {albumName: album.basename})" :aria-label="t('photos', 'Add selection to album {albumName}', {albumName: album.basename})"
@click="pickAlbum(album.basename)"> @click="pickAlbum(album)">
<template slot="icon"> <template slot="icon">
<img v-if="album.lastPhoto !== -1" class="album__image" :src="album.lastPhoto | toCoverUrl"> <img v-if="album.lastPhoto !== -1" class="album__image" :src="album.lastPhoto | toCoverUrl">
<div v-else class="album__image album__image--placeholder"> <div v-else class="album__image album__image--placeholder">
@ -42,8 +42,9 @@
<template slot="subtitle"> <template slot="subtitle">
{{ n('photos', '%n item', '%n photos and videos', album.nbItems) }} {{ n('photos', '%n item', '%n photos and videos', album.nbItems) }}
<!-- TODO: finish collaboration --> <template v-if="isSharedAlbum(album)">
<!-- {{ n('photos', 'Share with %n user', 'Share with %n users', album.isShared) }}--> {{ t('photos', 'Shared by') }}&nbsp;<NcUserBubble :display-name="album.collaborators[0].label" :user="album.collaborators[0].id" />
</template>
</template> </template>
</NcListItem> </NcListItem>
</ul> </ul>
@ -70,10 +71,12 @@
import Plus from 'vue-material-design-icons/Plus.vue' import Plus from 'vue-material-design-icons/Plus.vue'
import ImageMultiple from 'vue-material-design-icons/ImageMultiple.vue' import ImageMultiple from 'vue-material-design-icons/ImageMultiple.vue'
import { NcButton, NcListItem, NcLoadingIcon } from '@nextcloud/vue' import { NcButton, NcListItem, NcLoadingIcon, NcUserBubble } from '@nextcloud/vue'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import { translate, translatePlural } from '@nextcloud/l10n'
import FetchAlbumsMixin from '../../mixins/FetchAlbumsMixin.js' import FetchAlbumsMixin from '../../mixins/FetchAlbumsMixin.js'
import FetchSharedAlbumsMixin from '../../mixins/FetchSharedAlbumsMixin.js'
import AlbumForm from './AlbumForm.vue' import AlbumForm from './AlbumForm.vue'
export default { export default {
@ -85,6 +88,7 @@ export default {
NcButton, NcButton,
NcListItem, NcListItem,
NcLoadingIcon, NcLoadingIcon,
NcUserBubble,
AlbumForm, AlbumForm,
}, },
@ -100,6 +104,7 @@ export default {
mixins: [ mixins: [
FetchAlbumsMixin, FetchAlbumsMixin,
FetchSharedAlbumsMixin,
], ],
data() { data() {
@ -108,15 +113,44 @@ export default {
} }
}, },
computed: {
/** @return {object[]} */
allAlbums() {
return [...Object.values(this.albums), ...Object.values(this.sharedAlbums)]
},
},
methods: { methods: {
albumCreatedHandler() { albumCreatedHandler() {
this.showAlbumCreationForm = false this.showAlbumCreationForm = false
this.fetchAlbums()
}, },
pickAlbum(albumBaseName) { pickAlbum(album) {
this.$emit('album-picked', albumBaseName) this.$emit('album-picked', album)
}, },
/**
* @param {object} album
* @return {boolean}
*/
isSharedAlbum(album) {
return album.filename.match(/^\/photos\/.+\/sharedalbums\//) !== null
},
/**
* @param {object} album The album's full name, including the userid.
* @return {string} The album name without the userId between parentheses.
*/
originalName(album) {
if (this.isSharedAlbum(album)) {
return album.basename.replace(new RegExp(`\\(${album.collaborators[0].id}\\)$`), '')
} else {
return album.basename
}
},
t: translate,
n: translatePlural,
}, },
} }
</script> </script>

Просмотреть файл

@ -32,8 +32,8 @@ export default {
data() { data() {
return { return {
errorFetchingAlbums: null, errorFetchingSharedAlbums: null,
loadingAlbums: false, loadingSharedAlbums: false,
} }
}, },
@ -42,7 +42,7 @@ export default {
], ],
async beforeMount() { async beforeMount() {
this.fetchAlbums() this.fetchSharedAlbums()
}, },
computed: { computed: {
@ -56,26 +56,26 @@ export default {
'addSharedAlbums', 'addSharedAlbums',
]), ]),
async fetchAlbums() { async fetchSharedAlbums() {
if (this.loadingAlbums) { if (this.loadingSharedAlbums) {
return return
} }
try { try {
this.loadingAlbums = true this.loadingSharedAlbums = true
this.errorFetchingAlbums = null this.errorFetchingSharedAlbums = null
const albums = await fetchAlbums(`/photos/${getCurrentUser()?.uid}/sharedalbums`, this.abortController.signal) const albums = await fetchAlbums(`/photos/${getCurrentUser()?.uid}/sharedalbums`, this.abortController.signal)
this.addSharedAlbums({ albums }) this.addSharedAlbums({ albums })
} catch (error) { } catch (error) {
if (error.response?.status === 404) { if (error.response?.status === 404) {
this.errorFetchingAlbums = 404 this.errorFetchingSharedAlbums = 404
} else { } else {
this.errorFetchingAlbums = error this.errorFetchingSharedAlbums = error
} }
} finally { } finally {
this.loadingAlbums = false this.loadingSharedAlbums = false
} }
}, },
}, },

Просмотреть файл

@ -25,8 +25,8 @@
ref="collectionContent" ref="collectionContent"
:collection="album" :collection="album"
:collection-file-ids="albumFileIds" :collection-file-ids="albumFileIds"
:loading="loadingAlbums || loadingFiles" :loading="loadingSharedAlbums || loadingFiles"
:error="errorFetchingAlbums || errorFetchingFiles"> :error="errorFetchingSharedAlbums || errorFetchingFiles">
<!-- Header --> <!-- Header -->
<HeaderNavigation key="navigation" <HeaderNavigation key="navigation"
slot="header" slot="header"

Просмотреть файл

@ -21,15 +21,15 @@
--> -->
<template> <template>
<CollectionsList :collections="sharedAlbums" <CollectionsList :collections="sharedAlbums"
:loading="loadingAlbums" :loading="loadingSharedAlbums"
:error="errorFetchingAlbums" :error="errorFetchingSharedAlbums"
class="albums-list"> class="albums-list">
<HeaderNavigation key="navigation" <HeaderNavigation key="navigation"
slot="header" slot="header"
:loading="loadingAlbums" :loading="loadingSharedAlbums"
:title="t('photos', 'Shared albums')" :title="t('photos', 'Shared albums')"
:root-title="t('photos', 'Shared albums')" :root-title="t('photos', 'Shared albums')"
@refresh="fetchAlbums" /> @refresh="fetchSharedAlbums" />
<CollectionCover :key="collection.basename" <CollectionCover :key="collection.basename"
slot-scope="{collection}" slot-scope="{collection}"

Просмотреть файл

@ -230,7 +230,7 @@ export default {
}, },
methods: { methods: {
...mapActions(['deleteFiles', 'addFilesToAlbum']), ...mapActions(['deleteFiles', 'addFilesToAlbum', 'addFilesToSharedAlbum']),
getContent() { getContent() {
this.fetchFiles('', { this.fetchFiles('', {
@ -254,9 +254,13 @@ export default {
// TODO: finish when implementing upload // TODO: finish when implementing upload
}, },
async addSelectionToAlbum(albumName) { async addSelectionToAlbum(album) {
this.showAlbumPicker = false this.showAlbumPicker = false
await this.addFilesToAlbum({ albumName, fileIdsToAdd: this.selectedFileIds }) if (album.filename.match(/^\/photos\/.+\/sharedalbums\//) !== null) {
await this.addFilesToSharedAlbum({ albumName: album.basename, fileIdsToAdd: this.selectedFileIds })
} else {
await this.addFilesToAlbum({ albumName: album.basename, fileIdsToAdd: this.selectedFileIds })
}
}, },
async deleteSelection() { async deleteSelection() {