diff options
| -rw-r--r-- | controller/guicontroller.php | 21 | ||||
| -rw-r--r-- | lib/tokenstorage.php | 24 | ||||
| -rw-r--r-- | templates/index.php | 40 | ||||
| -rw-r--r-- | templates/indexStats.php | 11 |
4 files changed, 92 insertions, 4 deletions
diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 06ea681..2c05750 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -61,6 +61,7 @@ class GuiController extends Controller $res = new TemplateResponse('grauphel', 'index'); $res->setParams(array('apiurl' => $this->getApiUrl())); $this->addNavigation($res); + $this->addStats($res); return $res; } @@ -74,6 +75,26 @@ class GuiController extends Controller $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')) { diff --git a/lib/tokenstorage.php b/lib/tokenstorage.php index 9a173f5..f8f0806 100644 --- a/lib/tokenstorage.php +++ b/lib/tokenstorage.php @@ -106,6 +106,30 @@ class TokenStorage 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(); diff --git a/templates/index.php b/templates/index.php index 7b7c6a6..e63df37 100644 --- a/templates/index.php +++ b/templates/index.php @@ -1,13 +1,45 @@ +<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> diff --git a/templates/indexStats.php b/templates/indexStats.php new file mode 100644 index 0000000..78274da --- /dev/null +++ b/templates/indexStats.php @@ -0,0 +1,11 @@ +<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> |
