fetch file version done and Code Clean Up
This commit is contained in:
parent
0f8a12352d
commit
ac5e55673a
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -37,12 +37,13 @@
|
|||
<script>
|
||||
import Actions from '@nextcloud/vue/dist/Components/Actions'
|
||||
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
|
||||
|
||||
import ListItemIcon from '@nextcloud/vue/dist/Components/ListItemIcon'
|
||||
export default {
|
||||
name: 'VersionEntry',
|
||||
|
||||
components: {
|
||||
Actions,
|
||||
ListItemIcon
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -23,32 +23,22 @@
|
|||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import VueClipboard from 'vue-clipboard2'
|
||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
|
||||
|
||||
import VersionTab from '../../files_versions/src/views/VersionTab'
|
||||
import TabSections from '../../files_versions/src/services/TabSections'
|
||||
|
||||
// Init Version Tab Service
|
||||
if (!window.OCA.Versions) {
|
||||
window.OCA.Versions = {}
|
||||
}
|
||||
|
||||
Object.assign(window.OCA.Versions, { VersionTabSections: new TabSections() })
|
||||
|
||||
Vue.prototype.t = t
|
||||
Vue.prototype.n = n
|
||||
Vue.use(VueClipboard)
|
||||
|
||||
// Init Sharing tab component
|
||||
// Init Version tab component
|
||||
const View = Vue.extend(VersionTab)
|
||||
let TabInstance = null
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
if (OCA.Files && OCA.Files.Sidebar) {
|
||||
OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab({
|
||||
id: 'versions',
|
||||
name: t('files_versions', 'version'),
|
||||
id: 'version_new',
|
||||
name: t('files_versions', 'VueVersions'),
|
||||
icon: 'icon-version',
|
||||
async mount(el, fileInfo, context) {
|
||||
if (TabInstance) {
|
||||
|
|
|
@ -21,9 +21,29 @@
|
|||
|
||||
import client from './DavClient'
|
||||
import { genFileInfo } from '../utils/fileUtils'
|
||||
import axios from "@nextcloud/axios";
|
||||
import {generateRemoteUrl} from "@nextcloud/router";
|
||||
import { getCurrentUser } from '@nextcloud/auth';
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
|
||||
let FileVersion = async function(fileId) {
|
||||
|
||||
|
||||
// init params
|
||||
const VersionsUrl = '/versions/' + fileId
|
||||
const response = await client.getDirectoryContents(VersionsUrl,{
|
||||
data: `<?xml version="1.0"?>
|
||||
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
|
||||
<d:prop>
|
||||
<d:getcontentlength />
|
||||
<d:getcontenttype />
|
||||
<d:getlastmodified />
|
||||
</d:prop>
|
||||
</d:propfind>`,
|
||||
details: true,
|
||||
})
|
||||
console.log(response);
|
||||
/** return response.data.map(FileVersion); */
|
||||
|
||||
return response.data
|
||||
};
|
||||
/**
|
||||
* Retrieve the files list
|
||||
*
|
||||
|
@ -31,55 +51,4 @@ import { getCurrentUser } from '@nextcloud/auth';
|
|||
* @param {Object} [options] optional options for axios
|
||||
* @returns {Array} the file list
|
||||
*/
|
||||
export default async function(client) {
|
||||
// getDirectoryContents doesn't accept / for root
|
||||
getCurrentUser(){
|
||||
return this._currentUser || getCurrentUser().uid
|
||||
}
|
||||
|
||||
// init params
|
||||
const shareUrl = generateRemoteUrl('dav') + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id')
|
||||
const format = 'json'
|
||||
|
||||
// TODO: replace with proper getFUllpath implementation of our own FileInfo model
|
||||
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
|
||||
// Fetch Version
|
||||
const fetchFileVersions = await axios.get(shareUrl, {
|
||||
params: {
|
||||
format,
|
||||
path,
|
||||
},
|
||||
})
|
||||
// wait for data
|
||||
const response = await client.getDirectoryContents(fixedPath, Object.assign({
|
||||
data: `<?xml version="1.0"?>
|
||||
<d:propfind xmlns:d="DAV:"
|
||||
xmlns:oc="http://owncloud.org/ns"
|
||||
xmlns:nc="http://nextcloud.org/ns"
|
||||
xmlns:ocs="http://open-collaboration-services.org/ns">
|
||||
<d:prop>
|
||||
<d:getlastmodified />
|
||||
<d:getetag />
|
||||
<d:getcontenttype />
|
||||
<d:resourcetype />
|
||||
<oc:fileid />
|
||||
<oc:permissions />
|
||||
<oc:size />
|
||||
<d:getcontentlength />
|
||||
<nc:has-preview />
|
||||
<nc:mount-type />
|
||||
<nc:is-encrypted />
|
||||
<ocs:share-permissions />
|
||||
<oc:tags />
|
||||
<oc:favorite />
|
||||
<oc:comments-unread />
|
||||
<oc:owner-id />
|
||||
<oc:owner-display-name />
|
||||
<oc:share-types />
|
||||
</d:prop>
|
||||
</d:propfind>`,
|
||||
details: true,
|
||||
}, options))
|
||||
|
||||
return response.data.map(FileVersion)
|
||||
}
|
||||
export default FileVersion;
|
||||
|
|
|
@ -1,206 +0,0 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
||||
*
|
||||
* @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 Images from '../models/images'
|
||||
import Videos from '../models/videos'
|
||||
import Audios from '../models/audios'
|
||||
|
||||
export default class Viewer {
|
||||
|
||||
_state;
|
||||
_mimetypes;
|
||||
|
||||
constructor() {
|
||||
this._mimetypes = []
|
||||
this._state = {}
|
||||
this._state.file = ''
|
||||
this._state.files = []
|
||||
this._state.loadMore = () => ([])
|
||||
this._state.onPrev = () => {}
|
||||
this._state.onNext = () => {}
|
||||
this._state.onClose = () => {}
|
||||
this._state.canLoop = true
|
||||
this._state.handlers = []
|
||||
|
||||
// ! built-in handlers
|
||||
this.registerHandler(Images)
|
||||
this.registerHandler(Videos)
|
||||
this.registerHandler(Audios)
|
||||
|
||||
console.debug('OCA.Viewer initialized')
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered handlers
|
||||
*
|
||||
* @readonly
|
||||
* @memberof Viewer
|
||||
*/
|
||||
get availableHandlers() {
|
||||
return this._state.handlers
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new handler
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @param {Object} handler a new unregistered handler
|
||||
*/
|
||||
registerHandler(handler) {
|
||||
this._state.handlers.push(handler)
|
||||
this._mimetypes.push.apply(this._mimetypes, handler.mimes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current opened file
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {string} the currently opened file
|
||||
*/
|
||||
get file() {
|
||||
return this._state.file
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current files list
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {Object[]} the currently opened file
|
||||
*/
|
||||
get files() {
|
||||
return this._state.files
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported mimetypes that can be opened with the viewer
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {array} list of mimetype strings that the viewer can open
|
||||
*/
|
||||
get mimetypes() {
|
||||
return this._mimetypes
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method provided to fetch more results
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {Function}
|
||||
*/
|
||||
get loadMore() {
|
||||
return this._state.loadMore
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the method to run on previous navigation
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {Function}
|
||||
*/
|
||||
get onPrev() {
|
||||
return this._state.onPrev
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the method to run on next navigation
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {Function}
|
||||
*/
|
||||
get onNext() {
|
||||
return this._state.onNext
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the method to run on viewer close
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {Function}
|
||||
*/
|
||||
get onClose() {
|
||||
return this._state.onClose
|
||||
}
|
||||
|
||||
/**
|
||||
* Is looping over the provided list allowed?
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get canLoop() {
|
||||
return this._state.canLoop
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the path into the viewer
|
||||
*
|
||||
* @memberof Viewer
|
||||
* @param {Object} options Options for opening the viewer
|
||||
* @param {string} options.path path of the file to open
|
||||
* @param {Object[]} [options.list] the list of files as objects (fileinfo) format
|
||||
* @param {Function} options.loadMore callback for loading more files
|
||||
* @param {boolean} options.canLoop can the viewer loop over the array
|
||||
* @param {Function} options.onPrev callback when navigating back to previous file
|
||||
* @param {Function} options.onNext callback when navigation forward to next file
|
||||
* @param {Function} options.onClose callback when closing the viewer
|
||||
*/
|
||||
open({ path, list = [], loadMore = () => ([]), canLoop = true, onPrev = () => {}, onNext = () => {}, onClose = () => {} } = {}) {
|
||||
// TODO: remove legacy method in NC 20 ?
|
||||
if (typeof arguments[0] === 'string') {
|
||||
path = arguments[0]
|
||||
console.warn('Opening the viewer with a single string parameter is deprecated. Please use a destructuring object instead', `OCA.Viewer.open({ path: '${path}' })`)
|
||||
}
|
||||
|
||||
if (!path.startsWith('/')) {
|
||||
throw new Error('Please use an absolute path')
|
||||
}
|
||||
|
||||
if (!Array.isArray(list)) {
|
||||
throw new Error('The files list must be an array')
|
||||
}
|
||||
|
||||
if (typeof loadMore !== 'function') {
|
||||
throw new Error('The loadMore method must be a function')
|
||||
}
|
||||
|
||||
this._state.file = path
|
||||
this._state.files = list
|
||||
this._state.loadMore = loadMore
|
||||
this._state.onPrev = onPrev
|
||||
this._state.onNext = onNext
|
||||
this._state.onClose = onClose
|
||||
this._state.canLoop = canLoop
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the opened file
|
||||
*
|
||||
* @memberof Viewer
|
||||
*/
|
||||
close() {
|
||||
this._state.file = ''
|
||||
this._state.files = []
|
||||
this._state.canLoop = true
|
||||
this._state.loadMore = () => ([])
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ import { getCurrentUser } from '@nextcloud/auth'
|
|||
|
||||
const getRootPath = function() {
|
||||
if (getCurrentUser()) {
|
||||
return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`)
|
||||
return generateRemoteUrl(`dav/versions/${getCurrentUser().uid}`)
|
||||
} else {
|
||||
return generateRemoteUrl('webdav').replace('/remote.php', '/public.php')
|
||||
}
|
||||
|
|
|
@ -29,42 +29,32 @@
|
|||
</div>
|
||||
<template>
|
||||
<!-- Version information -->
|
||||
<VersionEntry :versions="versionsList" />
|
||||
<!-- <VersionEntry :versions="versionsList" /> -->
|
||||
{{versionsList}}
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateRemoteUrl } from '@nextcloud/router'
|
||||
import { ListItemIcon } from '@nextcloud/vue'
|
||||
import VersionEntry from '../components/VersionEntry'
|
||||
import FileVersion from "../services/FileVersion";
|
||||
import fetchFileVersions from "../services/FileVersion";
|
||||
import { ListItemIcon } from '@nextcloud/vue'
|
||||
import VersionEntry from '../components/VersionEntry'
|
||||
import fetchFileVersions from "../services/FileVersion";
|
||||
|
||||
export default {
|
||||
export default {
|
||||
name: 'VersionTab',
|
||||
|
||||
components: {
|
||||
|
||||
ListItemIcon,
|
||||
VersionEntry,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
config: new Config(),
|
||||
|
||||
error: '',
|
||||
expirationInterval: null,
|
||||
loading: true,
|
||||
|
||||
fileInfo: null,
|
||||
|
||||
currentUser: null,
|
||||
|
||||
client: null,
|
||||
_fileInfo: null,
|
||||
|
||||
// version object
|
||||
versionsList: [],
|
||||
|
@ -75,14 +65,9 @@ export default {
|
|||
setFileInfo(fileInfo) {
|
||||
this._fileInfo = fileInfo
|
||||
},
|
||||
|
||||
getFileInfo() {
|
||||
return this._fileInfo
|
||||
},
|
||||
|
||||
setCurrentUser(user) {
|
||||
this._currentUser = user
|
||||
},
|
||||
setClient(client) {
|
||||
this._client = client
|
||||
},
|
||||
|
@ -91,30 +76,25 @@ export default {
|
|||
* @param {Object} fileInfo the current file FileInfo
|
||||
*/
|
||||
async update(fileInfo) {
|
||||
fileInfo = this.fileInfo
|
||||
name = this._fileInfo.get('name')
|
||||
this._fileInfo = fileInfo
|
||||
/** name = this._fileInfo.get('name') */
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the Version infos
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the existing shares infos
|
||||
*/
|
||||
async getVersions() {
|
||||
try {
|
||||
this.loading = true
|
||||
const fetchVersions = fetchFileVersions(this._fileInfo.get('id'));
|
||||
fetchVersions();
|
||||
const fetchVersions = await fetchFileVersions(this._fileInfo.get('id'));
|
||||
this.versionsList = fetchVersions;
|
||||
}
|
||||
catch(e){
|
||||
console.log(error);
|
||||
}
|
||||
this.loading = false
|
||||
}
|
||||
|
||||
},
|
||||
mounted() {
|
||||
this.getVersions()
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue