album: refactor add modal

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/767/head
Varun Patil 2023-08-02 12:28:44 -07:00
parent d32793e9c0
commit 254329e1c2
4 changed files with 58 additions and 45 deletions

View File

@ -34,7 +34,7 @@
<!-- Selection Modals -->
<FaceMoveModal ref="faceMoveModal" @moved="deletePhotos" :updateLoading="updateLoading" />
<AddToAlbumModal ref="addToAlbumModal" @added="clearSelection" />
<AddToAlbumModal ref="addToAlbumModal" @change="clearSelection" />
<MoveToFolderModal ref="moveToFolderModal" @moved="refresh" />
</div>
</template>

View File

@ -5,9 +5,9 @@
</template>
<div class="outer">
<AlbumPicker @select="updateAlbums" :photos="photos" />
<AlbumPicker @select="update" :photos="photos" :disabled="!!opsTotal" />
<div v-if="processing">
<div class="progress-bar" v-if="opsTotal">
<NcProgressBar :value="progress" :error="true" />
</div>
</div>
@ -37,60 +37,54 @@ export default defineComponent({
data: () => ({
show: false,
photos: [] as IPhoto[],
progress: 0,
processing: false,
processed: new Set<IPhoto>(),
photosDone: 0,
totalOperations: 0,
opsDone: 0,
opsTotal: 0,
}),
computed: {
progress(): number {
return Math.min(this.opsTotal ? Math.round((this.opsDone * 100) / this.opsTotal) : 100, 100);
},
},
methods: {
open(photos: IPhoto[]) {
this.progress = 0;
this.processing = false;
this.show = true;
this.photos = photos;
},
added(photos: IPhoto[]) {
this.$emit('added', photos);
this.show = true;
this.opsTotal = 0;
},
close() {
this.photos = [];
this.processing = false;
this.show = false;
this.photos = [];
this.opsTotal = 0;
this.$emit('close');
},
async processAlbum(album: IAlbum, action: 'add' | 'remove') {
const name = album.name || album.album_id.toString();
const gen = action === 'add'
? dav.addToAlbum(album.user, name, this.photos)
: dav.removeFromAlbum(album.user, name, this.photos);
for await (const fids of gen) {
this.photosDone += fids.length;
this.photos.forEach((p) => {
if (fids.includes(p.fileid)) {
this.processed.add(p);
}
});
async update(selection: IAlbum[], deselection: IAlbum[]) {
if (this.opsTotal) return;
// Total number of DAV calls (ugh DAV)
this.opsTotal = this.photos.length * (selection.length + deselection.length);
// Add the photos to the selected albums
for (const album of selection) {
for await (const fids of dav.addToAlbum(album.user, album.name, this.photos)) {
this.opsDone += fids.filter((f) => f).length;
}
}
this.progress = Math.round((this.photosDone * 100) / this.totalOperations);
},
async updateAlbums(albumsToAddTo: IAlbum[], albumsToRemoveFrom: IAlbum[] = []) {
if (this.processing) return;
this.processing = true;
this.processed = new Set<IPhoto>();
this.totalOperations = this.photos.length * (albumsToAddTo.length + albumsToRemoveFrom.length);
// Remove the photos from the deselected albums
for (const album of deselection) {
for await (const fids of dav.removeFromAlbum(album.user, album.name, this.photos)) {
this.opsDone += fids.filter((f) => f).length;
}
}
await Promise.all(albumsToAddTo.map((album) => this.processAlbum(album, 'add')));
await Promise.all(albumsToRemoveFrom.map((album) => this.processAlbum(album, 'remove')));
const n = this.processed.size;
this.added(Array.from(this.processed));
showInfo(this.n('memories', '{n} processed', '{n} processed', n, { n }));
const n = this.photos.length;
showInfo(this.n('memories', '{n} photo updated', '{n} photos updated', n, { n }));
this.$emit('change');
this.close();
},
},
@ -101,4 +95,8 @@ export default defineComponent({
.outer {
margin-top: 15px;
}
.progress-bar {
margin-top: 10px;
}
</style>

View File

@ -159,7 +159,7 @@ type Collaborator = {
};
export default defineComponent({
name: 'AddToAlbumModal',
name: 'AlbumCollaborators',
components: {
Magnify,
Close,

View File

@ -43,7 +43,8 @@
<div class="actions">
<NcButton
:aria-label="t('memories', 'Create a new album.')"
:aria-label="t('memories', 'Create new album.')"
:disabled="disabled"
class="new-album-button"
type="tertiary"
@click="showAlbumCreationForm = true"
@ -55,7 +56,13 @@
</NcButton>
<div class="submit-btn-wrapper">
<NcButton :aria-label="t('memories', 'Save')" class="new-album-button" type="primary" @click="submit">
<NcButton
class="new-album-button"
type="primary"
:aria-label="t('memories', 'Save changes')"
:disabled="disabled"
@click="submit"
>
{{ t('memories', 'Save changes') }}
</NcButton>
<span class="remove-notice" v-if="deselection.size > 0">
@ -107,6 +114,12 @@ export default defineComponent({
type: Array as PropType<IPhoto[]>,
required: true,
},
/** Disable controls */
disabled: {
type: Boolean,
default: false,
},
},
components: {
AlbumForm,
@ -180,6 +193,8 @@ export default defineComponent({
},
toggleAlbumSelection(album: IAlbum) {
if (this.disabled) return;
if (this.selection.has(album)) {
this.selection.delete(album);