Commit fbbd4e95 authored by o's avatar o

beautify resource editor

parent e6ea2336
Pipeline #4236 passed with stages
in 18 minutes and 3 seconds
......@@ -8,13 +8,17 @@ class ResourcesAdminController < ApplicationController
def show
@resource_name = params['resource_name']
@resource_action =
if ['create','list','deleted'].include? params['resource_action']
then params['resource_action']
else 'create' end
if resource_list.include? @resource_name
begin
@resource_schema = api.resource_schema(@resource_name)['schema']
resources = api.resource_list(@resource_name, 'both')
@resources = resources['data']
resources = api.resource_list(@resource_name, @resource_action == 'deleted')
@resources = resources['data'] || []
@resources.sort! {|a,b| a['uid'] <=> b['uid']}
@deleted_resources = resources['deleted']
@deleted_resources = resources['deleted'] || []
@deleted_resources.sort! {|a,b| a['uid'] <=> b['uid']}
rescue ApiBackend::ApiError
flash[:danger] = :failed
......@@ -29,12 +33,13 @@ class ResourcesAdminController < ApplicationController
@resource_name = (
params[:resource_name] if resource_list.include? params[:resource_name])
case params[:commit]
when 'delete'
if params[:delete].present?
@res = api.resource_delete(uid)
when 'purge'
@resource_action='list'
elsif params[:purge].present?
@res = api.resource_purge(uid)
when 'create'
@resource_action='deleted'
elsif params[:create].present?
if resource_list.include? @resource_name
data = {}
params.each do |name, v|
......@@ -46,22 +51,25 @@ class ResourcesAdminController < ApplicationController
@resource_name,
params[:owner],
data)
@resource_action='list'
end
when 'save'
elsif params[:save].present?
if params['add_owner'].present?
api.resource_add_owner(uid, params['add_owner'])
end
params.each do |name, v|
if v == "1" && name =~ /remove_(.*)/
if v == "on" && name =~ /remove_(.*)/
api.resource_remove_owner(uid, $1)
end
end
@resource_action='list'
else
flash[:danger] = :failed
return
end
flash[:success] = :success
redirect_to resources_admin_path(resource_name: @resource_name)
redirect_to resources_admin_path(
resource_name: @resource_name, resource_action: @resource_action)
rescue ApiError => e
flash[:danger] = e.api_msg
end
......
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<% @resource_schema.each do |n,v| %>
<div class="form-group">
<%= label_tag n %>
<%= case v
when 'text'
text_field_tag('data_'+n, "", class: 'form-control')
when Array
select_tag('data_'+n, options_for_select(v), class: 'form-control')
end %>
</div>
<% end %>
<div class="form-group">
<%=label_tag 'owner' %>
<%=text_field_tag 'owner', "", class: 'form-control' %>
</div>
<%= submit_tag t(:create), name: 'create', class: "btn btn-primary" %>
<% end %>
<% @resources.each do |res| %>
<% resource_ui_id = SecureRandom.hex(32) %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<%= hidden_field_tag 'resource_action', 'list' %>
<%= hidden_field_tag 'uid', res['uid'] %>
<div class="tooltipsummary">
<b><%= res['resource']['email'] %></b>
<span class="tooltiptext"><%= res['resource'].to_json %></span>
</div>
<br />
<br />
<div class="form-group">
<%=label_tag 'remove_owner' %>
<% res['owners'].each do |o| %>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input class="custom-control-input"
type="checkbox"
id="remove_<%= o.gsub("@","_") %>_<%= resource_ui_id %>"
name="remove_<%= o %>" />
<%= label_tag("remove_#{o}_#{resource_ui_id}", o, class: "custom-control-label") %>
</div>
</div>
<% end %>
</div>
<div class="form-group">
<%=label_tag 'add_owner' %>
<%=text_field_tag('add_owner', '', class: "form-control") %>
</div>
<%= submit_tag(t(:submit), name: 'save', class: "btn btn-primary") %>
<button type="button" class="btn btn-warning" onclick="
style.display='none';
document.getElementById('delete_<%= resource_ui_id %>').style.display='inline';
"><%= t :delete %></button>
<%= submit_tag(t(:delete),
name: "delete",
id: "delete_#{resource_ui_id}",
class: "btn btn-danger", style: "display:none") %>
<% end %>
<hr />
<% end %>
<% @deleted_resources.each do |res| %>
<% resource_ui_id = SecureRandom.hex(32) %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<%= hidden_field_tag 'uid', res['uid'] %>
<div class="tooltipsummary">
<b><%= res['resource']['email'] %></b>
<span class="tooltiptext"><%= res['resource'].to_json %></span>
</div>,
<%= res['deleted_at'] %>
<br />
<button type="button" class="btn btn-warning" onclick="
style.display='none';
document.getElementById('purge_<%= resource_ui_id %>').style.display='inline';
"><%= t :purge %></button>
<%= submit_tag(t(:purge),
name: "purge",
id: "purge_#{resource_ui_id}",
class: "btn btn-danger", style: "display:none") %>
<% end %>
<% end %>
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<% ['create','list','deleted'].each do |pane| %>
<a class="nav-item nav-link <%= if pane == @resource_action then "active" else "" end %>"
href="?resource_name=<%= @resource_name %>&resource_action=<%= pane %>"
role="tab">
<%= pane %>
</a>
<% end %>
&nbsp;&nbsp;&nbsp;
<%= form_tag "", method: :get do %>
<div class="form-group">
<%= select_tag(:resource_name,
options_for_select([['----',nil]]+resource_list,
@resource_name || '----'),
onchange: 'submit()') %>
</div>
<% end %>
</div>
</nav>
<%= form_tag "", method: :get do %>
<%= select_tag(:resource_name, options_for_select(resource_list, @resource_name)) %>
<%= submit_tag 'select' %>
<% end %>
<hr />
<%= render 'resource_menu' %>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane show active" role="tabpanel">
<p>
<% if @resource_name.present? %>
<%=
case @resource_action
when 'create'
render 'resource_create'
when 'list'
render 'resource_list'
when 'deleted'
render 'resource_list_deleted'
end
%>
<% if @resource_name %>
<h4>New:</h4>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<% @resource_schema.each do |n,v| %>
<%= label_tag n %>
<%= case v
when 'text'
text_field_tag 'data_'+n
when Array
select_tag 'data_'+n, options_for_select(v)
end %>
<br />
<% end %>
<%=label_tag 'owner' %>
<%=text_field_tag 'owner'%>
<%= submit_tag 'create' %>
<% end %>
<hr />
<h4>Existing:</h4>
<% @resources.each do |res| %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<%= hidden_field_tag 'uid', res['uid'] %>
<div class="tooltipsummary"><%= res['resource']['email'] %>
<span class="tooltiptext"><%= res['resource'].to_json %></span>
</div>
<%= submit_tag 'delete' %>
</br />
Remove <br />
<% res['owners'].each do |o| %>
<%= check_box_tag "remove_#{o}" %> &nbsp; <%= o %> <br />
<% end %>
<%=label_tag 'add_owner' %>
<%=text_field_tag 'add_owner'%>
<br />
<%= submit_tag 'save' %>
<% end %>
<hr />
<% end %>
<h4>Deleted:</h4>
<% @deleted_resources.each do |res| %>
<%= form_tag do %>
<%= hidden_field_tag 'resource_name', @resource_name %>
<%= hidden_field_tag 'uid', res['uid'] %>
<div class="tooltipsummary"><%= res['resource']['email'] %>
<span class="tooltiptext"><%= res['resource'].to_json %></span>
</div>,
<%= res['deleted_at'] %> <br />
<%= submit_tag 'purge' %>
<% end %>
<hr />
<% end %>
<% end %>
</p>
</div>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment