-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: добавляет вьюшки и контроллеры для Server
- Loading branch information
1 parent
ac9785b
commit 0daa10b
Showing
12 changed files
with
246 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
class Admin::ServerController < ApplicationController | ||
def index; end | ||
include ServerConcern | ||
|
||
load_and_authorize_resource | ||
# before_action :set_server, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
server_index | ||
end | ||
|
||
def new | ||
@server = Server.new | ||
end | ||
|
||
def create | ||
server_create | ||
end | ||
|
||
def update | ||
server_update | ||
end | ||
|
||
def destroy | ||
server_destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module ServerConcern | ||
extend ActiveSupport::Concern | ||
|
||
included do # rubocop:disable Metrics/BlockLength | ||
def server_index | ||
@query = Server.ransack(params[:q]) | ||
@pagy, @servers = pagy(@query.result.order(:name)) | ||
end | ||
|
||
def server_create | ||
@server = Server.new(server_params) | ||
|
||
if @server.save | ||
redirect_back(fallback_location: root_path) | ||
else | ||
render(:new, status: :unprocessable_entity) | ||
end | ||
end | ||
|
||
def server_update | ||
if @server.update(server_params) | ||
redirect_back(fallback_location: root_path) | ||
else | ||
render(:edit, status: :unprocessable_entity) | ||
end | ||
end | ||
|
||
def server_destroy | ||
assigned_models_count = Channel.where(server_id: params[:id]).count | ||
|
||
if assigned_models_count.zero? | ||
@server.destroy | ||
else | ||
flash[:error] = t('message.admin.server.delete.error') | ||
end | ||
redirect_to(admin_server_index_path) | ||
end | ||
|
||
private | ||
|
||
def set_server | ||
@server = Server.find(params[:id]) | ||
end | ||
|
||
def server_params | ||
params.require(:server).permit( | ||
:name, | ||
:ip_address, | ||
:inventory_id, | ||
:service_id, | ||
:room_id, | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= turbo_stream.dispatch_event "modalClose" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_stream.update "modal-title", t('admin.server.edit') %> | ||
<%= turbo_stream.update "modal-body", partial: "shared/admin/form/server", | ||
locals: { path: admin_server_path(@server), server: @server } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<% provide :page_title, "Службы" %> | ||
<%= render 'shared/admin/navbar/admin', selected: "asrc" %> | ||
<%= render 'shared/flash_alert' %> | ||
<div class="row mx-0"> | ||
<div class="col-2 ps-0 my-4"> | ||
<%= render 'shared/admin/navbar/asrc_navbar', selected: "server" %> | ||
<div class="accordion mb-3" id="accordionFilter"> | ||
<div class="accordion-item"> | ||
<h2 class="accordion-header" id="headingFilter"> | ||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseFilter" aria-expanded="true" aria-controls="collapseFilter"> | ||
<%= t('filtration')%> | ||
</button> | ||
</h2> | ||
<div id="collapseFilter" class="accordion-collapse collapse shadow" aria-labelledby="headingFilter" data-bs-parent="#accordionFilter"> | ||
<%= search_form_for(@query, url: admin_server_index_path, method: :get, class: "rounded accordion-body") do |f| %> | ||
<div id="for-clear"> | ||
<%= f.label :name, class: "mb-1" %> | ||
<%= f.search_field :name_cont, class:"form-control mb-2", placeholder:"Название" %> | ||
<%= f.label :ip_address, class: "mb-1" %> | ||
<%= f.search_field :ip_address_cont, class:"form-control mb-2", placeholder:"192.168.1.101" %> | ||
<%= f.label :inventory_id, class: "mb-1"%> | ||
<%= f.search_field :inventory_id_cont, class:"form-control mb-2", placeholder:"4321" %> | ||
|
||
<%= f.label :service_id, class: "mb-1" %> | ||
<%= f.collection_select(:service_id_eq, Service.all, | ||
:id, :name, {:include_blank => t('combobox_blank')}, {:class =>'form-select mb-2'}) %> | ||
<%= f.label :room_id, class: "mb-1" %> | ||
<%= f.collection_select(:room_id_eq, Service.all, | ||
:id, :name, {:include_blank => t('combobox_blank')}, {:class =>'form-select mb-2'}) %> | ||
</div> | ||
<%= f.submit t('b_accept'), class: 'btn btn-primary w-100 my-2'%> | ||
<div id="b_clear" onclick="formClear()" class="btn btn-secondary w-100"> | ||
<%= t("b_clear")%> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
<%= render 'shared/modal_button_add', path: new_admin_server_path, classes: "btn btn-primary w-100", text: t("b_add") %> | ||
</div> | ||
<div class="col-10 my-4 p-0"> | ||
<div class="shadow rounded px-2"> | ||
<div class="table-responsive"> | ||
<table class="table table-hover"> | ||
<%= render 'shared/ui/table/caption/all_items', | ||
count: Server.count %> | ||
<thead> | ||
<tr> | ||
<th scope="col"><%= t('activerecord.attributes.server.id') %></th> | ||
<th scope="col"><%= t('activerecord.attributes.server.name') %></th> | ||
<th scope="col"><%= t('activerecord.attributes.server.ip_address') %></th> | ||
<th scope="col"><%= t('activerecord.attributes.server.inventory_id') %></th> | ||
<th scope="col"><%= t('activerecord.attributes.server.service') %></th> | ||
<th scope="col"><%= t('activerecord.attributes.server.room') %></th> | ||
<%= render 'shared/ui/table/header/action' %> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @servers.each do |server| %> | ||
<tr class="align-middle"> | ||
<td><%= server.id %></td> | ||
<td><%= server.name %></td> | ||
|
||
<% if server.ip_address.nil? %> | ||
<td><%= "——" %></td> | ||
<% else %> | ||
<td><%= server.ip_address %></td> | ||
<% end %> | ||
|
||
<% if server.inventory_id.nil? %> | ||
<td><%= "——" %></td> | ||
<% else %> | ||
<td><%= server.inventory_id %></td> | ||
<% end %> | ||
|
||
<% if server.service.nil? %> | ||
<td><%= "——" %></td> | ||
<% else %> | ||
<td><%= server.service.name %></td> | ||
<% end %> | ||
|
||
<% if server.room.nil? %> | ||
<td><%= "——" %></td> | ||
<% else %> | ||
<td><%= server.room.name %></td> | ||
<% end %> | ||
|
||
<%= render 'shared/ui/table/cell/action', | ||
edit_path: edit_admin_server_path(server.id), | ||
destroy_path: admin_server_path(server.id) %> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row my-5"> | ||
<div class="col-2"> | ||
</div> | ||
<div class="col-10"> | ||
<div class="row"> | ||
<div class="col"></div> | ||
<div class="col"> | ||
<%= pagination @pagy %> | ||
</div> | ||
<div class="col"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
function formClear(){ | ||
let form = document.getElementById('for-clear') | ||
let inputs = Array.from(form.getElementsByTagName("input")) | ||
let selects = Array.from(form.getElementsByTagName("select")) | ||
inputs.forEach((input) =>{ | ||
input.value = null | ||
}) | ||
selects.forEach((select) =>{ | ||
select.value = "" | ||
}) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= turbo_stream.update "modal-title", t('admin.server.new') %> | ||
<%= turbo_stream.update "modal-body", partial: "shared/admin/form/server", | ||
locals: { path: admin_server_index_path, server: @server } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= turbo_stream.dispatch_event "modalClose" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= simple_form_for server, as: :server, url: path, | ||
class: "form-group row" do |f| %> | ||
<div class="row"> | ||
<%= f.input :name, placeholder: 'Название службы', input_html: {:tabindex => 1}%> | ||
<%= f.input :ip_address, input_html: { :tabindex => 2}, include_blank: false %> | ||
<%= f.input :inventory_id, input_html: { :tabindex => 3 }, include_blank: false %> | ||
<%= f.association :service, input_html: { :tabindex => 4}, include_blank: false %> | ||
<%= f.association :room, input_html: { :tabindex => 5}, include_blank: false %> | ||
</div> | ||
|
||
<%= render 'shared/form/actions', f:f %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.