mirror of https://github.com/nextcloud/calendar
replicate routes in PHP router, fix Controller naming, include previous data attributes as js variables
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
parent
17528bc11e
commit
6be78cba15
|
@ -12,7 +12,8 @@ module.exports = {
|
|||
OC: true,
|
||||
OCA: true,
|
||||
Vue: true,
|
||||
VueRouter: true
|
||||
VueRouter: true,
|
||||
oca_calendar: true
|
||||
},
|
||||
parserOptions: {
|
||||
parser: 'babel-eslint'
|
||||
|
|
|
@ -71,12 +71,6 @@ class Application extends App {
|
|||
return new Controller\SettingsController($c->getAppName(), $request, $userSession, $config);
|
||||
});
|
||||
|
||||
$container->registerService('TimezoneController', function(IAppContainer $c) {
|
||||
$request = $c->query('Request');
|
||||
|
||||
return new Controller\TimezoneController($c->getAppName(), $request);
|
||||
});
|
||||
|
||||
$container->registerService('ViewController', function(IAppContainer $c) {
|
||||
$request = $c->query('Request');
|
||||
$userSession = $c->getServer()->getUserSession();
|
|
@ -25,6 +25,18 @@ return [
|
|||
'routes' => [
|
||||
//Main view
|
||||
['name' => 'view#index', 'url' => '/', 'verb' => 'GET'],
|
||||
// we need to reflect all our javascript routes here as well,
|
||||
// so that you don't get forwarded to the files app on reload
|
||||
['name' => 'view#indexViewTimerange', 'url' => '/month/{timeRange}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerange', 'url' => '/agendaDay/{timeRange}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerange', 'url' => '/agendaWeek/{timeRange}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeNew', 'url' => '/month/{timeRange}/new/{mode}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeNew', 'url' => '/agendaDay/{timeRange}/new/{mode}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeNew', 'url' => '/agendaWeek/{timeRange}/new/{mode}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeEdit', 'url' => '/month/{timeRange}/edit/{mode}/{objectId}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeEdit', 'url' => '/agendaDay/{timeRange}/edit/{mode}/{objectId}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
['name' => 'view#indexViewTimerangeEdit', 'url' => '/agendaWeek/{timeRange}/edit/{mode}/{objectId}/{recurrenceId}/', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'view#public_index_with_branding', 'url' => '/p/{token}', 'verb' => 'GET'],
|
||||
['name' => 'view#public_index_with_branding_and_fancy_name', 'url' => '/p/{token}/{fancyName}', 'verb' => 'GET'],
|
||||
['name' => 'view#public_index_for_embedding', 'url' => '/embed/{token}', 'verb' => 'GET'],
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Calendar App
|
||||
*
|
||||
* @author Georg Ehrke
|
||||
* @copyright 2016 Georg Ehrke <oc.list@georgehrke.com>
|
||||
* @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
|
||||
* @author Raghu Nayyar
|
||||
* @copyright 2016 Raghu Nayyar <hey@raghunayyar.com>
|
||||
*
|
||||
|
@ -23,16 +23,12 @@
|
|||
*/
|
||||
namespace OCA\Calendar\Controller;
|
||||
|
||||
use OC\AppFramework\Http\Request;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IURLGenerator;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
class ViewController extends Controller {
|
||||
|
||||
|
@ -50,27 +46,20 @@ class ViewController extends Controller {
|
|||
* @var IUserSession
|
||||
*/
|
||||
private $userSession;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request an instance of the request
|
||||
* @param IUserSession $userSession
|
||||
* @param IConfig $config
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param EventDispatcherInterface $eventDispatcherInterface
|
||||
*/
|
||||
public function __construct($appName, IRequest $request, IUserSession $userSession,
|
||||
IConfig $config, IURLGenerator $urlGenerator, EventDispatcherInterface $eventDispatcherInterface) {
|
||||
IConfig $config, IURLGenerator $urlGenerator) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->eventDispatcher = $eventDispatcherInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,14 +68,93 @@ class ViewController extends Controller {
|
|||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function index() {
|
||||
$templateParameters = $this->getTemplateParams();
|
||||
public function index():TemplateResponse {
|
||||
\OCP\Util::connectHook('\OCP\Config', 'js', $this, 'addJavaScriptVariablesForIndex');
|
||||
return new TemplateResponse('calendar', 'main');
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function indexViewTimerange():TemplateResponse {
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexWithBranding(string $token):TemplateResponse {
|
||||
$params = $this->getPublicTemplateParameters($token);
|
||||
$params['isEmbedded'] = false;
|
||||
|
||||
return new TemplateResponse('calendar', 'public', $params, 'base');
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexWithBrandingAndFancyName(string $token):TemplateResponse {
|
||||
return $this->publicIndexWithBranding($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
* @NoSameSiteCookieRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexForEmbedding(string $token):TemplateResponse {
|
||||
$params = $this->getPublicTemplateParameters($token);
|
||||
$params['isEmbedded'] = true;
|
||||
|
||||
$response = new TemplateResponse('calendar', 'main', $params, 'base');
|
||||
$response->addHeader('X-Frame-Options', 'ALLOW');
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexForEmbeddingLegacy(string $token):TemplateResponse {
|
||||
return $this->publicIndexForEmbedding($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* add parameters to javascript for user sites
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
public function addJavaScriptVariablesForIndex(array $array) {
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $user->getUID();
|
||||
$emailAddress = $user->getEMailAddress();
|
||||
|
||||
$initialView = $this->config->getUserValue($userId, $this->appName, 'currentView', null);
|
||||
$showWeekends = $this->config->getUserValue($userId, $this->appName, 'showWeekends', 'yes');
|
||||
$skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no');
|
||||
$weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no');
|
||||
$firstRun = $this->config->getUserValue($userId, $this->appName, 'firstRun', null);
|
||||
|
@ -108,121 +176,44 @@ class ViewController extends Controller {
|
|||
$initialView = 'month';
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch('OCA\Calendar::loadAdditionalScripts');
|
||||
|
||||
return new TemplateResponse('calendar', 'main', array_merge($templateParameters, [
|
||||
'initialView' => $initialView,
|
||||
$array['array']['oca_calendar'] = \json_encode([
|
||||
'emailAddress' => $emailAddress,
|
||||
'skipPopover' => $skipPopover,
|
||||
'weekNumbers' => $weekNumbers,
|
||||
'firstRun' => $firstRun,
|
||||
'isPublic' => false,
|
||||
'isEmbedded' => false,
|
||||
'token' => '',
|
||||
'initialView' => $initialView,
|
||||
'showWeekends' => $showWeekends,
|
||||
'skipPopover' => $skipPopover,
|
||||
'timezone' => $timezone,
|
||||
]));
|
||||
'weekNumbers' => $weekNumbers,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
* add parameters to javascript for public sites
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
* @param array $array
|
||||
*/
|
||||
public function publicIndexWithBranding($token) {
|
||||
$templateParameters = $this->getTemplateParams();
|
||||
$publicTemplateParameters = $this->getPublicTemplateParameters($token);
|
||||
$params = array_merge($templateParameters, $publicTemplateParameters);
|
||||
$params['isEmbedded'] = false;
|
||||
|
||||
return new TemplateResponse('calendar', 'public', $params, 'base');
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexWithBrandingAndFancyName($token) {
|
||||
return $this->publicIndexWithBranding($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
* @NoSameSiteCookieRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexForEmbedding($token) {
|
||||
$templateParameters = $this->getTemplateParams();
|
||||
$publicTemplateParameters = $this->getPublicTemplateParameters($token);
|
||||
$params = array_merge($templateParameters, $publicTemplateParameters);
|
||||
$params['isEmbedded'] = true;
|
||||
|
||||
$response = new TemplateResponse('calendar', 'main', $params, 'base');
|
||||
|
||||
$response->addHeader('X-Frame-Options', 'ALLOW');
|
||||
$csp = new ContentSecurityPolicy();
|
||||
$csp->addAllowedScriptDomain('*');
|
||||
$response->setContentSecurityPolicy($csp);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function publicIndexForEmbeddingLegacy($token) {
|
||||
return $this->publicIndexForEmbedding($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* get common parameters used for all three routes
|
||||
* @return array
|
||||
*/
|
||||
private function getTemplateParams() {
|
||||
$runningOn = $this->config->getSystemValue('version');
|
||||
$runningOnNextcloud12OrLater = version_compare($runningOn, '12', '>=');
|
||||
|
||||
$shareeCanEditShares = !$runningOnNextcloud12OrLater;
|
||||
$shareeCanEditCalendarProperties = $runningOnNextcloud12OrLater;
|
||||
|
||||
$appVersion = $this->config->getAppValue($this->appName, 'installed_version');
|
||||
$isIE = $this->request->isUserAgent([Request::USER_AGENT_IE]);
|
||||
$defaultColor = $this->config->getAppValue('theming', 'color', '#0082C9');
|
||||
$canSharePublicLink = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
|
||||
|
||||
return [
|
||||
'appVersion' => $appVersion,
|
||||
'isIE' => $isIE,
|
||||
'defaultColor' => $defaultColor,
|
||||
'shareeCanEditShares' => $shareeCanEditShares ? 'yes' : 'no',
|
||||
'shareeCanEditCalendarProperties' => $shareeCanEditCalendarProperties ? 'yes' : 'no',
|
||||
'canSharePublicLink' => $canSharePublicLink,
|
||||
public function addJavaScriptVariablesForPublicIndex($array) {
|
||||
$array['array']['oca_calendar'] = \json_encode([
|
||||
'emailAddress' => '',
|
||||
'firstRun' => 'no',
|
||||
'initialView' => 'month',
|
||||
'showWeekends' => 'yes',
|
||||
'skipPopover' => 'no',
|
||||
'timezone' => 'automatic',
|
||||
];
|
||||
'weekNumbers' => 'no',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* get common parameters for public sites
|
||||
*
|
||||
* @param string $token
|
||||
* @return array
|
||||
*/
|
||||
private function getPublicTemplateParameters($token) {
|
||||
$shareURL = $this->request->getServerProtocol() . '://';
|
||||
private function getPublicTemplateParameters(string $token):array {
|
||||
$serverProtocol = $this->request->getServerProtocol();
|
||||
|
||||
$shareURL = $serverProtocol . '://';
|
||||
$shareURL .= $this->request->getServerHost();
|
||||
$shareURL .= $this->request->getRequestUri();
|
||||
|
||||
|
@ -231,25 +222,16 @@ class ViewController extends Controller {
|
|||
|
||||
$remoteBase = $this->urlGenerator->linkTo('', 'remote.php');
|
||||
$remoteBase .= '/dav/public-calendars/' . $token . '?export';
|
||||
$downloadURL = $this->urlGenerator->getAbsoluteURL($remoteBase);
|
||||
|
||||
$downloadUrl = $this->urlGenerator->getAbsoluteURL($remoteBase);
|
||||
|
||||
$protocolLength = strlen($this->request->getServerProtocol()) + 3;
|
||||
$webcalUrl = 'webcal://' . substr($downloadUrl, $protocolLength);
|
||||
$webcalURL = (($serverProtocol === 'http') ? 'webcal' : 'webcals') . '://';
|
||||
$webcalURL .= substr($downloadURL, \strlen($serverProtocol) + 3);
|
||||
|
||||
return [
|
||||
'initialView' => 'month',
|
||||
'emailAddress' => '',
|
||||
'skipPopover' => 'no',
|
||||
'weekNumbers' => 'no',
|
||||
'firstRun' => 'no',
|
||||
'isPublic' => true,
|
||||
'shareURL' => $shareURL,
|
||||
'previewImage' => $previewImage,
|
||||
'webcalURL' => $webcalUrl,
|
||||
'downloadURL' => $downloadUrl,
|
||||
'token' => $token,
|
||||
'timezone' => 'automatic',
|
||||
'webcalURL' => $webcalURL,
|
||||
'downloadURL' => $downloadURL,
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue