Adds multiple albums selection
Signed-off-by: Alexander Saltykov <temp.kroogi@gmail.com>pull/752/head
parent
7eca2b7111
commit
ccbd550ba1
|
@ -33,7 +33,7 @@
|
||||||
</template>
|
</template>
|
||||||
{{ t('memories', 'Add to album') }}
|
{{ t('memories', 'Add to album') }}
|
||||||
</NcButton>
|
</NcButton>
|
||||||
<AddToAlbumModal ref="addToAlbumModal" @added="update" />
|
<AddToAlbumModal ref="addToAlbumModal" @added="loadAlbums" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="outer">
|
<div class="outer">
|
||||||
<AlbumPicker @select="selectAlbum" :photos="photos" />
|
<AlbumPicker @select="selectAlbums" :photos="photos" />
|
||||||
|
|
||||||
<div v-if="processing">
|
<div v-if="processing">
|
||||||
<NcProgressBar :value="Math.round((photosDone * 100) / photos.length)" :error="true" />
|
<NcProgressBar :value="Math.round((photosDone * 100) / photos.length)" :error="true" />
|
||||||
|
@ -60,19 +60,32 @@ export default defineComponent({
|
||||||
this.$emit('close');
|
this.$emit('close');
|
||||||
},
|
},
|
||||||
|
|
||||||
async selectAlbum(album: IAlbum) {
|
async selectAlbums(albums: IAlbum[]) {
|
||||||
if (this.processing) return;
|
if (this.processing) return;
|
||||||
|
const processed = new Set<IPhoto>();
|
||||||
|
const photosDone = new Set<number>();
|
||||||
|
|
||||||
|
await Promise.all(albums.map(async (album) => {
|
||||||
const name = album.name || album.album_id.toString();
|
const name = album.name || album.album_id.toString();
|
||||||
const gen = dav.addToAlbum(album.user, name, this.photos);
|
const gen = dav.addToAlbum(album.user, name, this.photos);
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
|
|
||||||
for await (const fids of gen) {
|
for await (const fids of gen) {
|
||||||
this.photosDone += fids.filter((f) => f).length;
|
fids.forEach((f) => {
|
||||||
this.added(this.photos.filter((p) => fids.includes(p.fileid)));
|
if (f) {
|
||||||
|
photosDone.add(f);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
this.photos.forEach((p) => {
|
||||||
|
if (fids.includes(p.fileid)) {
|
||||||
|
processed.add(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.photosDone = photosDone.size;
|
||||||
|
}));
|
||||||
const n = this.photosDone;
|
const n = this.photosDone;
|
||||||
|
this.added(Array.from(processed));
|
||||||
showInfo(this.n('memories', '{n} item added to album', '{n} items added to album', n, { n }));
|
showInfo(this.n('memories', '{n} item added to album', '{n} items added to album', n, { n }));
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
albumName: album.name,
|
albumName: album.name,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
@click="pickAlbum(album)"
|
@click.prevent="pickAlbum(album)"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<XImg v-if="album.last_added_photo !== -1" class="album__image" :src="toCoverUrl(album.last_added_photo)" />
|
<XImg v-if="album.last_added_photo !== -1" class="album__image" :src="toCoverUrl(album.last_added_photo)" />
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #extra>
|
<template #extra>
|
||||||
<div v-if="album.has_file" class="check-circle-icon">
|
<div v-if="selectedAlbums.has(album)" class="check-circle-icon">
|
||||||
<XImg :src="checkmarkIcon" />
|
<XImg :src="checkmarkIcon" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -35,6 +35,7 @@
|
||||||
</NcListItem>
|
</NcListItem>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<div class="actions">
|
||||||
<NcButton
|
<NcButton
|
||||||
:aria-label="t('memories', 'Create a new album.')"
|
:aria-label="t('memories', 'Create a new album.')"
|
||||||
class="new-album-button"
|
class="new-album-button"
|
||||||
|
@ -46,6 +47,23 @@
|
||||||
</template>
|
</template>
|
||||||
{{ t('memories', 'Create new album') }}
|
{{ t('memories', 'Create new album') }}
|
||||||
</NcButton>
|
</NcButton>
|
||||||
|
|
||||||
|
<div class="submit-btn-wrapper">
|
||||||
|
<NcButton
|
||||||
|
:aria-label="t('memories', `Add to ${selectedCount} albums.`)"
|
||||||
|
class="new-album-button"
|
||||||
|
type="primary"
|
||||||
|
@click="submit"
|
||||||
|
>
|
||||||
|
{{ t('memories', 'Add to albums') }}
|
||||||
|
</NcButton>
|
||||||
|
<span class="remove-notice" v-if="unselectedCount > 0">
|
||||||
|
{{ t('memories', 'And remove from') }} {{ n('memories', '{n} album', '{n} albums', unselectedCount , {
|
||||||
|
n: unselectedCount,
|
||||||
|
})}}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AlbumForm
|
<AlbumForm
|
||||||
|
@ -100,6 +118,10 @@ export default defineComponent({
|
||||||
loadingAlbums: true,
|
loadingAlbums: true,
|
||||||
photoId: -1,
|
photoId: -1,
|
||||||
checkmarkIcon,
|
checkmarkIcon,
|
||||||
|
selectedAlbums: new Set<IAlbum>(),
|
||||||
|
unselectedAlbums: new Set<IAlbum>(),
|
||||||
|
selectedCount: 0,
|
||||||
|
unselectedCount: 0,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -143,6 +165,9 @@ export default defineComponent({
|
||||||
try {
|
try {
|
||||||
const res = await axios.get<IAlbum[]>(API.ALBUM_LIST(3, this.photoId));
|
const res = await axios.get<IAlbum[]>(API.ALBUM_LIST(3, this.photoId));
|
||||||
this.albums = res.data;
|
this.albums = res.data;
|
||||||
|
this.selectedAlbums = new Set(this.albums.filter(album => album.has_file));
|
||||||
|
this.unselectedAlbums = new Set();
|
||||||
|
this.unselectedCount = 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -151,8 +176,28 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
pickAlbum(album: IAlbum) {
|
pickAlbum(album: IAlbum) {
|
||||||
this.$emit('select', album);
|
if (this.selectedAlbums.has(album)) {
|
||||||
|
this.selectedAlbums.delete(album);
|
||||||
|
this.unselectedAlbums.add(album)
|
||||||
|
} else if (this.unselectedAlbums.has(album)) {
|
||||||
|
this.selectedAlbums.add(album)
|
||||||
|
this.unselectedAlbums.delete(album);
|
||||||
|
} else {
|
||||||
|
this.selectedAlbums.add(album)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.unselectedCount = this.albums.reduce((acc, album) => {
|
||||||
|
if (album.has_file && this.unselectedAlbums.has(album)) {
|
||||||
|
acc += 1;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, 0); this.selectedAlbums.size;
|
||||||
|
this.selectedCount = this.selectedAlbums.size;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
submit() {
|
||||||
|
this.$emit('select', Array.from(this.selectedAlbums));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -231,5 +276,21 @@ export default defineComponent({
|
||||||
.new-album-button {
|
.new-album-button {
|
||||||
margin-top: 32px;
|
margin-top: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-btn-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-notice {
|
||||||
|
font-size: small;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue