show tags and note titles in the notebook
authorChristian Weiske <cweiske@cweiske.de>
Fri, 22 Aug 2014 20:16:16 +0000 (22:16 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 22 Aug 2014 20:16:16 +0000 (22:16 +0200)
appinfo/routes.php
controller/guicontroller.php
grauphel.css [new file with mode: 0644]
lib/notestorage.php
templates/appnavigation.php
templates/index.php
templates/tag.php [new file with mode: 0644]

index 5585bdb190afd26bc43cd4335be024b1e354755c..d4a8cd646b67347ff47e54f0635bd662b0e4b50f 100644 (file)
@@ -63,6 +63,11 @@ $application->registerRoutes(
                 'name' => 'gui#index',
                 'verb' => 'GET',
             ),
                 'name' => 'gui#index',
                 'verb' => 'GET',
             ),
+            array(
+                'url'  => '/tag/{rawtag}',
+                'name' => 'gui#tag',
+                'verb' => 'GET',
+            ),
         )
     )
 );
         )
     )
 );
index b92d374e73fb0623d242f63e0f43aef9e06b31e8..92cdf9c6588184666694ff76f43b57c1307a6a91 100644 (file)
@@ -70,7 +70,30 @@ class GuiController extends Controller
         return $res;
     }
 
         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());
     {
         $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);
         $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)
     }
 
     protected function addStats(TemplateResponse $res)
@@ -87,8 +130,7 @@ class GuiController extends Controller
         }
 
         $username = $this->user->getUid();
         }
 
         $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', '');
         $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 (file)
index 0000000..c2594eb
--- /dev/null
@@ -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;
+}
index f3a904de996c9a303efe6cefe94ceb7cc623df03..d9ceaabe6bc96a29de7cea30e8ff1e2021d31d12 100644 (file)
@@ -54,6 +54,17 @@ class NoteStorage
 
     public function getTags()
     {
 
     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
      *
      * 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
      */
      *
      * @return array Array of short note objects
      */
-    public function loadNotesOverview($since = null)
+    public function loadNotesOverview($since = null, $rawtag = null)
     {
         $result = \OC_DB::executeAudited(
     {
         $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();
             . ' 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;
             }
         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(
             $notes[] = array(
                 'guid' => $row['note_guid'],
                 'ref'  => array(
index 78b4358bbaf6d467ff392388b03295a9ebdab119..e50f08328e62be53d01417fb605673f08c7a4da0 100644 (file)
@@ -1,7 +1,7 @@
 <div id="app-navigation">
   <ul>
 <div id="app-navigation">
   <ul>
-    <?php foreach ($_['navigationItems'] as $item) { ?>
-      <li data-id="<?php p($item['id']) ?>" class="nav-<?php p($item['id']) ?>"><a href="<?php p(isset($item['href']) ? $item['href'] : '#') ?>"><?php p($item['name']);?></a></li>
+    <?php foreach ($_['tags'] as $tag) { ?>
+      <li data-id="<?php p($tag['id']) ?>"><a href="<?php p(isset($tag['href']) ? $tag['href'] : '#') ?>"><?php p($tag['name']);?></a></li>
     <?php } ?>
   </ul>
 
     <?php } ?>
   </ul>
 
index bc51f4b8639ea6b4374dbbd16b48e769f45b58dd..ac6dcfed012227adc2ade604308ab2e2dc9c674c 100644 (file)
@@ -1,33 +1,4 @@
-<style type="text/css">
-.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;
-}
-</style>
+<link rel="stylesheet" href="<?php p(OCP\Util::linkTo('grauphel','grauphel.css')); ?>" type="text/css"/>
 
 <?php /** @var $l OC_L10N */ ?>
 <?php $_['appNavigation']->printPage(); ?>
 
 <?php /** @var $l OC_L10N */ ?>
 <?php $_['appNavigation']->printPage(); ?>
diff --git a/templates/tag.php b/templates/tag.php
new file mode 100644 (file)
index 0000000..ea80ed0
--- /dev/null
@@ -0,0 +1,13 @@
+<link rel="stylesheet" href="<?php p(OCP\Util::linkTo('grauphel','grauphel.css')); ?>" type="text/css"/>
+
+<?php /** @var $l OC_L10N */ ?>
+<?php $_['appNavigation']->printPage(); ?>
+
+<div id="app-content">
+  <h1>Notebook: <?php p($_['tag']); ?></h1>
+  <ul>
+    <?php foreach ($_['notes'] as $note) { ?>
+      <li data-id="<?php p($note['guid']); ?>"><a href="#"><?php p($note['title']); ?></a></li>
+    <?php } ?>
+  </ul>
+</div>