$res = new TemplateResponse('grauphel', 'index');
$res->setParams(array('apiurl' => $this->getApiUrl()));
$this->addNavigation($res);
+ $this->addStats($res);
return $res;
}
$res->setParams($params);
}
+ protected function addStats(TemplateResponse $res)
+ {
+ if ($this->user === null) {
+ return;
+ }
+
+ $username = $this->user->getUid();
+ $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
+ $tokens = new \OCA\Grauphel\Lib\TokenStorage();
+
+ $nav = new \OCP\Template('grauphel', 'indexStats', '');
+ $nav->assign('notes', count($notes->loadNotesOverview($username)));
+ $nav->assign('syncrev', $notes->loadSyncData($username)->latestSyncRevision);
+ $nav->assign('tokens', count($tokens->loadForUser($username, 'access')));
+
+ $params = $res->getParams();
+ $params['stats'] = $nav;
+ $res->setParams($params);
+ }
+
protected function checkDeps()
{
if (!class_exists('OAuthProvider')) {
return $token;
}
+ /**
+ * Load multiple tokens
+ *
+ * @param string $username User name
+ * @param string $type Token type: temp, access, verify
+ *
+ * @return array Array of Token objects
+ */
+ public function loadForUser($username, $type)
+ {
+ $result = \OC_DB::executeAudited(
+ 'SELECT * FROM `*PREFIX*grauphel_oauth_tokens`'
+ . ' WHERE `token_user` = ? AND `token_type` = ?',
+ array($username, $type)
+ );
+
+ $tokens = array();
+ while ($tokenRow = $result->fetchRow()) {
+ $tokens[] = $this->fromDb($tokenRow);
+ }
+
+ return $tokens;
+ }
+
protected function fromDb($tokenRow)
{
$token = new Token();
+<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>
+
<?php /** @var $l OC_L10N */ ?>
<?php $_['appNavigation']->printPage(); ?>
<div id="app-content">
- <div style="margin: 1ex">
- <h1 style="font-size: 2em; font-weight: bold">Tomboy notes server</h1>
- <p style="margin: 1em;">
+ <div>
+ <h1>Tomboy notes server</h1>
+ <p>
Use the following sync server URL with tomboy/conboy/tomdroid:
</p>
- <pre style="margin: 1em; background-color: #DDD; padding: 1ex; font-family: monospace"><?php p($_['apiurl']); ?></pre>
+ <pre><?php p($_['apiurl']); ?></pre>
</div>
+ <?php isset($_['stats']) && $_['stats']->printPage(); ?>
</div>
--- /dev/null
+<h2>Stats</h2>
+<dl>
+ <dt>Number of notes</dt>
+ <dd><?php p($_['notes']); ?></dd>
+
+ <dt>Number of registered apps</dt>
+ <dd><?php p($_['tokens']); ?></dd>
+
+ <dt>Sync revision</dt>
+ <dd><?php p($_['syncrev']); ?></dd>
+</dl>