aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/models')
-rw-r--r--apps/files/src/models/Setting.js73
-rw-r--r--apps/files/src/models/Tab.js128
2 files changed, 201 insertions, 0 deletions
diff --git a/apps/files/src/models/Setting.js b/apps/files/src/models/Setting.js
new file mode 100644
index 00000000000..1db1d818e69
--- /dev/null
+++ b/apps/files/src/models/Setting.js
@@ -0,0 +1,73 @@
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+export default class Setting {
+
+ _close
+ _el
+ _name
+ _open
+ _order
+
+ /**
+ * Create a new files app setting
+ *
+ * @since 19.0.0
+ * @param {string} name the name of this setting
+ * @param {object} component the component
+ * @param {Function} component.el function that returns an unmounted dom element to be added
+ * @param {Function} [component.open] callback for when setting is added
+ * @param {Function} [component.close] callback for when setting is closed
+ * @param {number} [component.order] the order of this setting, lower numbers are shown first
+ */
+ constructor(name, { el, open, close, order }) {
+ this._name = name
+ this._el = el
+ this._open = open
+ this._close = close
+ this._order = order || 0
+
+ if (typeof this._open !== 'function') {
+ this._open = () => {}
+ }
+
+ if (typeof this._close !== 'function') {
+ this._close = () => {}
+ }
+
+ if (typeof this._el !== 'function') {
+ throw new Error('Setting must have an `el` function that returns a DOM element')
+ }
+
+ if (typeof this._name !== 'string') {
+ throw new Error('Setting must have a `name` string')
+ }
+
+ if (typeof this._order !== 'number') {
+ throw new Error('Setting must have an `order` number')
+ }
+ }
+
+ get name() {
+ return this._name
+ }
+
+ get el() {
+ return this._el
+ }
+
+ get open() {
+ return this._open
+ }
+
+ get close() {
+ return this._close
+ }
+
+ get order() {
+ return this._order
+ }
+
+}
diff --git a/apps/files/src/models/Tab.js b/apps/files/src/models/Tab.js
new file mode 100644
index 00000000000..b67d51f277f
--- /dev/null
+++ b/apps/files/src/models/Tab.js
@@ -0,0 +1,128 @@
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import DOMPurify from 'dompurify'
+
+export default class Tab {
+
+ _id
+ _name
+ _icon
+ _iconSvgSanitized
+ _mount
+ _setIsActive
+ _update
+ _destroy
+ _enabled
+ _scrollBottomReached
+
+ /**
+ * Create a new tab instance
+ *
+ * @param {object} options destructuring object
+ * @param {string} options.id the unique id of this tab
+ * @param {string} options.name the translated tab name
+ * @param {?string} options.icon the icon css class
+ * @param {?string} options.iconSvg the icon in svg format
+ * @param {Function} options.mount function to mount the tab
+ * @param {Function} [options.setIsActive] function to forward the active state of the tab
+ * @param {Function} options.update function to update the tab
+ * @param {Function} options.destroy function to destroy the tab
+ * @param {Function} [options.enabled] define conditions whether this tab is active. Must returns a boolean
+ * @param {Function} [options.scrollBottomReached] executed when the tab is scrolled to the bottom
+ */
+ constructor({ id, name, icon, iconSvg, mount, setIsActive, update, destroy, enabled, scrollBottomReached } = {}) {
+ if (enabled === undefined) {
+ enabled = () => true
+ }
+ if (scrollBottomReached === undefined) {
+ scrollBottomReached = () => { }
+ }
+
+ // Sanity checks
+ if (typeof id !== 'string' || id.trim() === '') {
+ throw new Error('The id argument is not a valid string')
+ }
+ if (typeof name !== 'string' || name.trim() === '') {
+ throw new Error('The name argument is not a valid string')
+ }
+ if ((typeof icon !== 'string' || icon.trim() === '') && typeof iconSvg !== 'string') {
+ throw new Error('Missing valid string for icon or iconSvg argument')
+ }
+ if (typeof mount !== 'function') {
+ throw new Error('The mount argument should be a function')
+ }
+ if (setIsActive !== undefined && typeof setIsActive !== 'function') {
+ throw new Error('The setIsActive argument should be a function')
+ }
+ if (typeof update !== 'function') {
+ throw new Error('The update argument should be a function')
+ }
+ if (typeof destroy !== 'function') {
+ throw new Error('The destroy argument should be a function')
+ }
+ if (typeof enabled !== 'function') {
+ throw new Error('The enabled argument should be a function')
+ }
+ if (typeof scrollBottomReached !== 'function') {
+ throw new Error('The scrollBottomReached argument should be a function')
+ }
+
+ this._id = id
+ this._name = name
+ this._icon = icon
+ this._mount = mount
+ this._setIsActive = setIsActive
+ this._update = update
+ this._destroy = destroy
+ this._enabled = enabled
+ this._scrollBottomReached = scrollBottomReached
+
+ if (typeof iconSvg === 'string') {
+ this._iconSvgSanitized = DOMPurify.sanitize(iconSvg)
+ }
+
+ }
+
+ get id() {
+ return this._id
+ }
+
+ get name() {
+ return this._name
+ }
+
+ get icon() {
+ return this._icon
+ }
+
+ get iconSvg() {
+ return this._iconSvgSanitized
+ }
+
+ get mount() {
+ return this._mount
+ }
+
+ get setIsActive() {
+ return this._setIsActive || (() => undefined)
+ }
+
+ get update() {
+ return this._update
+ }
+
+ get destroy() {
+ return this._destroy
+ }
+
+ get enabled() {
+ return this._enabled
+ }
+
+ get scrollBottomReached() {
+ return this._scrollBottomReached
+ }
+
+}