'name' => 'gui#index',
'verb' => 'GET',
),
+ array(
+ 'url' => '/tag/{rawtag}',
+ 'name' => 'gui#tag',
+ 'verb' => 'GET',
+ ),
)
)
);
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());
$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)
}
$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', '');
'/'
);
}
+
+ protected function getNotes()
+ {
+ $username = $this->user->getUid();
+ $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
+ $notes->setUsername($username);
+ return $notes;
+ }
}
?>
--- /dev/null
+.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;
+}
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);
}
/**
* 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(
<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>
-<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(); ?>
--- /dev/null
+<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>