Skip to content

Commit

Permalink
reduce to one single template
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <github@dartcafe.de>
  • Loading branch information
dartcafe committed Oct 20, 2023
1 parent 94fcac5 commit aab027f
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 94 deletions.
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
['name' => 'public#watch_poll', 'url' => '/s/{token}/watch', 'verb' => 'GET'],

['name' => 'admin#index', 'url' => '/administration', 'verb' => 'GET'],

['name' => 'admin#list', 'url' => '/administration/polls', 'verb' => 'GET'],
['name' => 'admin#takeover', 'url' => '/administration/poll/{pollId}/takeover', 'verb' => 'PUT'],

['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#index', 'url' => '/not-found', 'verb' => 'GET', 'postfix' => 'notfound'],
['name' => 'page#index', 'url' => '/list/{id}', 'verb' => 'GET', 'postfix' => 'list'],
['name' => 'page#index', 'url' => '/list/{category}', 'verb' => 'GET', 'postfix' => 'list', 'defaults' => array('category' => 'relevant')],
['name' => 'page#index', 'url' => '/combo', 'verb' => 'GET', 'postfix' => 'combo'],
['name' => 'page#vote', 'url' => '/vote/{id}', 'verb' => 'GET'],

Expand Down
10 changes: 8 additions & 2 deletions lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@
use OCA\Polls\Service\PollService;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\Util;

class AdminController extends BaseController {
public function __construct(
string $appName,
IRequest $request,
ISession $session,
private IURLGenerator $urlGenerator,
private PollService $pollService
private PollService $pollService,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request, $session);
}
Expand All @@ -46,7 +50,9 @@ public function __construct(
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
Util::addScript(AppConstants::APP_ID, 'polls-main');
$this->eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent());
return new TemplateResponse(AppConstants::APP_ID, 'main', ['urlGenerator' => $this->urlGenerator]);
}

/**
Expand Down
13 changes: 10 additions & 3 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
use OCP\AppFramework\Controller;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Util;

class PageController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private IURLGenerator $urlGenerator,
private NotificationService $notificationService
private NotificationService $notificationService,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request);
}
Expand All @@ -47,7 +51,9 @@ public function __construct(
* @NoCSRFRequired
*/
public function index(): TemplateResponse {
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
Util::addScript(AppConstants::APP_ID, 'polls-main');
$this->eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent());
return new TemplateResponse(AppConstants::APP_ID, 'main');
}

/**
Expand All @@ -56,6 +62,7 @@ public function index(): TemplateResponse {
*/
public function vote(int $id): TemplateResponse {
$this->notificationService->removeNotification($id);
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
Util::addScript(AppConstants::APP_ID, 'polls-main');
return new TemplateResponse(AppConstants::APP_ID, 'main');
}
}
6 changes: 4 additions & 2 deletions lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Util;

class PublicController extends BaseController {
public function __construct(
Expand Down Expand Up @@ -69,10 +70,11 @@ public function __construct(
* @return TemplateResponse|PublicTemplateResponse
*/
public function votePage(string $token) {
Util::addScript(AppConstants::APP_ID, 'polls-main');
if ($this->userSession->isLoggedIn()) {
return new TemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
return new TemplateResponse(AppConstants::APP_ID, 'main');
} else {
$template = new PublicTemplateResponse(AppConstants::APP_ID, 'polls.tmpl', ['urlGenerator' => $this->urlGenerator]);
$template = new PublicTemplateResponse(AppConstants::APP_ID, 'main');
$template->setFooterVisible(false);
return $template;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
use OCA\Polls\AppConstants;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
use OCP\Util;

class AdminSettings implements ISettings {
public function getForm(): TemplateResponse {
return new TemplateResponse(AppConstants::APP_ID, 'admin', []);
Util::addScript(AppConstants::APP_ID, 'polls-adminSettings');
return new TemplateResponse(AppConstants::APP_ID, 'main', []);
}

public function getSection(): string {
Expand Down
4 changes: 3 additions & 1 deletion lib/Settings/PersonalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
use OCA\Polls\AppConstants;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
use OCP\Util;

class PersonalSettings implements ISettings {
public function getForm(): TemplateResponse {
return new TemplateResponse(AppConstants::APP_ID, 'settings', []);
Util::addScript(AppConstants::APP_ID, 'polls-userSettings');
return new TemplateResponse(AppConstants::APP_ID, 'main', []);
}

public function getSection(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/js/adminSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const store = new Store({

/* eslint-disable-next-line no-new */
new Vue({
el: '#admin_settings',
el: '#content_polls',
store,
render: (h) => h(AdminSettingsPage),
})
9 changes: 9 additions & 0 deletions src/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ export default new Router({
},
},
},
{
path: '/list',
redirect: {
name: 'list',
params: {
type: 'relevant',
},
},
},
{
path: '/list/:type?',
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/js/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const store = new Store({

/* eslint-disable-next-line no-new */
new Vue({
el: '#user_settings',
el: '#content_polls',
store,
render: (h) => h(UserSettingsPage),
})
27 changes: 0 additions & 27 deletions templates/admin.php

This file was deleted.

1 change: 1 addition & 0 deletions templates/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="content_polls" />
28 changes: 0 additions & 28 deletions templates/polls.tmpl.php

This file was deleted.

27 changes: 0 additions & 27 deletions templates/settings.php

This file was deleted.

0 comments on commit aab027f

Please sign in to comment.