2023-08-22 16:28:23 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
move shift/archive logic out of template
diff --git a/skopos.lua b/skopos.lua index 764dcdb..64b2b58 100644 --- a/skopos.lua +++ b/skopos.lua @@ -1,4 +1,4 @@ -local lud = require "ludweb" + local lud = require "ludweb" local data = require "data" local auth = require "auth" @@ -389,31 +389,29 @@ function App:routes() self:log(LOG_INFO, "user "..user.nick.." edited ticket "..name.."#"..tcode) return "/p/"..name.."/t/"..tcode, 303 end}, - {"POST", "/p/([-_%w]+)/t/(%d+)/shift/(%d+)", - function (req, name, tcode, state_id) + {"POST", "/p/([-_%w]+)/t/(%d+)/shift/(%w+)", + function (req, name, tcode, direction) local user = self:get_user(req) if user == nil then return "/login", 303 end local proj = self.model:get_user_project(user.id, name) if proj == nil then return "not found", 404 end local tick = self.model:get_ticket(proj.id, tcode) if tick == nil then return "not found", 404 end - self.model:shift_ticket(user.id, tick, tonumber(state_id)) - local path = "/" - if req.query.from == "proj" then - path = "/p/"..name + local state_id = tick.state_id + if direction == "left" then + state_id = state_id - 1 + elseif direction == "right" then + state_id = state_id + 1 + else + self:log(LOG_ERROR, "invalid shift direction: "..direction) + return "invalid shift direction", 500 + end + if state_id == 0 or state_id > #self.model.states then + self.model:archive_ticket(tick.id) + self:log(LOG_INFO, "user "..user.nick.." archived ticket "..name.."#"..tcode) + else + self.model:shift_ticket(user.id, tick, state_id) end - return path, 303 - end}, - {"POST", "/p/([-_%w]+)/t/(%d+)/archive", - function (req, name, tcode) - local user = self:get_user(req) - if user == nil then return "/login", 303 end - local proj = self.model:get_user_project(user.id, name) - if proj == nil then return "not found", 404 end - local tick = self.model:get_ticket(proj.id, tcode) - if tick == nil then return "not found", 404 end - self.model:archive_ticket(tick.id) - self:log(LOG_INFO, "user "..user.nick.." archived ticket "..name.."#"..tcode) local path = "/" if req.query.from == "proj" then path = "/p/"..name diff --git a/view/board.html b/view/board.html index 9843b3a..962ff18 100644 --- a/view/board.html +++ b/view/board.html @@ -48,20 +48,11 @@ </div> <div class="buttons"> % set base_path = "/p/"..$card.proj_name.."/t/"..$card.code - % set shift_path = $base_path.."/shift/" - % set lpath = $shift_path..($state_id-1) - % set rpath = $shift_path..($state_id+1) - % set archive_path = $base_path.."/archive" - % if $state_id == 1 then - % set lpath = $archive_path - % end - % if $state_id == #$states then - % set rpath = $archive_path - % end - <form action="{{$lpath}}?from={{$from}}" method="post"> + % set shift_path = $base_path.."/shift" + <form action="{{$shift_path}}/left?from={{$from}}" method="post"> <button type="submit">←</button> </form> - <form action="{{$rpath}}?from={{$from}}" method="post"> + <form action="{{$shift_path}}/right?from={{$from}}" method="post"> <button type="submit">→</button> </form> </div>