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

build price to room #62

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ AllCops:
- 'db/*.rb'
- 'bin/**/*'
- 'config/environments/*.rb'
- 'config/routes.rb'

Style/Documentation:
Enabled: false
32 changes: 20 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkout lại file này

archive-zip (0.12.0)
io-like (~> 0.3.0)
arel (9.0.0)
Expand All @@ -61,11 +63,14 @@ GEM
rails (>= 3.1)
builder (3.2.3)
byebug (11.0.1)
carrierwave (1.3.1)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
childprocess (1.0.1)
carrierwave (2.0.1)
activemodel (>= 5.0.0)
activesupport (>= 5.0.0)
addressable (~> 2.6)
image_processing (~> 1.1)
mimemagic (>= 0.3.0)
mini_mime (>= 0.1.3)
childprocess (2.0.0)
rake (< 13.0)
chromedriver-helper (2.1.1)
archive-zip (~> 0.10)
Expand Down Expand Up @@ -126,7 +131,7 @@ GEM
dry-logic (~> 1.0, >= 1.0.2)
erubi (1.8.0)
execjs (2.7.0)
faker (2.2.0)
faker (2.2.1)
i18n (>= 0.8)
ffi (1.11.1)
figaro (1.1.1)
Expand All @@ -137,6 +142,9 @@ GEM
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
image_processing (1.9.3)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.13, < 3)
io-like (0.3.0)
jaro_winkler (1.5.3)
jbuilder (2.9.1)
Expand Down Expand Up @@ -171,9 +179,6 @@ GEM
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mimemagic (0.3.3)
mini_magick (4.9.5)
mini_mime (1.0.2)
Expand All @@ -186,14 +191,15 @@ GEM
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
parallel (1.17.0)
parser (2.6.3.0)
parser (2.6.4.0)
ast (~> 2.4.0)
popper_js (1.14.5)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.1)
puma (3.12.1)
rack (2.0.7)
rack-test (1.1.0)
Expand Down Expand Up @@ -260,6 +266,8 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
ruby-vips (2.0.14)
ffi (~> 1.9)
ruby_dep (1.5.0)
rubyzip (1.2.3)
sass (3.7.4)
Expand All @@ -283,8 +291,8 @@ GEM
tilt
select2-rails (4.0.3)
thor (~> 0.14)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
selenium-webdriver (3.142.4)
childprocess (>= 0.5, < 3.0)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
Expand Down
30 changes: 30 additions & 0 deletions app/assets/stylesheets/manager/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,34 @@ td.action{

#admin_table td{
word-break: break-word;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bỏ dòng này

}

.new-price {
float: right;
}

.price {
float: right;
}

.voucher {
border: 1px solid #cbd4d4;
padding: 0 15px;
}

.fa-times-circle {
font-size: 20px !important;
padding: 10px 0 !important;
color: darkslategrey !important;
float: right;
}

.fa-times-circle:hover {
color: red;
}

.add_fields {
color: darkslategrey;
text-decoration: none !important;
}
31 changes: 18 additions & 13 deletions app/controllers/manager/prices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,53 @@

module Manager
class PricesController < BaseController
before_action :price, only: %i[edit update destroy]
before_action :load_price, only: %i[edit update]
before_action :load_room, only: %i[edit new]

def index
@prices = Price.includes(:bills, :vouchers).newest
end

def edit
@price.vouchers.build
end

def new
@price = Price.new
@price = @room.build_price
@price.vouchers.build
end

def create
@price = Price.new(price_params)
@price = Price.new price_params
if @price.save
redirect_to manager_prices_path, flash: { success: t(".success") }
redirect_to manager_room_path(@price.room_id), flash: { success: t(".success") }
else
render :new
end
end

def edit; end

def update
if @price.update(price_params)
redirect_to manager_prices_path, flash: { success: t(".success") }
if @price.update price_params
redirect_to manager_room_path(@price.room_id), flash: { success: t(".success") }
else
render :edit
end
end

def destroy
redirect_to manager_prices_path, flash: { success: t(".success") } if @price.destroy
end

private

def price_params
params.require(:price).permit(:cost, :cleaning_fee, vouchers_attributes: %i[id code sale date_off _destroy])
params.require(:price).permit :room_id, :cost, :cleaning_fee,
vouchers_attributes: %i[id code sale date_off _destroy]
end

def price
def load_price
@price = Price.find(params[:id])
end

def load_room
@room = Room.find params[:room_id]
end
end
end
33 changes: 20 additions & 13 deletions app/controllers/manager/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def new
@room.current_step = session[:room_step]
end

def edit; end
def edit
@room.room_images.build
@room.current_step = session[:room_step]
end

def show
@room_utilities = @room.utilities
Expand All @@ -25,15 +28,24 @@ def create
session[:room_params].deep_merge!(room_params) if room_params
@room = current_admin.rooms.build session[:room_params]
@room.current_step = session[:room_step]
btn_action_step @room
return redirect_to manager_room_path(@room), success: t(".create_room") if btn_action_step @room

if @room.last_step?
redirect_to new_manager_room_path
else
render :new
end
end

def update
if @room.update room_params
upload_images if params[:room_images]
redirect_to manager_room_path(@room), success: t(".update_success")
@room.update room_params
@room.current_step = session[:room_step]
return redirect_to manager_room_path(@room), success: t(".update_success") if btn_action_step @room

if @room.last_step?
redirect_to edit_manager_room_path
else
render :edit, danger: t(".update_fail")
render :edit
end
end

Expand Down Expand Up @@ -74,18 +86,13 @@ def btn_action_step(room)
session.delete(:room_step)
session.delete(:room_params)
upload_images if params[:room_images]
redirect_to manager_room_path(room), success: t(".create_room")
return
return true
else
room.next_step
end
session[:room_step] = room.current_step
end
if room.last_step?
redirect_to new_manager_room_path
else
render :new
end
false
end
end
end
2 changes: 0 additions & 2 deletions app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

class Address < ApplicationRecord
belongs_to :area

validates :name, presence: true
end
2 changes: 1 addition & 1 deletion app/models/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Price < ApplicationRecord
has_many :bills, dependent: :destroy
has_many :vouchers, through: :bills
has_many :rooms, dependent: :destroy
belongs_to :room

validates :cost,
format: { with: /\A\d+(?:\.\d{0,2})?\z/ },
Expand Down
3 changes: 1 addition & 2 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class Room < ApplicationRecord
belongs_to :location
belongs_to :user
belongs_to :favorite_space
belongs_to :price
belongs_to :area
has_many :room_images
has_one :price

validates :address, presence: true, length: { maximum: 50 }, if: :step_content?
validates :name, presence: true, length: { maximum: 50 }, if: :step_home?
validates :guest, :bed_room, :bath_room, presence: true,
numericality: { only_integer: true }, if: :step_home?

validates :type_room, presence: true, if: :step_home?

enum type_room: { private_room: 0, entire: 1 }
Expand Down
2 changes: 2 additions & 0 deletions app/views/manager/prices/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
= form_for [:manager, @price] do |price|
h2.text-center = t(".price")
= render "shared/manager/error_messages", object: @price

= price.hidden_field :room_id, value: @room.id
= price.label :cost
= price.number_field :cost, step: :any, class: "form-control", placeholder: "$"
br/
Expand Down
16 changes: 0 additions & 16 deletions app/views/manager/prices/_price.html.slim

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/manager/prices/index.html.slim

This file was deleted.

12 changes: 12 additions & 0 deletions app/views/manager/rooms/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
li
= link_to "#menu3", class: "nav-link", data:{toggle: "tab"} do
= t ".image"
li
- if @room.price.present?
a.nav-link data-toggle="tab" href="#menu4" = t ".price"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dùng link_to

- else
= link_to "Add Price", new_manager_room_price_path(@room), class: "fa fa-plus btn btn-primary"
.tab-content
#home.tab-pane.fade.show.active
h3 = @room.name
Expand Down Expand Up @@ -56,3 +61,10 @@
h3 = t ".image"
- @room.room_images.each do |img|
= image_tag img.image.url, class: "image-detail"
#menu4.tab-pane.fade
h3 = t ".price"
- if @room.price.present?
= @room.price.cost
- @room.price.bills.each do |f|
= bill_vouchers(f)
= link_to "Edit Price", edit_manager_room_price_path(@room, @room.price), class: "btn btn-primary"
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,3 @@ en:
not_valid: "wrong format or size is too big"
format: "wrong format"
size: "is too big"
favorite_space: "Manager Favorite Spaces"
Loading