From 64c78508c590b422a394ed0d602cb9a2780e3274 Mon Sep 17 00:00:00 2001 From: BlackPearl96 Date: Mon, 19 Aug 2019 09:15:54 +0700 Subject: [PATCH] Delete Room --- app/assets/javascripts/manager/custom.js | 12 +++++ app/assets/stylesheets/manager/custom.scss | 4 ++ app/controllers/manager/rooms_controller.rb | 13 ++++- app/views/manager/rooms/_room.html.slim | 4 +- app/views/manager/rooms/show.html.slim | 56 +++++++++++++++++++++ config/environments/development.rb | 5 -- config/locales/en.yml | 1 + 7 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 app/views/manager/rooms/show.html.slim diff --git a/app/assets/javascripts/manager/custom.js b/app/assets/javascripts/manager/custom.js index 80f5df8..c592409 100644 --- a/app/assets/javascripts/manager/custom.js +++ b/app/assets/javascripts/manager/custom.js @@ -24,6 +24,11 @@ function previewImages() { } $(document).ready(function(){ + $('#room_table').DataTable({ + scrollY: 500, + "pageLength": 25, + }); + $('#admin_table').DataTable({ scrollY: 500, "pageLength": 25, @@ -33,6 +38,13 @@ $(document).ready(function(){ ] }); + $("#micropost_picture").bind("change", function(){ + var size_in_megabytes = this.files(0).size/1024/1024; + if (size_in_megabytes > 5) { + alert("Maximum file size is 5MB. Please choose an other file!"); + } + }); + $('#member_table').DataTable({ scrollY: 500, "pageLength": 25, diff --git a/app/assets/stylesheets/manager/custom.scss b/app/assets/stylesheets/manager/custom.scss index 2f6a580..e6f9a18 100644 --- a/app/assets/stylesheets/manager/custom.scss +++ b/app/assets/stylesheets/manager/custom.scss @@ -358,6 +358,10 @@ td.action{ padding: 0; } +td.action{ + padding: 0; +} + .action{ padding: 0 10px 0 10px; margin: 0 10px 0 10px; diff --git a/app/controllers/manager/rooms_controller.rb b/app/controllers/manager/rooms_controller.rb index 02799b8..c06aa0d 100644 --- a/app/controllers/manager/rooms_controller.rb +++ b/app/controllers/manager/rooms_controller.rb @@ -2,7 +2,7 @@ module Manager class RoomsController < BaseController - before_action :load_room, only: %i[edit update] + before_action :load_room, only: %i[edit update show destroy] def index @rooms = Room.sort_by_name @@ -15,6 +15,8 @@ def new def edit; end + def show; end + def create @room = current_admin.rooms.build room_params if @room.save @@ -34,6 +36,15 @@ def update end end + def destroy + if @room.destroy + flash[:success] = t ".deleted_success" + else + flash[:danger] = t ".deleted_fail" + end + redirect_to manager_rooms_path + end + private def room_params diff --git a/app/views/manager/rooms/_room.html.slim b/app/views/manager/rooms/_room.html.slim index a96c287..11863bd 100644 --- a/app/views/manager/rooms/_room.html.slim +++ b/app/views/manager/rooms/_room.html.slim @@ -1,6 +1,6 @@ tr td - = room.name + = link_to room.name, manager_room_path(room) td = room.location.name td @@ -8,3 +8,5 @@ tr td.action = link_to t(".edit"), edit_manager_room_path(room), class: "action btn btn-outline-info" + = link_to t(".delete"), manager_room_path(room), method: :delete, + data: {confirm: t(".sure") }, class: "action btn btn-outline-danger" diff --git a/app/views/manager/rooms/show.html.slim b/app/views/manager/rooms/show.html.slim new file mode 100644 index 0000000..fd0ba40 --- /dev/null +++ b/app/views/manager/rooms/show.html.slim @@ -0,0 +1,56 @@ +.bs-example + ul.nav.nav-tabs + li.nav-item + = link_to "#home", class: "nav-link active", data:{toggle: "tab"} do + = t ".description" + li + = link_to "#menu1", class: "nav-link", data:{toggle: "tab"} do + = t ".room" + li + = link_to "#menu2", class: "nav-link", data:{toggle: "tab"} do + = t ".utility" + li + = link_to "#menu3", class: "nav-link", data:{toggle: "tab"} do + = t ".image" + .tab-content + #home.tab-pane.fade.show.active + h3 = @room.name + = @room.description + #menu1.tab-pane.fade + h3 = t ".room" + div.row + .col-md-3 + = t ".guest" + .col-md-9 + = @room.guest + div.row + .col-md-3 + = t ".bed_room" + .col-md-9 + = @room.bed_room + div.row + .col-md-3 + = t ".bath_room" + .col-md-9 + = @room.bath_room + div.row + .col-md-3 + = t ".acreage" + .col-md-9 + = @room.acreage + div.row + .col-md-3 + = t ".address" + .col-md-9 + = @room.address + div.row + .col-md-3 + = t ".type_room" + .col-md-9 + = @room.type_room + #menu2.tab-pane.fade + h3 = t ".utility" + #menu3.tab-pane.fade + h3 = t ".image" + - @room.room_images.each do |img| + = image_tag img.image.url, class: "image-detail" diff --git a/config/environments/development.rb b/config/environments/development.rb index 9975caa..87f2659 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,11 +1,6 @@ # frozen_string_literal: true Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. diff --git a/config/locales/en.yml b/config/locales/en.yml index bb2b181..2494fe3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -25,6 +25,7 @@ en: update_success: Update Success! update_fail: Update Failed deleted_success: Deleted success + deleted_fail: Deleted fail new: create_room: Create Room edit: