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

Inicia implementação do breadcrumb. #57

Merged
merged 10 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ruby '3.2.2'
gem 'rails', '~> 7.1.3.1'

gem 'bootsnap', require: false
gem 'breadcrumbs_on_rails'
gem 'cpf_cnpj'
gem 'cssbundling-rails'
gem 'devise'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ GEM
bigdecimal (3.1.8)
bootsnap (1.18.3)
msgpack (~> 1.2)
breadcrumbs_on_rails (4.1.0)
railties (>= 5.0)
builder (3.3.0)
capybara (3.40.0)
addressable
Expand Down Expand Up @@ -317,6 +319,7 @@ PLATFORMS

DEPENDENCIES
bootsnap
breadcrumbs_on_rails
capybara (>= 2.15)
cpf_cnpj
cssbundling-rails
Expand Down
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
//= link_tree ../images
//= link_tree ../builds
//= link breadcrumb_style.css
14 changes: 14 additions & 0 deletions app/assets/stylesheets/breadcrumb_style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ol.breadcrumb li {
margin: 0 0.5rem;

a {
text-decoration: none;
color: #ffc107;
font-weight: 700;
}

a:hover {
color: #f5b905;
transition: all 0.5s;
}
}
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
before_action :warn_tower_registration_incomplete
add_breadcrumb 'Home', :root_path

private

Expand Down
32 changes: 26 additions & 6 deletions app/controllers/common_areas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,57 @@ class CommonAreasController < ApplicationController
before_action :set_condo, only: %i[new create]
before_action :set_common_area, only: %i[show edit update]

add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path, only: %i[show new create edit update]
before_action :set_breadcrumbs_for_register, only: %i[new create]
before_action :set_breadcrumbs_for_details, only: %i[show edit update]

def index; end

def show
redirect_to(root_path, notice: t('alerts.common_area.not_allowed')) unless manager_signed_in?
redirect_to(root_path, notice: I18n.t('alerts.common_area.not_allowed')) unless manager_signed_in?
end

def new
@common_area = CommonArea.new
end

def edit; end
def edit
add_breadcrumb I18n.t('breadcrumb.edit')
end

def create
@common_area = @condo.common_areas.create(common_area_params)
if @common_area.save
redirect_to @common_area, notice: t('notices.common_area.created')
redirect_to @common_area, notice: I18n.t('notices.common_area.created')
else
flash[:alert] = t('alerts.common_area.not_created')
flash[:alert] = I18n.t('alerts.common_area.not_created')
render :new, status: :unprocessable_entity
end
end

def update
add_breadcrumb I18n.t('breadcrumb.edit')
if @common_area.update(common_area_params)
redirect_to @common_area, notice: t('notices.common_area.updated')
redirect_to @common_area, notice: I18n.t('notices.common_area.updated')
else
flash[:alert] = t('alerts.common_area.not_updated')
flash[:alert] = I18n.t('alerts.common_area.not_updated')
render :edit, status: :unprocessable_entity
end
end

private

def set_breadcrumbs_for_register
add_breadcrumb @condo.name.to_s, condo_path(@condo)
add_breadcrumb I18n.t('breadcrumb.common_area.new')
end

def set_breadcrumbs_for_details
add_breadcrumb @common_area.condo.name.to_s, condo_path(@common_area.condo)
add_breadcrumb I18n.t('breadcrumb.common_area.index'), condo_common_areas_path(@common_area.condo)
add_breadcrumb @common_area.name.to_s, common_area_path(@common_area)
end

def set_condo
@condo = Condo.find(params[:condo_id])
end
Expand Down
18 changes: 17 additions & 1 deletion app/controllers/condos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ class CondosController < ApplicationController
before_action :authenticate_manager!, only: %i[new create edit update]
before_action :set_condo, only: %i[show edit update]

add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path, only: %i[new create show edit update]
before_action :set_breadcrumbs_for_details, only: %i[show edit update]

def index
@condos = Condo.all
end

def show; end

def new
add_breadcrumb I18n.t('breadcrumb.condo.new')
@condo = Condo.new
end

def edit; end
def edit
add_breadcrumb I18n.t('breadcrumb.edit')
end

def create
add_breadcrumb I18n.t('breadcrumb.condo.new')
@condo = Condo.new(condo_params)

if @condo.save
Expand All @@ -22,6 +33,7 @@ def create
end

def update
add_breadcrumb I18n.t('breadcrumb.edit')
if @condo.update(condo_params)
redirect_to @condo, notice: t('notices.condo.updated')
else
Expand All @@ -32,6 +44,10 @@ def update

private

def set_breadcrumbs_for_details
add_breadcrumb @condo.name.to_s, condo_path(@condo)
end

def condo_params
params.require(:condo).permit(:name, :registration_number,
address_attributes: %i[public_place number neighborhood city state zip])
Expand Down
19 changes: 16 additions & 3 deletions app/controllers/floors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
class FloorsController < ApplicationController
before_action :assure_floor_type_registration, only: [:show]
before_action :authenticate_manager!, only: [:show]
before_action :assure_floor_type_registration, only: [:show]
before_action :set_tower, only: %i[show]
thalytalima211 marked this conversation as resolved.
Show resolved Hide resolved

add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path, only: %i[show]
before_action :set_breadcrumbs_for_details, only: %i[show]

def show; end

def show
private

def set_tower
@tower = Tower.find params[:tower_id]
end

private
def set_breadcrumbs_for_details
add_breadcrumb @tower.condo.name.to_s, condo_path(@tower.condo)
add_breadcrumb I18n.t('breadcrumb.tower.index'), condo_towers_path(@tower.condo)
add_breadcrumb @tower.name.to_s, @tower
add_breadcrumb @floor.print_identifier
end

def assure_floor_type_registration
@floor = Floor.find params[:id]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/managers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ class ManagersController < ApplicationController
before_action :authenticate_manager!, only: %i[new create]

def new
add_breadcrumb I18n.t('breadcrumb.manager.new')
@manager = Manager.new
end

def create
add_breadcrumb I18n.t('breadcrumb.manager.new')
@manager = Manager.new(manager_params)
if @manager.save
redirect_to root_path, notice: <<~NOTICE
Expand Down
49 changes: 38 additions & 11 deletions app/controllers/towers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
class TowersController < ApplicationController
before_action :set_tower, only: %i[show edit_floor_units update_floor_units]
before_action :authenticate_manager!, only: %i[show new edit_floor_units create update_floor_units]
before_action :set_tower, only: %i[show edit_floor_units update_floor_units]
before_action :set_condo, only: %i[new create]

add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path,
only: %i[show new create edit_floor_units update_floor_units]
before_action :set_breadcrumbs_for_details, only: %i[show edit_floor_units update_floor_units]
before_action :set_breadcrumbs_for_register, only: %i[new create]

def show; end

def new
@tower = Tower.new condo_id: params[:condo_id]
@tower = Tower.new condo: @condo
end

def edit_floor_units
add_breadcrumb I18n.t('breadcrumb.tower.floor_type')
@unit_types = UnitType.order :description
end

def create
@tower = Tower.new tower_params.merge! condo_id: condo_id_param
@tower = Tower.new tower_params.merge! condo: @condo

if @tower.save
@tower.generate_floors
Expand All @@ -26,14 +33,8 @@ def create
end

def update_floor_units
is_all_unit_types_selected = true
unit_types = params.require :unit_types
unit_types.each_value { |value| is_all_unit_types_selected = false if value.blank? }

if is_all_unit_types_selected
update_units(unit_types)
return redirect_to @tower, notice: t('notices.floor.updated')
end
add_breadcrumb I18n.t('breadcrumb.tower.floor_type')
return redirect_to @tower, notice: t('notices.floor.updated') if all_unit_types_selected

@unit_types = UnitType.order :description
flash.now[:alert] = t('alerts.units.not_updated')
Expand All @@ -52,6 +53,21 @@ def update_units(unit_types)
@tower.complete!
end

def all_unit_types_selected
is_all_unit_types_selected = true
unit_types = params.require :unit_types
unit_types.each_value { |value| is_all_unit_types_selected = false if value.blank? }

return unless is_all_unit_types_selected

update_units(unit_types)
true
end

def set_condo
@condo = Condo.find params[:condo_id]
end

def set_tower
@tower = Tower.find params[:id]
end
Expand All @@ -63,4 +79,15 @@ def tower_params
def condo_id_param
params.require :condo_id
end

def set_breadcrumbs_for_details
add_breadcrumb @tower.condo.name.to_s, @tower.condo
add_breadcrumb I18n.t('breadcrumb.tower.index'), condo_towers_path(@tower.condo)
add_breadcrumb @tower.name.to_s, @tower
end

def set_breadcrumbs_for_register
add_breadcrumb @condo.name.to_s, @condo
add_breadcrumb I18n.t('breadcrumb.tower.new')
end
end
22 changes: 21 additions & 1 deletion app/controllers/unit_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ class UnitTypesController < ApplicationController
before_action :set_condo
before_action :authenticate_manager!

add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path, only: %i[new show edit create update]
before_action :set_breadcrumb_for_details, only: %i[show edit update]
before_action :set_breadcrumb_for_register, only: %i[new create]

def index; end

def show; end

def new
@unit_type = UnitType.new
end

def edit; end
def edit
add_breadcrumb I18n.t('breadcrumb.edit')
end

def create
@unit_type = UnitType.new(unit_type_params)
Expand All @@ -24,6 +32,7 @@ def create
end

def update
add_breadcrumb I18n.t('breadcrumb.edit')
if @unit_type.update(unit_type_params)
redirect_to condo_unit_type_path(@condo, @unit_type), notice: t('notices.unit_type.updated')
else
Expand All @@ -45,4 +54,15 @@ def set_condo
def unit_type_params
params.require(:unit_type).permit(:description, :metreage, :fraction)
end

def set_breadcrumb_for_details
add_breadcrumb @condo.name, @condo
add_breadcrumb I18n.t('breadcrumb.unit_type.index'), condo_unit_types_path(@condo)
add_breadcrumb @unit_type.description, condo_unit_type_path(@condo, @unit_type)
end

def set_breadcrumb_for_register
add_breadcrumb @condo.name, @condo
add_breadcrumb I18n.t('breadcrumb.unit_type.new')
end
end
29 changes: 27 additions & 2 deletions app/controllers/units_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
class UnitsController < ApplicationController
before_action :authenticate_manager!, only: [:show]
before_action :set_tower_and_floor, only: [:show]
before_action :set_unit, only: %i[show]

def show
add_breadcrumb I18n.t('breadcrumb.condo.index'), :condos_path, only: %i[show]
before_action :set_breadcrumbs_for_details, only: %i[show]

def show; end

private

def set_breadcrumbs_for_details
add_breadcrumb @tower.condo.name.to_s, condo_path(@tower.condo)
set_breadcrumb_for_tower
add_breadcrumb @floor.print_identifier, tower_floor_path(@tower, @floor)
add_breadcrumb @unit.print_identifier
end

def set_breadcrumb_for_tower
add_breadcrumb I18n.t('breadcrumb.tower.index'), condo_towers_path(@tower.condo)
add_breadcrumb @tower.name.to_s, @tower
end

def set_unit
@unit = Unit.find params[:id]
@tower = @unit.floor.tower
end

def set_tower_and_floor
@tower = Tower.find(params[:tower_id])
thalytalima211 marked this conversation as resolved.
Show resolved Hide resolved
@floor = Floor.find(params[:floor_id])
end
end
1 change: 1 addition & 0 deletions app/views/common_areas/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Áreas Comuns</h1>
1 change: 1 addition & 0 deletions app/views/condos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Condomínios</h1>
3 changes: 1 addition & 2 deletions app/views/condos/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<h1>Cadastre um novo Condomínio:</h1>

<%= render 'form' %>

<%= render 'form' %>
2 changes: 0 additions & 2 deletions app/views/condos/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


<h1><%= @condo.name %></h1>
<p>CNPJ: <%= @condo.registration_number %></p>
<p>Endereço: <%= @condo.full_address %></p>
Expand Down
Loading
Loading