login

<     >

2023-07-25 16:03:20 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

some groundwork for board view

diff --git a/data.lua b/data.lua
index ce7790c..a2d5f12 100644
--- a/data.lua
+++ b/data.lua
@@ -177,6 +177,34 @@ function Model:add_comment(user_id, ticket_id, text)
     ]], ticket_id, user_id, text)
 end
 
+-- return a list of columns ordered by state ID
+-- each column is a list of cards ordered by time
+-- column[0] contains extra info: `name`
+-- each card is a ticket DB object with keys `proj_name` and `user_name` added
+function Model:get_board(user_id, proj_id)
+    -- TODO: filter by proj_id if it's not nil
+    local query = [[
+    SELECT 
+        Ticket.*, 
+        User.name AS author_name, 
+        Project.name AS proj_name
+    FROM 
+        Membership
+    JOIN 
+        Project ON Membership.proj_id = Project.id
+    JOIN 
+        Ticket ON Project.id = Ticket.proj_id
+    JOIN 
+        User ON Ticket.user_id = User.id
+    WHERE 
+        Membership.user_id = ?;
+    ]]
+    local tickets = self.db:execute(query, user_id)
+    local columns = {}
+    -- TODO: fill columns from DB data
+    return columns
+end
+
 function Model:close()
     self.db:close()
 end

diff --git a/skopos.lua b/skopos.lua
index 39ad829..b860d60 100644
--- a/skopos.lua
+++ b/skopos.lua
@@ -46,7 +46,9 @@ function App:routes()
     function (req)
         local user = self:get_user(req)
         if user == nil then return "/login", 303 end
-        local env = {title=self.title, user=user}
+        -- TODO: set proj_id
+        local columns = self.model:get_board(user.id)
+        local env = {title=self.title, user=user, columns=columns}
         return lud.template.render_file("view/home.html", env)
     end},
     {"GET", "/join",

diff --git a/view/board.css b/view/board.css
new file mode 100644
index 0000000..a6765f9
--- /dev/null
+++ b/view/board.css
@@ -0,0 +1,43 @@
+.kanban-board {
+    display: flex;
+    justify-content: space-between;
+    padding: 20px;
+}
+
+.kanban-column {
+    background-color: #f2f2f2;
+    width: 30%;
+    padding: 20px;
+    border-radius: 10px;
+    box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
+}
+
+.kanban-column h2 {
+    margin-bottom: 20px;
+}
+
+.kanban-card {
+    background-color: white;
+    padding: 10px;
+    margin-bottom: 10px;
+    border-radius: 5px;
+    box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
+}
+
+.buttons {
+    display: flex;
+    justify-content: space-between;
+    margin-top: 10px;
+}
+
+button {
+    padding: 5px;
+    border: none;
+    background-color: #ddd;
+    cursor: pointer;
+}
+
+button:disabled {
+    background-color: #aaa;
+    cursor: not-allowed;
+}

diff --git a/view/home.html b/view/home.html
index eaf7e79..65bf4fe 100644
--- a/view/home.html
+++ b/view/home.html
@@ -5,10 +5,26 @@
   <title>{{$title}}</title>
   <style>
     .centered { text-align: center; }
+    % include view/board.css
   </style>
 </head>
 <body>
-  <h1 class="centered">Home</h1>
-    <p>Welcome {{$user.name}}!</p>
+  <h1 class="centered">Global Board</h1>
+  <div class="kanban-board">
+    % for column in $columns do
+    <div class="kanban-column">
+      <h2>{{$column[0].name}}</h2>
+      % for card in $column do
+      <div class="kanban-card">
+        <p>{{$card.title}}</p>
+        <div class="buttons">
+          <button disabled>←</button>
+          <button>→</button>
+        </div>
+      </div>
+      % end
+    </div>
+    % end
+  </div>
 </body>
 </html>