Add vue app for collaboration resources

Signed-off-by: Julius Härtl <jus@bitgrid.net>

Add js api for resources

Signed-off-by: Julius Härtl <jus@bitgrid.net>

More frontend work

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-01-17 13:11:16 +01:00
parent d6aae4317d
commit 322f7c3c85
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
5 changed files with 521 additions and 0 deletions

View File

@ -0,0 +1,108 @@
/*
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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/>.
*
*/
import Vue from 'vue'
import { PopoverMenu } from 'nextcloud-vue'
import ClickOutside from 'vue-click-outside'
import { VTooltip } from 'v-tooltip'
Vue.prototype.t = t;
Vue.component('PopoverMenu', PopoverMenu)
Vue.directive('ClickOutside', ClickOutside)
Vue.directive('Tooltip', VTooltip)
import View from './views/CollaborationView'
let selectAction = {};
let icons = {};
let types = {};
window.Collaboration = {
/**
*
* @param type
* @param {callback} selectCallback should return a promise
*/
registerType(type, typeDefinition) {
types[type] = typeDefinition;
},
trigger(type) {
return types[type].action()
},
getTypes() {
return Object.keys(types);
},
getIcon(type) {
return types[type].icon;
},
getLabel(type) {
return t('files_sharing', 'Link to a {label}', { label: types[type].typeString || type }, 1)
},
getLink(type, id) {
/* TODO: Allow action to be executed instead of href as well */
return types[type].link(id);
}
}
window.Collaboration.registerType('files', {
action: () => {
return new Promise((resolve, reject) => {
OC.dialogs.filepicker('Link to a file', function (f) {
const client = OC.Files.getClient();
client.getFileInfo(f).then((status, fileInfo) => {
resolve(fileInfo.id)
}, () => {
reject()
})
}, false);
})
},
link: (id) => OC.generateUrl('/f/') + id,
icon: 'nav-icon-files',
/** used in "Link to a {typeString}" */
typeString: 'file'
});
/* TODO: temporary data for testing */
window.Collaboration.registerType('calendar', {
action: () => {
return new Promise((resolve, reject) => {
var id = window.prompt("calendar id", "1");
resolve(id);
})
},
icon: 'icon-calendar-dark',
typeName: 'calendar',
});
window.Collaboration.registerType('contact', {
action: () => {
return new Promise((resolve, reject) => {
var id = window.prompt("contacts id", "1");
resolve(id);
})
},
icon: 'icon-contacts-dark',
typeName: 'contact',
});
export { Vue, View }

View File

@ -0,0 +1,158 @@
<!--
- @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
-
- @author Julius Härtl <jus@bitgrid.net>
-
- @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>
<li class="collection-list">
<avatar :displayName="collection.name" :allowPlaceholder="true"></avatar>
<span class="username" title="">{{ collection.name }}</span>
<div class="linked-icons">
<transition name="fade">
<a v-if="!detailsOpen" v-for="resource in collection.resources" :href="getLink(resource)" v-tooltip="resource.name"><span :class="getIcon(resource)"></span></a>
</transition>
</div>
<span class="sharingOptionsGroup">
<div class="share-menu" v-click-outside="close">
<a href="#" class="icon icon-more" @click="toggle"></a>
<span class="icon icon-loading-small hidden"></span>
<div class="popovermenu" :class="{open: isOpen}">
<popover-menu :menu="menu"></popover-menu>
</div>
</div>
</span>
<transition name="fade">
<ul class="resource-list-details" v-if="detailsOpen" v-click-outside="hideDetails">
<li v-for="resource in collection.resources">
<a :href="getLink(resource)"><span :class="getIcon(resource)"></span> {{ resource.name }}</a>
<span class="icon-delete"></span>
</li>
</ul>
</transition>
</li>
</template>
<script>
import { Avatar } from 'nextcloud-vue';
export default {
name: 'CollectionListItem',
components: {
Avatar
},
props: {
collection: {
type: Object
}
},
data() {
return {
isOpen: false,
detailsOpen: false
}
},
computed: {
menu() {
return [
{
action: () => {
this.detailsOpen = true
this.isOpen = false
},
icon: 'icon-info',
text: t('files_sharing', 'Details'),
},
{
action: () => { },
icon: 'icon-rename',
text: t('files_sharing', 'Rename collection'),
},{
action: () => { },
icon: 'icon-delete',
text: t('files_sharing', 'Remove collection'),
}
]
},
getIcon() {
return (resource) => [window.Collaboration.getIcon(resource.type)]
},
getLink() {
return (resource) => window.Collaboration.getLink(resource.type, resource.id)
}
},
methods: {
open() {
this.isOpen = true
},
close() {
this.isOpen = false
},
toggle() {
this.isOpen = !this.isOpen
},
hideDetails() {
this.detailsOpen = false
}
}
}
</script>
<style scoped lang="scss">
.fade-enter-active, .fade-leave-active {
transition: opacity .3s ease;
}
.fade-enter, .fade-leave-to
/* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
}
.linked-icons {
display: flex;
span {
padding: 16px;
display: block;
background-repeat: no-repeat;
background-position: center;
opacity: 0.7;
&:hover {
opacity: 1;
}
}
}
.collection-list {
flex-wrap: wrap;
.resource-list-details {
width: 100%;
li {
display: flex;
margin-left: 44px;
a {
flex-grow: 1;
padding: 3px;
}
}
span {
display: inline-block;
padding: 8px;
vertical-align: top;
margin-right: 10px;
}
}
}
</style>

View File

@ -0,0 +1,59 @@
/*
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @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/>.
*
*/
import axios from 'nextcloud-axios';
class Service {
constructor() {
this.service = axios.create();
}
listCollection(collectionId) {
return this.service.get(`/collaboration/resources/collections/${collectionId}`)
}
addResource(collectionId, resource) {
return this.service.post(`/collaboration/resources/collections/${collectionId}`)
}
removeResource() {
return this.service.post(`/collaboration/resources/collections/${collectionId}`)
}
createCollectionOnResource(resourceType, resourceId) {
return this.service.post(`/collaboration/resources/${resourceType}/${resourceId}`)
}
getCollectionByResource(resourceType, resourceId) {
return this.service.get(`/collaboration/resources/${resourceType}/${resourceId}`)
}
getProviders() {
}
search() {
}
}
export default new Service;

View File

@ -83,6 +83,18 @@
self.trigger('sharesChanged', shareModel);
});
import('./../src/collaborationresources').then((Resources) => {
var vm = new Resources.Vue({
el: '#collaborationResources',
render: h => h(Resources.View),
data: {
model: this.model.toJSON()
},
});
this.model.on('change', () => { vm.data = this.model.toJSON() })
})
} else {
this.$el.empty();
// TODO: render placeholder text?

View File

@ -0,0 +1,184 @@
<template>
<div :class="{'icon-loading': !collections}">
<ul id="shareWithList" class="shareWithList" v-if="collections">
<li @click="showSelect">
<div class="avatar"><span class="icon-category-integration icon-white"></span></div>
<multiselect v-model="value" :options="options" :placeholder="placeholder" tag-placeholder="Create a new collection" ref="select" @select="select" label="title" track-by="title" :reset-after="true">
<template slot="singleLabel" slot-scope="props">
<span class="option__desc">
<span class="option__title">{{ props.option.title }}</span></span>
</template>
<template slot="option" slot-scope="props">
<span class="option__wrapper">
<span v-if="props.option.class" :class="props.option.class" class="avatar"></span>
<avatar v-else :displayName="props.option.title" :allowPlaceholder="true"></avatar>
<span class="option__title">{{ props.option.title }}</span>
</span>
</template>
</multiselect>
</li>
<collection-list-item v-for="collection in collections" :collection="collection" :key="collection.id" />
</ul>
</div>
</template>
<style lang="scss" scoped>
.multiselect {
width: 100%;
margin-left: 3px;
}
span.avatar {
padding: 16px;
display: block;
background-repeat: no-repeat;
background-position: center;
opacity: 0.7;
&:hover {
opacity: 1;
}
}
/** TODO provide white icon in core */
.icon-category-integration.icon-white {
filter: invert(100%);
padding: 16px;
display: block;
background-repeat: no-repeat;
background-position: center;
}
.option__wrapper {
display: flex;
.avatar {
display: block;
background-color: var(--color-background-darker) !important;
}
.option__title {
padding: 4px;
}
}
</style>
<style lang="scss">
/** TODO check why this doesn't work when scoped */
.shareWithList .multiselect:not(.multiselect--active ) .multiselect__tags {
border: none !important;
input::placeholder {
color: var(--color-main-text);
}
}
</style>
<script>
import { Multiselect, Avatar } from 'nextcloud-vue';
import CollectionListItem from '../components/CollectionListItem';
import axios from 'nextcloud-axios';
export default {
name: 'CollaborationView',
components: {
CollectionListItem,
Avatar,
Multiselect: Multiselect,
},
data() {
return {
selectIsOpen: false,
generatingCodes: false,
codes: undefined,
value: null,
model: {},
collections: null
};
},
mounted() {
let resourceId = this.$root.model.id
/** TODO move to service */
const resourceBase = OC.linkToOCS(`collaboration/resources/files`);
axios.get(`${resourceBase}${resourceId}?format=json`, {
headers: {
'OCS-APIRequest': true,
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((response) => {
this.collections = response.data.ocs.data
});
},
computed: {
placeholder() {
return t('files_sharing', 'Add to a collection');
},
options() {
let options = [];
let types = window.Collaboration.getTypes();
for(let type in types) {
options.push({
type: types[type],
title: window.Collaboration.getLabel(types[type]),
class: window.Collaboration.getIcon(types[type]),
action: () => window.Collaboration.trigger(types[type])
})
}
for(let index in this.collections) {
options.push({
title: this.collections[index].name
})
}
return options;
}
},
created: function() {
},
methods: {
select(selectedOption, id) {
selectedOption.action().then((id) => {
console.log('Create a new collection with')
console.log('This file ', this.$root.model.id)
console.log('Selected resource ', selectedOption.type, id)
this.createCollection(this.$root.model.id, selectedOption.type, id)
}).catch((e) => {
console.error('No resource selected');
});
},
showSelect() {
this.selectIsOpen = true
this.$refs.select.$el.focus()
},
hideSelect() {
this.selectIsOpen = false
},
isVueComponent(object) {
return object._isVue
},
createCollection(resourceIdBase, resourceType, resourceId) {
/** TODO move to service */
const resourceBase = OC.linkToOCS(`collaboration/resources/files`, 2);
axios.post(`${resourceBase}${resourceIdBase}?format=json`, {
name: 'Example collection'
}, {
headers: {
'OCS-APIRequest': true,
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((response) => {
console.log(response.data.ocs.data)
});
},
addResourceToCollection(collectionId, resourceType, resourceId) {
/** TODO move to service */
const resourceBase = OC.linkToOCS(`collaboration/resources/collections`, 2);
axios.post(`${resourceBase}${collectionId}?format=json`, {
resourceType,
resourceId
}, {
headers: {
'OCS-APIRequest': true,
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((response) => {
console.log(response)
});
}
}
}
</script>