Browse Source

Use proper public javascript methods

Signed-off-by: Julius Härtl <jus@bitgrid.net>
tags/v16.0.0alpha1
Julius Härtl 5 years ago
parent
commit
51057c539f
No account linked to committer's email address

+ 8
- 50
apps/files_sharing/src/collaborationresources.js View File

@@ -36,55 +36,10 @@ 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'
});
console.log('register types');

/* TODO: temporary data for testing */
window.Collaboration.registerType('calendar', {
window.OCP.Collaboration.registerType('calendar', {
action: () => {
return new Promise((resolve, reject) => {
var id = window.prompt("calendar id", "1");
@@ -92,9 +47,10 @@ window.Collaboration.registerType('calendar', {
})
},
icon: 'icon-calendar-dark',
typeName: 'calendar',
typeString: 'calendar',
link: (id) => '#' + id,
});
window.Collaboration.registerType('contact', {
window.OCP.Collaboration.registerType('contact', {
action: () => {
return new Promise((resolve, reject) => {
var id = window.prompt("contacts id", "1");
@@ -102,7 +58,9 @@ window.Collaboration.registerType('contact', {
})
},
icon: 'icon-contacts-dark',
typeName: 'contact',
link: (id) => '#' + id,
/** used in "Link to a {typeString}" */
typeString: 'contact'
});

export { Vue, View }

+ 9
- 8
apps/files_sharing/src/components/CollectionListItem.vue View File

@@ -24,11 +24,12 @@
<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>
<transition name="fade">
<div class="linked-icons" v-if="!detailsOpen">
<a v-for="resource in collection.resources" :href="getLink(resource)" v-tooltip="resource.name" :key="resource.id"><span :class="getIcon(resource)"></span></a>
</div>
</transition>

<span class="sharingOptionsGroup">
<div class="share-menu" v-click-outside="close">
<a href="#" class="icon icon-more" @click="toggle"></a>
@@ -41,7 +42,7 @@
<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>
<a :href="getLink(resource)"><span :class="getIcon(resource)"></span> {{ resource.name || '' }}</a>
<span class="icon-delete"></span>
</li>
</ul>
@@ -91,10 +92,10 @@
]
},
getIcon() {
return (resource) => [window.Collaboration.getIcon(resource.type)]
return (resource) => [window.OCP.Collaboration.getIcon(resource.type)]
},
getLink() {
return (resource) => window.Collaboration.getLink(resource.type, resource.id)
return (resource) => window.OCP.Collaboration.getLink(resource.type, resource.id)
}
},
methods: {

+ 19
- 0
apps/files_sharing/src/files_sharing.js View File

@@ -13,4 +13,23 @@ import '../js/sharetabview'
import '../js/share'
import '../js/sharebreadcrumbview'

window.OCP.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'
});

window.OCA.Sharing = OCA.Sharing

+ 11
- 7
apps/files_sharing/src/views/CollaborationView.vue View File

@@ -110,13 +110,13 @@
},
options() {
let options = [];
let types = window.Collaboration.getTypes();
let types = window.OCP.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])
title: window.OCP.Collaboration.getLabel(types[type]),
class: window.OCP.Collaboration.getIcon(types[type]),
action: () => window.OCP.Collaboration.trigger(types[type])
})
}
for(let index in this.collections) {
@@ -161,13 +161,16 @@
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((response) => {
console.log(response.data.ocs.data)
let newCollection = response.data.ocs.data
console.log('Add new collection', newCollection)
this.collections.push(newCollection)
this.addResourceToCollection(newCollection.id, resourceType.toString(), resourceId.toString())
});
},
addResourceToCollection(collectionId, resourceType, resourceId) {
/** TODO move to service */
const resourceBase = OC.linkToOCS(`collaboration/resources/collections`, 2);
axios.post(`${resourceBase}${collectionId}?format=json`, {
return axios.post(`${resourceBase}${collectionId}?format=json`, {
resourceType,
resourceId
}, {
@@ -176,7 +179,8 @@
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((response) => {
console.log(response)
console.log('Add new collection', response.data.ocs.data)
this.collections.find((_item) => _item.id === collectionId).resources.push(response.data.ocs.data)
});
}
}

Loading…
Cancel
Save