login

<     >

2023-08-10 13:32:38 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

archive/restore projects

diff --git a/data.lua b/data.lua
index 8d31210..eeb9813 100644
--- a/data.lua
+++ b/data.lua
@@ -167,6 +167,14 @@ function Model:update_project(old_name, new_name, desc, goal, color, priority)
     self.db:execute(query, new_name, desc, goal, color, priority, old_name)
 end
 
+function Model:archive_project(proj_id)
+    self.db:execute("UPDATE Project SET is_active = FALSE WHERE id = ?;", proj_id)
+end
+
+function Model:restore_project(proj_id)
+    self.db:execute("UPDATE Project SET is_active = TRUE WHERE id = ?;", proj_id)
+end
+
 function Model:del_project(proj_id)
     self.db:execute("DELETE FROM Membership WHERE proj_id = ?;", proj_id)
     self.db:execute("DELETE FROM Ticket WHERE proj_id = ?;", proj_id)

diff --git a/skopos.lua b/skopos.lua
index b64bd28..0004cc8 100644
--- a/skopos.lua
+++ b/skopos.lua
@@ -213,6 +213,28 @@ function App:routes()
         end
         return "/p", 303
     end},
+    {"POST", "/p/([-_%w]+)/archive",
+    function (req, name)
+        local user = self:get_user(req)
+        if user == nil then return "/login", 303 end
+        local proj = self.model:get_project(name)
+        if proj ~= nil and proj.is_active ~= 0 then
+            self.model:archive_project(proj.id)
+            self:log(LOG_INFO, "user "..user.nick.." archived project "..name)
+        end
+        return "/p", 303
+    end},
+    {"POST", "/p/([-_%w]+)/restore",
+    function (req, name)
+        local user = self:get_user(req)
+        if user == nil then return "/login", 303 end
+        local proj = self.model:get_project(name)
+        if proj ~= nil and proj.is_active == 0 then
+            self.model:restore_project(proj.id)
+            self:log(LOG_INFO, "user "..user.nick.." restored project "..name)
+        end
+        return "/p", 303
+    end},
     -- tickets
     {"GET", "/p/([-_%w]+)/t/new",
     function (req, name)

diff --git a/view/projs.html b/view/projs.html
index a96457c..03f1c52 100644
--- a/view/projs.html
+++ b/view/projs.html
@@ -5,6 +5,7 @@
   <title>{{$title}} - Projects</title>
   <style>
     .centered { text-align: center; }
+    .archived { background-color: #FFFF90; }
     % include view/table.css
   </style>
 </head>
@@ -19,16 +20,29 @@
       <th>priority</th>
       <th>color</th>
       <th>edit</th>
+      <th>status</th>
       <th>delete</th>
     </tr>
     % for proj in $projs do
-      <tr>
+      % if $proj.is_active ~= 0 then
+        % set row_class = ""
+        % set action = "archive"
+      % else
+        % set row_class = ' class="archived"'
+        % set action = "restore"
+      % end
+      <tr{{!$row_class}}>
         <td><a href="/p/{{$proj.name}}">{{$proj.name}}</a></td>
         <td>{{$proj.desc}}</td>
         <td>{{$proj.priority}}</td>
         <td><span style="background-color:{{$proj.color}};">{{$proj.color}}</span></td>
         <td><a href="/p/{{$proj.name}}/edit">edit</a></td>
         <td>
+          <form action="/p/{{$proj.name}}/{{$action}}" method="post">
+            <button type="submit">{{$action}}</button>
+          </form>
+        </td>
+        <td>
           <form action="/p/{{$proj.name}}/del" method="post">
             <button type="submit">delete</button>
           </form>