2020-06-08 16:39:26 +03:00
|
|
|
<template>
|
|
|
|
<div id="app-dashboard">
|
2020-07-10 15:16:45 +03:00
|
|
|
<h2>{{ greeting.icon }} {{ greeting.text }}</h2>
|
2020-06-08 16:39:26 +03:00
|
|
|
|
2020-07-27 12:17:31 +03:00
|
|
|
<Draggable v-model="layout" class="panels" @end="saveLayout">
|
2020-07-22 12:29:35 +03:00
|
|
|
<div v-for="panelId in layout" :key="panels[panelId].id" class="panel">
|
2020-06-15 09:18:50 +03:00
|
|
|
<div class="panel--header">
|
2020-07-22 12:29:35 +03:00
|
|
|
<h3 :class="panels[panelId].iconClass">
|
|
|
|
{{ panels[panelId].title }}
|
|
|
|
</h3>
|
2020-06-15 09:18:50 +03:00
|
|
|
</div>
|
2020-07-10 18:35:18 +03:00
|
|
|
<div class="panel--content">
|
|
|
|
<div :ref="panels[panelId].id" :data-id="panels[panelId].id" />
|
|
|
|
</div>
|
2020-07-22 12:29:35 +03:00
|
|
|
</div>
|
|
|
|
</Draggable>
|
2020-07-31 15:51:14 +03:00
|
|
|
<a class="edit-panels icon-add" @click="showModal">{{ t('dashboard', 'Edit widgets') }}</a>
|
2020-06-15 09:18:50 +03:00
|
|
|
<Modal v-if="modal" @close="closeModal">
|
|
|
|
<div class="modal__content">
|
2020-07-31 15:51:14 +03:00
|
|
|
<h3>{{ t('dashboard', 'Edit widgets') }}</h3>
|
2020-07-27 12:17:31 +03:00
|
|
|
<Draggable v-model="layout"
|
|
|
|
class="panels"
|
|
|
|
tag="ol"
|
|
|
|
@end="saveLayout">
|
2020-06-15 09:18:50 +03:00
|
|
|
<li v-for="panel in sortedPanels" :key="panel.id">
|
|
|
|
<input :id="'panel-checkbox-' + panel.id"
|
|
|
|
type="checkbox"
|
|
|
|
class="checkbox"
|
|
|
|
:checked="isActive(panel)"
|
|
|
|
@input="updateCheckbox(panel, $event.target.checked)">
|
2020-07-22 12:29:35 +03:00
|
|
|
<label :for="'panel-checkbox-' + panel.id" :class="panel.iconClass">
|
2020-06-15 09:18:50 +03:00
|
|
|
{{ panel.title }}
|
|
|
|
</label>
|
|
|
|
</li>
|
2020-07-27 12:17:31 +03:00
|
|
|
</Draggable>
|
|
|
|
<transition-group name="flip-list" tag="ol">
|
|
|
|
<li v-for="panel in sortedPanels" :key="panel.id">
|
|
|
|
<input :id="'panel-checkbox-' + panel.id"
|
|
|
|
type="checkbox"
|
|
|
|
class="checkbox"
|
|
|
|
:checked="isActive(panel)"
|
|
|
|
@input="updateCheckbox(panel, $event.target.checked)">
|
|
|
|
<label :for="'panel-checkbox-' + panel.id" :class="panel.iconClass">
|
|
|
|
{{ panel.title }}
|
|
|
|
</label>
|
2020-06-15 09:18:50 +03:00
|
|
|
</li>
|
|
|
|
</transition-group>
|
2020-07-27 12:17:31 +03:00
|
|
|
|
|
|
|
<a :href="appStoreUrl" class="button">{{ t('dashboard', 'Get more widgets from the app store') }}</a>
|
2020-06-08 16:39:26 +03:00
|
|
|
</div>
|
2020-06-15 09:18:50 +03:00
|
|
|
</Modal>
|
2020-06-08 16:39:26 +03:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Vue from 'vue'
|
|
|
|
import { loadState } from '@nextcloud/initial-state'
|
|
|
|
import { getCurrentUser } from '@nextcloud/auth'
|
2020-06-15 09:18:50 +03:00
|
|
|
import { Modal } from '@nextcloud/vue'
|
2020-07-22 12:29:35 +03:00
|
|
|
import Draggable from 'vuedraggable'
|
2020-06-15 09:18:50 +03:00
|
|
|
import axios from '@nextcloud/axios'
|
|
|
|
import { generateUrl } from '@nextcloud/router'
|
2020-06-08 16:39:26 +03:00
|
|
|
|
|
|
|
const panels = loadState('dashboard', 'panels')
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
2020-06-15 09:18:50 +03:00
|
|
|
components: {
|
|
|
|
Modal,
|
|
|
|
Draggable,
|
|
|
|
},
|
2020-06-08 16:39:26 +03:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
timer: new Date(),
|
|
|
|
callbacks: {},
|
|
|
|
panels,
|
2020-07-31 14:18:47 +03:00
|
|
|
displayName: getCurrentUser()?.displayName,
|
|
|
|
uid: getCurrentUser()?.uid,
|
2020-06-15 09:18:50 +03:00
|
|
|
layout: loadState('dashboard', 'layout').filter((panelId) => panels[panelId]),
|
|
|
|
modal: false,
|
2020-07-22 12:29:35 +03:00
|
|
|
appStoreUrl: generateUrl('/settings/apps'),
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
greeting() {
|
|
|
|
const time = this.timer.getHours()
|
2020-07-31 14:18:47 +03:00
|
|
|
const shouldShowName = this.displayName && this.uid !== this.displayName
|
2020-06-08 16:39:26 +03:00
|
|
|
|
|
|
|
if (time > 18) {
|
2020-07-31 14:18:47 +03:00
|
|
|
return { icon: '🌙', text: shouldShowName ? t('dashboard', 'Good evening, {name}', { name: this.name }) : t('dashboard', 'Good evening') }
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
if (time > 12) {
|
2020-07-31 14:18:47 +03:00
|
|
|
return { icon: '☀', text: shouldShowName ? t('dashboard', 'Good afternoon, {name}', { name: this.name }) : t('dashboard', 'Good afternoon') }
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
if (time === 12) {
|
2020-07-31 14:18:47 +03:00
|
|
|
return { icon: '🍽', text: shouldShowName ? t('dashboard', 'Time for lunch, {name}', { name: this.name }) : t('dashboard', 'Time for lunch') }
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
2020-06-11 05:20:57 +03:00
|
|
|
if (time > 5) {
|
2020-07-31 14:18:47 +03:00
|
|
|
return { icon: '🌄', text: shouldShowName ? t('dashboard', 'Good morning, {name}', { name: this.name }) : t('dashboard', 'Good morning') }
|
2020-06-11 05:20:57 +03:00
|
|
|
}
|
2020-07-31 14:18:47 +03:00
|
|
|
return { icon: '🦉', text: shouldShowName ? t('dashboard', 'Have a night owl, {name}', { name: this.name }) : t('dashboard', 'Have a night owl') }
|
2020-06-08 16:39:26 +03:00
|
|
|
},
|
2020-06-15 09:18:50 +03:00
|
|
|
isActive() {
|
|
|
|
return (panel) => this.layout.indexOf(panel.id) > -1
|
|
|
|
},
|
|
|
|
sortedPanels() {
|
|
|
|
return Object.values(this.panels).sort((a, b) => {
|
|
|
|
const indexA = this.layout.indexOf(a.id)
|
|
|
|
const indexB = this.layout.indexOf(b.id)
|
|
|
|
if (indexA === -1 || indexB === -1) {
|
|
|
|
return indexB - indexA || a.id - b.id
|
|
|
|
}
|
|
|
|
return indexA - indexB || a.id - b.id
|
|
|
|
})
|
|
|
|
},
|
2020-06-08 16:39:26 +03:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
callbacks() {
|
2020-06-15 09:18:50 +03:00
|
|
|
this.rerenderPanels()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
setInterval(() => {
|
|
|
|
this.timer = new Date()
|
|
|
|
}, 30000)
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Method to register panels that will be called by the integrating apps
|
|
|
|
*
|
|
|
|
* @param {string} app The unique app id for the widget
|
|
|
|
* @param {function} callback The callback function to register a panel which gets the DOM element passed as parameter
|
|
|
|
*/
|
|
|
|
register(app, callback) {
|
|
|
|
Vue.set(this.callbacks, app, callback)
|
|
|
|
},
|
|
|
|
rerenderPanels() {
|
2020-06-08 16:39:26 +03:00
|
|
|
for (const app in this.callbacks) {
|
|
|
|
const element = this.$refs[app]
|
2020-07-27 12:17:31 +03:00
|
|
|
if (this.layout.indexOf(app) === -1) {
|
|
|
|
continue
|
|
|
|
}
|
2020-06-15 09:18:50 +03:00
|
|
|
if (this.panels[app] && this.panels[app].mounted) {
|
2020-07-10 11:02:44 +03:00
|
|
|
continue
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
if (element) {
|
|
|
|
this.callbacks[app](element[0])
|
|
|
|
Vue.set(this.panels[app], 'mounted', true)
|
|
|
|
} else {
|
|
|
|
console.error('Failed to register panel in the frontend as no backend data was provided for ' + app)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-06-15 09:18:50 +03:00
|
|
|
|
|
|
|
saveLayout() {
|
|
|
|
axios.post(generateUrl('/apps/dashboard/layout'), {
|
|
|
|
layout: this.layout.join(','),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
showModal() {
|
|
|
|
this.modal = true
|
|
|
|
},
|
|
|
|
closeModal() {
|
|
|
|
this.modal = false
|
|
|
|
},
|
|
|
|
updateCheckbox(panel, currentValue) {
|
|
|
|
const index = this.layout.indexOf(panel.id)
|
|
|
|
if (!currentValue && index > -1) {
|
|
|
|
this.layout.splice(index, 1)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.layout.push(panel.id)
|
|
|
|
}
|
|
|
|
Vue.set(this.panels[panel.id], 'mounted', false)
|
|
|
|
this.saveLayout()
|
|
|
|
this.$nextTick(() => this.rerenderPanels())
|
2020-06-08 16:39:26 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
#app-dashboard {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2020-07-11 12:50:24 +03:00
|
|
|
|
2020-06-08 16:39:26 +03:00
|
|
|
h2 {
|
|
|
|
text-align: center;
|
2020-06-11 05:21:24 +03:00
|
|
|
font-size: 32px;
|
|
|
|
line-height: 130%;
|
|
|
|
padding: 80px 16px 32px;
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
.panels {
|
2020-07-22 12:29:35 +03:00
|
|
|
width: auto;
|
|
|
|
margin: auto;
|
|
|
|
max-width: 1500px;
|
2020-06-08 16:39:26 +03:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2020-06-11 05:21:24 +03:00
|
|
|
flex-direction: row;
|
2020-07-10 11:02:44 +03:00
|
|
|
align-items: flex-start;
|
2020-06-11 05:21:24 +03:00
|
|
|
flex-wrap: wrap;
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
|
2020-06-15 09:18:50 +03:00
|
|
|
.panel, .panels > div {
|
2020-07-10 18:04:57 +03:00
|
|
|
width: 320px;
|
|
|
|
max-width: 100%;
|
|
|
|
margin: 16px;
|
2020-07-10 18:35:18 +03:00
|
|
|
background-color: var(--color-main-background-translucent);
|
2020-07-10 18:04:57 +03:00
|
|
|
border-radius: var(--border-radius-large);
|
|
|
|
border: 2px solid var(--color-border);
|
2020-06-08 16:39:26 +03:00
|
|
|
|
2020-07-22 12:29:35 +03:00
|
|
|
&.sortable-ghost {
|
|
|
|
opacity: 0.1;
|
|
|
|
}
|
|
|
|
|
2020-06-15 09:18:50 +03:00
|
|
|
& > .panel--header {
|
2020-06-08 16:39:26 +03:00
|
|
|
position: sticky;
|
2020-07-10 18:35:18 +03:00
|
|
|
display: flex;
|
2020-07-11 12:50:24 +03:00
|
|
|
z-index: 1;
|
2020-06-08 16:39:26 +03:00
|
|
|
top: 50px;
|
2020-07-10 18:35:18 +03:00
|
|
|
padding: 16px;
|
2020-07-10 18:59:17 +03:00
|
|
|
// TO DO: use variables here
|
|
|
|
background: linear-gradient(170deg, rgba(0, 130,201, 0.2) 0%, rgba(255,255,255,.1) 50%, rgba(255,255,255,0) 100%);
|
|
|
|
border-top-left-radius: calc(var(--border-radius-large) - 2px);
|
|
|
|
border-top-right-radius: calc(var(--border-radius-large) - 2px);
|
2020-06-11 05:21:24 +03:00
|
|
|
backdrop-filter: blur(4px);
|
2020-07-10 18:35:18 +03:00
|
|
|
cursor: grab;
|
|
|
|
|
2020-07-22 12:29:35 +03:00
|
|
|
&, ::v-deep * {
|
|
|
|
-webkit-touch-callout: none;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-khtml-user-select: none;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:35:18 +03:00
|
|
|
&:active {
|
|
|
|
cursor: grabbing;
|
|
|
|
}
|
|
|
|
|
2020-06-15 09:18:50 +03:00
|
|
|
a {
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
2020-06-08 16:39:26 +03:00
|
|
|
|
2020-06-11 05:21:24 +03:00
|
|
|
h3 {
|
2020-06-15 09:18:50 +03:00
|
|
|
display: block;
|
|
|
|
flex-grow: 1;
|
2020-06-11 05:21:24 +03:00
|
|
|
margin: 0;
|
|
|
|
font-size: 20px;
|
|
|
|
font-weight: bold;
|
|
|
|
background-size: 32px;
|
2020-07-31 15:48:59 +03:00
|
|
|
background-position: 14px 12px;
|
2020-07-11 12:50:24 +03:00
|
|
|
padding: 16px 8px 16px 60px;
|
2020-07-10 18:35:18 +03:00
|
|
|
cursor: grab;
|
2020-06-11 05:21:24 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-10 18:35:18 +03:00
|
|
|
|
|
|
|
& > .panel--content {
|
|
|
|
margin: 0 16px 16px 16px;
|
2020-07-22 12:29:35 +03:00
|
|
|
height: 420px;
|
|
|
|
overflow: auto;
|
2020-07-10 18:35:18 +03:00
|
|
|
}
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
|
2020-07-10 18:04:57 +03:00
|
|
|
.edit-panels {
|
2020-06-15 09:18:50 +03:00
|
|
|
position: fixed;
|
|
|
|
bottom: 20px;
|
|
|
|
right: 20px;
|
|
|
|
padding: 10px;
|
|
|
|
padding-left: 35px;
|
|
|
|
padding-right: 15px;
|
|
|
|
background-position: 10px center;
|
2020-07-10 18:35:18 +03:00
|
|
|
opacity: .7;
|
|
|
|
background-color: var(--color-main-background);
|
2020-07-10 18:04:57 +03:00
|
|
|
border-radius: var(--border-radius-pill);
|
2020-06-15 09:18:50 +03:00
|
|
|
&:hover {
|
2020-07-10 18:35:18 +03:00
|
|
|
opacity: 1;
|
2020-06-15 09:18:50 +03:00
|
|
|
background-color: var(--color-background-hover);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.modal__content {
|
|
|
|
width: 30vw;
|
|
|
|
margin: 20px;
|
|
|
|
ol {
|
2020-07-27 12:17:31 +03:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2020-06-15 09:18:50 +03:00
|
|
|
list-style-type: none;
|
|
|
|
}
|
|
|
|
li label {
|
|
|
|
padding: 10px;
|
|
|
|
display: block;
|
|
|
|
list-style-type: none;
|
2020-07-22 12:29:35 +03:00
|
|
|
background-size: 16px;
|
|
|
|
background-position: left center;
|
|
|
|
padding-left: 26px;
|
2020-06-15 09:18:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.flip-list-move {
|
|
|
|
transition: transform 1s;
|
|
|
|
}
|
|
|
|
|
2020-06-08 16:39:26 +03:00
|
|
|
</style>
|