aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-08-22 22:16:16 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-08-22 22:16:16 +0200
commit3e3dfcc65e13be5a49423bb90fc12e67f6b613dd (patch)
tree450ed5b99de648f2a9b86720ecb82fba62cfe50c
parentcd37bde4ef0747a11c1221e937027fe17f2894fe (diff)
downloadgrauphel-3e3dfcc65e13be5a49423bb90fc12e67f6b613dd.tar.gz
grauphel-3e3dfcc65e13be5a49423bb90fc12e67f6b613dd.zip
show tags and note titles in the notebook
-rw-r--r--appinfo/routes.php5
-rw-r--r--controller/guicontroller.php56
-rw-r--r--grauphel.css28
-rw-r--r--lib/notestorage.php22
-rw-r--r--templates/appnavigation.php4
-rw-r--r--templates/index.php31
-rw-r--r--templates/tag.php13
7 files changed, 121 insertions, 38 deletions
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 @@
<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>
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 @@
-<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(); ?>
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 @@
+<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>