summaryrefslogtreecommitdiffstats
path: root/src/views/Albums.vue
blob: 97b5f3765035e486f5cdbb0bdb283b99f7b9a21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!--
 - @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me>
 -
 - @author Louis Chemineau <louis@chmn.me>
 -
 - @license AGPL-3.0-or-later
 -
 - This program is free software: you can redistribute it and/or modify
 - it under the terms of the GNU Affero General Public License as
 - published by the Free Software Foundation, either version 3 of the
 - License, or (at your option) any later version.
 -
 - This program is distributed in the hope that it will be useful,
 - but WITHOUT ANY WARRANTY; without even the implied warranty of
 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 - GNU Affero General Public License for more details.
 -
 - You should have received a copy of the GNU Affero General Public License
 - along with this program. If not, see <http://www.gnu.org/licenses/>.
 -
 -->
<template>
	<div>
		<CollectionsList :collections="albums"
			:loading="loadingAlbums"
			:error="errorFetchingAlbums"
			class="albums-list">
			<HeaderNavigation key="navigation"
				slot="header"
				:loading="loadingAlbums"
				:title="t('photos', 'Albums')"
				:root-title="t('photos', 'Albums')"
				@refresh="fetchAlbums">
				<NcButton :aria-label="t('photos', 'Create a new album.')"
					@click="showAlbumCreationForm = true">
					<template #icon>
						<Plus />
					</template>
					{{ t('photos', 'New album') }}
				</NcButton>
			</HeaderNavigation>

			<CollectionCover :key="collection.basename"
				slot-scope="{collection}"
				:link="`/albums/${collection.basename}`"
				:alt-img="t('photos', 'Cover photo for album {albumName}', { albumName: collection.basename })"
				:cover-url="collection.lastPhoto | coverUrl">
				<h2 class="album__name">
					{{ collection.basename }}
				</h2>

				<div slot="subtitle" class="album__details">
					{{ collection.date }} ⸱ {{ n('photos', '%n item', '%n photos and videos', collection.nbItems,) }}
				</div>
			</CollectionCover>

			<NcEmptyContent slot="empty-collections-list" :title="t('photos', 'There is no album yet!')">
				<FolderMultipleImage slot="icon" />
			</NcEmptyContent>
		</CollectionsList>

		<NcModal v-if="showAlbumCreationForm"
			:title="t('photos', 'New album')"
			@close="showAlbumCreationForm = false">
			<AlbumForm @done="handleAlbumCreated" />
		</NcModal>
	</div>
</template>

<script>
import Plus from 'vue-material-design-icons/Plus.vue'
import FolderMultipleImage from 'vue-material-design-icons/FolderMultipleImage.vue'

import { generateUrl } from '@nextcloud/router'
import { NcModal, NcButton, NcEmptyContent } from '@nextcloud/vue'

import FetchAlbumsMixin from '../mixins/FetchAlbumsMixin.js'
import CollectionsList from '../components/Collection/CollectionsList.vue'
import CollectionCover from '../components/Collection/CollectionCover.vue'
import HeaderNavigation from '../components/HeaderNavigation.vue'
import AlbumForm from '../components/Albums/AlbumForm.vue'

export default {
	name: 'Albums',
	components: {
		Plus,
		FolderMultipleImage,
		NcModal,
		NcButton,
		NcEmptyContent,
		CollectionsList,
		CollectionCover,
		HeaderNavigation,
		AlbumForm,
	},

	filters: {
		/**
		 * @param {string} lastPhoto The album's last photos.
		 */
		coverUrl(lastPhoto) {
			if (lastPhoto === -1) {
				return ''
			}

			return generateUrl(`/apps/photos/api/v1/preview/${lastPhoto}?x=${512}&y=${512}`)
		},
	},

	mixins: [
		FetchAlbumsMixin,
	],

	data() {
		return {
			showAlbumCreationForm: false,
		}
	},

	methods: {
		handleAlbumCreated({ album }) {
			this.showAlbumCreationForm = false
			this.$router.push(`albums/${album.basename}`)
		},
	},
}
</script>
<style lang="scss" scoped>
.albums-list {
	display: flex;
	flex-direction: column;

	.album__name {
		font-weight: normal;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
}
</style>