From 4380966ab87930527a33f4022e473c081e3e8d79 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 28 Jul 2020 00:34:33 +0800 Subject: [PATCH] Add Inviting CRUD --- .../venue_management_invitings_controller.rb | 66 +++++++ .../admin/venue_managements_controller.rb | 46 +++-- app/models/venue_management_inviting.rb | 33 ++++ app/models/venue_management_main.rb | 9 +- .../venue_management_invitings/_form.html.erb | 169 ++++++++++++++++++ .../_index.html.erb | 58 ++++++ .../venue_management_invitings/edit.html.erb | 5 + .../venue_management_invitings/index.html.erb | 4 + .../venue_management_invitings/new.html.erb | 5 + .../admin/venue_managements/_form.html.erb | 22 +-- .../admin/venue_managements/_index.html.erb | 6 +- .../venue_management_invitings.html.erb | 5 + config/locales/en.yml | 26 ++- config/locales/zh_tw.yml | 45 ++++- config/routes.rb | 6 +- lib/venue_management/engine.rb | 12 +- 16 files changed, 468 insertions(+), 49 deletions(-) create mode 100644 app/controllers/admin/venue_management_invitings_controller.rb create mode 100644 app/models/venue_management_inviting.rb create mode 100644 app/views/admin/venue_management_invitings/_form.html.erb create mode 100644 app/views/admin/venue_management_invitings/_index.html.erb create mode 100644 app/views/admin/venue_management_invitings/edit.html.erb create mode 100644 app/views/admin/venue_management_invitings/index.html.erb create mode 100644 app/views/admin/venue_management_invitings/new.html.erb create mode 100644 app/views/admin/venue_managements/venue_management_invitings.html.erb diff --git a/app/controllers/admin/venue_management_invitings_controller.rb b/app/controllers/admin/venue_management_invitings_controller.rb new file mode 100644 index 0000000..d1a0c9f --- /dev/null +++ b/app/controllers/admin/venue_management_invitings_controller.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +class Admin::VenueManagementInvitingsController < OrbitAdminController + include Admin::VenueManagementsHelper + before_action ->(module_app = @app_title) { set_variables module_app } + before_action :set_venue_management_inviting, only: [:edit, :update, :destroy] + + def initialize + super + @app_title = 'venue_management' + end + + def index + @table_fields = [ + 'venue_management.title', + 'vm_inviting.case_no', + 'vm_inviting.publish_times', + 'vm_inviting.rents', + 'vm_inviting.royalty', + 'vm_inviting.house_tax_payer', + 'vm_inviting.land_tax_payer', + 'vm_inviting.contractor_manager', + 'vm_inviting.bid_result', + ] + @invitings = VenueManagementInviting.order(updated_at: :desc).page(params[:page]).per(10) + end + + def new + @venue_management = VenueManagementMain.find(params[:id]) + @venue_management_inviting = @venue_management.venue_management_invitings.build + end + + def create + @venue_management_inviting = VenueManagementInviting.new(venue_management_inviting_params) + @venue_management_inviting.save + + redirect_to params['referer_url'] + end + + def edit + @venue_management = VenueManagementMain.find(@venue_management_inviting.venue_management_main_id) + end + + def update + @venue_management_inviting.update_attributes(venue_management_inviting_params) + + redirect_to venue_management_invitings_admin_venue_management_path(@venue_management_inviting.venue_management_main_id) + end + + def destroy + @venue_management_main_id = @venue_management_inviting.venue_management_main_id + @venue_management_inviting.destroy + + redirect_to venue_management_invitings_admin_venue_management_path(@venue_management_main_id) + end + + private + + def set_venue_management_inviting + @venue_management_inviting = VenueManagementInviting.find(params[:id]) + end + + def venue_management_inviting_params + params.require(:venue_management_inviting).permit! + end +end diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index e2531f3..6d482df 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -4,7 +4,7 @@ class Admin::VenueManagementsController < OrbitAdminController require 'axlsx' helper Admin::VenueManagementsFieldHelper before_action ->(module_app = @app_title) { set_variables module_app } - before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy] + before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings] def initialize super @@ -22,13 +22,13 @@ class Admin::VenueManagementsController < OrbitAdminController @filter_fields = filter_fields(@categories) @table_fields = [:category, 'venue_management.title', 'venue_management.event_during', 'venue_management.signup_during', 'venue_management.signup_count', 'venue_management.inviting_hostory', 'venue_management.memorabilia','venue_management.export'] - if !params[:sort].blank? + if !params[:sort].blank? if params[:sort] == 'event_during' - sort = {:venue_management_start_date.to_sym=>params[:order]} + sort = {:venue_management_start_date.to_sym=>params[:order]} elsif params[:sort] == 'signup_during' - sort = {:signup_start_date.to_sym=>params[:order]} + sort = {:signup_start_date.to_sym=>params[:order]} else - sort = {params[:sort].to_sym=>params[:order]} + sort = {params[:sort].to_sym=>params[:order]} end else sort = {:signup_start_date=>"desc"} @@ -37,7 +37,7 @@ class Admin::VenueManagementsController < OrbitAdminController @venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category")) @venue_managements = search_data(@venue_managements,[:title]).page(params[:page]).per(10) - + if request.xhr? render :partial => "index" end @@ -72,7 +72,7 @@ class Admin::VenueManagementsController < OrbitAdminController end def create - + if !venue_management_params['venue_management_links_attributes'].nil? venue_management_params['venue_management_links_attributes'].each do |idx,link| venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? @@ -139,7 +139,7 @@ class Admin::VenueManagementsController < OrbitAdminController params[:venue_management_main][:registration_status] = (params[:venue_management_main][:registration_status] ? params[:venue_management_main][:registration_status] : []) - + uid = params[:id].split('-').last @venue_management = VenueManagementMain.find_by(:uid=>uid) @@ -171,7 +171,7 @@ class Admin::VenueManagementsController < OrbitAdminController venue_management_params['venue_management_links_attributes'].delete(idx.to_s) if link['url'].blank? end end - + @venue_management.update_user_id = current_user.id if @venue_management.update_attributes(venue_management_params) @venue_management.venue_management_signup_fields.each{|t| t.destroy if t["to_delete"] == true} @@ -183,7 +183,7 @@ class Admin::VenueManagementsController < OrbitAdminController end end - + def set_write_off @venue_management.donation_write_off_status = true @@ -202,14 +202,14 @@ class Admin::VenueManagementsController < OrbitAdminController def venue_management_signup_field @field_name = 'venue_management_main' - @attribute = VenueManagementMain.find(params[:id]) + @attribute = VenueManagementMain.find(params[:id]) @attribute_type = 'venue_management' @class = 'venue_managements' end def venue_management_submission_field @field_name = 'venue_management_main' - @attribute = VenueManagementMain.find(params[:id]) + @attribute = VenueManagementMain.find(params[:id]) @attribute_type = 'venue_management' @class = 'venue_managements' end @@ -221,7 +221,7 @@ class Admin::VenueManagementsController < OrbitAdminController else @venue_management_signups = VenueManagementSignup.where(:venue_management_main_id => @venue_management.id).page(params[:page]).per(10) end - + end def edit_venue_management_signup @@ -230,7 +230,7 @@ class Admin::VenueManagementsController < OrbitAdminController end def delete_venue_management_signup - + @venue_management_signup = VenueManagementSignup.find(params[:id]) @venue_management_id = @venue_management_signup.venue_management_main_id @@ -240,6 +240,20 @@ class Admin::VenueManagementsController < OrbitAdminController redirect_to "/admin/venue_managements/@venue_management_id.to_s/venue_management_signup" end + def venue_management_invitings + @table_fields = [ + 'vm_inviting.case_no', + 'vm_inviting.publish_times', + 'vm_inviting.rents', + 'vm_inviting.royalty', + 'vm_inviting.house_tax_payer', + 'vm_inviting.land_tax_payer', + 'vm_inviting.contractor_manager', + 'vm_inviting.bid_result', + ] + @invitings = @venue_management.venue_management_invitings.page(params[:page]).per(10) + end + private def set_venue_management @@ -251,7 +265,7 @@ class Admin::VenueManagementsController < OrbitAdminController end def create_set (save_flag) VenueManagementSignup.attribute_names.each do |attr_signup| - if !(['_id', 'created_at', 'updated_at','venue_management_main_id'].include? attr_signup) + if !(['_id', 'created_at', 'updated_at','venue_management_main_id'].include? attr_signup) signup_set = @venue_management.venue_management_signup_field_sets.select{|v| v.field_name==attr_signup } if signup_set.length==0 if ['status','name','tel','phone','email','password'].include? attr_signup @@ -295,7 +309,7 @@ class Admin::VenueManagementsController < OrbitAdminController end end VenueManagementSignupContribute.attribute_names.each do |attr_submission| - if !(['_id', 'created_at', 'updated_at','venue_management_signup_id'].include? attr_submission) + if !(['_id', 'created_at', 'updated_at','venue_management_signup_id'].include? attr_submission) signup_set = @venue_management.venue_management_submission_field_sets.select{|v| v.field_name==attr_submission } if signup_set.length==0 name1 = Hash.new diff --git a/app/models/venue_management_inviting.rb b/app/models/venue_management_inviting.rb new file mode 100644 index 0000000..1b40638 --- /dev/null +++ b/app/models/venue_management_inviting.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'orbit_form_helper' + +class VenueManagementInviting + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Enum + + PAYERS = [ :school, :vendor ].freeze + BID_RESULTS = [ :failure, :abandoned, :qualified ].freeze + + field :case_no, type: String + field :publish_times, type: Integer + field :start_date, type: Date, default: Time.now + field :end_date, type: Date, default: Time.now + field :close_date, type: Date, default: Time.now + field :bid_date, type: Date, default: Time.now + field :evaluation_date, type: Date, default: Time.now + field :early_rent, type: Integer + field :operation_rent, type: Integer + field :royalty, type: Integer + field :contractor_manager # save user_id + enum :house_tax_payer, PAYERS + enum :land_tax_payer, PAYERS + enum :bid_result, BID_RESULTS + field :details, localize: true + + belongs_to :venue_management_main + has_many :venue_management_links, :as => :venue_object, :autosave => true, :dependent => :destroy + accepts_nested_attributes_for :venue_management_links, :allow_destroy => true + +end diff --git a/app/models/venue_management_main.rb b/app/models/venue_management_main.rb index d1a0135..11c0c2f 100644 --- a/app/models/venue_management_main.rb +++ b/app/models/venue_management_main.rb @@ -6,7 +6,7 @@ class VenueManagementMain # encoding: utf-8 include OrbitCategory::Categorizable include Slug - + field :title, as: :slug_title, type: String, localize: true field :speaker, localize: true field :content, localize: true @@ -25,7 +25,7 @@ class VenueManagementMain field :contribute_start_date, :type => Date field :contribute_end_date, :type => Date - + field :contribute_file_count, type: String field :registration_status , :type => Array #C: 投稿者 G:一般 @@ -36,6 +36,7 @@ class VenueManagementMain belongs_to :venue_management_item has_many :venue_management_links, :autosave => true, :dependent => :destroy + has_many :venue_management_invitings, :autosave => true, :dependent => :destroy has_many :venue_management_files, :autosave => true, :dependent => :destroy has_many :venue_management_item_contents, :autosave => true, :dependent => :destroy has_many :venue_management_signups, :autosave => true, :dependent => :destroy @@ -64,7 +65,7 @@ class VenueManagementMain r = "#{date1.strftime('%Y-%m-%d')}" if date2 - r += " - #{date2.strftime('%Y-%m-%d')}" + r += " - #{date2.strftime('%Y-%m-%d')}" else r += " - #{I18n.t(:no_deadline)}" end @@ -82,7 +83,7 @@ class VenueManagementMain def get_attribute_values(attribute_type=nil) @attribute_values = attribute_type.venue_management_signup_values rescue nil end - + def get_value_from_field_id(field_id,attribute_type=nil) values = get_attribute_values(attribute_type) value = values.detect {|value| value.venue_management_signup_field_id == field_id} rescue nil diff --git a/app/views/admin/venue_management_invitings/_form.html.erb b/app/views/admin/venue_management_invitings/_form.html.erb new file mode 100644 index 0000000..ad4d5f7 --- /dev/null +++ b/app/views/admin/venue_management_invitings/_form.html.erb @@ -0,0 +1,169 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + +
+ + +
+ +
+ <%= f.hidden_field :venue_management_main_id %> +
+ +
+ <%= f.text_field :case_no %> +
+
+
+ +
+ <%= f.number_field :publish_times %> +
+
+
+ +
+ <%= f.datetime_picker :start_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_inviting.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :end_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_inviting.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :close_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_inviting.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :bid_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_inviting.new_record? %> +
+
+
+ +
+ <%= f.datetime_picker :evaluation_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @venue_management_inviting.new_record? %> +
+
+
+ +
+ <%= f.number_field :early_rent %> +
+
+
+ +
+ <%= f.number_field :operation_rent %> +
+
+
+ +
+ <%= f.number_field :royalty %> +
+
+
+ +
+ <%= f.select :house_tax_payer, VenueManagementInviting::PAYERS.map { |p| [t("vm_inviting.enums.#{p}"), p] }, :include_blank => true %> +
+
+
+ +
+ <%= f.select :land_tax_payer, VenueManagementInviting::PAYERS.map { |p| [t("vm_inviting.enums.#{p}"), p] }, :include_blank => true %> +
+
+
+ +
+ <%= f.select :bid_result, VenueManagementInviting::BID_RESULTS.map { |p| [t("vm_inviting.enums.bid_result.#{p}"), p] }, :include_blank => true %> +
+
+
+
+ + + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+
+ <%= f.fields_for :details_translations do |f| %> + <%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@venue_management_inviting.details_translations[locale] rescue nil) %> + <% end %> +
+
+
+
+ + <% end %> + + +
+ +
+ + + <% if @venue_management_inviting && !@venue_management_inviting.venue_management_links.blank? %> +
+ <% @venue_management_inviting.venue_management_links.each_with_index do |venue_management_link, i| %> + <%= f.fields_for :venue_management_links, venue_management_link do |f| %> + <%= render :partial => 'form_link', :object => venue_management_link, :locals => {:f => f, :i => i} %> + <% end %> + <% end %> +
+
+ <% end %> + + +
+
+

+ <%= hidden_field_tag 'venue_management_link_field_count', @venue_management_inviting.venue_management_links.count %> + <%= t(:add) %> +

+
+
+
+
+ + +
+ <%= get_referer_url[:venue_managemention] rescue "" %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), venue_management_invitings_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %> +
diff --git a/app/views/admin/venue_management_invitings/_index.html.erb b/app/views/admin/venue_management_invitings/_index.html.erb new file mode 100644 index 0000000..d5319eb --- /dev/null +++ b/app/views/admin/venue_management_invitings/_index.html.erb @@ -0,0 +1,58 @@ + +<% if 'venue_management_invitings' == params[:action] %> +

<%= @venue_management.title %>

+<% end %> + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @invitings.each do |inviting| %> + + <% if 'venue_management_invitings' != params[:action] %> + + <% end %> + + + + + + + + + + <% end %> + +
<%= inviting.venue_management_main.title %> + <%= link_to inviting.case_no, admin_venue_management_inviting_path(inviting.id), :target => '_blank' %> + +
+ +
+
<%= inviting.publish_times %><%= "#{inviting.early_rent} / #{inviting.operation_rent}" %><%= inviting.royalty %><%= t("vm_inviting.enums.#{inviting.house_tax_payer}") %><%= t("vm_inviting.enums.#{inviting.land_tax_payer}") %><%= inviting.contractor_manager %><%= t("vm_inviting.enums.bid_result.#{inviting.bid_result}") %>
+ +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@invitings), class: "pagination pagination-centered" + end +%> +<% if @venue_management.present? %> + +
+
+ <%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), new_admin_venue_management_inviting_path(id: @venue_management.id), class: "btn btn-primary" %> +
+
+ +<% end %> diff --git a/app/views/admin/venue_management_invitings/edit.html.erb b/app/views/admin/venue_management_invitings/edit.html.erb new file mode 100644 index 0000000..4dce640 --- /dev/null +++ b/app/views/admin/venue_management_invitings/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @venue_management_inviting, url: admin_venue_management_inviting_path(@venue_management_inviting), html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/venue_management_invitings/index.html.erb b/app/views/admin/venue_management_invitings/index.html.erb new file mode 100644 index 0000000..be82942 --- /dev/null +++ b/app/views/admin/venue_management_invitings/index.html.erb @@ -0,0 +1,4 @@ + + <%= render 'index' %> + +<%= render 'layouts/delete_modal', delete_options: @delete_options %> diff --git a/app/views/admin/venue_management_invitings/new.html.erb b/app/views/admin/venue_management_invitings/new.html.erb new file mode 100644 index 0000000..8e39716 --- /dev/null +++ b/app/views/admin/venue_management_invitings/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @venue_management_inviting, url: admin_venue_management_invitings_path, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> diff --git a/app/views/admin/venue_managements/_form.html.erb b/app/views/admin/venue_managements/_form.html.erb index 58c761b..ba0edd2 100644 --- a/app/views/admin/venue_managements/_form.html.erb +++ b/app/views/admin/venue_managements/_form.html.erb @@ -11,7 +11,7 @@ <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> <%= javascript_include_tag "lib/file-type" %> - <%= javascript_include_tag "lib/module-area" %> + <%= javascript_include_tag "lib/module-area" %> <% end %>