login

<     >

2023-08-02 11:46:15 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

update ui to include project goal, color and priority

diff --git a/data.lua b/data.lua
index ae0c245..78e1bca 100644
--- a/data.lua
+++ b/data.lua
@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS Project (
     name TEXT NOT NULL UNIQUE,
     desc TEXT,
     goal TEXT,
-    color INTEGER,
+    color TEXT,
     priority INTEGER NOT NULL,
     is_active INTEGER NOT NULL
 );
@@ -134,8 +134,12 @@ function Model:del_invite(user_id, uuid)
     self.db:execute("DELETE FROM Invite WHERE user_id = ? AND uuid = ?;", user_id, uuid)
 end
 
-function Model:create_project(user_id, name, desc)
-    self.db:execute("INSERT INTO Project(name, desc) VALUES (?, ?);", name, desc)
+function Model:create_project(user_id, name, desc, goal, color, priority)
+    local query = [[
+        INSERT INTO Project(time, name, desc, goal, color, priority, is_active)
+        VALUES (unixepoch(), ?, ?, ?, ?, ?, 1);
+    ]]
+    self.db:execute(query, name, desc, goal, color, priority)
     local proj_id = self.db:execute("SELECT id FROM Project WHERE name = ?;", name)[1].id
     self.db:execute("INSERT INTO Membership(proj_id, user_id) VALUES (?, ?);", proj_id, user_id)
     return proj_id
@@ -148,7 +152,7 @@ end
 function Model:get_user_projects(user_id)
     return self.db:execute([[
         SELECT * FROM Project JOIN Membership ON Project.id = Membership.proj_id
-        WHERE Membership.user_id = ?;
+        WHERE Membership.user_id = ? ORDER BY priority DESC;
     ]], user_id)
 end
 

diff --git a/skopos.lua b/skopos.lua
index 613fe11..c354ee8 100644
--- a/skopos.lua
+++ b/skopos.lua
@@ -154,7 +154,10 @@ function App:routes()
         if user == nil then return "/login", 303 end
         local name = req.form.name
         local desc = req.form.desc
-        self.model:create_project(user.id, name, desc)
+        local goal = req.form.goal
+        local color = req.form.color
+        local priority = tonumber(req.form.priority or 0)
+        self.model:create_project(user.id, name, desc, goal, color, priority)
         self:log(LOG_INFO, "user "..user.nick.." created project "..name)
         return "/p", 303
     end},

diff --git a/view/form.css b/view/form.css
index b3c35ba..2f3af01 100644
--- a/view/form.css
+++ b/view/form.css
@@ -2,6 +2,17 @@
       padding: 0;
       list-style-type: none;
     }
+    .field-list tr td {
+      padding: 2px 7px;
+    }
+    .field-list tr td:first-child {
+      background-color: #EEF7DC;
+      font-weight: bold;
+      text-align: right;
+    }
+    .field-list tr td:nth-child(2) {
+      font-size: 18px;
+    }
     .flat-field {
       margin: 5px;
       font-size: 18px;

diff --git a/view/proj_form.html b/view/proj_form.html
index be738d5..e6480ab 100644
--- a/view/proj_form.html
+++ b/view/proj_form.html
@@ -11,14 +11,54 @@
 <body>
   <h1 class="centered">Project</h1>
   <form action="/new-project" method="post">
-    <ul class="centered ul-form">
-      <li><input
-        type="text" class="flat-field" name="name" placeholder="Name" required
-        pattern="[-_A-Za-z0-9]+" autofocus>
-      </li>
-      <li><input type="text" class="flat-field" name="desc" placeholder="Description"></li>
-      <li><input type="submit" class="flat-button" value="Create"></li>
-    </ul>
+    <table class="field-list">
+      <tbody>
+        <tr>
+          <td>
+            <label for="name">Name:</label>
+          </td>
+          <td>
+            <input
+              type="text" class="flat-field" id="name" name="name" required
+              pattern="[-_A-Za-z0-9]+" autofocus>
+          </td>
+        </tr>
+        <tr>
+          <td>
+            <label for="desc">Description:</label>
+          </td>
+          <td>
+            <input type="text" class="flat-field" id="desc" name="desc" size="30">
+          </td>
+        </tr>
+        <tr>
+          <td>
+            <label for="goal">Goal:</label>
+          </td>
+          <td>
+            <input type="text" class="flat-field" id="goal" name="goal" size="50">
+          </td>
+        </tr>
+        <tr>
+          <td>
+            <label for="color">Color:</label>
+          </td>
+          <td>
+            <input type="color" class="flat-field" id="color" name="color" value="#000000">
+          </td>
+        </tr>
+        <tr>
+          <td>
+            <label for="priority">Priority:</label>
+          </td>
+          <td>
+            <input type="number" class="flat-field" id="priority" name="priority" required>
+          </td>
+        </tr>
+      </tbody>
+    </table>
+    <br>
+    <input type="submit" class="flat-button" value="Create">
   </form>
 </body>
 </html>

diff --git a/view/projs.html b/view/projs.html
index 0c2f3e2..f84996b 100644
--- a/view/projs.html
+++ b/view/projs.html
@@ -16,12 +16,16 @@
     <tr>
       <th>name</th>
       <th>description</th>
+      <th>priority</th>
+      <th>color</th>
       <th>delete</th>
     </tr>
     % for proj in $projs do
       <tr>
         <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>
           <form action="/del-project/{{$proj.name}}" method="post">
             <button type="submit">delete</button>