X-Git-Url: https://git.cweiske.de/grauphel.git/blobdiff_plain/a6e6dc9e303ccddf1cb6e699f5e43295af361e0f..8ee6bfe97633d31c6b89cebbc434837eca04d6dd:/controller/guicontroller.php diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 6f0a15c..97a7f10 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -17,6 +17,7 @@ use \OCP\AppFramework\Controller; use \OCP\AppFramework\Http\TemplateResponse; use \OCA\Grauphel\Lib\Client; use \OCA\Grauphel\Lib\TokenStorage; +use \OCA\Grauphel\Lib\Response\ErrorResponse; /** * Owncloud frontend @@ -72,6 +73,47 @@ class GuiController extends Controller return $res; } + /** + * Show contents of a note + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function note($guid) + { + $res = new TemplateResponse('grauphel', 'gui-note'); + + $note = $this->getNotes()->load($guid, false); + if ($note === null) { + return new ErrorResponse('Note does not exist'); + } + + $converter = new \OCA\Grauphel\Lib\Converter\Html(); + $converter->internalLinkHandler = array($this, 'noteLinkHandler'); + $res->setParams( + array( + 'note' => $note, + 'note-content' => $converter->convert( + $note->{'note-content'} + ), + ) + ); + + $this->addNavigation($res); + return $res; + } + + public function noteLinkHandler($noteTitle) + { + $guid = $this->getNotes()->loadGuidByTitle($noteTitle); + if ($guid === null) { + return '#'; + } + return $this->urlGen->linkToRoute( + 'grauphel.gui.note', array('guid' => $guid) + ); + } + /** * Show all notes of a tag * @@ -81,6 +123,12 @@ class GuiController extends Controller public function tag($rawtag) { $notes = $this->getNotes()->loadNotesOverview(null, $rawtag); + usort( + $notes, + function($noteA, $noteB) { + return strcmp($noteA['title'], $noteB['title']); + } + ); $res = new TemplateResponse('grauphel', 'tag'); $res->setParams(