9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/grauphel.htm
14 namespace OCA\Grauphel\Controller;
16 use \OCP\AppFramework\Controller;
17 use \OCP\AppFramework\Http\TemplateResponse;
24 * @author Christian Weiske <cweiske@cweiske.de>
25 * @copyright 2014 Christian Weiske
26 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
27 * @version Release: @package_version@
28 * @link http://cweiske.de/grauphel.htm
30 class GuiController extends Controller
33 * constructor of the controller
35 * @param string $appName Name of the app
36 * @param IRequest $request Instance of the request
38 public function __construct($appName, \OCP\IRequest $request, $user, $urlGen)
40 parent::__construct($appName, $request);
42 $this->urlGen = $urlGen;
44 //default http header: we assume something is broken
45 header('HTTP/1.0 500 Internal Server Error');
51 * Tomdroid wants this to be a public page. Sync fails otherwise.
57 public function index()
61 $res = new TemplateResponse('grauphel', 'index');
64 'apiroot' => $this->getApiRootUrl(),
65 'apiurl' => $this->urlGen->linkToRoute('grauphel.api.index')
68 $this->addNavigation($res);
69 $this->addStats($res);
74 * Show all notes of a tag
79 public function tag($rawtag)
81 $notes = $this->getNotes()->loadNotesOverview(null, $rawtag);
83 $res = new TemplateResponse('grauphel', 'tag');
86 'tag' => substr($rawtag, 16),
91 $this->addNavigation($res, $rawtag);
96 protected function addNavigation(TemplateResponse $res, $selectedRawtag = null)
98 $nav = new \OCP\Template('grauphel', 'appnavigation', '');
99 $nav->assign('apiroot', $this->getApiRootUrl());
101 $params = $res->getParams();
102 $params['appNavigation'] = $nav;
103 $res->setParams($params);
105 if ($this->user === null) {
109 $rawtags = $this->getNotes()->getTags();
112 foreach ($rawtags as $rawtag) {
113 if (substr($rawtag, 0, 16) == 'system:notebook:') {
115 'name' => substr($rawtag, 16),
117 'href' => $this->urlGen->linkToRoute(
118 'grauphel.gui.tag', array('tag' => $rawtag)
123 $nav->assign('tags', $tags);
126 protected function addStats(TemplateResponse $res)
128 if ($this->user === null) {
132 $username = $this->user->getUid();
133 $notes = $this->getNotes();
134 $tokens = new \OCA\Grauphel\Lib\TokenStorage();
136 $nav = new \OCP\Template('grauphel', 'indexStats', '');
137 $nav->assign('notes', count($notes->loadNotesOverview()));
138 $nav->assign('syncrev', $notes->loadSyncData()->latestSyncRevision);
139 $nav->assign('tokens', count($tokens->loadForUser($username, 'access')));
141 $params = $res->getParams();
142 $params['stats'] = $nav;
143 $res->setParams($params);
146 protected function checkDeps()
148 if (!class_exists('OAuthProvider')) {
149 throw new \Exception('PHP extension "oauth" is required');
153 protected function getApiRootUrl()
155 //we need to remove the trailing / for tomdroid and conboy
157 $this->urlGen->getAbsoluteURL(
158 $this->urlGen->linkToRoute('grauphel.gui.index')
164 protected function getNotes()
166 $username = $this->user->getUid();
167 $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
168 $notes->setUsername($username);