Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User edit improvement (WIP) #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Admin::UsersController < Admin::ApplicationController
before_action :set_user, only: %i[show edit update lock unlock resend_confirmation_mail resend_invitation_mail]
before_action :set_user, only: %i[show edit update lock unlock resend_confirmation_mail resend_invitation_mail direct_confirm]
# before_action :set_breadcrumbs, only: %i[new edit create update], if: -> { request.format.html? }

def index
Expand Down Expand Up @@ -38,7 +38,10 @@ def create

def update
if @user.update_without_password(user_params)
redirect_to admin_user_url(@user), notice: t(".shared.notice.updated")
respond_to do |format|
format.html { redirect_to admin_user_path(@user), notice: t(".shared.notice.updated") }
format.js { render }
end
else
prepare_meta_tags title: t("admin.users.edit.title")
render :edit
Expand Down Expand Up @@ -77,6 +80,11 @@ def resend_invitation_mail
redirect_to admin_user_url(@user), notice: t(".shared.notice.sent_confirmation_mail")
end

def direct_confirm
@user.confirm
redirect_to admin_user_url(@user), notice: t(".shared.notice.user_direct_confirmed")
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
37 changes: 37 additions & 0 deletions app/views/admin/users/_tr_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%= form_with model: user, url: admin_user_path(user) do |f| %>
<td><%= user.id %></td>
<td class="py-1"><%= f.text_field :email, class: 'form-control' -%></td>
<td><%= time_tag user.created_at %></td>
<td><%= time_tag user.current_sign_in_at if user.current_sign_in_at %></td>
<td>
<% if user.admin? %>
<span class="badge badge-success">
<%= t("admin.users.shared.status.admin") %>
</span>
<% end %>
<% unless user.confirmed? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.pending_confirmation") %>
</span>
<% end %>
<% if user.pending_reconfirmation? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.pending_reconfirmation") %>
</span>
<% end %>
<% if user.created_by_invite? && !user.invited_to_sign_up? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.inviting") %>
</span>
<% end %>
<% if user.access_locked? %>
<span class="badge badge-danger">
<%= t("admin.users.shared.status.locked") %>
</span>
<% end %>
</td>
<td>
<%= link_to t(".table.actions.show"), admin_user_path(user) %>
<%= f.submit t(".actions.save"), class: "btn btn-sm btn-outline-primary" -%>
</td>
<% end %>
37 changes: 2 additions & 35 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,8 @@
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.id %></td>
<td><%= user.email %></td>
<td><%= time_tag user.created_at %></td>
<td><%= time_tag user.current_sign_in_at if user.current_sign_in_at %></td>
<td>
<% if user.admin? %>
<span class="badge badge-success">
<%= t("admin.users.shared.status.admin") %>
</span>
<% end %>
<% unless user.confirmed? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.pending_confirmation") %>
</span>
<% end %>
<% if user.pending_reconfirmation? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.pending_reconfirmation") %>
</span>
<% end %>
<% if user.created_by_invite? && !user.invited_to_sign_up? %>
<span class="badge badge-warning">
<%= t("admin.users.shared.status.inviting") %>
</span>
<% end %>
<% if user.access_locked? %>
<span class="badge badge-danger">
<%= t("admin.users.shared.status.locked") %>
</span>
<% end %>
</td>
<td>
<%= link_to t(".table.actions.show"), admin_user_path(user) %>
</td>
<tr id="admin-user-<%= user.id -%>">
<%= render partial: 'tr_form', locals: { user: user } -%>
</tr>
<% end %>
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<li class="action_bar-item">
<%= link_to t(".actions.resend_confirmation_mail"), resend_confirmation_mail_admin_user_path(@user), method: :patch, class: "btn text-primary" %>
</li>
<li class="action_bar-item">
<%= link_to t(".actions.direct_confirm"), direct_confirm_admin_user_path(@user), method: :patch, class: "btn text-primary" %>
</li>
<% end %>
<% if @user.created_by_invite? && [email protected]_to_sign_up? %>
<li class="action_bar-item">
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/users/update.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$("#admin-user-<%= @user.id -%>").html('<%= j render(partial: "tr_form", locals: { user: @user }) -%>');
6 changes: 6 additions & 0 deletions config/locales/views/admin/users/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ en:
created: "User created"
sent_confirmation_mail: "Confirmation mail sent"
sent_invitation_mail: "Invitation mail sent"
user_direct_confirmed: "User confirmed"
confirmation:
lock: "Are you sure lock the user?"
unlock: "Are you sure unlock the user?"
Expand All @@ -31,12 +32,17 @@ en:
status: "Status"
actions:
show: "Show"
tr_form:
actions:
show: "Show"
save: "Save"
show:
actions:
lock: "Lock"
unlock: "Unlock"
resend_confirmation_mail: "Resend confirmation mail"
resend_invitation_mail: "Resend invitation mail"
direct_confirm: "Direct confirm"
email: "Email"
created_at: "Created at"
current_sign_in_at: "Current sign in at"
Expand Down
6 changes: 6 additions & 0 deletions config/locales/views/admin/users/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ zh-CN:
created: "用户创建成功"
sent_confirmation_mail: "激活邮件已发送"
sent_invitation_mail: "邀请邮件已发送"
user_direct_confirmed: "用户已激活"
confirmation:
lock: "确定要禁用该用户吗?"
unlock: "确定要恢复该用户吗?"
Expand All @@ -31,12 +32,17 @@ zh-CN:
status: "状态"
actions:
show: "查看"
tr_form:
actions:
show: "查看"
save: "保存"
show:
actions:
lock: "禁用"
unlock: "启用"
resend_confirmation_mail: "重发激活邮件"
resend_invitation_mail: "重发邀请邮件"
direct_confirm: "直接激活"
email: "邮箱"
created_at: "创建于"
current_sign_in_at: "最后登录"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
patch :unlock
patch :resend_confirmation_mail
patch :resend_invitation_mail
patch :direct_confirm
end
end
end
Expand Down