-
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.
Merge branch 'feature/device-cp-improving' into develop
- Loading branch information
Showing
67 changed files
with
1,382 additions
and
688 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Admin::ChannelController < ApplicationController | ||
include ChannelConcern | ||
load_and_authorize_resource | ||
before_action :set_channel, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
channel_index | ||
end | ||
|
||
def new | ||
@channel = Channel.new | ||
end | ||
|
||
def create | ||
channel_create | ||
end | ||
|
||
def update | ||
channel_update | ||
end | ||
|
||
def destroy | ||
authorize!(:destroy, :channel_admin) | ||
channel_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
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,26 @@ | ||
class Admin::ServerController < ApplicationController | ||
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,64 @@ | ||
module ChannelConcern | ||
extend ActiveSupport::Concern | ||
|
||
included do # rubocop:disable Metrics/BlockLength | ||
def channel_index | ||
@query = Channel.ransack(params[:q]) | ||
@pagy, @channels = pagy(@query.result.order(:id)) | ||
end | ||
|
||
def channel_create | ||
@channel = Channel.new(channel_params) | ||
|
||
if @channel.save | ||
redirect_back(fallback_location: root_path) | ||
else | ||
render(:new, status: :unprocessable_entity) | ||
end | ||
end | ||
|
||
def channel_update | ||
if @channel.update(channel_params) | ||
redirect_back(fallback_location: root_path) | ||
else | ||
render(:new, status: :unprocessable_entity) | ||
end | ||
end | ||
|
||
def channel_destroy | ||
assigned_histories = History.where(channel_id: @channel.id).count | ||
|
||
if assigned_histories.zero? | ||
if @channel.destroy | ||
flash[:success] = t('message.admin.channel.delete.success') | ||
else | ||
flash[:error] = t('message.admin.channel.delete.error') | ||
end | ||
else | ||
flash[:error] = t('message.admin.channel.delete.error') | ||
end | ||
redirect_to(admin_channel_index_path) | ||
end | ||
|
||
private | ||
|
||
def set_channel | ||
@channel = Channel.find(params[:id]) | ||
end | ||
|
||
def channel_params | ||
params.require(:channel).permit( | ||
:channel_id, | ||
:server_id, | ||
:control_point_id, | ||
:location_description, | ||
:self_background, | ||
:pre_emergency_limit, | ||
:emergency_limit, | ||
:consumption, | ||
:conversion_coefficient, | ||
:service_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 |
---|---|---|
|
@@ -53,7 +53,7 @@ def organization_params | |
:zip_code, | ||
:phone, | ||
:fax, | ||
:email, | ||
) | ||
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
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
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
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
Oops, something went wrong.