Newer
Older
- @copyright Copyright (c) 2021 Jonas Heinrich
-
- @author Jonas Heinrich <onny@project-insanity.org>
-
- @license GNU AGPL version 3 or any later version
-
- 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>
<DashboardWidget :items="items"
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
:show-more-url="showMoreUrl"
:loading="state === 'loading'">
<template #empty-content>
<EmptyContent
v-if="emptyContentMessage"
:icon="emptyContentIcon">
<template #desc>
{{ emptyContentMessage }}
</template>
</EmptyContent>
</template>
</DashboardWidget>
</template>
<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { DashboardWidget } from '@nextcloud/vue-dashboard'
import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'
const requesttoken = axios.defaults.headers.requesttoken
export default {
name: 'Dashboard',
components: {
DashboardWidget,
EmptyContent,
},
data() {
return {
notifications: [],
state: 'loading',
darkThemeColor: OCA.Accessibility.theme === 'dark' ? 'ffffff' : '000000',
}
},
computed: {
items() {
return this.notifications.map((n) => {
return {
id: n.id,
avatarUrl: n.favicon,
mainText: n.name,
subText: n.tags.replaceAll(',', ', '),
}
})
},
emptyContentMessage() {
if (this.state === 'error') {
}
return ''
},
emptyContentIcon() {
if (this.state === 'error') {
return 'icon-close'
} else if (this.state === 'ok') {
return 'icon-checkmark'
}
return 'icon-checkmark'
},
},
beforeMount() {
this.fetchNotifications()
},
methods: {
fetchNotifications() {
const req = {}
axios.defaults.headers.requesttoken = requesttoken
axios.get(generateUrl('/apps/podcast/api/favorites'), req).then((response) => {
this.processNotifications(response.data)
this.state = 'ok'
}).catch((error) => {
clearInterval(this.loop)
if (error.response && error.response.status === 401) {
showError(t('podcast', 'Failed to fetch favorite podcast episodes'))
this.state = 'error'
} else {
// there was an error in notif processing
console.debug(error)
}
})
},
processNotifications(newNotifications) {
console.log(newNotifications)
this.notifications = newNotifications
},
},
}
</script>