color modified date as files app does it
[grauphel.git] / controller / guicontroller.php
index fc97b049a7b2bd687849ba92015b6c87604fcc47..127daafb1ada681d6b5f4f94c95c5c0b602a27f3 100644 (file)
@@ -88,14 +88,26 @@ class GuiController extends Controller
             return new ErrorResponse('Note does not exist');
         }
 
-        $converter = new \OCA\Grauphel\Lib\Converter\Html();
+        $converter = new \OCA\Grauphel\Converter\Html();
         $converter->internalLinkHandler = array($this, 'noteLinkHandler');
+
+        try {
+            $contentHtml = $converter->convert($note->{'note-content'});
+        } catch (\OCA\Grauphel\Converter\Exception $e) {
+            $contentHtml = '<div class="error">'
+                . '<p>There was an error converting the note to HTML:</p>'
+                . '<blockquote><tt>' . htmlspecialchars($e->getMessage()) . '</tt></blockquote>'
+                . '<p>Please open a bug report at'
+                . ' <a class="lined" href="http://github.com/cweiske/grauphel/issues">'
+                . 'github.com/cweiske/grauphel/issues</a>'
+                . ' and attach the XML version of the note.'
+                . '</div>';
+        }
+
         $res->setParams(
             array(
                 'note' => $note,
-                'note-content' => $converter->convert(
-                    $note->{'note-content'}
-                ),
+                'note-content' => $contentHtml,
                 'links' => array(
                     'json' => $this->urlGen->linkToRoute(
                         'grauphel.api.note', array(
@@ -109,7 +121,7 @@ class GuiController extends Controller
             )
         );
 
-        $selectedRawtag = null;
+        $selectedRawtag = 'grauphel:special:untagged';
         if (count($note->tags) > 0) {
             $selectedRawtag = $note->tags[0];
         }
@@ -137,7 +149,7 @@ class GuiController extends Controller
      */
     public function tag($rawtag)
     {
-        $notes = $this->getNotes()->loadNotesOverview(null, $rawtag);
+        $notes = $this->getNotes()->loadNotesOverview(null, $rawtag, true);
         usort(
             $notes,
             function($noteA, $noteB) {
@@ -145,6 +157,17 @@ class GuiController extends Controller
             }
         );
 
+        foreach ($notes as &$note) {
+            $diffInDays = intval(
+                (time() - strtotime($note['last-change-date'])) / 86400
+            );
+            $value = 0 + $diffInDays;
+            if ($value > 160) {
+                $value = 160;
+            }
+            $note['dateColor'] = '#' . str_repeat(sprintf('%02X', $value), 3);
+        }
+
         $res = new TemplateResponse('grauphel', 'tag');
         $res->setParams(
             array(