Add eslint settings and reorganize files

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

Add files_sharing package-lock

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-01-31 11:03:03 +01:00
parent e404ce7096
commit d1a4856b5d
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
8 changed files with 6424 additions and 130 deletions

View file

@ -0,0 +1,22 @@
module.exports = {
env: {
browser: true,
es6: true
},
globals: {
t: true,
n: true,
OC: true,
OCA: true
},
extends: 'eslint:recommended',
parserOptions: {
sourceType: 'module'
},
rules: {
indent: ['error', 'tab'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always']
}
};

6245
apps/files_sharing/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -20,20 +20,24 @@
* *
*/ */
import Vue from 'vue' import Vue from 'vue';
import Vuex from 'vuex' import Vuex from 'vuex';
import { PopoverMenu } from 'nextcloud-vue' import { PopoverMenu } from 'nextcloud-vue';
import ClickOutside from 'vue-click-outside' import ClickOutside from 'vue-click-outside';
import { VTooltip } from 'v-tooltip' import { VTooltip } from 'v-tooltip';
import { Store } from './services/collections'; import { CollectionStore as Store } from './collectionstore';
Vue.prototype.t = t; Vue.prototype.t = t;
Vue.component('PopoverMenu', PopoverMenu) Vue.component('PopoverMenu', PopoverMenu);
Vue.directive('ClickOutside', ClickOutside) Vue.directive('ClickOutside', ClickOutside);
Vue.directive('Tooltip', VTooltip) Vue.directive('Tooltip', VTooltip);
Vue.use(Vuex); Vue.use(Vuex);
import View from './CollaborationView' import View from './views/CollaborationView';
export { Vue, View, Store } export {
Vue,
View,
Store
};

View file

@ -0,0 +1,101 @@
/*
* @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 CollectionService {
constructor() {
this.http = axios;
this.baseUrl = OC.linkToOCS('collaboration/resources', 2);
}
listCollection(collectionId) {
return this.http.get(`${this.baseUrl}collections/${collectionId}`);
}
renameCollection(collectionId, collectionName) {
const resourceBase = OC.linkToOCS('collaboration/resources/collections', 2);
return this.http.put(`${resourceBase}${collectionId}?format=json`, {
collectionName
}).then(result => {
return result.data.ocs.data;
});
}
getCollectionsByResource(resourceType, resourceId) {
const resourceBase = OC.linkToOCS(`collaboration/resources/${resourceType}`, 2);
return this.http.get(`${resourceBase}${resourceId}?format=json`)
.then(result => {
return result.data.ocs.data;
})
.catch(error => {
console.error(error);
return Promise.reject(error);
});
}
createCollection(resourceType, resourceId, name) {
const resourceBase = OC.linkToOCS(`collaboration/resources/${resourceType}`, 2);
return this.http.post(`${resourceBase}${resourceId}?format=json`, {
name: name
})
.then((response) => {
return response.data.ocs.data;
})
.catch(error => {
console.error(error);
return Promise.reject(error);
});
}
addResource(collectionId, resourceType, resourceId) {
resourceId = '' + resourceId;
const resourceBase = OC.linkToOCS('collaboration/resources/collections', 2);
return this.http.post(`${resourceBase}${collectionId}?format=json`, {
resourceType,
resourceId
}).then((response) => {
return response.data.ocs.data;
});
}
removeResource(collectionId, resourceType, resourceId) {
return this.http.delete(`${this.baseUrl}/collections/${collectionId}`, { params: { resourceType, resourceId } } )
.then((response) => {
return response.data.ocs.data;
});
}
search(query) {
const searchBase = OC.linkToOCS('collaboration/resources/collections/search', 2);
return this.http.get(`${searchBase}%25${query}%25?format=json`)
.then((response) => {
return response.data.ocs.data;
});
}
}
const service = new CollectionService();
export default service;

View file

@ -20,86 +20,11 @@
* *
*/ */
import axios from 'nextcloud-axios';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Vue from 'vue'; import Vue from 'vue';
import service from './collectionservice';
class Service { const CollectionStoreModule = {
constructor() {
this.http = axios;
this.baseUrl = OC.linkToOCS(`collaboration/resources`);
}
listCollection(collectionId) {
return this.http.get(`${this.baseUrl}collections/${collectionId}`)
}
renameCollection(collectionId, collectionName) {
const resourceBase = OC.linkToOCS(`collaboration/resources/collections`, 2);
return this.http.put(`${resourceBase}${collectionId}?format=json`, {
collectionName
}).then(result => {
return result.data.ocs.data;
})
}
getCollectionsByResource(resourceType, resourceId) {
const resourceBase = OC.linkToOCS(`collaboration/resources/${resourceType}`);
return this.http.get(`${resourceBase}${resourceId}?format=json`)
.then(result => {
return result.data.ocs.data;
})
.catch(error => {
console.error(error);
return Promise.reject(error);
});
}
createCollection(resourceType, resourceId, name) {
const resourceBase = OC.linkToOCS(`collaboration/resources/${resourceType}`, 2);
return this.http.post(`${resourceBase}${resourceId}?format=json`, {
name: name
})
.then((response) => {
return response.data.ocs.data
})
.catch(error => {
console.error(error);
return Promise.reject(error);
});
}
addResource(collectionId, resourceType, resourceId) {
resourceId = '' + resourceId;
const resourceBase = OC.linkToOCS(`collaboration/resources/collections`, 2);
return this.http.post(`${resourceBase}${collectionId}?format=json`, {
resourceType,
resourceId
}).then((response) => {
return response.data.ocs.data
});
}
removeResource(collectionId, resourceType, resourceId) {
return this.http.delete(`${this.baseUrl}/collections/${collectionId}`, { params: { resourceType, resourceId } } )
.then((response) => {
return response.data.ocs.data
});
}
search(query) {
const searchBase = OC.linkToOCS(`collaboration/resources/collections/search`);
return this.http.get(`${searchBase}%25${query}%25?format=json`)
.then((response) => {
return response.data.ocs.data
});
}
}
const service = new Service();
const StoreModule = {
state: { state: {
collections: [] collections: []
}, },
@ -108,17 +33,17 @@ const StoreModule = {
state.collections = collections; state.collections = collections;
}, },
addCollection (state, collection) { addCollection (state, collection) {
state.collections.push(collection) state.collections.push(collection);
}, },
removeCollection (state, collectionId) { removeCollection (state, collectionId) {
state.collections = state.collections.filter(item => item.id !== collectionId) state.collections = state.collections.filter(item => item.id !== collectionId);
}, },
updateCollection(state, collection) { updateCollection(state, collection) {
let index = state.collections.findIndex((_item) => _item.id === collection.id) let index = state.collections.findIndex((_item) => _item.id === collection.id);
if (index !== -1) { if (index !== -1) {
Vue.set(state.collections, index, collection); Vue.set(state.collections, index, collection);
} else { } else {
state.collections.push(collection) state.collections.push(collection);
} }
} }
}, },
@ -126,60 +51,59 @@ const StoreModule = {
collectionsByResource(state) { collectionsByResource(state) {
return (resourceType, resourceId) => { return (resourceType, resourceId) => {
return state.collections.filter((collection) => { return state.collections.filter((collection) => {
return typeof collection.resources.find((resource) => resource && resource.id === ''+resourceId && resource.type === resourceType) !== 'undefined' return typeof collection.resources.find((resource) => resource && resource.id === ''+resourceId && resource.type === resourceType) !== 'undefined';
}) });
} };
}, },
getSearchResults(state) { getSearchResults(state) {
return (term) => { return (term) => {
return state.collections.filter((collection) => collection.name.contains(term)) return state.collections.filter((collection) => collection.name.contains(term));
} };
} }
}, },
actions: { actions: {
fetchCollectionsByResource(context, {resourceType, resourceId}) { fetchCollectionsByResource(context, {resourceType, resourceId}) {
return service.getCollectionsByResource(resourceType, resourceId).then((collections) => { return service.getCollectionsByResource(resourceType, resourceId).then((collections) => {
context.commit('addCollections', collections) context.commit('addCollections', collections);
return collections; return collections;
}); });
}, },
createCollection(context, {baseResourceType, baseResourceId, resourceType, resourceId, name}) { createCollection(context, {baseResourceType, baseResourceId, resourceType, resourceId, name}) {
return service.createCollection(baseResourceType, baseResourceId, name).then((collection) => { return service.createCollection(baseResourceType, baseResourceId, name).then((collection) => {
context.commit('addCollection', collection) context.commit('addCollection', collection);
context.dispatch('addResourceToCollection', { context.dispatch('addResourceToCollection', {
collectionId: collection.id, collectionId: collection.id,
resourceType, resourceId resourceType, resourceId
}) });
}) });
}, },
renameCollection(context, {collectionId, name}) { renameCollection(context, {collectionId, name}) {
return service.renameCollection(collectionId, name).then((collection) => { return service.renameCollection(collectionId, name).then((collection) => {
context.commit('updateCollection', collection) context.commit('updateCollection', collection);
return collection return collection;
}) });
}, },
addResourceToCollection(context, {collectionId, resourceType, resourceId}) { addResourceToCollection(context, {collectionId, resourceType, resourceId}) {
return service.addResource(collectionId, resourceType, resourceId).then((collection) => { return service.addResource(collectionId, resourceType, resourceId).then((collection) => {
context.commit('updateCollection', collection) context.commit('updateCollection', collection);
return collection return collection;
}) });
}, },
removeResource(context, {collectionId, resourceType, resourceId}) { removeResource(context, {collectionId, resourceType, resourceId}) {
return service.removeResource(collectionId, resourceType, resourceId).then((collection) => { return service.removeResource(collectionId, resourceType, resourceId).then((collection) => {
if (collection.resources.length > 0) { if (collection.resources.length > 0) {
context.commit('updateCollection', collection) context.commit('updateCollection', collection);
} else { } else {
context.commit('removeCollection', collectionId) context.commit('removeCollection', collectionId);
} }
}) });
}, },
search(context, query) { search(context, query) {
return service.search(query) return service.search(query);
} }
} }
} };
const Store = () => new Vuex.Store(StoreModule); const CollectionStore = () => new Vuex.Store(CollectionStoreModule);
export default service; export { CollectionStoreModule, CollectionStore };
export { StoreModule, Store };

View file

@ -55,8 +55,6 @@
</template> </template>
<script> <script>
import service from '../services/collections';
import { Avatar } from 'nextcloud-vue'; import { Avatar } from 'nextcloud-vue';
export default { export default {

View file

@ -1,12 +1,12 @@
__webpack_nonce__ = btoa(OC.requestToken) __webpack_nonce__ = btoa(OC.requestToken);
__webpack_public_path__ = OC.linkTo('files_sharing', 'js/dist/') __webpack_public_path__ = OC.linkTo('files_sharing', 'js/dist/');
import '../js/app' import '../js/app';
import '../js/sharedfilelist' import '../js/sharedfilelist';
import '../js/sharetabview' import '../js/sharetabview';
import '../js/share' import '../js/share';
import '../js/sharebreadcrumbview' import '../js/sharebreadcrumbview';
window.OCP.Collaboration.registerType('files', { window.OCP.Collaboration.registerType('files', {
action: () => { action: () => {
@ -14,15 +14,15 @@ window.OCP.Collaboration.registerType('files', {
OC.dialogs.filepicker('Link to a file', function (f) { OC.dialogs.filepicker('Link to a file', function (f) {
const client = OC.Files.getClient(); const client = OC.Files.getClient();
client.getFileInfo(f).then((status, fileInfo) => { client.getFileInfo(f).then((status, fileInfo) => {
resolve(fileInfo.id) resolve(fileInfo.id);
}, () => { }, () => {
reject() reject();
}) });
}, false); }, false);
}) });
}, },
/** used in "Link to a {typeString}" */ /** used in "Link to a {typeString}" */
typeString: t('files_sharing', 'file') typeString: t('files_sharing', 'file')
}); });
window.OCA.Sharing = OCA.Sharing window.OCA.Sharing = OCA.Sharing;

View file

@ -25,7 +25,7 @@
</template> </template>
<script> <script>
import CollectionList from './components/CollectionList' import CollectionList from './../components/CollectionList'
export default { export default {
name: 'CollaborationView', name: 'CollaborationView',