forked from nextcloud/richdocuments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitialStateService.php
More file actions
123 lines (101 loc) · 4.14 KB
/
InitialStateService.php
File metadata and controls
123 lines (101 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
namespace OCA\Richdocuments\Service;
use OCA\Richdocuments\AppConfig;
use OCA\Richdocuments\AppInfo\Application;
use OCA\Richdocuments\Db\Wopi;
use OCA\Richdocuments\TemplateManager;
use OCA\Theming\ImageManager;
use OCP\AppFramework\Services\IInitialState;
use OCA\Richdocuments\Service\SettingsService;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IURLGenerator;
class InitialStateService {
private bool $hasProvidedCapabilities = false;
public function __construct(
private IInitialState $initialState,
private AppConfig $appConfig,
private ImageManager $imageManager,
private TemplateManager $templateManager,
private CapabilitiesService $capabilitiesService,
private IURLGenerator $urlGenerator,
private Defaults $themingDefaults,
private IConfig $config,
private ?string $userId,
private SettingsService $settingsService,
) {
}
public function provideCapabilities(): void {
if ($this->hasProvidedCapabilities) {
return;
}
$this->initialState->provideInitialState('productName', $this->capabilitiesService->getProductName());
$this->initialState->provideInitialState('hasDrawSupport', $this->capabilitiesService->hasDrawSupport());
$this->initialState->provideInitialState('hasNextcloudBranding', $this->capabilitiesService->hasNextcloudBranding());
$this->initialState->provideInitialState('instanceId', $this->config->getSystemValue('instanceid'));
$this->initialState->provideInitialState('wopi_callback_url', $this->appConfig->getNextcloudUrl());
$this->provideOptions();
$this->hasProvidedCapabilities = true;
}
public function provideDocument(Wopi $wopi, array $params): void {
$this->provideCapabilities();
$this->initialState->provideInitialState('document', $this->prepareParams($params));
$this->initialState->provideInitialState('wopi', $wopi);
$this->provideOptions();
}
public function providePresentation(bool $startPresentation = false): void {
$this->initialState->provideInitialState('startPresentation', $startPresentation);
}
public function provideAdminSettings(): void {
$this->initialState->provideInitialState('adminSettings', [
'templatesAvailable' => $this->capabilitiesService->hasTemplateSource(),
'templates' => $this->templateManager->getSystemFormatted(),
]);
}
public function prepareParams(array $params): array {
$defaults = [
'instanceId' => $this->config->getSystemValue('instanceid'),
'canonical_webroot' => $this->config->getAppValue(Application::APPNAME, 'canonical_webroot', ''),
'userId' => $this->userId,
'token' => '',
'token_ttl' => 0,
'directEdit' => false,
'directGuest' => false,
'path' => '',
'urlsrc' => '',
'fileId' => '',
'title' => '',
'permissions' => '',
'isPublicShare' => false,
];
return array_merge($defaults, $params);
}
private function provideOptions(): void {
$this->initialState->provideInitialState('loggedInUser', $this->userId ?? false);
$this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud'));
$this->initialState->provideInitialState('uiDefaults', [
'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'notebookbar')
]);
$logoType = 'logoheader';
$logoSet = $this->imageManager->hasImage($logoType);
if (!$logoSet) {
$logoType = 'logo';
$logoSet = $this->imageManager->hasImage($logoType);
}
$logo = $logoSet ? $this->imageManager->getImageUrlAbsolute($logoType) : false;
$this->initialState->provideInitialState('theming-customLogo', $logo);
$this->initialState->provideInitialState('open_local_editor', $this->config->getAppValue(Application::APPNAME, 'open_local_editor', 'yes') === 'yes');
$fileName = $this->config->getUserValue($this->userId, Application::APPNAME, 'browsersetting');
if ($fileName) {
$browserSetting = $this->settingsService->getSettingsFile('userconfig/' . $this->userId,
'browsersetting',
$fileName);
$this->initialState->provideInitialState('browsersetting', $browserSetting->getContent());
}
}
}