Category management

master
E. Almqvist 3 years ago
parent 2732e393b2
commit 8059628f94
  1. 40
      src/app.rb
  2. 4
      src/db_models.rb
  3. 4
      src/lib/database.rb
  4. 18
      src/views/admin/categories/edit.slim
  5. 6
      src/views/admin/index.slim
  6. 31
      src/views/admin/roles/edit.slim
  7. 1
      src/views/stylesheets/style.sass

@ -423,3 +423,43 @@ post "/admin/categories" do
end
redirect back
end
get "/admin/categories/:id/delete" do
id = params[:id].to_i
user = get_current_user
auth_denied unless user.permitted? :cateman
Category.delete "id = ?", id
flash[:success] = "Removed category."
redirect back
end
get "/admin/categories/:id/edit" do
id = params[:id].to_i
user = get_current_user
auth_denied unless user.permitted? :cateman
catobj = Category.find_by_id id
if catobj then
serve :"admin/categories/edit", {category: catobj}
else
raise Sinatra::NotFound
end
end
post "/admin/roles/:id/update" do
id = params[:id].to_i
user = get_current_user
auth_denied unless user.permitted? :cateman
data = {
name: params[:name],
color: params[:color],
}
resp = Category.edit id, data
flash[:success] = "Updated category."
redirect "/admin/roles/#{id}/edit"
end

@ -227,10 +227,6 @@ class Role < EntityModel
}
self.insert data
end
def self.edit(roleid, data)
self.update data, "id = #{roleid}"
end
end

@ -75,6 +75,10 @@ class EntityModel
self.query(q, *data.values, *args)
end
def self.edit(id, data)
self.update(data, "id=?", id)
end
def self.insert(data) # Inserts new data into the table
entstr, valstr = self.gen_insert_query data.keys
begin

@ -0,0 +1,18 @@
.content-container
article.card.border
h2 = "Edit Category '#{category.name}'"
.form-container
form action="/admin/categories/#{category.id}/update" method="post"
label Category name
input type="text" name="name" pattern="#{NAME_REGEX_STR}" maxlength="#{MAX_NAME_LEN}" oninput="this.reportValidity()" title="#{REGISTER_ERRORS[:name_desc]}" value="#{category.name}"
label Category color
input type="color" name="color" value="#{category.color}"
input type="submit" value="Update"
a.button href="/admin/categories/#{category.id}/delete"
| [DELETE CATEGORY]
a.button href="/admin"
| [GO BACK]

@ -3,13 +3,13 @@ div
nav
ul.button-container
li
a.button href="#users" = "Manage Users"
a.button href="#users" = "Users"
li
a.button href="#roles" = "Roles"
li
a.button href="#auctions" = "Auctions"
li
a.button href="#categories" = "Category Settings"
a.button href="#categories" = "Categories"
#admin-panel
@ -73,7 +73,7 @@ div
input type="text" name="name" pattern="#{NAME_REGEX_STR}" maxlength="#{MAX_NAME_LEN}" oninput="this.reportValidity()" title="#{REGISTER_ERRORS[:name_desc]}"
label Category color
input type="color" name="color" value="#010ffa"
input type="color" name="color" value="#ffffff"
input type="submit" value="Create category"

@ -1,19 +1,20 @@
article.card.border
h2 = "Edit role '#{role.name}'"
.content-container
article.card.border
h2 = "Edit role '#{role.name}'"
.form-container
form action="/admin/roles/#{role.id}/update" method="post"
label Role name
input type="text" name="name" pattern="#{NAME_REGEX_STR}" maxlength="#{MAX_NAME_LEN}" oninput="this.reportValidity()" title="#{REGISTER_ERRORS[:name_desc]}" value="#{role.name}"
.form-container
form action="/admin/roles/#{role.id}/update" method="post"
label Role name
input type="text" name="name" pattern="#{NAME_REGEX_STR}" maxlength="#{MAX_NAME_LEN}" oninput="this.reportValidity()" title="#{REGISTER_ERRORS[:name_desc]}" value="#{role.name}"
label Role color
input type="color" name="color" value="#{role.color}"
label Role color
input type="color" name="color" value="#{role.color}"
label Role flags int
input type="number" name="flags" value="#{role.flags}"
label Role flags int
input type="number" name="flags" value="#{role.flags}"
input type="submit" value="Update"
a.button href="/admin/roles/#{role.id}/delete"
| [DELETE ROLE]
a.button href="/admin"
| [GO BACK]
input type="submit" value="Update"
a.button href="/admin/roles/#{role.id}/delete"
| [DELETE ROLE]
a.button href="/admin"
| [GO BACK]

@ -33,6 +33,7 @@ $special_clr: #4776C1
html
background-color: $bg_clr
scroll-behavior: smooth
.content-container
display: flex

Loading…
Cancel
Save