From: Christian Weiske Date: Fri, 22 Aug 2014 20:16:16 +0000 (+0200) Subject: show tags and note titles in the notebook X-Git-Tag: v0.1.0~2 X-Git-Url: https://git.cweiske.de/grauphel.git/commitdiff_plain/3e3dfcc65e13be5a49423bb90fc12e67f6b613dd?hp=cd37bde4ef0747a11c1221e937027fe17f2894fe show tags and note titles in the notebook --- diff --git a/appinfo/routes.php b/appinfo/routes.php index 5585bdb..d4a8cd6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -63,6 +63,11 @@ $application->registerRoutes( 'name' => 'gui#index', 'verb' => 'GET', ), + array( + 'url' => '/tag/{rawtag}', + 'name' => 'gui#tag', + 'verb' => 'GET', + ), ) ) ); diff --git a/controller/guicontroller.php b/controller/guicontroller.php index b92d374..92cdf9c 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -70,7 +70,30 @@ class GuiController extends Controller return $res; } - protected function addNavigation(TemplateResponse $res) + /** + * Show all notes of a tag + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function tag($rawtag) + { + $notes = $this->getNotes()->loadNotesOverview(null, $rawtag); + + $res = new TemplateResponse('grauphel', 'tag'); + $res->setParams( + array( + 'tag' => substr($rawtag, 16), + 'rawtag' => $rawtag, + 'notes' => $notes, + ) + ); + $this->addNavigation($res, $rawtag); + + return $res; + } + + protected function addNavigation(TemplateResponse $res, $selectedRawtag = null) { $nav = new \OCP\Template('grauphel', 'appnavigation', ''); $nav->assign('apiroot', $this->getApiRootUrl()); @@ -78,6 +101,26 @@ class GuiController extends Controller $params = $res->getParams(); $params['appNavigation'] = $nav; $res->setParams($params); + + if ($this->user === null) { + return; + } + + $rawtags = $this->getNotes()->getTags(); + sort($rawtags); + $tags = array(); + foreach ($rawtags as $rawtag) { + if (substr($rawtag, 0, 16) == 'system:notebook:') { + $tags[] = array( + 'name' => substr($rawtag, 16), + 'id' => $rawtag, + 'href' => $this->urlGen->linkToRoute( + 'grauphel.gui.tag', array('tag' => $rawtag) + ), + ); + } + } + $nav->assign('tags', $tags); } protected function addStats(TemplateResponse $res) @@ -87,8 +130,7 @@ class GuiController extends Controller } $username = $this->user->getUid(); - $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); - $notes->setUsername($username); + $notes = $this->getNotes(); $tokens = new \OCA\Grauphel\Lib\TokenStorage(); $nav = new \OCP\Template('grauphel', 'indexStats', ''); @@ -118,5 +160,13 @@ class GuiController extends Controller '/' ); } + + protected function getNotes() + { + $username = $this->user->getUid(); + $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); + $notes->setUsername($username); + return $notes; + } } ?> diff --git a/grauphel.css b/grauphel.css new file mode 100644 index 0000000..c2594eb --- /dev/null +++ b/grauphel.css @@ -0,0 +1,28 @@ +.app-grauphel #app-content { + box-sizing: border-box; + padding: 2ex; +} + +.app-grauphel #app-content h1 { + font-weight: bold; + font-size: 2em; + margin-bottom: 1ex; +} +.app-grauphel #app-content h2 { + font-weight: bold; + font-size: 150%; + margin-bottom: 1ex; + margin-top: 2ex; +} +.app-grauphel #app-content dt { + font-weight: bold; +} +.app-grauphel #app-content dd { + margin-left: 3ex; +} +.app-grauphel #app-content pre { + margin: 1em; + background-color: #DDD; + padding: 1ex; + font-family: monospace; +} diff --git a/lib/notestorage.php b/lib/notestorage.php index f3a904d..d9ceaab 100644 --- a/lib/notestorage.php +++ b/lib/notestorage.php @@ -54,6 +54,17 @@ class NoteStorage public function getTags() { + $result = \OC_DB::executeAudited( + 'SELECT `note_tags` FROM `*PREFIX*grauphel_notes`' + . ' WHERE note_user = ?', + array($this->username) + ); + + $tags = array(); + while ($row = $result->fetchRow()) { + $tags = array_merge($tags, json_decode($row['note_tags'])); + } + return array_unique($tags); } /** @@ -273,24 +284,29 @@ class NoteStorage * Load notes for the given user in short form. * Optionally only those changed after $since revision * - * @param integer $since Revision number after which the notes changed + * @param integer $since Revision number after which the notes changed + * @param string $rawtag Filter by tags * * @return array Array of short note objects */ - public function loadNotesOverview($since = null) + public function loadNotesOverview($since = null, $rawtag = null) { $result = \OC_DB::executeAudited( - 'SELECT `note_guid`, `note_title`, `note_last_sync_revision`' + 'SELECT `note_guid`, `note_title`, `note_last_sync_revision`, `note_tags`' . ' FROM `*PREFIX*grauphel_notes`' . ' WHERE note_user = ?', array($this->username) ); $notes = array(); + $jsRawtag = json_encode($rawtag); while ($row = $result->fetchRow()) { if ($since !== null && $row['note_last_sync_revision'] <= $since) { continue; } + if ($rawtag !== null && strpos($row['note_tags'], $jsRawtag) === false) { + continue; + } $notes[] = array( 'guid' => $row['note_guid'], 'ref' => array( diff --git a/templates/appnavigation.php b/templates/appnavigation.php index 78b4358..e50f083 100644 --- a/templates/appnavigation.php +++ b/templates/appnavigation.php @@ -1,7 +1,7 @@
diff --git a/templates/index.php b/templates/index.php index bc51f4b..ac6dcfe 100644 --- a/templates/index.php +++ b/templates/index.php @@ -1,33 +1,4 @@ - + printPage(); ?> diff --git a/templates/tag.php b/templates/tag.php new file mode 100644 index 0000000..ea80ed0 --- /dev/null +++ b/templates/tag.php @@ -0,0 +1,13 @@ + + + +printPage(); ?> + +
+

Notebook:

+
    + +
  • + +
+