summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJonas Sulzer <jonas@violoncello.ch>2020-09-02 00:54:44 +0200
committerJonas Sulzer <jonas@violoncello.ch>2020-09-02 10:05:22 +0200
commitff9224e4adbfc1aee8503a2104276173a6b77d94 (patch)
tree4c25db1d8d82a1b3197a2a0fb8032e2401584999 /lib
parent3aced1be96746606f27de50c202676ebc5b4a8c1 (diff)
👌 IMPROVE: use vue Content components and transmit serverData over initialState
- use vue components `Content` and `AppContent` with it's respective styling to be independent from server styling - use OCP\IInitialStateService and @nextcloud/initial-state to transmit the serverData instead of using a hidden span element and jsonEncode/Decode this is needed to use the `Content` component, so the vue instance can be mounted to #content directly (otherwise server styling for #content interfers with the vue styling) - also improves some general styling (mostly widths and margins/paddings) Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/NavigationController.php41
-rw-r--r--lib/Controller/OStatusController.php33
-rw-r--r--lib/Controller/SocialPubController.php22
3 files changed, 52 insertions, 44 deletions
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 918684ff..b1b0dcd3 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
+ * @author Jonas Sulzer <jonas@violoncello.ch>
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
@@ -50,6 +51,7 @@ use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
+use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -109,7 +111,7 @@ class NavigationController extends Controller {
* @param MiscService $miscService
*/
public function __construct(
- IL10N $l10n, IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator,
+ IL10N $l10n, IRequest $request, $userId, IConfig $config, IInitialStateService $initialStateService, IURLGenerator $urlGenerator,
AccountService $accountService, DocumentService $documentService,
ConfigService $configService, CheckService $checkService, MiscService $miscService
) {
@@ -118,6 +120,7 @@ class NavigationController extends Controller {
$this->userId = $userId;
$this->l10n = $l10n;
$this->config = $config;
+ $this->initialStateService = $initialStateService;
$this->urlGenerator = $urlGenerator;
$this->checkService = $checkService;
@@ -141,33 +144,32 @@ class NavigationController extends Controller {
* @throws SocialAppConfigException
*/
public function navigate(string $path = ''): TemplateResponse {
- $data = [
- 'serverData' => [
- 'public' => false,
- 'firstrun' => false,
- 'setup' => false,
- 'isAdmin' => OC::$server->getGroupManager()
- ->isAdmin($this->userId),
- 'cliUrl' => $this->getCliUrl()
- ]
+ $serverData = [
+ 'public' => false,
+ 'firstrun' => false,
+ 'setup' => false,
+ 'isAdmin' => OC::$server->getGroupManager()
+ ->isAdmin($this->userId),
+ 'cliUrl' => $this->getCliUrl()
];
try {
- $data['serverData']['cloudAddress'] = $this->configService->getCloudUrl();
+ $serverData['cloudAddress'] = $this->configService->getCloudUrl();
} catch (SocialAppConfigException $e) {
$this->checkService->checkInstallationStatus(true);
$cloudAddress = $this->setupCloudAddress();
if ($cloudAddress !== '') {
- $data['serverData']['cloudAddress'] = $cloudAddress;
+ $serverData['cloudAddress'] = $cloudAddress;
} else {
- $data['serverData']['setup'] = true;
+ $serverData['setup'] = true;
- if ($data['serverData']['isAdmin']) {
+ if ($serverData['isAdmin']) {
$cloudAddress = $this->request->getParam('cloudAddress');
if ($cloudAddress !== null) {
$this->configService->setCloudUrl($cloudAddress);
} else {
- return new TemplateResponse(Application::APP_NAME, 'main', $data);
+ $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData);
+ return new TemplateResponse(Application::APP_NAME, 'main');
}
}
}
@@ -179,9 +181,9 @@ class NavigationController extends Controller {
$this->configService->setSocialUrl();
}
- if ($data['serverData']['isAdmin']) {
+ if ($serverData['isAdmin']) {
$checks = $this->checkService->checkDefault();
- $data['serverData']['checks'] = $checks;
+ $serverData['checks'] = $checks;
}
/*
@@ -189,7 +191,7 @@ class NavigationController extends Controller {
*/
try {
$this->accountService->createActor($this->userId, $this->userId);
- $data['serverData']['firstrun'] = true;
+ $serverData['firstrun'] = true;
} catch (AccountAlreadyExistsException $e) {
// we do nothing
} catch (NoUserException $e) {
@@ -198,7 +200,8 @@ class NavigationController extends Controller {
// neither.
}
- return new TemplateResponse(Application::APP_NAME, 'main', $data);
+ $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', $serverData);
+ return new TemplateResponse(Application::APP_NAME, 'main');
}
private function setupCloudAddress(): string {
diff --git a/lib/Controller/OStatusController.php b/lib/Controller/OStatusController.php
index ad848960..3ca22a34 100644
--- a/lib/Controller/OStatusController.php
+++ b/lib/Controller/OStatusController.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
+ * @author Jonas Sulzer <jonas@violoncello.ch>
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
@@ -44,6 +45,7 @@ use OCA\Social\Service\MiscService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
@@ -83,11 +85,12 @@ class OStatusController extends Controller {
* @param IUserSession $userSession
*/
public function __construct(
- IRequest $request, CacheActorService $cacheActorService, AccountService $accountService,
+ IRequest $request, IInitialStateService $initialStateService, CacheActorService $cacheActorService, AccountService $accountService,
CurlService $curlService, MiscService $miscService, IUserSession $userSession
) {
parent::__construct(Application::APP_NAME, $request);
+ $this->initialStateService = $initialStateService;
$this->cacheActorService = $cacheActorService;
$this->accountService = $accountService;
$this->curlService = $curlService;
@@ -118,16 +121,15 @@ class OStatusController extends Controller {
throw new Exception('Failed to retrieve current user');
}
- return new TemplateResponse(
- 'social', 'ostatus', [
- 'serverData' => [
- 'account' => $actor->getAccount(),
- 'currentUser' => [
- 'uid' => $user->getUID(),
- 'displayName' => $user->getDisplayName(),
- ]
+ $this->initialStateService->provideInitialState('social', 'serverData', [
+ 'account' => $actor->getAccount(),
+ 'currentUser' => [
+ 'uid' => $user->getUID(),
+ 'displayName' => $user->getDisplayName(),
]
- ], 'guest'
+ ]);
+ return new TemplateResponse(
+ 'social', 'main', 'guest'
);
} catch (Exception $e) {
return $this->fail($e);
@@ -148,13 +150,12 @@ class OStatusController extends Controller {
try {
$following = $this->accountService->getActor($local);
+ $this->initialStateService->provideInitialState('social', 'serverData', [
+ 'local' => $local,
+ 'account' => $following->getAccount()
+ ]);
return new TemplateResponse(
- 'social', 'ostatus', [
- 'serverData' => [
- 'local' => $local,
- 'account' => $following->getAccount()
- ]
- ], 'guest'
+ 'social', 'main', 'guest'
);
} catch (Exception $e) {
return $this->fail($e);
diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php
index 253c9308..8fada3ae 100644
--- a/lib/Controller/SocialPubController.php
+++ b/lib/Controller/SocialPubController.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
+ * @author Jonas Sulzer <jonas@violoncello.ch>
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
@@ -48,6 +49,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
@@ -98,13 +100,14 @@ class SocialPubController extends Controller {
* @param ConfigService $configService
*/
public function __construct(
- $userId, IRequest $request, IL10N $l10n, NavigationController $navigationController,
+ $userId, IInitialStateService $initialStateService, IRequest $request, IL10N $l10n, NavigationController $navigationController,
CacheActorService $cacheActorService, AccountService $accountService, StreamService $streamService,
ConfigService $configService
) {
parent::__construct(Application::APP_NAME, $request);
$this->userId = $userId;
+ $this->initialStateService = $initialStateService;
$this->l10n = $l10n;
$this->navigationController = $navigationController;
$this->accountService = $accountService;
@@ -126,9 +129,6 @@ class SocialPubController extends Controller {
return $this->navigationController->navigate('');
}
$data = [
- 'serverData' => [
- 'public' => true,
- ],
'application' => 'Social'
];
@@ -142,6 +142,10 @@ class SocialPubController extends Controller {
} catch (Exception $e) {
return $this->fail($e);
}
+
+ $this->initialStateService->provideInitialState('social', 'serverData', [
+ 'public' => true,
+ ]);
$page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data);
$page->setStatus($status);
$page->setHeaderTitle($this->l10n->t('Social'));
@@ -229,14 +233,14 @@ class SocialPubController extends Controller {
$stream = $this->streamService->getStreamById($postId, true);
$data = [
'id' => $postId,
- 'item' => $stream,
- 'serverData' => [
- 'public' => ($this->userId === null),
- ],
'application' => 'Social'
];
- return new TemplateResponse(Application::APP_NAME, 'stream', $data);
+ $this->initialStateService->provideInitialState(Application::APP_NAME, 'item', $stream );
+ $this->initialStateService->provideInitialState(Application::APP_NAME, 'serverData', [
+ 'public' => ($this->userId === null),
+ ]);
+ return new TemplateResponse(Application::APP_NAME, 'main', $data);
}