diff options
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 34 | ||||
-rw-r--r-- | lib/Settings/Admin.php | 20 | ||||
-rw-r--r-- | src/components/AdminSettings.vue | 49 |
4 files changed, 72 insertions, 32 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index 8f1636d5..f04ce9e8 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -52,6 +52,7 @@ return [ ['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'], ['name' => 'settings#updateWatermarkSettings', 'url' => 'settings/watermark', 'verb' => 'POST'], ['name' => 'settings#checkSettings', 'url' => 'settings/check', 'verb' => 'GET'], + ['name' => 'settings#demoServers', 'url' => 'settings/demo', 'verb' => 'GET'], //Mobile access ['name' => 'directView#show', 'url' => '/direct/{token}', 'verb' => 'GET'], diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 45f6ed28..22ff4bba 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -12,12 +12,16 @@ namespace OCA\Richdocuments\Controller; use OCA\Richdocuments\Service\CapabilitiesService; +use OCA\Richdocuments\Service\DemoService; use OCA\Richdocuments\WOPI\DiscoveryManager; use OCA\Richdocuments\WOPI\Parser; use \OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\NotFoundResponse; +use OCP\Http\Client\IClientService; +use OCP\ICache; use \OCP\IRequest; use \OCP\IL10N; use OCA\Richdocuments\AppConfig; @@ -39,6 +43,8 @@ class SettingsController extends Controller{ private $userId; /** @var CapabilitiesService */ private $capabilitiesService; + /** @var DemoService */ + private $demoService; /** * @param string $appName @@ -52,14 +58,16 @@ class SettingsController extends Controller{ * @param CapabilitiesService $capabilitiesService */ public function __construct($appName, - IRequest $request, - IL10N $l10n, - AppConfig $appConfig, - IConfig $config, - DiscoveryManager $discoveryManager, - Parser $wopiParser, - $userId, - CapabilitiesService $capabilitiesService) { + IRequest $request, + IL10N $l10n, + AppConfig $appConfig, + IConfig $config, + DiscoveryManager $discoveryManager, + Parser $wopiParser, + $userId, + CapabilitiesService $capabilitiesService, + DemoService $demoService + ) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->appConfig = $appConfig; @@ -68,6 +76,7 @@ class SettingsController extends Controller{ $this->wopiParser = $wopiParser; $this->userId = $userId; $this->capabilitiesService = $capabilitiesService; + $this->demoService = $demoService; } /** @@ -88,6 +97,14 @@ class SettingsController extends Controller{ return new DataResponse(); } + public function demoServers() { + $demoServers = $this->demoService->fetchDemoServers(true); + if (count($demoServers) > 0) { + return new DataResponse($demoServers); + } + return new NotFoundResponse([]); + } + /** * @NoAdminRequired * @@ -155,6 +172,7 @@ class SettingsController extends Controller{ } $this->discoveryManager->refretch(); + $this->capabilitiesService->clear(); try { $capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities'); if (is_array($capaUrlSrc) && $capaUrlSrc['action'] === 'getinfo') { diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 08aa8640..2c511022 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -25,9 +25,9 @@ namespace OCA\Richdocuments\Settings; use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Capabilities; +use OCA\Richdocuments\Service\DemoService; use OCA\Richdocuments\TemplateManager; use OCP\AppFramework\Http\TemplateResponse; -use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\Settings\ISettings; @@ -45,8 +45,8 @@ class Admin implements ISettings { /** @var array */ private $capabilities; - /** @var IClientService */ - private $clientService; + /** @var DemoService */ + private $demoService; /** * Admin template settings @@ -60,13 +60,13 @@ class Admin implements ISettings { AppConfig $appConfig, TemplateManager $manager, Capabilities $capabilities, - IClientService $clientService + DemoService $demoService ) { $this->config = $config; $this->appConfig = $appConfig; $this->manager = $manager; $this->capabilities = $capabilities->getCapabilities()['richdocuments']; - $this->clientService = $clientService; + $this->demoService = $demoService; } /** * @return TemplateResponse @@ -89,7 +89,7 @@ class Admin implements ISettings { 'templates' => $this->manager->getSystemFormatted(), 'templatesAvailable' => array_key_exists('templates', $this->capabilities) && $this->capabilities['templates'], 'settings' => $this->appConfig->getAppSettings(), - 'demo_servers' => $this->fetchDemoServers() + 'demo_servers' => $this->demoService->fetchDemoServers() ] ], 'blank' @@ -112,12 +112,4 @@ class Admin implements ISettings { return 0; } - private function fetchDemoServers() { - // FIXME: add caching - $demoServerList = 'http://col.la/nextclouddemoservers'; - $client = $this->clientService->newClient(); - $response = $client->get($demoServerList); - return json_decode($response->getBody(), true)['servers'] ?? []; - } - } diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 5515cbe2..b8fb644b 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -71,16 +71,32 @@ <div> <input id="demoserver" v-model="serverMode" type="radio" name="serverMode" value="demo" class="radio" - :disabled="updating"> - <label for="demoserver">Use a demo server</label><br> - <div class="option-inline"> - <p><em>{{ t('richdocuments', 'You can use a demo server provided by Collabora and other service providers for giving Collabora Online a try.') }}</em></p> - <p> + :disabled="updating" @input="fetchDemoServers"> + <label for="demoserver">{{ t('richdocuments', 'Use a demo server') }}</label><br> + <p class="option-inline"> + <em>{{ t('richdocuments', 'You can use a demo server provided by Collabora and other service providers for giving Collabora Online a try.') }}</em> + </p> + <div v-if="serverMode === 'demo'" class="option-inline"> + <p v-if="demoServers === null"> + {{ t('richdocuments', 'Loading available demo servers …') }} + </p> + <p v-else-if="demoServers.length > 0"> <multiselect v-if="serverMode === 'demo'" v-model="settings.demoUrl" :custom-label="demoServerLabel" track-by="demo_url" label="demo_url" placeholder="Select a demo server" :options="demoServers" :searchable="false" :allow-empty="false" :disabled="updating" @input="setDemoServer" /> </p> + <p v-else> + {{ t('richdocuments', 'No available demo servers found.') }} + </p> + + <p v-if="settings.demoUrl"> + <em> + {{ t('richdocuments', 'Documents opened with the demo server configured will be sent to a 3rd party server. Only use this for evaluating Collabora Online.') }}<br> + <a :href="settings.demoUrl.provider_url" target="_blank" rel="noreferrer noopener" + class="external">{{ providerDescription }}</a> + </em> + </p> </div> </div> </fieldset> @@ -196,8 +212,9 @@ export default { }, data() { return { - serverMode: 'custom', + serverMode: '', serverError: SERVER_STATE_OK, + demoServers: null, updating: false, groups: [], tags: [], @@ -227,8 +244,8 @@ export default { } }, computed: { - demoServers() { - return this.initial.demo_servers + providerDescription() { + return t('richdocuments', 'Contact {0} to get an own installation.', [this.settings.demoUrl.provider_name]) }, isSetup() { return this.serverError === SERVER_STATE_OK @@ -261,9 +278,18 @@ export default { this.uiVisible.canonical_webroot = this.settings.canonical_webroot !== '' this.uiVisible.external_apps = this.settings.external_apps !== '' + this.demoServers = this.initial.demo_servers this.checkIfDemoServerIsActive() }, methods: { + async fetchDemoServers() { + try { + const result = await axios.get(generateUrl('/apps/richdocuments/settings/demo')) + this.demoServers = result.data + } catch (e) { + this.demoServers = [] + } + }, update() { this.updating = true let settings = this.settings @@ -271,7 +297,7 @@ export default { this.updating = false }).catch((error) => { this.updating = false - OC.Notification.showTemporary('Failed to save settings') + OC.Notification.showTemporary(t('richdocuments', 'Failed to save settings')) console.error(error) }) }, @@ -348,7 +374,10 @@ export default { } }, checkIfDemoServerIsActive() { - this.settings.demoUrl = this.initial.demo_servers.find((server) => server.demo_url === this.settings.wopi_url) + this.settings.demoUrl = this.demoServers.find((server) => server.demo_url === this.settings.wopi_url) + if (this.settings.wopi_url !== '') { + this.serverMode = 'custom' + } if (this.settings.demoUrl) { this.serverMode = 'demo' } |