aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/services
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-05-23 17:03:04 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2019-10-29 12:56:00 +0100
commitfd90af50d910e659aa8df0d380424383c6c09620 (patch)
tree76d8ddcc7cf44ba6852f31b0a2323d23d6b1c258 /apps/files/src/services
parentea6f423e2c8e50cf1357a0e2182dc4c9a9bf981e (diff)
downloadnextcloud-server-fd90af50d910e659aa8df0d380424383c6c09620.tar.gz
nextcloud-server-fd90af50d910e659aa8df0d380424383c6c09620.zip
Add OCA.Files.Sidebar
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/src/services')
-rw-r--r--apps/files/src/services/FileInfo.js67
-rw-r--r--apps/files/src/services/Sidebar.js109
2 files changed, 176 insertions, 0 deletions
diff --git a/apps/files/src/services/FileInfo.js b/apps/files/src/services/FileInfo.js
new file mode 100644
index 00000000000..aa026df1445
--- /dev/null
+++ b/apps/files/src/services/FileInfo.js
@@ -0,0 +1,67 @@
+/**
+ * @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 axios from '@nextcloud/axios'
+
+export default async function(url) {
+ const response = await axios({
+ method: 'PROPFIND',
+ url,
+ 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>`
+ })
+
+ // TODO: create new parser or use cdav-lib when available
+ const file = OCA.Files.App.fileList.filesClient._client.parseMultiStatus(response.data)
+ // TODO: create new parser or use cdav-lib when available
+ const fileInfo = OCA.Files.App.fileList.filesClient._parseFileInfo(file[0])
+
+ // TODO remove when no more legacy backbone is used
+ fileInfo.get = (key) => fileInfo[key]
+ fileInfo.isDirectory = () => fileInfo.mimetype === 'httpd/unix-directory'
+
+ return fileInfo
+}
diff --git a/apps/files/src/services/Sidebar.js b/apps/files/src/services/Sidebar.js
new file mode 100644
index 00000000000..8f02a1b51ab
--- /dev/null
+++ b/apps/files/src/services/Sidebar.js
@@ -0,0 +1,109 @@
+/**
+ * @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/>.
+ *
+ */
+
+export default class Sidebar {
+
+ #state;
+ #view;
+
+ constructor() {
+ // init empty state
+ this.#state = {}
+
+ // init default values
+ this.#state.tabs = []
+ this.#state.views = []
+ this.#state.file = ''
+ this.#state.activeTab = ''
+ console.debug('OCA.Files.Sidebar initialized')
+ }
+
+ /**
+ * Get the sidebar state
+ *
+ * @readonly
+ * @memberof Sidebar
+ * @returns {Object} the data state
+ */
+ get state() {
+ return this.#state
+ }
+
+ /**
+ * @memberof Sidebar
+ * Register a new tab view
+ *
+ * @param {Object} tab a new unregistered tab
+ * @memberof Sidebar
+ * @returns {Boolean}
+ */
+ registerTab(tab) {
+ const hasDuplicate = this.#state.tabs.findIndex(check => check.name === tab.name) > -1
+ if (!hasDuplicate) {
+ this.#state.tabs.push(tab)
+ return true
+ }
+ console.error(`An tab with the same name ${tab.name} already exists`, tab)
+ return false
+ }
+
+ registerSecondaryView(view) {
+ const hasDuplicate = this.#state.views.findIndex(check => check.cid === view.cid) > -1
+ if (!hasDuplicate) {
+ this.#state.views.push(view)
+ return true
+ }
+ console.error(`A similar view already exists`, view)
+ return false
+ }
+
+ /**
+ * Set the current sidebar file data
+ *
+ * @param {string} path the file path to load
+ * @memberof Sidebar
+ */
+ set file(path) {
+ this.#state.file = path
+ }
+
+ /**
+ * Set the current sidebar file data
+ *
+ * @returns {String} the current opened file
+ * @memberof Sidebar
+ */
+ get file() {
+ return this.#state.file
+ }
+
+ /**
+ * Set the current sidebar tab
+ *
+ * @param {string} id the tab unique id
+ * @memberof Sidebar
+ */
+ set activeTab(id) {
+ this.#state.activeTab = id
+ }
+
+}