Initial admin/user index/show

This commit is contained in:
2024-09-16 15:17:31 +02:00
parent d031245655
commit 11d944b64c
16 changed files with 222 additions and 10 deletions

View File

@@ -0,0 +1,29 @@
class Admin::UsersController < ApplicationController
before_action :authorize!
before_action :set_user, only: [ :show, :edit ]
def index
@users = User.all.order(:lastname, :firstname)
end
def edit
end
def show
end
def new
end
def create
end
def update
end
private
def set_user
@user = User.find(params[:id])
end
end

View File

@@ -0,0 +1,2 @@
module Admin::UsersHelper
end

View File

@@ -0,0 +1,4 @@
class Admin::UserPolicy < ApplicationPolicy
def index
end
end

View File

@@ -0,0 +1,11 @@
<div class="shadow bg-gray-100 p-2">
<%= icon "user", class: "size-10" %>
<p>
<%= user.name %>
<span class="badge inline"><%= user.role %></span>
</p>
<p><%= user.email %></p>
<p>E-Mail Verifiziert:
<%= icon bool_icon(user.verified), class: "icon #{user.verified ? "text-green-600" : "text-red-600"}" %>
<p><%= user.created_at %></p>
</div>

View File

@@ -0,0 +1,34 @@
<%= turbo_frame_tag dom_id(user) do %>
<tr id="<%= dom_id user %>" class="bg-role-<%= user.role %>-light odd:bg-opacity-25 even:bg-opacity-15 text-hsrm-gray whitespace-nowrap hover:bg-opacity-30"">
<td class="p-2 py-3 text-center">
<%= link_to admin_user_path(user) do %>
<span class="badge badge-xl text-role-<%= user.role %> bg-role-<%= user.role %>-light rounded-lg shadow">
<%= user.id %>
</span>
<% end %>
</td>
<td class="p-2 py-3">
<%= user.name %>
</td>
<td class="p-2 py-3">
<%= icon bool_icon(user.verified), class: "icon #{user.verified ? "text-green-600" : "text-red-600"}", title: "E-Mail-Adresse verifiziert" %>
<%= user.email %>
</td>
<td class="p-2 py-3">
<span class="badge block w-28 bg-role-<%= user.role %>-light">
<%= user.role %>
</span>
</td>
<td class="p-2 py-3 flex space-x-2 justify-center">
<%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-user-light hover:texft-black">User</span>
<% end unless user.user? %>
<%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-operator-light hover:texft-black">Operator</span>
<% end unless user.operator? %>
<%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-admin-light hover:texft-black">Admin</span>
<% end unless user.admin? %>
</td>
</tr>
<% end %>

View File

@@ -0,0 +1,4 @@
<div>
<h1 class="font-bold text-4xl">Admin::Users#create</h1>
<p>Find me in app/views/admin/users/create.html.erb</p>
</div>

View File

@@ -0,0 +1,4 @@
<div>
<h1 class="font-bold text-4xl">Admin::Users#edit</h1>
<p>Find me in app/views/admin/users/edit.html.erb</p>
</div>

View File

@@ -0,0 +1,23 @@
<div class="w-full">
<% content_for :title, "Current Print Jobs" %>
<div class="flex items-center justify-between py-4">
<h1 class="text-4xl font-bold text-hsrm-gray">Benutzerliste</h1>
<%= link_to "Filter", "#", class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %>
</div>
<div class="min-w-full overflow-auto shadow-lg">
<table class="w-full py-8 table-auto">
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
<tr>
<th class="w-1 p-2 py-3 text-center">ID</th>
<th class="w-1 p-2 py-3 text-left">Name</th>
<th class="p-2 py-3 text-left">E-Mail-Adresse</th>
<th class="w-1 p-2 py-3 text-center">Rolle</th>
<th class="w-1 p-2 py-3 text-center">Rolle ändern zu</th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "user_tr", collection: @users, as: :user %>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,4 @@
<div>
<h1 class="font-bold text-4xl">Admin::Users#new</h1>
<p>Find me in app/views/admin/users/new.html.erb</p>
</div>

View File

@@ -0,0 +1,33 @@
<div>
<h1 class="font-bold text-4xl">Benutzer Details</h1>
<%= render partial: 'user', locals: { user: @user } %>
</div>
<p>Some Stats:
<ul>
<li>Druckaufträge insgesammt: <%= @user.jobs_as_costumer.count %></li>
<li>davon abgebrochen: <%= @user.jobs_as_costumer.canceled.count %></li>
<li>letzten 5 Druckaufträge</li>
</ul>
</p>
<div class="min-w-full overflow-auto shadow-lg">
<table class="w-full py-8 table-auto">
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
<tr>
<th class="w-1 p-2 py-3 text-center"> ID </th>
<th class="w-1 p-2 py-3 text-center"> Vorschau </th>
<th class="w-1 p-2 py-3 text-left"> Auftraggeber </th>
<th class="p-2 py-3 text-left"> PDF </th>
<th class="w-1 p-1 py-3 text-left"> A0 </th>
<th class="w-1 p-1 py-3 text-left"> A1 </th>
<th class="w-1 p-1 py-3 text-left"> A2 </th>
<th class="w-1 p-1 py-3 text-left"> A3 </th>
<th class="w-1 p-2 py-3 text-center text-nowrap"> no DIN </th>
<th class="w-1 p-2 py-3 text-center"> Kosten </th>
<th class="w-1 p-2 py-3 text-center"> Status </th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "jobs/job_tr", collection: @user.jobs_as_costumer.limit(5), as: :job, locals: { no_actions: true } %>
</tbody>
</table>
</div>

View File

@@ -0,0 +1,4 @@
<div>
<h1 class="font-bold text-4xl">Admin::Users#update</h1>
<p>Find me in app/views/admin/users/update.html.erb</p>
</div>

View File

@@ -53,15 +53,17 @@
<%= job.status %>
</span>
</td>
<td class="p-2 py-3 text-right">
<% # TODO: Refactor to helper function %>
<% if defined?(no_turbo_stream) && no_turbo_stream %>
<%= turbo_frame_tag dom_id(job, :cancel_button) do %>
<%= render partial: "jobs/cancel_button", locals: { job: job } %>
<% end %>
<% else %>
<%= turbo_frame_tag dom_id(job, :cancel_button), src: cancel_button_job_path(job), loading: 'lazy' do %>
<%= icon("ellipsis-horizontal-circle", class: "icon icon-disabled size-10", title: "Loading...") %>
<% unless defined?(no_actions) && no_actions %>
<td class="p-2 py-3 text-right">
<% # TODO: Refactor to helper function %>
<% if defined?(no_turbo_stream) && no_turbo_stream %>
<%= turbo_frame_tag dom_id(job, :cancel_button) do %>
<%= render partial: "jobs/cancel_button", locals: { job: job } %>
<% end %>
<% else %>
<%= turbo_frame_tag dom_id(job, :cancel_button), src: cancel_button_job_path(job), loading: 'lazy' do %>
<%= icon("ellipsis-horizontal-circle", class: "icon icon-disabled size-10", title: "Loading...") %>
<% end %>
<% end %>
<% end %>
</td>

View File

@@ -18,7 +18,7 @@ Rails.application.routes.draw do
end
resource :profile, only: [ :show, :edit, :destroy ]
namespace :admin do
resources :users
resources :users, only: [ :index, :show ]
resources :jobs
resource :dashboard, only: [ :show ]
end

View File

@@ -29,6 +29,12 @@ module.exports = {
"status-paid-light": "#86efac", // green-300
"status-canceled": "#7f1d1d", // red-900
"status-canceled-light": "#fca5a5", // red-300
"role-user": "#14532d", // green
"role-user-light": "#86efac",
"role-operator": "#713f12", // yellow
"role-operator-light": "#fde047",
"role-admin": "#7f1d1d", // red
"role-admin-light": "#fca5a5",
},
},
},
@@ -48,6 +54,12 @@ module.exports = {
"text-status-canceled",
"bg-status-canceled-light",
"border-status-canceled-light",
"text-role-user",
"bg-role-user-light",
"text-role-operator",
"bg-role-operator-light",
"text-role-admin",
"bg-role-admin-light",
],
plugins: [
require("@tailwindcss/forms"),

View File

@@ -0,0 +1,33 @@
require "test_helper"
class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get admin_users_index_url
assert_response :success
end
test "should get edit" do
get admin_users_edit_url
assert_response :success
end
test "should get show" do
get admin_users_show_url
assert_response :success
end
test "should get new" do
get admin_users_new_url
assert_response :success
end
test "should get create" do
get admin_users_create_url
assert_response :success
end
test "should get update" do
get admin_users_update_url
assert_response :success
end
end

View File

@@ -0,0 +1,13 @@
require "test_helper"
# See https://actionpolicy.evilmartians.io/#/testing?id=testing-policies
class Admin::UserPolicyTest < ActiveSupport::TestCase
def test_index
end
def test_create
end
def test_manage
end
end