login

<     >

2023-09-24 08:29:31 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

add backlog page

now the first state is "todo"
inactive tickets with state todo -> backlog
inactive tickets with state done -> archive

diff --git a/data.lua b/data.lua
index e3b7280..05e9e81 100644
--- a/data.lua
+++ b/data.lua
@@ -289,16 +289,20 @@ function Model:get_tickets(proj_id, state_id)
     return self.db:execute(query, proj_id, state_id)
 end
 
+function Model:get_backlog_tickets(proj_id)
+    local query = [[
+        SELECT * FROM Ticket WHERE proj_id = ? AND is_active = FALSE
+        AND state_id = 1 ORDER BY priority DESC;
+    ]]
+    return self.db:execute(query, proj_id)
+end
+
 function Model:get_archived_tickets(proj_id)
     local query = [[
         SELECT * FROM Ticket WHERE proj_id = ? AND is_active = FALSE
-        ORDER BY state_id ASC, code DESC;
+        AND state_id = 5 ORDER BY code DESC;
     ]]
-    local ticks = self.db:execute(query, proj_id)
-    for i = 1, #ticks do
-        ticks[i].state = self.states[ticks[i].state_id]
-    end
-    return ticks
+    return self.db:execute(query, proj_id)
 end
 
 function Model:update_ticket(tick_id, title, desc, priority)
@@ -461,7 +465,7 @@ end
 local function open(path)
     local self = setmetatable({path=path}, Model)
     self.db = lud.sqlite.open(path)
-    self.states = {"backlog", "design", "progress", "review", "done"}
+    self.states = {"todo", "design", "progress", "review", "done"}
     return self
 end
 

diff --git a/skopos.lua b/skopos.lua
index 477c7a9..d082e38 100644
--- a/skopos.lua
+++ b/skopos.lua
@@ -210,15 +210,20 @@ function App:routes()
         }
         return {fname="view/board.html", env=env}
     end},
-    {"GET", "/p/([-_%w]+)/a",
-    function (req, name)
+    {"GET", "/p/([-_%w]+)/([ab])",
+    function (req, name, page)
         local user = self:get_user(req)
         if user == nil then return "/login?after="..req.path, 303 end
         local proj = self.model:get_user_project(user.id, name)
         if proj == nil then return "not found", 404 end
-        local ticks = self.model:get_archived_tickets(proj.id)
-        local env = {title=self.title, user=user, proj=proj, ticks=ticks}
-        return {fname="view/archive.html", env=env}
+        local ticks
+        if page == "b" then
+            ticks = self.model:get_backlog_tickets(proj.id)
+        else -- "a"
+            ticks = self.model:get_archived_tickets(proj.id)
+        end
+        local env = {title=self.title, user=user, proj=proj, page=page, ticks=ticks}
+        return {fname="view/inactive.html", env=env}
     end},
     {"POST", "/p",
     function (req)
@@ -430,7 +435,13 @@ function App:routes()
         if tick == nil then return "not found", 404 end
         self.model:restore_ticket(tick.id)
         self:log(LOG_INFO, "user "..user.nick.." restored ticket "..name.."#"..tcode)
-        return "/p/"..name.."/a", 303
+        local page
+        if tick.state_id == 1 then
+            page = "b" -- backlog
+        else
+            page = "a" -- archive
+        end
+        return "/p/"..name.."/"..page, 303
     end},
     {"POST", "/p/([-_%w]+)/t/(%d+)/del",
     function (req, name, tcode)

diff --git a/view/archive.html b/view/archive.html
deleted file mode 100644
index 1660c10..0000000
--- a/view/archive.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>{{$proj.name}} archive - {{$title}}</title>
-  <style>
-    .centered { text-align: center; }
-    % include view/menu.css
-    % include view/table.css
-  </style>
-</head>
-<body>
-  % include view/menu.html
-  <h1 class="centered">{{$proj.name}} - archived tickets</h1>
-  <table class="center">
-    <tr>
-      <th>code</th>
-      <th>creation</th>
-      <th>title</th>
-      <th>state</th>
-      <th>priority</th>
-      <th>restore</th>
-    </tr>
-    % for tick in $ticks do
-      % set base_path = "/p/"..$proj.name.."/t/"..$tick.code
-      <tr>
-        <td><a href="{{$base_path}}">#{{$tick.code}}</a></td>
-        <td>{{os.date("%F %R", $tick.time)}}</td>
-        <td>{{$tick.title}}</td>
-        <td>{{$tick.state}}</td>
-        <td>{{$tick.priority}}</td>
-        <td>
-          <form action="{{$base_path}}/restore" method="post">
-            <button type="submit">restore</button>
-          </form>
-        </td>
-      </tr>
-    % end
-  </table>
-</body>
-</html>

diff --git a/view/inactive.html b/view/inactive.html
new file mode 100644
index 0000000..568afaf
--- /dev/null
+++ b/view/inactive.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  % if $page == "b" then
+  %   set page_name = "backlog"
+  %   set action_name = "todo"
+  % else
+  %   set page_name = "archive"
+  %   set action_name = "restore"
+  % end
+  <title>{{$proj.name}} {{$page_name}} - {{$title}}</title>
+  <style>
+    .centered { text-align: center; }
+    % include view/menu.css
+    % include view/table.css
+  </style>
+</head>
+<body>
+  % include view/menu.html
+  <h1 class="centered">{{$proj.name}} - {{$page_name}}</h1>
+  <table class="center">
+    <tr>
+      <th>code</th>
+      <th>creation</th>
+      <th>title</th>
+      <th>priority</th>
+      <th>{{$action_name}}</th>
+    </tr>
+    % for tick in $ticks do
+      % set base_path = "/p/"..$proj.name.."/t/"..$tick.code
+      <tr>
+        <td><a href="{{$base_path}}">#{{$tick.code}}</a></td>
+        <td>{{os.date("%F %R", $tick.time)}}</td>
+        <td>{{$tick.title}}</td>
+        <td>{{$tick.priority}}</td>
+        <td>
+          <form action="{{$base_path}}/restore" method="post">
+            <button type="submit">{{$action_name}}</button>
+          </form>
+        </td>
+      </tr>
+    % end
+  </table>
+</body>
+</html>

diff --git a/view/menu.html b/view/menu.html
index 69a185e..3a90923 100644
--- a/view/menu.html
+++ b/view/menu.html
@@ -5,6 +5,7 @@
     % if $proj ~= nil then
       <a href="/p/{{$proj.name}}">{{$proj.name}}</a>
       <a href="/p/{{$proj.name}}/m">members</a>
+      <a href="/p/{{$proj.name}}/b">backlog</a>
       <a href="/p/{{$proj.name}}/a">archive</a>
       % if $tick ~= nil then
       <a href="/p/{{$proj.name}}/t/{{$tick.code}}/c/new">new comment</a>