X-Git-Url: https://git.cweiske.de/grauphel.git/blobdiff_plain/6c8ad60e9888fa5625dad2460ca073f93ac1ae0d..35e58ea1056480418d36b08a98f288d583805b23:/controller/guicontroller.php diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 6f0a15c..6fffcb2 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,74 @@ 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\Converter\Html(); + $converter->internalLinkHandler = array($this, 'noteLinkHandler'); + + try { + $contentHtml = $converter->convert($note->{'note-content'}); + } catch (\OCA\Grauphel\Converter\Exception $e) { + $contentHtml = '
' + . '

There was an error converting the note to HTML:

' + . '
' . htmlspecialchars($e->getMessage()) . '
' + . '

Please open a bug report at' + . ' ' + . 'github.com/cweiske/grauphel/issues' + . ' and attach the XML version of the note.' + . '

'; + } + + $res->setParams( + array( + 'note' => $note, + 'note-content' => $contentHtml, + 'links' => array( + 'json' => $this->urlGen->linkToRoute( + 'grauphel.api.note', array( + 'guid' => $guid, 'username' => $this->user->getUid() + ) + ), + 'xml' => $this->urlGen->linkToRoute( + 'grauphel.notes.xml', array('guid' => $guid) + ), + ) + ) + ); + + $selectedRawtag = 'grauphel:special:untagged'; + if (count($note->tags) > 0) { + $selectedRawtag = $note->tags[0]; + } + + $this->addNavigation($res, $selectedRawtag); + 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 * @@ -80,7 +149,13 @@ class GuiController extends Controller */ public function tag($rawtag) { - $notes = $this->getNotes()->loadNotesOverview(null, $rawtag); + $notes = $this->getNotes()->loadNotesOverview(null, $rawtag, true); + usort( + $notes, + function($noteA, $noteB) { + return strcmp($noteA['title'], $noteB['title']); + } + ); $res = new TemplateResponse('grauphel', 'tag'); $res->setParams( @@ -185,6 +260,7 @@ class GuiController extends Controller 'href' => $this->urlGen->linkToRoute( 'grauphel.gui.tag', array('rawtag' => $rawtag) ), + 'selected' => $rawtag == $selectedRawtag, ); } }