Skip to content

Commit

Permalink
Merge branch 'feature/room-expand' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
owlscatcher committed Feb 12, 2024
2 parents be671c8 + 89172a2 commit 39ab72e
Show file tree
Hide file tree
Showing 108 changed files with 2,094 additions and 401 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ GEM
zeitwerk (2.6.7)

PLATFORMS
x86_64-linux
x86_64-linux-musl

DEPENDENCIES
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/admin/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admin::AdminController < ApplicationController
load_and_authorize_resource
def index; end
def index
redirect_to(admin_users_path)
end
end
30 changes: 30 additions & 0 deletions app/controllers/admin/building_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Admin::BuildingController < ApplicationController
include BuildingConcern

load_and_authorize_resource
before_action :set_building, only: [:show, :edit, :update, :destroy]

def index
building_index
end

def new
authorize!(:new, :building_admin)
@building = Building.new
end

def create
authorize!(:create, :building_admin)
building_create
end

def update
authorize!(:update, :building_admin)
building_update
end

def destroy
authorize!(:destroy, :building_admin)
building_destroy
end
end
60 changes: 60 additions & 0 deletions app/controllers/admin/control_point_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class Admin::ControlPointController < ApplicationController
include ControlPointConcern
load_and_authorize_resource
before_action :set_control_point, only: [:show, :edit, :update, :destroy]

def index
@query = ControlPoint.ransack(params[:q])
@pagy, @control_points = pagy(@query.result.
order(:name))
end

def new
authorize!(:new, :control_point_admin)
@control_point = ControlPoint.new
end

def create
authorize!(:create, :control_point_admin)
control_point_create
end

def update
if @control_point.update(control_point_params)
redirect_back(fallback_location: root_path)
else
render(:edit, status: :unprocessable_entity)
end
end

def destroy
assigned_models_count =
Room.where(control_point_id: params[:id]).count +
Device.where(control_point_id: params[:id]).count +
Channel.where(control_point_id: params[:id]).count

if assigned_models_count.zero?
@control_point.destroy
else
flash[:error] = t('message.control_point.delete.error')
end
redirect_to(admin_control_point_index_path)
end

private

def set_control_point
@control_point = ControlPoint.find(params[:id])
end

def control_point_params
params.require(:control_point).permit(
:name,
:room_id,
:device_id,
:channel_id,
:description,
:service_id,
)
end
end
29 changes: 29 additions & 0 deletions app/controllers/admin/division_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Admin::DivisionController < ApplicationController
include DivisionConcern
load_and_authorize_resource
before_action :set_division, only: [:show, :edit, :update, :destroy]

def index
division_index
end

def new
authorize!(:new, :division_admin)
@division = Division.new
end

def create
authorize!(:create, :division_admin)
division_create
end

def update
authorize!(:update, :division_admin)
division_update
end

def destroy
authorize!(:destroy, :division_admin)
division_destroy
end
end
30 changes: 30 additions & 0 deletions app/controllers/admin/organization_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Admin::OrganizationController < ApplicationController
include OrganizationConcern

load_and_authorize_resource
before_action :set_organization, only: [:show, :edit, :update, :destroy]

def index
organization_index
end

def new
authorize!(:new, :organization_admin)
@organization = Organization.new
end

def create
authorize!(:create, :organization_admin)
organization_create
end

def update
authorize!(:update, :organization_admin)
organization_update
end

def destroy
authorize!(:destroy, :organization_admin)
organization_destroy
end
end
30 changes: 30 additions & 0 deletions app/controllers/admin/room_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Admin::RoomController < ApplicationController
include RoomConsern

load_and_authorize_resource
before_action :set_room, only: [:show, :edit, :update, :destroy]

def index
room_index
end

def new
authorize!(:new, :room_admin)
@room = Room.new
end

def create
authorize!(:create, :room_admin)
room_create
end

def update
authorize!(:update, :room_admin)
room_update
end

def destroy
authorize!(:destroy, :room_admin)
room_destroy
end
end
63 changes: 63 additions & 0 deletions app/controllers/admin/service_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Admin::ServiceController < ApplicationController
include ServiceConcern

load_and_authorize_resource
before_action :set_service, only: [:show, :edit, :update, :destroy]

def index
@query = Service.ransack(params[:q])
@pagy, @services = pagy(@query.result.order(:name))
end

def new
authorize!(:new, :service_admin)
@service = Service.new
end

def create
authorize!(:create, :service_admin)
service_create
end

def update
authorize!(:update, :service_admin)

if @service.update(service_params)
redirect_back(fallback_location: root_path)
else
render(:edit, status: :unprocessable_entity)
end
end

def destroy
authorize!(:destroy, :service_admin)

assigned_models_count =
Device.where(service_id: params[:id]).count +
User.where(service_id: params[:id]).count +
Server.where(service_id: params[:id]).count +
ControlPoint.where(service_id: params[:id]).count

if assigned_models_count.zero?
@service.destroy
else
flash[:error] = t('message.service.delete.error')
end
redirect_to(admin_service_index_path)
end

private

def set_service
@service = Service.find(params[:id])
end

def service_params
params.require(:service).permit(
:name,
:division_id,
:organization_id,
:building_id,
)
end
end
12 changes: 9 additions & 3 deletions app/controllers/api/v1/armstrong_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ class V1::ArmstrongController < ApplicationController
after_action :set_csp_header

def index
channels = Channel.all
channels = Channel.joins(:control_point, :server, :service)
result = channels.sort { |a, b| a[:server_id] <=> b[:server_id] }

render(json: result,
include: [
device: { include: [device_model: { only: [:name] }] },
room: { only: [:name] },
:server,
:service,
{ control_point: {
include: [
:room,
{ device: { include: :device_model } },
],
} },
])
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def set_time_zone(&block)
protected

def configure_permitted_parameters
attributes_sign_up = [:first_name, :last_name, :tabel_id, :role, :email,:service_id, :timezone]
attributes_sign_up = [:first_name, :last_name, :tabel_id, :role, :email, :service_id, :timezone]
attributes_update = [*attributes_sign_up.excluding(:service_id), :second_name, :email, :phone]
devise_parameter_sanitizer.permit(:sign_up, keys: attributes_sign_up)
devise_parameter_sanitizer.permit(:account_update, keys: attributes_update)
Expand Down
55 changes: 55 additions & 0 deletions app/controllers/concerns/building_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module BuildingConcern
extend ActiveSupport::Concern

included do # rubocop:disable Metrics/BlockLength
def building_index
@query = Building.ransack(params[:q])
@pagy, @buildings = pagy(@query.result.order(:name))
end

def building_create
@building = Building.new(building_params)

if @building.save
redirect_back(fallback_location: root_path)
else
render(:new, status: :unprocessable_entity)
end
end

def building_update
if @building.update(building_params)
redirect_back(fallback_location: root_path)
else
render(:edit, status: :unprocessable_entity)
end
end

def building_destroy
assigned_models_count =
Room.where(building_id: params[:id]).count +
Service.where(building_id: params[:id]).count

if assigned_models_count.zero?
@building.destroy
else
flash[:error] = t('message.admin.building.delete.error')
end
redirect_to(admin_building_index_path)
end

private

def set_building
@building = Building.find(params[:id])
end

def building_params
params.require(:building).permit(
:name,
:organization_id,
:description,
)
end
end
end
26 changes: 26 additions & 0 deletions app/controllers/concerns/control_point_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module ControlPointConcern
extend ActiveSupport::Concern

included do
def control_point_create
@control_point = ControlPoint.new(control_point_params)

if @control_point.save
redirect_back(fallback_location: root_path)
else
render(:new, status: :unprocessable_entity)
end
end

def control_point_params
params.require(:control_point).permit(
:name,
:device_id,
:room_id,
:channel_id,
:description,
:service_id,
)
end
end
end
Loading

0 comments on commit 39ab72e

Please sign in to comment.