diff --git a/.gitignore b/.gitignore index ee42172..6625c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ config/environments/*.local.yml # Ignore application configuration /config/application.yml + /public/uploads diff --git a/Gemfile.lock b/Gemfile.lock index 1ac352a..f2a0c0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,7 +126,7 @@ GEM dry-logic (~> 1.0, >= 1.0.2) erubi (1.8.0) execjs (2.7.0) - faker (2.2.0) + faker (2.1.2) i18n (>= 0.8) ffi (1.11.1) figaro (1.1.1) @@ -266,7 +266,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.2.0) + sassc (2.1.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) diff --git a/app/assets/javascripts/manager/custom.js b/app/assets/javascripts/manager/custom.js index 80f5df8..ce0c810 100644 --- a/app/assets/javascripts/manager/custom.js +++ b/app/assets/javascripts/manager/custom.js @@ -92,5 +92,9 @@ $(document).ready(function(){ $('[data-toggle="tooltip"]').tooltip(); $('.preview-image').on("change", previewImages); -}); + $('.address-edit').click(function() { + $('.name_address').val($(this).data('address-name')); + $('#edit_address').attr('action', $(this).data('address-url')); + }); +}); diff --git a/app/controllers/manager/addresses_controller.rb b/app/controllers/manager/addresses_controller.rb index 2588586..4fd73f1 100644 --- a/app/controllers/manager/addresses_controller.rb +++ b/app/controllers/manager/addresses_controller.rb @@ -2,6 +2,8 @@ module Manager class AddressesController < BaseController + before_action :load_address, only: %i[edit update] + def create @address = Address.new address_params if @address.save @@ -14,10 +16,27 @@ def create end end + def edit; end + + def update + if @address.update name: params[:name] + flash[:success] = t ".success" + else + flash.now[:danger] = t ".danger" + end + respond_to do |format| + format.js + end + end + private def address_params params.require(:address).permit :name, :area_id end + + def load_address + @address = Address.find params[:id] + end end end diff --git a/app/views/manager/addresses/update.js.slim b/app/views/manager/addresses/update.js.slim new file mode 100644 index 0000000..1abf604 --- /dev/null +++ b/app/views/manager/addresses/update.js.slim @@ -0,0 +1,6 @@ +- if @address.errors.present? + | $("#message_errors").html("#{j(render 'shared/manager/error_messages', object: @address)}"); + toastr.error("#{flash[:danger]}"); +- else + | $('.load-address').load(location.href + ' .load-address'); + toastr.success("#{flash[:success]}"); diff --git a/app/views/manager/areas/_address.html.slim b/app/views/manager/areas/_address.html.slim index 2c5698b..a496336 100644 --- a/app/views/manager/areas/_address.html.slim +++ b/app/views/manager/areas/_address.html.slim @@ -2,6 +2,6 @@ tr td = address_counter.next td - = address.name + = link_to address.name, "#", class: "link-to-edit address-edit", data: {toggle: "modal", target: "#myModal", address_name: address.name, address_url: manager_address_path(address)} td - = link_to t(".delete"), "#", class: "btn btn-danger" + = link_to t(".delete"), "#", class: "btn btn-danger" diff --git a/app/views/manager/areas/_edit_address.html.slim b/app/views/manager/areas/_edit_address.html.slim new file mode 100644 index 0000000..268b90e --- /dev/null +++ b/app/views/manager/areas/_edit_address.html.slim @@ -0,0 +1,14 @@ +#myModal.modal.fade + .modal-dialog + .modal-content + .modal-header + h4.modal-title = t ".edit" + = button_tag t(".btn"), class: "close", data: {dismiss: "modal"}, type: "button" + .modal-body + = form_tag "", method: :patch, id: "edit_address", remote: true do |f| + #message_errors + .form-group + = text_field_tag :name, nil, class: "form-control name_address" + = submit_tag t(".save"), class: "btn btn-primary" + .modal-footer + = button_tag t(".close"), class: "btn btn-danger", data: {dismiss: "modal"}, type: "button" diff --git a/app/views/manager/areas/_new_address.html.slim b/app/views/manager/areas/_new_address.html.slim index d59afb5..3b358b2 100644 --- a/app/views/manager/areas/_new_address.html.slim +++ b/app/views/manager/areas/_new_address.html.slim @@ -1,4 +1,4 @@ -#myModal.modal.fade +#new_address_modal.modal.fade .modal-dialog .modal-content .modal-header diff --git a/app/views/manager/areas/edit.html.slim b/app/views/manager/areas/edit.html.slim index 99d33a2..d1ef87a 100644 --- a/app/views/manager/areas/edit.html.slim +++ b/app/views/manager/areas/edit.html.slim @@ -18,7 +18,7 @@ .card-header h4.card-title = t ".address" - = link_to t(".address"), "#", class: "btn btn-primary btn-xs right btn_right", data: {toggle: "modal", target: "#myModal"} + = link_to t(".address"), "#", class: "btn btn-primary btn-xs right btn_right", data: {toggle: "modal", target: "#new_address_modal"} .card-body.load-address table.table.table-hover.table-striped thead @@ -29,3 +29,4 @@ = render partial: "address", collection: @addresses = paginate @addresses, theme: "twitter-bootstrap-4", pagination_class: "pagination-sm" = render "new_address", address: @address += render "edit_address" diff --git a/config/locales/en.yml b/config/locales/en.yml index bb2b181..11a641f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,7 +1,6 @@ en: please_choose_one: please choose one sure: "Are you sure?" - layouts: header: signup: "Sign Up" @@ -44,7 +43,6 @@ en: acreage: Acreage address: Address type_room: Type Rooms - shared: manager: left_menu: diff --git a/config/locales/manager/en.yml b/config/locales/manager/en.yml index 9a899ec..a36f95a 100644 --- a/config/locales/manager/en.yml +++ b/config/locales/manager/en.yml @@ -112,6 +112,14 @@ en: name: "Name" action: "Action" address: "New Address" + enter_name: "Enter address..." + area: + delete: "Delete" + sure: "Are you sure?" + new_area: + new: "New Areas" + save: "Save Changes" + close: "Close" update: success: "Update area successfully!" danger: "Update area has problem!" @@ -126,6 +134,18 @@ en: btn: "×" address: delete: "Delete" + edit_address: + btn: "×" + edit: "Edit Address" + save: "Save Changes" + close: "Close" + addresses: + create: + success: "Create address successfully!" + danger: "Create address has problem!" + update: + success: "Update address successfully!" + danger: "Update address has problem!" members: form: error: "The form contains %{count}." @@ -150,10 +170,6 @@ en: edit: update: "Update" edit_member: "Edit Member" - addresses: - create: - success: "Create address successfully!" - danger: "Create address has problem!" passwords: new: title: "Forgot Your Password?" diff --git a/config/routes.rb b/config/routes.rb index cdd1fe2..29946e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ resources :areas, except: %i[new create] do resources :addresses, only: %i[new create] end + resources :addresses, only: %i[destroy edit update] end root "home#index" end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb deleted file mode 100644 index 99f8bf4..0000000 --- a/spec/controllers/home_controller_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe HomeController, type: :controller do - describe "GET #index" do - it "returns http success" do - get :index - expect(response).to have_http_status(:success) - end - end -end