2020-07-13 08:27:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2013-04-03 17:50:29 +02:00
|
|
|
|
|
|
|
namespace OCA\Notes\Controller;
|
|
|
|
|
2020-09-20 14:45:49 +02:00
|
|
|
use OCA\Notes\Service\NotesService;
|
|
|
|
|
2015-01-26 14:21:50 +01:00
|
|
|
use OCP\AppFramework\Controller;
|
2015-02-11 13:04:28 +01:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2015-04-26 20:27:01 +02:00
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
2020-09-20 14:45:49 +02:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
2015-01-26 14:21:50 +01:00
|
|
|
use OCP\IRequest;
|
2020-09-20 14:45:49 +02:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IUserSession;
|
2013-08-17 17:05:09 +02:00
|
|
|
|
2013-04-03 17:50:29 +02:00
|
|
|
class PageController extends Controller {
|
2020-09-20 14:45:49 +02:00
|
|
|
/** @NotesService */
|
|
|
|
private $notesService;
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
/** @IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $AppName,
|
|
|
|
IRequest $request,
|
|
|
|
NotesService $notesService,
|
|
|
|
IUserSession $userSession,
|
|
|
|
IURLGenerator $urlGenerator
|
|
|
|
) {
|
2019-05-25 08:15:05 +02:00
|
|
|
parent::__construct($AppName, $request);
|
2020-09-20 14:45:49 +02:00
|
|
|
$this->notesService = $notesService;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2019-05-25 08:15:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2020-04-12 19:26:57 +02:00
|
|
|
public function index() : TemplateResponse {
|
2020-07-12 22:44:55 +02:00
|
|
|
$devMode = !is_file(dirname(__FILE__).'/../../js/notes-main.js');
|
2019-05-25 08:15:05 +02:00
|
|
|
$response = new TemplateResponse(
|
|
|
|
$this->appName,
|
2019-11-16 22:53:12 +01:00
|
|
|
$devMode ? 'dev-mode' : 'main',
|
2019-05-25 08:15:05 +02:00
|
|
|
[ ]
|
|
|
|
);
|
|
|
|
|
|
|
|
$csp = new ContentSecurityPolicy();
|
|
|
|
$csp->addAllowedImageDomain('*');
|
|
|
|
$response->setContentSecurityPolicy($csp);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2020-09-20 14:45:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function create() : RedirectResponse {
|
|
|
|
$note = $this->notesService->create($this->userSession->getUser()->getUID(), '', '');
|
|
|
|
$note->setContent('');
|
|
|
|
$url = $this->urlGenerator->linkToRoute('notes.page.index', [ 'id' => $note->getId() ]);
|
|
|
|
return new RedirectResponse($url);
|
|
|
|
}
|
2018-07-01 21:10:30 +02:00
|
|
|
}
|