Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/app.php15
-rw-r--r--appinfo/routes.php3
-rw-r--r--lib/AppInfo/Application.php42
-rw-r--r--lib/Controller/SettingsController.php69
-rw-r--r--package-lock.json15
-rw-r--r--package.json1
-rw-r--r--src/files.js32
-rw-r--r--src/views/FilesSettings.vue10
8 files changed, 157 insertions, 30 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
index 4913f8aa4..d52ea44fb 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -24,19 +24,4 @@ declare(strict_types=1);
namespace OCA\Text\AppInfo;
-$eventDispatcher = \OC::$server->getEventDispatcher();
-
-// only load text editor if the user is logged in
-if (\OC::$server->getUserSession()->isLoggedIn()) {
- $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () {
- \OCP\Util::addScript('text', 'files');
- \OCP\Util::addStyle('text', 'icons');
- });
-}
-
-$eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () {
- \OCP\Util::addScript('text', 'public');
- \OCP\Util::addStyle('text', 'icons');
-});
-
$app = \OC::$server->query(Application::class);
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 4951d865b..167cd01dd 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -39,11 +39,12 @@ return [
['name' => 'PublicSession#push', 'url' => '/public/session/push', 'verb' => 'POST'],
['name' => 'PublicSession#close', 'url' => '/public/session/close', 'verb' => 'GET'],
+
+ ['name' => 'Settings#updateConfig', 'url' => '/settings', 'verb' => 'POST'],
],
'ocs' => [
['name' => 'Workspace#folder', 'url' => '/workspace', 'verb' => 'GET'],
['name' => 'Workspace#publicFolder', 'url' => '/public/workspace', 'verb' => 'GET'],
['name' => 'Workspace#direct', 'url' => '/workspace/direct', 'verb' => 'POST'],
-
]
];
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 954a32e1a..5aef1e367 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -28,12 +28,24 @@ use OCA\Text\DirectEditing\TextDirectEditor;
use OCP\AppFramework\App;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IInitialStateService;
class Application extends App {
const APP_NAME = 'text';
+ /** @var IInitialStateService */
+ private $initialStateService;
+ /**
+ * @var \OCP\IUserSession
+ */
+ private $userSession;
+ /**
+ * @var \OCP\IConfig
+ */
+ private $config;
+
/**
* Application constructor.
@@ -45,12 +57,40 @@ class Application extends App {
parent::__construct(self::APP_NAME, $params);
$container = $this->getContainer();
+ $server = $container->getServer();
/** @var IEventDispatcher $eventDispatcher */
- $eventDispatcher = $this->getContainer()->getServer()->query(IEventDispatcher::class);
+ $eventDispatcher = $server->query(IEventDispatcher::class);
+ $this->initialStateService = $server->query(IInitialStateService::class);
+ $this->userSession = $server->getUserSession();
+ $this->config = $this->getContainer()->getServer()->getConfig();
+
$eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) {
$editor = $container->query(TextDirectEditor::class);
$event->register($editor);
});
+
+ if ($this->userSession->isLoggedIn()) {
+ $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () use ($initialStateService) {
+ \OCP\Util::addScript('text', 'files');
+ \OCP\Util::addStyle('text', 'icons');
+
+ $this->initialStateService->provideInitialState(
+ self::APP_NAME,
+ 'workspace_available',
+ $this->config->getAppValue(self::APP_NAME, 'workspace_available', true)
+ );
+ $this->initialStateService->provideInitialState(
+ self::APP_NAME,
+ 'workspace_enabled',
+ $this->config->getUserValue($this->userSession->getUser()->getUID(), self::APP_NAME, 'workspace_enabled', '1') === '1'
+ );
+ });
+ }
+
+ $eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () {
+ \OCP\Util::addScript('text', 'public');
+ \OCP\Util::addStyle('text', 'icons');
+ });
}
}
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
new file mode 100644
index 000000000..125ac8f7e
--- /dev/null
+++ b/lib/Controller/SettingsController.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @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/>.
+ *
+ */
+
+namespace OCA\Text\Controller;
+
+
+use OCA\Activity\Data;
+use OCA\Text\AppInfo\Application;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\IConfig;
+use OCP\IRequest;
+
+class SettingsController extends Controller {
+
+ /**
+ * @var IConfig
+ */
+ private $config;
+
+ const ACCEPTED_KEYS = [
+ 'workspace_enabled'
+ ];
+
+ public function __construct($appName, IRequest $request, IConfig $config, $userId) {
+ parent::__construct($appName, $request);
+
+ $this->config = $config;
+ $this->userId = $userId;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @param string $key
+ * @param string $value
+ * @return DataResponse
+ * @throws \OCP\PreConditionNotMetException
+ */
+ public function updateConfig(string $key, $value) {
+ if (!in_array($key, self::ACCEPTED_KEYS, true)) {
+ return new DataResponse(['message' => 'Invalid config key'], Http::STATUS_BAD_REQUEST);
+ }
+ $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
+ return new DataResponse([
+ $key => $value
+ ]);
+ }
+}
diff --git a/package-lock.json b/package-lock.json
index 2ffa3782f..3b106e92d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2982,6 +2982,21 @@
}
}
},
+ "@nextcloud/initial-state": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-0.2.0.tgz",
+ "integrity": "sha512-aFkEXxEchawyn1HWn/nStX25324/4+RcOHiHJ1gW/vVH6bPRW8suj9V1Rsi380mMRM7sjkICyeNPxOZ8f+WZrA==",
+ "requires": {
+ "core-js": "3.1.4"
+ },
+ "dependencies": {
+ "core-js": {
+ "version": "3.1.4",
+ "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.1.4.tgz",
+ "integrity": "sha512-YNZN8lt82XIMLnLirj9MhKDFZHalwzzrL9YLt6eb0T5D0EDl4IQ90IGkua8mHbnxNrkj1d8hbdizMc0Qmg1WnQ=="
+ }
+ }
+ },
"@nextcloud/router": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@nextcloud/router/-/router-0.1.0.tgz",
diff --git a/package.json b/package.json
index d22778b21..2187f869c 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
"dependencies": {
"@nextcloud/axios": "^0.5.0",
"@nextcloud/event-bus": "^0.2.1",
+ "@nextcloud/initial-state": "^0.2.0",
"@nextcloud/router": "^0.1.0",
"@nextcloud/vue": "^1.2.2",
"escape-html": "^1.0.3",
diff --git a/src/files.js b/src/files.js
index c0a486ebd..924a69d2b 100644
--- a/src/files.js
+++ b/src/files.js
@@ -26,10 +26,14 @@ import PreviewPlugin from './files/PreviewPlugin'
import { registerFileActionFallback, registerFileCreate, FilesWorkspacePlugin } from './helpers/files'
import { openMimetypesMarkdown, openMimetypesPlainText } from './helpers/mime'
import FilesSettings from './views/FilesSettings'
+import { loadState } from '@nextcloud/initial-state'
__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line
__webpack_public_path__ = OC.linkTo('text', 'js/') // eslint-disable-line
+const workspaceAvailable = loadState('text', 'workspace_available')
+const workspaceEnabled = loadState('text', 'workspace_enabled')
+
registerFileCreate()
document.addEventListener('DOMContentLoaded', () => {
@@ -52,22 +56,24 @@ document.addEventListener('DOMContentLoaded', () => {
})
OC.Plugins.register('OCA.Files.SidebarPreviewManager', new PreviewPlugin())
- const settings = document.createElement('div')
- document.getElementById('files-setting-showhidden').insertAdjacentElement('afterend', settings)
- Vue.prototype.t = window.t
- Vue.prototype.n = window.n
- Vue.prototype.OCA = window.OCA
- const vm = new Vue({
- render: h => h(FilesSettings, {}),
- })
- vm.$mount(settings)
+ if (workspaceAvailable) {
+ const settings = document.createElement('div')
+ document.getElementById('files-setting-showhidden').insertAdjacentElement('afterend', settings)
+ Vue.prototype.t = window.t
+ Vue.prototype.n = window.n
+ Vue.prototype.OCA = window.OCA
+ const vm = new Vue({
+ render: h => h(FilesSettings, {}),
+ })
+ vm.$mount(settings)
+ }
})
-
-OC.Plugins.register('OCA.Files.FileList', FilesWorkspacePlugin)
+if (workspaceAvailable) {
+ OC.Plugins.register('OCA.Files.FileList', FilesWorkspacePlugin)
+}
OCA.Text = {
Editor: FilesEditor,
- // FIXME get from capabilities
- RichWorkspaceEnabled: true,
+ RichWorkspaceEnabled: workspaceEnabled,
}
diff --git a/src/views/FilesSettings.vue b/src/views/FilesSettings.vue
index 7976e1612..78ad4526c 100644
--- a/src/views/FilesSettings.vue
+++ b/src/views/FilesSettings.vue
@@ -32,6 +32,8 @@
<script>
import { emit } from '@nextcloud/event-bus'
+import axios from '@nextcloud/axios'
+import { generateUrl } from '@nextcloud/router'
export default {
name: 'FilesSettings',
@@ -45,8 +47,16 @@ export default {
// FIXME: save to app config
if (this.showWorkspace) {
emit('Text::showRichWorkspace')
+ axios.post(generateUrl('/apps/text/settings'), {
+ key: 'workspace_enabled',
+ value: '1',
+ })
} else {
emit('Text::hideRichWorkspace')
+ axios.post(generateUrl('/apps/text/settings'), {
+ key: 'workspace_enabled',
+ value: '0',
+ })
}
},
},