From 336c1e86bdcdda79dbad7bceb39a21481cc1d915 Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 18 Aug 2017 16:07:19 +0300 Subject: [PATCH 01/15] Add #show for sponsors --- app/controllers/admin/sponsors_controller.rb | 18 ++++- app/views/admin/sponsors/_edit_form.html.haml | 20 +++++ app/views/admin/sponsors/_form.html.haml | 6 +- app/views/admin/sponsors/edit.html.haml | 1 + app/views/admin/sponsors/index.html.haml | 2 +- app/views/admin/sponsors/show.html.haml | 78 +++++++++++++++++++ config/routes.rb | 9 ++- .../20170822173332_add_swags_to_sponsors.rb | 10 +++ db/schema.rb | 14 +++- 9 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 app/views/admin/sponsors/_edit_form.html.haml create mode 100644 app/views/admin/sponsors/edit.html.haml create mode 100644 app/views/admin/sponsors/show.html.haml create mode 100644 db/migrate/20170822173332_add_swags_to_sponsors.rb diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 909c2d7c..5a639f52 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -4,11 +4,16 @@ module Admin load_and_authorize_resource :sponsor, through: :conference before_action :sponsorship_level_required, only: [:index, :new] + attr_accessor :type, :quantity + def index authorize! :index, Sponsor.new(conference_id: @conference.id) end - def edit; end + def show; end + + def edit + end def new @sponsor = @conference.sponsors.new @@ -27,8 +32,8 @@ module Admin def update if @sponsor.update_attributes(sponsor_params) - redirect_to admin_conference_sponsors_path( - conference_id: @conference.short_title), + redirect_to admin_conference_sponsor_path( + conference_id: @conference.short_title, id: @sponsor.id), notice: 'Sponsor successfully updated.' else flash.now[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}." @@ -47,10 +52,15 @@ module Admin end end + def generate_swags_hash(type, quantity) + swags_hash[type.to_s] = quantity.to_i + end + private def sponsor_params - params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id) + params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, + :payed, :swags, :swags_received, :company_address, :vat_registration, :has_banner) end def sponsorship_level_required diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml new file mode 100644 index 00000000..000ad4fe --- /dev/null +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -0,0 +1,20 @@ +.row + .col-md-12 + .page-header + %h1 + Edit + = @sponsor.name +.row + .col-md-8 + = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| + = f.input :name + = f.input :description + = f.input :picture + = f.input :website_url + = f.input :sponsorship_level, collection: @conference.sponsorship_levels + = f.input :company_address + = f.input :vat_registration + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture + %p.text-right + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/_form.html.haml index ba24f9f3..6221cfa2 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/_form.html.haml @@ -8,12 +8,16 @@ = @sponsor.name .row .col-md-8 - = semantic_form_for(@sponsor, url: (@sponsor.new_record? ? admin_conference_sponsors_path : admin_conference_sponsor_path(@conference.short_title, @sponsor))) do |f| + = semantic_form_for(@sponsor, url: (admin_conference_sponsors_path)) do |f| = f.input :name = f.input :description = image_tag f.object.picture.thumb.url if f.object.picture? = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels + -# = f.input :type + -# = f.input :quantity + -# - generate_swags_hash(type, quantity) + %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml new file mode 100644 index 00000000..aeb138a2 --- /dev/null +++ b/app/views/admin/sponsors/edit.html.haml @@ -0,0 +1 @@ += render 'edit_form' diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 1c8f1077..71223f17 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -21,7 +21,7 @@ %td = image_tag(sponsor.picture.thumb.url, width: '20%') %td - = sponsor.name + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) %td = truncate(sponsor.description) %td diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml new file mode 100644 index 00000000..bb0e5196 --- /dev/null +++ b/app/views/admin/sponsors/show.html.haml @@ -0,0 +1,78 @@ +.row + .col-md-12 + %h2 + = image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '') + = @sponsor.name +.row + .col-md-12 + .btn-group.pull-right + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, @sponsor), + method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, @sponsor), + method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{@sponsor.name}?" } + .col-md-12 + %table.table + %tr + %td.col-md-2 + %b Sponsorship payed? + %td + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, + method: :patch, url: payed_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + - if @sponsor.description? + %tr + %td.col-md-2 + %b Description + %td + = markdown(@sponsor.description) + %tr + %td.col-md-2 + %b Sponsorship Level + %td + = @sponsor.sponsorship_level.title + ( + = @sponsor.sponsorship_level.position + ) + %tr + %td.col-md-2 + %b Website url + %td + = link_to @sponsor.website_url, @sponsor.website_url + %tr + %td.col-md-2 + %b Has swags? + %td + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, + method: :patch, url: swags_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + - if @sponsor.company_address + %tr + %td.col-md-2 + %b Company's address + %td + = @sponsor.company_address + + - if @sponsor.vat_registration + %tr + %td.col-md-2 + %b Campany's VAT Registration Number + %td + = @sponsor.vat_registration + + - if @sponsor.swags + %tr + %td.col-md-2 + %b Swags received? + %td + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, + method: :patch, url: swags_received_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } diff --git a/config/routes.rb b/config/routes.rb index 0d7e7aec..dfa3d6e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,7 +117,14 @@ Osem::Application.routes.draw do resources :resources resources :tickets - resources :sponsors, except: [:show] + resources :sponsors do + member do + patch :payed + patch :swags + patch :swags_received + patch :has_banner + end + end resources :lodgings, except: [:show] resources :targets, except: [:show] resources :campaigns, except: [:show] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb new file mode 100644 index 00000000..31ef9a70 --- /dev/null +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -0,0 +1,10 @@ +class AddSwagsToSponsors < ActiveRecord::Migration + def change + add_column :sponsors, :payed, :boolean, default: false + add_column :sponsors, :swags, :boolean, default: false + add_column :sponsors, :swags_received, :boolean + add_column :sponsors, :company_address, :string + add_column :sponsors, :vat_registration, :string + add_column :sponsors, :has_banner, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 82f5923d..b1bb4136 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170816203325) do +ActiveRecord::Schema.define(version: 20170822173332) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -207,6 +207,9 @@ ActiveRecord::Schema.define(version: 20170816203325) do t.string "cfp_dates_updated_subject" t.text "program_schedule_public_body" t.text "cfp_dates_updated_body" + t.text "booths_acceptance_template" + t.text "booths_rejection_template" + t.string "booths_accetance_subject" t.boolean "send_on_booths_acceptance", default: false t.string "booths_acceptance_subject" t.text "booths_acceptance_body" @@ -325,11 +328,8 @@ ActiveRecord::Schema.define(version: 20170816203325) do t.integer "ticket_purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "token" end - add_index "physical_tickets", ["token"], name: "index_physical_tickets_on_token", unique: true - create_table "programs", force: :cascade do |t| t.integer "conference_id" t.integer "rating", default: 0 @@ -468,6 +468,12 @@ ActiveRecord::Schema.define(version: 20170816203325) do t.datetime "created_at" t.datetime "updated_at" t.string "picture" + t.boolean "payed", default: false + t.boolean "swags", default: false + t.boolean "swags_received" + t.string "company_address" + t.string "vat_registration" + t.boolean "has_banner", default: false end create_table "sponsorship_levels", force: :cascade do |t| From a0e1760ef1adeddcd6aed367d3cb6f65b271113a Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 23 Aug 2017 12:26:46 +0300 Subject: [PATCH 02/15] changes --- app/controllers/admin/sponsors_controller.rb | 34 ++++++++++++++- app/models/sponsor.rb | 2 + app/views/admin/sponsors/_edit_form.html.haml | 17 ++++++-- app/views/admin/sponsors/_form.html.haml | 3 -- app/views/admin/sponsors/show.html.haml | 42 +++++++++---------- config/routes.rb | 9 +--- .../20170822173332_add_swags_to_sponsors.rb | 10 ++--- db/schema.rb | 10 ++--- 8 files changed, 79 insertions(+), 48 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 5a639f52..af367250 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -4,7 +4,7 @@ module Admin load_and_authorize_resource :sponsor, through: :conference before_action :sponsorship_level_required, only: [:index, :new] - attr_accessor :type, :quantity + helper_method :generate_swags_hash def index authorize! :index, Sponsor.new(conference_id: @conference.id) @@ -53,14 +53,44 @@ module Admin end def generate_swags_hash(type, quantity) + swags_hash = Hash.new swags_hash[type.to_s] = quantity.to_i end + def get_swag_hash; end + + def paid + @sponsor.paid = !@sponsor.paid + if @sponsor.save + flash[:notice] = "Sponsor successfully updated." + else + flash[:error] = "Sponsor failed to be updated." + end + end + + def has_swag + @sponsor.has_swag = !@sponsor.has_swag + if @sponsor.save + flash[:notice] = "Sponsor successfully updated." + else + flash[:error] = "Sponsor failed to be updated." + end + end + + def swag_received + @sponsor.swag_received = !@sponsor.swag_received + if @sponsor.save + flash[:notice] = "Sponsor successfully updated." + else + flash[:error] = "Sponsor failed to be updated." + end + end + private def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :payed, :swags, :swags_received, :company_address, :vat_registration, :has_banner) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :type, :quantity) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index df687f20..c54b1f5c 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -2,6 +2,8 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference + attr_accessor :type, :quantity + has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } mount_uploader :picture, PictureUploader, mount_on: :logo_file_name diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 000ad4fe..98513372 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -2,8 +2,8 @@ .col-md-12 .page-header %h1 - Edit - = @sponsor.name + Edit + = @sponsor.name .row .col-md-8 = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| @@ -12,8 +12,17 @@ = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels - = f.input :company_address - = f.input :vat_registration + = f.input :address, label: 'Company\'s address' + = f.input :vat, label: 'VAT Registration Number' + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + = f.input :type, label: 'Swags type' + = f.input :quantity, label: 'Swags quantity', as: :number, in: 0..9999 + - generate_swags_hash(@type, @quantity) = image_tag f.object.picture.thumb.url if f.object.picture? = f.input :picture %p.text-right diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/_form.html.haml index 6221cfa2..c319e1ac 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/_form.html.haml @@ -15,9 +15,6 @@ = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels - -# = f.input :type - -# = f.input :quantity - -# - generate_swags_hash(type, quantity) %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index bb0e5196..5dd4defa 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -14,10 +14,10 @@ %table.table %tr %td.col-md-2 - %b Sponsorship payed? + %b Sponsorship paid? %td - = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, - method: :patch, url: payed_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.paid, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[paid]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', @@ -45,34 +45,34 @@ %td.col-md-2 %b Has swags? %td - = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, - method: :patch, url: swags_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - if @sponsor.company_address - %tr - %td.col-md-2 - %b Company's address - %td - = @sponsor.company_address - - if @sponsor.vat_registration - %tr - %td.col-md-2 - %b Campany's VAT Registration Number - %td - = @sponsor.vat_registration - - - if @sponsor.swags + - if @sponsor.has_swag %tr %td.col-md-2 %b Swags received? %td - = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swags, - method: :patch, url: swags_received_admin_conference_sponsor_path(@conference.short_title, @sponsor.id), + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', off_text: 'No' } + + - if @sponsor.address? + %tr + %td.col-md-2 + %b Company's address + %td + = @sponsor.address + - if @sponsor.vat? + %tr + %td.col-md-2 + %b Campany's VAT Registration Number + %td + = @sponsor.vat diff --git a/config/routes.rb b/config/routes.rb index dfa3d6e8..84b5ba89 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,14 +117,7 @@ Osem::Application.routes.draw do resources :resources resources :tickets - resources :sponsors do - member do - patch :payed - patch :swags - patch :swags_received - patch :has_banner - end - end + resources :sponsors resources :lodgings, except: [:show] resources :targets, except: [:show] resources :campaigns, except: [:show] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 31ef9a70..32adf654 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -1,10 +1,10 @@ class AddSwagsToSponsors < ActiveRecord::Migration def change - add_column :sponsors, :payed, :boolean, default: false - add_column :sponsors, :swags, :boolean, default: false - add_column :sponsors, :swags_received, :boolean - add_column :sponsors, :company_address, :string - add_column :sponsors, :vat_registration, :string + add_column :sponsors, :paid, :boolean, default: false + add_column :sponsors, :has_swag, :boolean, default: false + add_column :sponsors, :swag_received, :boolean + add_column :sponsors, :address, :string + add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false end end diff --git a/db/schema.rb b/db/schema.rb index b1bb4136..790527bb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -468,11 +468,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "created_at" t.datetime "updated_at" t.string "picture" - t.boolean "payed", default: false - t.boolean "swags", default: false - t.boolean "swags_received" - t.string "company_address" - t.string "vat_registration" + t.boolean "paid", default: false + t.boolean "has_swag", default: false + t.boolean "swag_received" + t.string "address" + t.string "vat" t.boolean "has_banner", default: false end From 4843021971784e12b964607c2681f295560e2faf Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 23 Aug 2017 23:08:58 +0300 Subject: [PATCH 03/15] multiple swags [wip] --- .rubocop_todo.yml | 1 + app/controllers/admin/sponsors_controller.rb | 21 +++++++++++-------- app/views/admin/sponsors/_edit_form.html.haml | 5 ++--- app/views/admin/sponsors/_swags.erb | 7 +++++++ 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 app/views/admin/sponsors/_swags.erb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a91f2ae9..6d74b5ff 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -585,6 +585,7 @@ Style/PredicateName: - 'spec/**/*' - 'app/models/comment.rb' - 'app/models/contact.rb' + - 'app/controllers/admin/sponsors_controller' # Offense count: 1 # Cop supports --auto-correct. diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index af367250..1c2147dc 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -12,8 +12,7 @@ module Admin def show; end - def edit - end + def edit; end def new @sponsor = @conference.sponsors.new @@ -52,8 +51,12 @@ module Admin end end + def add_swag + swags_hash = @sponsor.swags_hash + end + def generate_swags_hash(type, quantity) - swags_hash = Hash.new + swags_hash = {} swags_hash[type.to_s] = quantity.to_i end @@ -62,27 +65,27 @@ module Admin def paid @sponsor.paid = !@sponsor.paid if @sponsor.save - flash[:notice] = "Sponsor successfully updated." + flash[:notice] = 'Sponsor successfully updated.' else - flash[:error] = "Sponsor failed to be updated." + flash[:error] = 'Sponsor failed to be updated.' end end def has_swag @sponsor.has_swag = !@sponsor.has_swag if @sponsor.save - flash[:notice] = "Sponsor successfully updated." + flash[:notice] = 'Sponsor successfully updated.' else - flash[:error] = "Sponsor failed to be updated." + flash[:error] = 'Sponsor failed to be updated.' end end def swag_received @sponsor.swag_received = !@sponsor.swag_received if @sponsor.save - flash[:notice] = "Sponsor successfully updated." + flash[:notice] = 'Sponsor successfully updated.' else - flash[:error] = "Sponsor failed to be updated." + flash[:error] = 'Sponsor failed to be updated.' end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 98513372..d55fe311 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -20,9 +20,8 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - = f.input :type, label: 'Swags type' - = f.input :quantity, label: 'Swags quantity', as: :number, in: 0..9999 - - generate_swags_hash(@type, @quantity) + + = image_tag f.object.picture.thumb.url if f.object.picture? = f.input :picture %p.text-right diff --git a/app/views/admin/sponsors/_swags.erb b/app/views/admin/sponsors/_swags.erb new file mode 100644 index 00000000..ef3ac6a1 --- /dev/null +++ b/app/views/admin/sponsors/_swags.erb @@ -0,0 +1,7 @@ +
+ <%= f.inputs do %> + <%= f.input :type, label: 'Swags type' %> + <%= f.input :quantity, label: 'Swags quantity', as: :number, in: 0..9999 %> + <%- generate_swags_hash(@type, @quantity) %> + <% end %> +
From 93f7e07ebe63f4f103b6c25bf3ff93d0ae0a4ccd Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 25 Aug 2017 00:43:28 +0300 Subject: [PATCH 04/15] wip --- app/controllers/admin/sponsors_controller.rb | 20 ++++++++++++---- app/models/sponsor.rb | 3 ++- app/views/admin/sponsors/_edit_form.html.haml | 24 +++++++++++++------ app/views/admin/sponsors/show.html.haml | 14 +++++++++++ .../20170822173332_add_swags_to_sponsors.rb | 1 + db/schema.rb | 9 +++++-- 6 files changed, 56 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 1c2147dc..080b0b99 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -10,9 +10,14 @@ module Admin authorize! :index, Sponsor.new(conference_id: @conference.id) end - def show; end + def show + @sponsor.swag_index = @sponsor.swag_hash.length + end - def edit; end + def edit + @sponsor.swag_index = @sponsor.swag_hash.length + @sponsor.swag_hash = @sponsor.swag_hash + end def new @sponsor = @conference.sponsors.new @@ -30,6 +35,7 @@ module Admin end def update + if @sponsor.update_attributes(sponsor_params) redirect_to admin_conference_sponsor_path( conference_id: @conference.short_title, id: @sponsor.id), @@ -56,8 +62,12 @@ module Admin end def generate_swags_hash(type, quantity) - swags_hash = {} - swags_hash[type.to_s] = quantity.to_i + unless @sponsor.swag_hash + @sponsor.swag_hash = {} + end + + @sponsor.swag_hash[type.to_s] = quantity.to_i + @sponsor.update_attribute(:swag_hash, @sponsor.swag_hash) end def get_swag_hash; end @@ -93,7 +103,7 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :type, :quantity) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_hash, :type, :quantity, :swag_index) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index c54b1f5c..133d8dd2 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -2,7 +2,8 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - attr_accessor :type, :quantity + serialize :swag_hash, Hash + attr_accessor :type, :quantity, :swag_index has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index d55fe311..9ceb326f 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -4,25 +4,35 @@ %h1 Edit = @sponsor.name + = @sponsor.swag_index .row .col-md-8 = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| = f.input :name - = f.input :description + = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels = f.input :address, label: 'Company\'s address' = f.input :vat, label: 'VAT Registration Number' + %b Has Swags? = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", class: 'switch-checkbox', data: { size: 'small', off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - - = image_tag f.object.picture.thumb.url if f.object.picture? - = f.input :picture - %p.text-right - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + - @sponsor.swag_hash.each do |type, quantity| + .row + .col-md-6 + = f.input :type, label: 'Swag type' + .col-md-6 + = f.input :quantity, as: :number, in: 0..9999 + - generate_swags_hash(@type, @quantity) + = f.submit 'Add Swag', :type + .row + .col-md-8 + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture + %p.text-right + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 5dd4defa..abd47b3e 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -63,6 +63,20 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } + - if @sponsor.swag_index > 0 + %tr + %td.col-md-2 + %b Swag's Type + %td + %b Quantity + %tr + - @sponsor.swag_hash.each do |key, value| + %td.col-md-2 + = key + %td + = value + + - if @sponsor.address? %tr diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 32adf654..41811351 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -6,5 +6,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :address, :string add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false + add_column :sponsors, :swag_hash, :text end end diff --git a/db/schema.rb b/db/schema.rb index 790527bb..dad230b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -127,8 +127,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 - t.string "custom_domain" t.integer "booth_limit", default: 0 + t.string "custom_domain" end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" @@ -468,12 +468,18 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "created_at" t.datetime "updated_at" t.string "picture" + t.boolean "payed", default: false + t.boolean "swags", default: false + t.boolean "swags_received" + t.string "company_address" + t.string "vat_registration" t.boolean "paid", default: false t.boolean "has_swag", default: false t.boolean "swag_received" t.string "address" t.string "vat" t.boolean "has_banner", default: false + t.text "swag_hash" end create_table "sponsorship_levels", force: :cascade do |t| @@ -583,7 +589,6 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.boolean "is_admin", default: false t.string "username" t.boolean "is_disabled", default: false - t.string "token" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true From e55509183c9ab664607b3b25b4dbb37179a777db Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 25 Aug 2017 20:04:19 +0300 Subject: [PATCH 05/15] move swag fields to partial --- app/controllers/admin/sponsors_controller.rb | 7 ------- app/models/sponsor.rb | 11 ++++++++++- app/views/admin/sponsors/_edit_form.html.haml | 14 ++++++-------- app/views/admin/sponsors/_swag_fields.html.haml | 5 +++++ app/views/admin/sponsors/_swags.erb | 7 ------- 5 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 app/views/admin/sponsors/_swag_fields.html.haml delete mode 100644 app/views/admin/sponsors/_swags.erb diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 080b0b99..e3431baf 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -61,14 +61,7 @@ module Admin swags_hash = @sponsor.swags_hash end - def generate_swags_hash(type, quantity) - unless @sponsor.swag_hash - @sponsor.swag_hash = {} - end - @sponsor.swag_hash[type.to_s] = quantity.to_i - @sponsor.update_attribute(:swag_hash, @sponsor.swag_hash) - end def get_swag_hash; end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 133d8dd2..e4be27f0 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -3,11 +3,20 @@ class Sponsor < ActiveRecord::Base belongs_to :conference serialize :swag_hash, Hash - attr_accessor :type, :quantity, :swag_index + attr_accessor :type, :quantity, :swag_index, :hint_hash has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates :name, :website_url, :sponsorship_level, presence: true + + def generate_swags_hash(type, quantity) + unless swag_hash + swag_hash = {} + end + + swag_hash[type.to_s] = quantity.to_i + update_attribute(:swag_hash, @sponsor.swag_hash) + end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 9ceb326f..0855aefa 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -22,14 +22,12 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - @sponsor.swag_hash.each do |type, quantity| - .row - .col-md-6 - = f.input :type, label: 'Swag type' - .col-md-6 - = f.input :quantity, as: :number, in: 0..9999 - - generate_swags_hash(@type, @quantity) - = f.submit 'Add Swag', :type + + - @sponsor.swag_hash.each_with_index do |k, v, index| + =render partial: 'swag_fields', locals: {f: f, index: index} + + + .row .col-md-8 = image_tag f.object.picture.thumb.url if f.object.picture? diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml new file mode 100644 index 00000000..98eeb9af --- /dev/null +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -0,0 +1,5 @@ +.row + .col-md-6 + = text_field_tag "sponsor[swag_hash][#{index}][type]" + .col-md-6 + = text_field_tag "sponsor[swag_hash][#{index}][quantity]" diff --git a/app/views/admin/sponsors/_swags.erb b/app/views/admin/sponsors/_swags.erb deleted file mode 100644 index ef3ac6a1..00000000 --- a/app/views/admin/sponsors/_swags.erb +++ /dev/null @@ -1,7 +0,0 @@ -
- <%= f.inputs do %> - <%= f.input :type, label: 'Swags type' %> - <%= f.input :quantity, label: 'Swags quantity', as: :number, in: 0..9999 %> - <%- generate_swags_hash(@type, @quantity) %> - <% end %> -
From 2042d0eb7a56839109707c96b66c6eb768886fe3 Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 25 Aug 2017 23:42:14 +0300 Subject: [PATCH 06/15] Fix swag partial --- app/views/admin/sponsors/_edit_form.html.haml | 5 ++--- app/views/admin/sponsors/_swag_fields.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 0855aefa..1165f971 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -23,10 +23,9 @@ on_text: 'Yes', off_text: 'No' } - - @sponsor.swag_hash.each_with_index do |k, v, index| + - @sponsor.swag_hash.each_with_index do |hash, index| =render partial: 'swag_fields', locals: {f: f, index: index} - - + =render partial: 'swag_fields', locals: { f: f, index: @sponsor.swag_index} .row .col-md-8 diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml index 98eeb9af..b925e0c5 100644 --- a/app/views/admin/sponsors/_swag_fields.html.haml +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -1,5 +1,5 @@ .row .col-md-6 - = text_field_tag "sponsor[swag_hash][#{index}][type]" + = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swag_hash][#{index}][type]"} .col-md-6 - = text_field_tag "sponsor[swag_hash][#{index}][quantity]" + = f.input :quantity, input_html: { name: "sponsor[swag_hash][#{index}][quantity]"} From 4381f687b673ee267e0d8416ed6f1d5800f83996 Mon Sep 17 00:00:00 2001 From: nasia Date: Sat, 26 Aug 2017 20:41:36 +0300 Subject: [PATCH 07/15] Swags stored correctly --- app/controllers/admin/sponsors_controller.rb | 10 +++++----- app/models/sponsor.rb | 11 +---------- app/views/admin/sponsors/_edit_form.html.haml | 7 +++---- app/views/admin/sponsors/_swag_fields.html.haml | 4 ++-- app/views/admin/sponsors/show.html.haml | 8 ++++---- db/migrate/20170822173332_add_swags_to_sponsors.rb | 2 +- db/schema.rb | 4 ++-- 7 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index e3431baf..ae2e3fbb 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -11,12 +11,12 @@ module Admin end def show - @sponsor.swag_index = @sponsor.swag_hash.length + @sponsor.swag_index = @sponsor.swags.length end def edit - @sponsor.swag_index = @sponsor.swag_hash.length - @sponsor.swag_hash = @sponsor.swag_hash + @sponsor.swag_index = @sponsor.swags.length + @sponsor.swags = @sponsor.swags end def new @@ -63,7 +63,7 @@ module Admin - def get_swag_hash; end + def get_swags; end def paid @sponsor.paid = !@sponsor.paid @@ -96,7 +96,7 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_hash, :type, :quantity, :swag_index) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, swags: [:type, :quantity]) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index e4be27f0..6f670740 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -2,7 +2,7 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - serialize :swag_hash, Hash + serialize :swags, Hash attr_accessor :type, :quantity, :swag_index, :hint_hash has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } @@ -10,13 +10,4 @@ class Sponsor < ActiveRecord::Base mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates :name, :website_url, :sponsorship_level, presence: true - - def generate_swags_hash(type, quantity) - unless swag_hash - swag_hash = {} - end - - swag_hash[type.to_s] = quantity.to_i - update_attribute(:swag_hash, @sponsor.swag_hash) - end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 1165f971..5a24f4cf 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -22,10 +22,9 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - - @sponsor.swag_hash.each_with_index do |hash, index| - =render partial: 'swag_fields', locals: {f: f, index: index} - =render partial: 'swag_fields', locals: { f: f, index: @sponsor.swag_index} + - @sponsor.swags.each_with_index do |(key, value), index| + =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} + =render partial: 'swag_fields', locals: { f: f, index: @sponsor.swag_index, v_type: nil, v_quantity: 0} .row .col-md-8 diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml index b925e0c5..5cd9d154 100644 --- a/app/views/admin/sponsors/_swag_fields.html.haml +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -1,5 +1,5 @@ .row .col-md-6 - = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swag_hash][#{index}][type]"} + = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swags][#{index}][type]", value: v_type } .col-md-6 - = f.input :quantity, input_html: { name: "sponsor[swag_hash][#{index}][quantity]"} + = f.input :quantity, as: :number, in: 0...999, input_html: { name: "sponsor[swags][#{index}][quantity]", value: v_quantity} diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index abd47b3e..6cb0adf9 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -69,12 +69,12 @@ %b Swag's Type %td %b Quantity - %tr - - @sponsor.swag_hash.each do |key, value| + - @sponsor.swags.each do |key, value| + %tr %td.col-md-2 - = key + = value[:type] %td - = value + = value[:quantity] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 41811351..68303239 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -6,6 +6,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :address, :string add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false - add_column :sponsors, :swag_hash, :text + add_column :sponsors, :swags, :text end end diff --git a/db/schema.rb b/db/schema.rb index dad230b7..34f37a5f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -469,17 +469,17 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "updated_at" t.string "picture" t.boolean "payed", default: false - t.boolean "swags", default: false t.boolean "swags_received" t.string "company_address" t.string "vat_registration" + t.text "swag_hash" t.boolean "paid", default: false t.boolean "has_swag", default: false t.boolean "swag_received" t.string "address" t.string "vat" t.boolean "has_banner", default: false - t.text "swag_hash" + t.text "swags" end create_table "sponsorship_levels", force: :cascade do |t| From b770f9bd4dfcf377ac99388157ce4ece07e108d7 Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 27 Aug 2017 00:25:29 +0300 Subject: [PATCH 08/15] Add tabs to sponsor#index --- app/controllers/admin/sponsors_controller.rb | 6 +- app/views/admin/sponsors/_edit_form.html.haml | 1 - app/views/admin/sponsors/index.html.haml | 122 +++++++++++++----- 3 files changed, 94 insertions(+), 35 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index ae2e3fbb..da687124 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -4,7 +4,7 @@ module Admin load_and_authorize_resource :sponsor, through: :conference before_action :sponsorship_level_required, only: [:index, :new] - helper_method :generate_swags_hash + helper_method :add_swags def index authorize! :index, Sponsor.new(conference_id: @conference.id) @@ -57,8 +57,8 @@ module Admin end end - def add_swag - swags_hash = @sponsor.swags_hash + def add_swags(form, index) + render partial: 'swag_fields', locals: { f: form, index: (index + 1), v_type: nil, v_quantity: 0} end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml index 5a24f4cf..c5a65195 100644 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ b/app/views/admin/sponsors/_edit_form.html.haml @@ -24,7 +24,6 @@ off_text: 'No' } - @sponsor.swags.each_with_index do |(key, value), index| =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} - =render partial: 'swag_fields', locals: { f: f, index: @sponsor.swag_index, v_type: nil, v_quantity: 0} .row .col-md-8 diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 71223f17..0283e346 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -4,36 +4,96 @@ %h1 Sponsors %p.text-muted People supporting your conference -- if @conference.sponsors.any? - .row - .col-md-12 - %table.table.table-hover#sponsors - %thead - %th Logo - %th Name - %th Description - %th URL - %th Level - %th Actions - %tbody - - @conference.sponsors.each do |sponsor| - %tr - %td - = image_tag(sponsor.picture.thumb.url, width: '20%') - %td - = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) - %td - = truncate(sponsor.description) - %td - = sponsor.website_url - %td - = sponsor.sponsorship_level.title - %td - .btn-group - = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-primary' - = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } .row .col-md-12 - = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' + %div{ role: 'tabpanel' } + %ul.nav.nav-tabs{ role: 'tablist' } + %li.active{ role: 'presentation'} + %a{ 'aria-controls' => 'sponsorship', 'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship + %li{ role: 'Swags'} + %a{ 'aria-controls' => 'swags','data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + .tab-content + #sponsorship.tab-pane.active{ role: 'tabpanel' } + - if @conference.sponsors.any? + .row + .col-md-12 + %table.table.table-hover#sponsors + %thead + %th Logo + %th Name + %th Description + %th URL + %th Level + %th Actions + %tbody + - @conference.sponsors.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + + #swags.tab-pane.active{ role: 'tabpanel' } + - if @conference.sponsors.any? + .row + .col-md-12 + %table.table.table-hover#sponsors + %thead + %th Logo + %th Name + %th Banner + %th Swags + %th Swag Items + %th Received + %th Actions + %tbody + - @conference.sponsors.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + - if sponsor.has_banner + %span.fa.fa-check.text-success + - else + %span.fa.fa-times + %td + - if sponsor.has_swag + %span.fa.fa-check.text-success + - else + %span.fa.fa-times + %td + - if sponsor.has_swag + - sponsor.swags.each do |key, value| + = value[:type] + ( + = value[:quantity] + ) + %br + %td + - if sponsor.swag_received + %span.fa.fa-check.text-success + - else + %span.fa.fa-times + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + .row + .col-md-12 + = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' From 792a7fed1c9adf31f839154a1ad2d83f3a1862c4 Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 27 Aug 2017 15:42:52 +0300 Subject: [PATCH 09/15] Add confirmed sponsors --- app/controllers/admin/sponsors_controller.rb | 25 +++++- app/models/sponsor.rb | 23 +++++ app/views/admin/sponsors/_edit_form.html.haml | 33 ------- app/views/admin/sponsors/edit.html.haml | 34 ++++++- app/views/admin/sponsors/index.html.haml | 89 +++++++++++++++---- .../{_form.html.haml => new.html.haml} | 2 +- app/views/admin/sponsors/show.html.haml | 5 +- config/routes.rb | 7 +- .../20170822173332_add_swags_to_sponsors.rb | 2 + db/schema.rb | 7 +- 10 files changed, 162 insertions(+), 65 deletions(-) delete mode 100644 app/views/admin/sponsors/_edit_form.html.haml rename app/views/admin/sponsors/{_form.html.haml => new.html.haml} (85%) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index da687124..93fd32af 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -57,13 +57,32 @@ module Admin end end - def add_swags(form, index) - render partial: 'swag_fields', locals: { f: form, index: (index + 1), v_type: nil, v_quantity: 0} + def add_swags() + @sponsor.update_attributes(sponsor_params) + redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor) end + def confirm + @sponsor.confirm! + if @sponsor.save + redirect_to admin_conference_sponsors_path(@conference.short_title), + notice: 'Sponsor successfully confirmed!' + else + flash[:error] = 'Sponsor couldn\' t be confirmed.' + end + end - def get_swags; end + def cancel + @sponsor.cancel! + + if @sponsor.save + redirect_to admin_conference_sponsors_path(@conference.short_title), + notice: 'Sponsor successfully canceled' + else + flash[:error] = 'Sponsor couldn\'t be canceled' + end + end def paid @sponsor.paid = !@sponsor.paid diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 6f670740..c5fa0dd0 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -1,4 +1,6 @@ class Sponsor < ActiveRecord::Base + include ActiveRecord::Transitions + belongs_to :sponsorship_level belongs_to :conference @@ -10,4 +12,25 @@ class Sponsor < ActiveRecord::Base mount_uploader :picture, PictureUploader, mount_on: :logo_file_name validates :name, :website_url, :sponsorship_level, presence: true + + scope :confirmed, -> { where(state: 'confirmed') } + scope :unconfirmed, -> { where(state: 'uncofirmed') } + + state_machine initial: :uncofirmed do + state :uncofirmed + state :confirmed + + + event :confirm do + transitions to: :confirmed, from: [:uncofirmed] + end + + event :cancel do + transitions to: :uncofirmed, from: [:confirmed] + end + end + + def transition_possible?(transition) + self.class.state_machine.events_for(current_state).include?(transition) + end end diff --git a/app/views/admin/sponsors/_edit_form.html.haml b/app/views/admin/sponsors/_edit_form.html.haml deleted file mode 100644 index c5a65195..00000000 --- a/app/views/admin/sponsors/_edit_form.html.haml +++ /dev/null @@ -1,33 +0,0 @@ -.row - .col-md-12 - .page-header - %h1 - Edit - = @sponsor.name - = @sponsor.swag_index -.row - .col-md-8 - = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| - = f.input :name - = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } - = f.input :picture - = f.input :website_url - = f.input :sponsorship_level, collection: @conference.sponsorship_levels - = f.input :address, label: 'Company\'s address' - = f.input :vat, label: 'VAT Registration Number' - %b Has Swags? - = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, - method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", - class: 'switch-checkbox', data: { size: 'small', - off_color: 'warning', - on_text: 'Yes', - off_text: 'No' } - - @sponsor.swags.each_with_index do |(key, value), index| - =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} - - .row - .col-md-8 - = image_tag f.object.picture.thumb.url if f.object.picture? - = f.input :picture - %p.text-right - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index aeb138a2..f7f1f0bd 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -1 +1,33 @@ -= render 'edit_form' +.row + .col-md-12 + .page-header + %h1 + Edit + = @sponsor.name + = @sponsor.swag_index +.row + .col-md-8 + = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| + = f.input :name + = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } + = f.input :picture + = f.input :website_url + = f.input :sponsorship_level, collection: @conference.sponsorship_levels + = f.input :address, label: 'Company\'s address' + = f.input :vat, label: 'VAT Registration Number' + %b Has Swags? + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + - @sponsor.swags.each_with_index do |(key, value), index| + =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} + =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, v_type: nil, v_quantity: 0} + .row + .col-md-8 + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture + %p.text-right + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 0283e346..e104b170 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -7,14 +7,17 @@ .row .col-md-12 %div{ role: 'tabpanel' } - %ul.nav.nav-tabs{ role: 'tablist' } - %li.active{ role: 'presentation'} - %a{ 'aria-controls' => 'sponsorship', 'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship - %li{ role: 'Swags'} - %a{ 'aria-controls' => 'swags','data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + %ul.nav.nav-tabs + %li.active + %a{'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship + %li + %a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + %li + %a{'data-toggle' => 'tab', href: '#uncofirmed', role: 'tab'} Unconfirmed + .tab-content - #sponsorship.tab-pane.active{ role: 'tabpanel' } - - if @conference.sponsors.any? + #sponsorship.tab-pane.active + - if @conference.sponsors.confirmed.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -26,7 +29,7 @@ %th Level %th Actions %tbody - - @conference.sponsors.each do |sponsor| + - @conference.sponsors.confirmed.each do |sponsor| %tr %td = image_tag(sponsor.picture.thumb.url, width: '20%') @@ -41,12 +44,18 @@ %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-primary' + method: :get, class: 'btn btn-mini btn-primary' = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' - #swags.tab-pane.active{ role: 'tabpanel' } - - if @conference.sponsors.any? + #swags.tab-pane + - if @conference.sponsors.confirmed.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -59,7 +68,7 @@ %th Received %th Actions %tbody - - @conference.sponsors.each do |sponsor| + - @conference.sponsors.confirmed.each do |sponsor| %tr %td = image_tag(sponsor.picture.thumb.url, width: '20%') @@ -69,12 +78,12 @@ - if sponsor.has_banner %span.fa.fa-check.text-success - else - %span.fa.fa-times + %span.fa.fa-times.text-danger %td - if sponsor.has_swag %span.fa.fa-check.text-success - else - %span.fa.fa-times + %span.fa.fa-times.text-danger %td - if sponsor.has_swag - sponsor.swags.each do |key, value| @@ -91,9 +100,55 @@ %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-primary' + method: :get, class: 'btn btn-mini btn-primary' = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + + .tab-content + #unconfirmed.tab-pane + - if @conference.sponsors.unconfirmed.any? + .row + .col-md-12 + %table.table.table-hover#sponsors + %thead + %th Logo + %th Name + %th Description + %th URL + %th Level + %th Actions + %tbody + - @conference.sponsors.unconfirmed.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + .row .col-md-12 = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/new.html.haml similarity index 85% rename from app/views/admin/sponsors/_form.html.haml rename to app/views/admin/sponsors/new.html.haml index c319e1ac..5fbeed31 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/new.html.haml @@ -10,7 +10,7 @@ .col-md-8 = semantic_form_for(@sponsor, url: (admin_conference_sponsors_path)) do |f| = f.input :name - = f.input :description + = f.input :description, input_html: { rows: 7, data: { provide: 'markdown-editable' } } = image_tag f.object.picture.thumb.url if f.object.picture? = f.input :picture = f.input :website_url diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 6cb0adf9..abeaace8 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -43,7 +43,7 @@ = link_to @sponsor.website_url, @sponsor.website_url %tr %td.col-md-2 - %b Has swags? + %b Has swag? %td = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[has_swag]=", @@ -75,9 +75,6 @@ = value[:type] %td = value[:quantity] - - - - if @sponsor.address? %tr %td.col-md-2 diff --git a/config/routes.rb b/config/routes.rb index 84b5ba89..8d2f7099 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,7 +117,12 @@ Osem::Application.routes.draw do resources :resources resources :tickets - resources :sponsors + resources :sponsors do + member do + patch :confirm + patch :cancel + end + end resources :lodgings, except: [:show] resources :targets, except: [:show] resources :campaigns, except: [:show] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 68303239..d4901066 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -7,5 +7,7 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false add_column :sponsors, :swags, :text + add_column :sponsors, :courrier_info, :text + add_column :sponsors, :state, :string end end diff --git a/db/schema.rb b/db/schema.rb index 34f37a5f..e6c03e37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -468,11 +468,6 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "created_at" t.datetime "updated_at" t.string "picture" - t.boolean "payed", default: false - t.boolean "swags_received" - t.string "company_address" - t.string "vat_registration" - t.text "swag_hash" t.boolean "paid", default: false t.boolean "has_swag", default: false t.boolean "swag_received" @@ -480,6 +475,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.string "vat" t.boolean "has_banner", default: false t.text "swags" + t.text "courrier_info" + t.string "state" end create_table "sponsorship_levels", force: :cascade do |t| From 30e70cc5d61c7360df5b3d47a8f4c6a9dd45d08e Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 27 Aug 2017 23:40:32 +0300 Subject: [PATCH 10/15] add courier info --- app/controllers/admin/sponsors_controller.rb | 17 +-- app/models/sponsor.rb | 15 ++- .../admin/sponsors/_courier_fields.html.haml | 7 ++ .../admin/sponsors/_swag_fields.html.haml | 4 +- app/views/admin/sponsors/edit.html.haml | 10 +- app/views/admin/sponsors/index.html.haml | 109 +++++++++--------- app/views/admin/sponsors/show.html.haml | 58 +++++++--- .../20170822173332_add_swags_to_sponsors.rb | 4 +- db/schema.rb | 14 +-- spec/features/sponsor_spec.rb | 3 +- 10 files changed, 146 insertions(+), 95 deletions(-) create mode 100644 app/views/admin/sponsors/_courier_fields.html.haml diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 93fd32af..de7e293b 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -11,12 +11,13 @@ module Admin end def show - @sponsor.swag_index = @sponsor.swags.length + @sponsor.swag_index = @sponsor.swag.length + @sponsor.courier_index = @sponsor.courier_info.length end def edit - @sponsor.swag_index = @sponsor.swags.length - @sponsor.swags = @sponsor.swags + @sponsor.swag_index = @sponsor.swag.length + @sponsor.courier_index = @sponsor.courier_info.length end def new @@ -35,7 +36,6 @@ module Admin end def update - if @sponsor.update_attributes(sponsor_params) redirect_to admin_conference_sponsor_path( conference_id: @conference.short_title, id: @sponsor.id), @@ -57,7 +57,7 @@ module Admin end end - def add_swags() + def add_swags @sponsor.update_attributes(sponsor_params) redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor) end @@ -67,7 +67,7 @@ module Admin if @sponsor.save redirect_to admin_conference_sponsors_path(@conference.short_title), - notice: 'Sponsor successfully confirmed!' + notice: 'Sponsor successfully confirmed!' else flash[:error] = 'Sponsor couldn\' t be confirmed.' end @@ -78,7 +78,7 @@ module Admin if @sponsor.save redirect_to admin_conference_sponsors_path(@conference.short_title), - notice: 'Sponsor successfully canceled' + notice: 'Sponsor successfully canceled' else flash[:error] = 'Sponsor couldn\'t be canceled' end @@ -115,7 +115,8 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, swags: [:type, :quantity]) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, :courier_index, + swags: [:type, :quantity], courier_info: [:courier_name, :tracking_number, :boxes]) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index c5fa0dd0..2cca5df2 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -5,7 +5,10 @@ class Sponsor < ActiveRecord::Base belongs_to :conference serialize :swags, Hash - attr_accessor :type, :quantity, :swag_index, :hint_hash + serialize :courier_info, Hash + + attr_accessor :type, :quantity, :swag_index, :courier_index, + :courier_name, :tracking_number, :boxes has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } @@ -14,19 +17,19 @@ class Sponsor < ActiveRecord::Base validates :name, :website_url, :sponsorship_level, presence: true scope :confirmed, -> { where(state: 'confirmed') } - scope :unconfirmed, -> { where(state: 'uncofirmed') } + scope :unconfirmed, -> { where(state: 'unconfirmed') } - state_machine initial: :uncofirmed do - state :uncofirmed + state_machine initial: :unconfirmed do + state :unconfirmed state :confirmed event :confirm do - transitions to: :confirmed, from: [:uncofirmed] + transitions to: :confirmed, from: [:unconfirmed] end event :cancel do - transitions to: :uncofirmed, from: [:confirmed] + transitions to: :unconfirmed, from: [:confirmed] end end diff --git a/app/views/admin/sponsors/_courier_fields.html.haml b/app/views/admin/sponsors/_courier_fields.html.haml new file mode 100644 index 00000000..232942e8 --- /dev/null +++ b/app/views/admin/sponsors/_courier_fields.html.haml @@ -0,0 +1,7 @@ +.row + .col-md-4 + = f.input :courrier_name, label: 'Courier\'s name', input_html: { name: "sponsor[courier_info][#{index}][courier_name]", value: name_value } + .col-md-4 + = f.input :tracking_number, input_html: { name: "sponsor[courier_info][#{index}][tracking_number]", value: tracking_value} + .col-md-4 + = f.input :boxes, as: :number, in: 0...999, label: 'Number of boxes', input_html: { name: "sponsor[courier_info][#{index}][boxes]", value: boxes_value } diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml index 5cd9d154..1c73b03e 100644 --- a/app/views/admin/sponsors/_swag_fields.html.haml +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -1,5 +1,5 @@ .row .col-md-6 - = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swags][#{index}][type]", value: v_type } + = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swags][#{index}][type]", value: type_value } .col-md-6 - = f.input :quantity, as: :number, in: 0...999, input_html: { name: "sponsor[swags][#{index}][quantity]", value: v_quantity} + = f.input :quantity, as: :number, in: 0...999, input_html: { name: "sponsor[swags][#{index}][quantity]", value: quantity_value} diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index f7f1f0bd..304e3a51 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -4,7 +4,6 @@ %h1 Edit = @sponsor.name - = @sponsor.swag_index .row .col-md-8 = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| @@ -23,8 +22,13 @@ on_text: 'Yes', off_text: 'No' } - @sponsor.swags.each_with_index do |(key, value), index| - =render partial: 'swag_fields', locals: {f: f, index: index, v_type: value[:type].to_s, v_quantity: value[:quantity].to_i} - =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, v_type: nil, v_quantity: 0} + =render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i} + =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil} + + - @sponsor.courier_info.each_with_index do |(key, value), index| + =render partial: 'courier_fields', locals: {f: f, index: index, name_value: value[:courier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} + =render partial: 'courier_fields', locals: {f: f, index: @sponsor.courier_index, name_value: nil, tracking_value: nil, boxes_value: nil} + .row .col-md-8 = image_tag f.object.picture.thumb.url if f.object.picture? diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index e104b170..5536f756 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -13,19 +13,18 @@ %li %a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags %li - %a{'data-toggle' => 'tab', href: '#uncofirmed', role: 'tab'} Unconfirmed + %a{'data-toggle' => 'tab', href: '#unconfirmed', role: 'tab'} Unconfirmed .tab-content #sponsorship.tab-pane.active - if @conference.sponsors.confirmed.any? .row .col-md-12 - %table.table.table-hover#sponsors + %table.table.table-hover#sponsorship %thead %th Logo %th Name - %th Description - %th URL + %th Payment %th Level %th Actions %tbody @@ -36,9 +35,10 @@ %td = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) %td - = truncate(sponsor.description) - %td - = sponsor.website_url + - if sponsor.payed + %span.fa.fa-check.text-success + - else + %span.fa.fa-times.text-danger %td = sponsor.sponsorship_level.title %td @@ -52,13 +52,14 @@ method: :patch, class: 'btn btn-mini btn-success' - if sponsor.transition_possible? :cancel = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-default' - + method: :patch, class: 'btn btn-mini btn-warning' + - else + %p No confirmed sponsors yet! #swags.tab-pane - if @conference.sponsors.confirmed.any? .row .col-md-12 - %table.table.table-hover#sponsors + %table.table.table-hover#swags %thead %th Logo %th Name @@ -71,7 +72,8 @@ - @conference.sponsors.confirmed.each do |sponsor| %tr %td - = image_tag(sponsor.picture.thumb.url, width: '20%') + - if sponsor.picture? + = image_tag(sponsor.picture.thumb.url, width: '20%') %td = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) %td @@ -96,7 +98,7 @@ - if sponsor.swag_received %span.fa.fa-check.text-success - else - %span.fa.fa-times + %span.fa.fa-times.text-danger %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), @@ -108,47 +110,48 @@ method: :patch, class: 'btn btn-mini btn-success' - if sponsor.transition_possible? :cancel = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-default' - - .tab-content - #unconfirmed.tab-pane - - if @conference.sponsors.unconfirmed.any? - .row - .col-md-12 - %table.table.table-hover#sponsors - %thead - %th Logo - %th Name - %th Description - %th URL - %th Level - %th Actions - %tbody - - @conference.sponsors.unconfirmed.each do |sponsor| - %tr - %td - = image_tag(sponsor.picture.thumb.url, width: '20%') - %td - = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) - %td - = truncate(sponsor.description) - %td - = sponsor.website_url - %td - = sponsor.sponsorship_level.title - %td - .btn-group - = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-mini btn-primary' - = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } - - if sponsor.transition_possible? :confirm - = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-success' - - if sponsor.transition_possible? :cancel - = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-default' - + method: :patch, class: 'btn btn-mini btn-warning' + - else + %p No confirmed sponsors yet! + #unconfirmed.tab-pane + - if @conference.sponsors.unconfirmed.any? + .row + .col-md-12 + %table.table.table-hover#unconfirmed + %thead + %th Logo + %th Name + %th Description + %th URL + %th Level + %th Actions + %tbody + - @conference.sponsors.unconfirmed.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-warning' + - else + %p There are no unconfirmed sponsors .row .col-md-12 = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index abeaace8..6be3281a 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -1,7 +1,8 @@ .row .col-md-12 %h2 - = image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '') + - if @sponsor.picture? + = image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '') = @sponsor.name .row .col-md-12 @@ -41,6 +42,20 @@ %b Website url %td = link_to @sponsor.website_url, @sponsor.website_url + + + - if @sponsor.address? + %tr + %td.col-md-2 + %b Company's address + %td + = @sponsor.address + - if @sponsor.vat? + %tr + %td.col-md-2 + %b Campany's VAT Registration Number + %td + = @sponsor.vat %tr %td.col-md-2 %b Has swag? @@ -75,15 +90,32 @@ = value[:type] %td = value[:quantity] - - if @sponsor.address? - %tr - %td.col-md-2 - %b Company's address - %td - = @sponsor.address - - if @sponsor.vat? - %tr - %td.col-md-2 - %b Campany's VAT Registration Number - %td - = @sponsor.vat + %tr + %td.col-md-2 + %b Swag Received? + %td + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + .row + .col-md-12 + %table.table + - if @sponsor.courier_index > 0 + %tr + %td.col-md-2 + %b Courrier's name + %td.col-md-2 + %b Tracking Number + %td + %b Number of boxes + - @sponsor.courier_info.each do |key, value| + %tr + %td.col-md-2 + = value[:courier_name] + %td + = value[:tracking_number] + %td + = value[:boxes] diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index d4901066..02b6094c 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -6,8 +6,8 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :address, :string add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false - add_column :sponsors, :swags, :text - add_column :sponsors, :courrier_info, :text + add_column :sponsors, :swag, :text + add_column :sponsors, :courier_info, :text add_column :sponsors, :state, :string end end diff --git a/db/schema.rb b/db/schema.rb index e6c03e37..91a3a0f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -48,11 +48,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.text "reasoning" t.string "state" t.string "logo_link" - t.string "website_url" - t.text "submitter_relationship" t.integer "conference_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "website_url" + t.text "submitter_relationship" end create_table "campaigns", force: :cascade do |t| @@ -207,9 +207,6 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.string "cfp_dates_updated_subject" t.text "program_schedule_public_body" t.text "cfp_dates_updated_body" - t.text "booths_acceptance_template" - t.text "booths_rejection_template" - t.string "booths_accetance_subject" t.boolean "send_on_booths_acceptance", default: false t.string "booths_acceptance_subject" t.text "booths_acceptance_body" @@ -328,8 +325,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.integer "ticket_purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "token" end + add_index "physical_tickets", ["token"], name: "index_physical_tickets_on_token", unique: true + create_table "programs", force: :cascade do |t| t.integer "conference_id" t.integer "rating", default: 0 @@ -474,8 +474,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.string "address" t.string "vat" t.boolean "has_banner", default: false - t.text "swags" - t.text "courrier_info" + t.text "swag" + t.text "courier_info" t.string "state" end diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index c6b5009e..dafe13db 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -26,7 +26,8 @@ feature Sponsor do click_button 'Create Sponsor' expect(flash).to eq('Sponsor successfully created.') - within('table#sponsors') do + click_link 'Unconfirmed' + within('table#unconfirmed') do expect(page.has_content?('SUSE')).to be true expect(page.has_content?('The original provider')).to be true expect(page.has_content?('http://www.suse.com')).to be true From 819d55366c33f61804a61f8da0f5d628674ee910 Mon Sep 17 00:00:00 2001 From: nasia Date: Mon, 28 Aug 2017 15:24:51 +0300 Subject: [PATCH 11/15] Change fields and views --- .rubocop_todo.yml | 2 +- app/controllers/admin/sponsors_controller.rb | 9 ++-- app/models/sponsor.rb | 9 ++-- .../admin/sponsors/_carrier_fields.html.haml | 7 +++ .../admin/sponsors/_courier_fields.html.haml | 7 --- .../admin/sponsors/_swag_fields.html.haml | 4 +- app/views/admin/sponsors/edit.html.haml | 11 ++-- app/views/admin/sponsors/index.html.haml | 18 ++++--- app/views/admin/sponsors/show.html.haml | 52 +++++++++---------- .../20170822173332_add_swags_to_sponsors.rb | 3 +- db/schema.rb | 16 +++--- 11 files changed, 73 insertions(+), 65 deletions(-) create mode 100644 app/views/admin/sponsors/_carrier_fields.html.haml delete mode 100644 app/views/admin/sponsors/_courier_fields.html.haml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6d74b5ff..5c3ce628 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -585,7 +585,7 @@ Style/PredicateName: - 'spec/**/*' - 'app/models/comment.rb' - 'app/models/contact.rb' - - 'app/controllers/admin/sponsors_controller' + - 'app/controllers/admin/sponsors_controller.rb' # Offense count: 1 # Cop supports --auto-correct. diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index de7e293b..a0cd177b 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -12,12 +12,13 @@ module Admin def show @sponsor.swag_index = @sponsor.swag.length - @sponsor.courier_index = @sponsor.courier_info.length + @sponsor.carrier_index = @sponsor.swag_transportation.length end def edit + @sponsor.swag = @sponsor.swag @sponsor.swag_index = @sponsor.swag.length - @sponsor.courier_index = @sponsor.courier_info.length + @sponsor.carrier_index = @sponsor.swag_transportation.length end def new @@ -115,8 +116,8 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, - :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, :courier_index, - swags: [:type, :quantity], courier_info: [:courier_name, :tracking_number, :boxes]) + :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, :carrier_index, :amount, + swag: [:type, :quantity], swag_transportation: [:carrier_name, :tracking_number, :boxes]) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 2cca5df2..41ef44d3 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -4,11 +4,11 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - serialize :swags, Hash - serialize :courier_info, Hash + serialize :swag, Hash + serialize :swag_transportation, Hash - attr_accessor :type, :quantity, :swag_index, :courier_index, - :courier_name, :tracking_number, :boxes + attr_accessor :type, :quantity, :swag_index, :carrier_index, + :carrier_name, :tracking_number, :boxes has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } @@ -23,7 +23,6 @@ class Sponsor < ActiveRecord::Base state :unconfirmed state :confirmed - event :confirm do transitions to: :confirmed, from: [:unconfirmed] end diff --git a/app/views/admin/sponsors/_carrier_fields.html.haml b/app/views/admin/sponsors/_carrier_fields.html.haml new file mode 100644 index 00000000..8ed811dd --- /dev/null +++ b/app/views/admin/sponsors/_carrier_fields.html.haml @@ -0,0 +1,7 @@ +.row + .col-md-4 + = f.input :courrier_name, label: 'carrier\'s name', input_html: { name: "sponsor[swag_transportation][#{index}][carrier_name]", value: name_value } + .col-md-4 + = f.input :tracking_number, input_html: { name: "sponsor[swag_transportation][#{index}][tracking_number]", value: tracking_value} + .col-md-4 + = f.input :boxes, as: :number, in: 0...999, label: 'Number of boxes', input_html: { name: "sponsor[swag_transportation][#{index}][boxes]", value: boxes_value } diff --git a/app/views/admin/sponsors/_courier_fields.html.haml b/app/views/admin/sponsors/_courier_fields.html.haml deleted file mode 100644 index 232942e8..00000000 --- a/app/views/admin/sponsors/_courier_fields.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -.row - .col-md-4 - = f.input :courrier_name, label: 'Courier\'s name', input_html: { name: "sponsor[courier_info][#{index}][courier_name]", value: name_value } - .col-md-4 - = f.input :tracking_number, input_html: { name: "sponsor[courier_info][#{index}][tracking_number]", value: tracking_value} - .col-md-4 - = f.input :boxes, as: :number, in: 0...999, label: 'Number of boxes', input_html: { name: "sponsor[courier_info][#{index}][boxes]", value: boxes_value } diff --git a/app/views/admin/sponsors/_swag_fields.html.haml b/app/views/admin/sponsors/_swag_fields.html.haml index 1c73b03e..502d41cc 100644 --- a/app/views/admin/sponsors/_swag_fields.html.haml +++ b/app/views/admin/sponsors/_swag_fields.html.haml @@ -1,5 +1,5 @@ .row .col-md-6 - = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swags][#{index}][type]", value: type_value } + = f.input :type, label: 'Swag\'s type', input_html: { name: "sponsor[swag][#{index}][type]", value: type_value } .col-md-6 - = f.input :quantity, as: :number, in: 0...999, input_html: { name: "sponsor[swags][#{index}][quantity]", value: quantity_value} + = f.input :quantity, as: :number, in: 0...9999, input_html: { name: "sponsor[swag][#{index}][quantity]", value: quantity_value} diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index 304e3a51..73630b3e 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -8,11 +8,12 @@ .col-md-8 = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| = f.input :name + = f.input :amount, as: :number, label: 'Donation amount' = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels - = f.input :address, label: 'Company\'s address' + = f.input :address, label: 'Sponsor\'s address', hint: 'Please include the legal company name, along with the address, as you want it to be shown on the invoice' = f.input :vat, label: 'VAT Registration Number' %b Has Swags? = check_box_tag @conference.short_title, @sponsor.id, @sponsor.has_swag, @@ -21,13 +22,13 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - @sponsor.swags.each_with_index do |(key, value), index| + - @sponsor.swag.each_with_index do |(key, value), index| =render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i} =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil} - - @sponsor.courier_info.each_with_index do |(key, value), index| - =render partial: 'courier_fields', locals: {f: f, index: index, name_value: value[:courier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} - =render partial: 'courier_fields', locals: {f: f, index: @sponsor.courier_index, name_value: nil, tracking_value: nil, boxes_value: nil} + - @sponsor.swag_transportation.each_with_index do |(key, value), index| + =render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} + =render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil} .row .col-md-8 diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 5536f756..6ae4e7fe 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -24,6 +24,7 @@ %thead %th Logo %th Name + %th Donation %th Payment %th Level %th Actions @@ -34,6 +35,8 @@ = image_tag(sponsor.picture.thumb.url, width: '20%') %td = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = sponsor.amount %td - if sponsor.payed %span.fa.fa-check.text-success @@ -88,17 +91,20 @@ %span.fa.fa-times.text-danger %td - if sponsor.has_swag - - sponsor.swags.each do |key, value| + - sponsor.swag.each do |key, value| = value[:type] ( = value[:quantity] ) %br + %td - - if sponsor.swag_received - %span.fa.fa-check.text-success - - else - %span.fa.fa-times.text-danger + = check_box_tag @conference.short_title, sponsor.id, sponsor.swag_received, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{sponsor.id}?sponsor[swag_received]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } %td .btn-group = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), @@ -135,7 +141,7 @@ %td = truncate(sponsor.description) %td - = sponsor.website_url + = link_to sponsor.website_url, sponsor.website_url %td = sponsor.sponsorship_level.title %td diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 6be3281a..7186ab4e 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -13,6 +13,12 @@ method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete the sponsor #{@sponsor.name}?" } .col-md-12 %table.table + %tr + - if @sponsor.amount? + %td.col-md-2 + %b Donation amount + %td + = @sponsor.amount %tr %td.col-md-2 %b Sponsorship paid? @@ -47,13 +53,13 @@ - if @sponsor.address? %tr %td.col-md-2 - %b Company's address + %b Sponsor's address %td = @sponsor.address - if @sponsor.vat? %tr %td.col-md-2 - %b Campany's VAT Registration Number + %b Sponsor's VAT Registration Number %td = @sponsor.vat %tr @@ -67,6 +73,20 @@ on_text: 'Yes', off_text: 'No' } + + - if @sponsor.has_swag + %tr + %td.col-md-2 + %b Swag's Type + %td + %b Quantity + - @sponsor.swag.each do |key, value| + %tr + %td.col-md-2 + = value[:type] + %td + = value[:quantity] + - if @sponsor.has_swag %tr %td.col-md-2 @@ -78,32 +98,10 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } - - if @sponsor.swag_index > 0 - %tr - %td.col-md-2 - %b Swag's Type - %td - %b Quantity - - @sponsor.swags.each do |key, value| - %tr - %td.col-md-2 - = value[:type] - %td - = value[:quantity] - %tr - %td.col-md-2 - %b Swag Received? - %td - = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received, - method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=", - class: 'switch-checkbox', data: { size: 'small', - off_color: 'warning', - on_text: 'Yes', - off_text: 'No' } .row .col-md-12 %table.table - - if @sponsor.courier_index > 0 + - if @sponsor.carrier_index > 0 %tr %td.col-md-2 %b Courrier's name @@ -111,10 +109,10 @@ %b Tracking Number %td %b Number of boxes - - @sponsor.courier_info.each do |key, value| + - @sponsor.swag_transportation.each do |key, value| %tr %td.col-md-2 - = value[:courier_name] + = value[:carrier_name] %td = value[:tracking_number] %td diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index 02b6094c..f6fad91e 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -1,13 +1,14 @@ class AddSwagsToSponsors < ActiveRecord::Migration def change add_column :sponsors, :paid, :boolean, default: false + add_column :sponsors, :amount, :float add_column :sponsors, :has_swag, :boolean, default: false add_column :sponsors, :swag_received, :boolean add_column :sponsors, :address, :string add_column :sponsors, :vat, :string add_column :sponsors, :has_banner, :boolean, default: false add_column :sponsors, :swag, :text - add_column :sponsors, :courier_info, :text + add_column :sponsors, :swag_transportation, :text add_column :sponsors, :state, :string end end diff --git a/db/schema.rb b/db/schema.rb index 91a3a0f7..4e484104 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -48,11 +48,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.text "reasoning" t.string "state" t.string "logo_link" + t.string "website_url" + t.text "submitter_relationship" t.integer "conference_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "website_url" - t.text "submitter_relationship" end create_table "campaigns", force: :cascade do |t| @@ -127,8 +127,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 - t.integer "booth_limit", default: 0 t.string "custom_domain" + t.integer "booth_limit", default: 0 end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" @@ -207,6 +207,9 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.string "cfp_dates_updated_subject" t.text "program_schedule_public_body" t.text "cfp_dates_updated_body" + t.text "booths_acceptance_template" + t.text "booths_rejection_template" + t.string "booths_accetance_subject" t.boolean "send_on_booths_acceptance", default: false t.string "booths_acceptance_subject" t.text "booths_acceptance_body" @@ -325,11 +328,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.integer "ticket_purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "token" end - add_index "physical_tickets", ["token"], name: "index_physical_tickets_on_token", unique: true - create_table "programs", force: :cascade do |t| t.integer "conference_id" t.integer "rating", default: 0 @@ -469,13 +469,14 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.datetime "updated_at" t.string "picture" t.boolean "paid", default: false + t.float "amount" t.boolean "has_swag", default: false t.boolean "swag_received" t.string "address" t.string "vat" t.boolean "has_banner", default: false t.text "swag" - t.text "courier_info" + t.text "swag_transportation" t.string "state" end @@ -586,6 +587,7 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.boolean "is_admin", default: false t.string "username" t.boolean "is_disabled", default: false + t.string "token" end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true From 9d2d1c0e5a4000c4c8fed3e26ab505c48e09b767 Mon Sep 17 00:00:00 2001 From: nasia Date: Mon, 28 Aug 2017 22:10:08 +0300 Subject: [PATCH 12/15] Exclude haml-lint --- .haml-lint_todo.yml | 7 ++++++- app/views/admin/sponsors/edit.html.haml | 8 ++++---- app/views/admin/sponsors/index.html.haml | 14 +++++++------- app/views/admin/sponsors/new.html.haml | 3 +-- spec/features/sponsor_spec.rb | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index b79ddc17..44e4d016 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -89,8 +89,12 @@ linters: - "app/views/admin/schedules/show.html.haml" - "app/views/admin/splashpages/_form.html.haml" - "app/views/admin/splashpages/show.html.haml" - - "app/views/admin/sponsors/_form.html.haml" + - "app/views/admin/sponsors/_carrier_fields.html.haml" + - "pp/views/admin/sponsors/_swag_fields.html.haml" + - "app/views/admin/sponsors/edit.html.haml" - "app/views/admin/sponsors/index.html.haml" + - "app/views/admin/sponsors/new.html.haml" + - "app/views/admin/sponsors/show.html.haml" - "app/views/admin/sponsorship_levels/_form.html.haml" - "app/views/admin/sponsorship_levels/index.html.haml" - "app/views/admin/targets/_form.html.haml" @@ -365,6 +369,7 @@ linters: - "app/views/admin/emails/index.html.haml" - "app/views/admin/events/show.html.haml" - "app/views/admin/reports/index.html.haml" + - "app/views/admin/sponsors/index.html.haml" - "app/views/admin/users/show.html.haml" - "app/views/admin/venues/_form.html.haml" - "app/views/conferences/index.html.haml" diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index 73630b3e..d4c0645f 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -23,12 +23,12 @@ on_text: 'Yes', off_text: 'No' } - @sponsor.swag.each_with_index do |(key, value), index| - =render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i} - =render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil} + = render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i} + = render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil} - @sponsor.swag_transportation.each_with_index do |(key, value), index| - =render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} - =render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil} + = render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} + = render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil} .row .col-md-8 diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 6ae4e7fe..981db762 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -9,18 +9,18 @@ %div{ role: 'tabpanel' } %ul.nav.nav-tabs %li.active - %a{'data-toggle' => 'tab', href: '#sponsorship', role: 'tab'} Sponsorship + %a{ 'data-toggle' => 'tab', href: '#sponsorship', role: 'tab' } Sponsorship %li - %a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags + %a{ 'data-toggle' => 'tab', href: '#swags', role: 'tab' } Swags %li - %a{'data-toggle' => 'tab', href: '#unconfirmed', role: 'tab'} Unconfirmed + %a{'data-toggle' => 'tab', href: '#unconfirmed', role: 'tab' } Unconfirmed .tab-content #sponsorship.tab-pane.active - if @conference.sponsors.confirmed.any? .row .col-md-12 - %table.table.table-hover#sponsorship + %table.table.table-hover %thead %th Logo %th Name @@ -36,7 +36,7 @@ %td = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) %td - = sponsor.amount + = sponsor.amount %td - if sponsor.payed %span.fa.fa-check.text-success @@ -62,7 +62,7 @@ - if @conference.sponsors.confirmed.any? .row .col-md-12 - %table.table.table-hover#swags + %table.table.table-hover %thead %th Logo %th Name @@ -123,7 +123,7 @@ - if @conference.sponsors.unconfirmed.any? .row .col-md-12 - %table.table.table-hover#unconfirmed + %table.table.table-hover#sponsors %thead %th Logo %th Name diff --git a/app/views/admin/sponsors/new.html.haml b/app/views/admin/sponsors/new.html.haml index 5fbeed31..a94b1d03 100644 --- a/app/views/admin/sponsors/new.html.haml +++ b/app/views/admin/sponsors/new.html.haml @@ -2,8 +2,7 @@ .col-md-12 .page-header %h1 - -if @sponsor.new_record? - New + New Sponsor = @sponsor.name .row diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index dafe13db..c10a00b8 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -27,7 +27,7 @@ feature Sponsor do expect(flash).to eq('Sponsor successfully created.') click_link 'Unconfirmed' - within('table#unconfirmed') do + within('table#sponsors') do expect(page.has_content?('SUSE')).to be true expect(page.has_content?('The original provider')).to be true expect(page.has_content?('http://www.suse.com')).to be true From 7cd16353171d823610fef59c0bb2246ee1747c8f Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 29 Aug 2017 12:04:31 +0300 Subject: [PATCH 13/15] add to_contact and contacted tabs --- .haml-lint_todo.yml | 3 +- app/controllers/admin/sponsors_controller.rb | 18 ++++--- app/models/sponsor.rb | 16 ++++-- app/views/admin/sponsors/index.html.haml | 57 ++++++++++++++++++-- config/routes.rb | 1 + spec/features/sponsor_spec.rb | 2 +- 6 files changed, 78 insertions(+), 19 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 44e4d016..3fc8440b 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -90,7 +90,7 @@ linters: - "app/views/admin/splashpages/_form.html.haml" - "app/views/admin/splashpages/show.html.haml" - "app/views/admin/sponsors/_carrier_fields.html.haml" - - "pp/views/admin/sponsors/_swag_fields.html.haml" + - "app/views/admin/sponsors/_swag_fields.html.haml" - "app/views/admin/sponsors/edit.html.haml" - "app/views/admin/sponsors/index.html.haml" - "app/views/admin/sponsors/new.html.haml" @@ -273,6 +273,7 @@ linters: - "app/views/admin/questions/show.html.haml" - "app/views/admin/roles/show.html.haml" - "app/views/admin/schedules/index.html.haml" + - "app/views/admin/sponsors/index.html.haml" - "app/views/admin/sponsorship_levels/index.html.haml" - "app/views/admin/users/_event_registrations.html.haml" - "app/views/admin/users/show.html.haml" diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index a0cd177b..0d99e807 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -4,8 +4,6 @@ module Admin load_and_authorize_resource :sponsor, through: :conference before_action :sponsorship_level_required, only: [:index, :new] - helper_method :add_swags - def index authorize! :index, Sponsor.new(conference_id: @conference.id) end @@ -58,11 +56,6 @@ module Admin end end - def add_swags - @sponsor.update_attributes(sponsor_params) - redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor) - end - def confirm @sponsor.confirm! @@ -85,6 +78,17 @@ module Admin end end + def contact + @sponsor.contact! + + if @sponsor.save + redirect_to admin_conference_sponsors_path(@conference.short_title), + notice: 'Sponsor\'s state successfully updated' + else + flash[:error] = 'Sponsor\'s state couldn\'t be updated' + end + end + def paid @sponsor.paid = !@sponsor.paid if @sponsor.save diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 41ef44d3..f1cd2dca 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -17,18 +17,24 @@ class Sponsor < ActiveRecord::Base validates :name, :website_url, :sponsorship_level, presence: true scope :confirmed, -> { where(state: 'confirmed') } - scope :unconfirmed, -> { where(state: 'unconfirmed') } + scope :contacted, -> { where(state: 'contacted') } + scope :to_contact, -> { where(state: 'to_contact') } - state_machine initial: :unconfirmed do - state :unconfirmed + state_machine initial: :to_contact do + state :to_contact state :confirmed + state :contacted event :confirm do - transitions to: :confirmed, from: [:unconfirmed] + transitions to: :confirmed, from: [:to_contact, :contacted] end event :cancel do - transitions to: :unconfirmed, from: [:confirmed] + transitions to: :to_contact, from: [:confirmed, :contacted] + end + + event :contact do + transitions to: :contacted, from: [:to_contact] end end diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 981db762..64366320 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -13,7 +13,9 @@ %li %a{ 'data-toggle' => 'tab', href: '#swags', role: 'tab' } Swags %li - %a{'data-toggle' => 'tab', href: '#unconfirmed', role: 'tab' } Unconfirmed + %a{ 'data-toggle' => 'tab', href: '#contacted', role: 'tab' } Contacted + %li + %a{ 'data-toggle' => 'tab', href: '#to_contact', role: 'tab' } To contact .tab-content #sponsorship.tab-pane.active @@ -114,16 +116,20 @@ - if sponsor.transition_possible? :confirm = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :contact + = link_to 'Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' - if sponsor.transition_possible? :cancel = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), method: :patch, class: 'btn btn-mini btn-warning' + - else %p No confirmed sponsors yet! - #unconfirmed.tab-pane - - if @conference.sponsors.unconfirmed.any? + #contacted.tab-pane + - if @conference.sponsors.contacted.any? .row .col-md-12 - %table.table.table-hover#sponsors + %table.table.table-hover %thead %th Logo %th Name @@ -132,7 +138,7 @@ %th Level %th Actions %tbody - - @conference.sponsors.unconfirmed.each do |sponsor| + - @conference.sponsors.contacted.each do |sponsor| %tr %td = image_tag(sponsor.picture.thumb.url, width: '20%') @@ -156,6 +162,47 @@ - if sponsor.transition_possible? :cancel = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), method: :patch, class: 'btn btn-mini btn-warning' + #to_contact.tab-pane + - if @conference.sponsors.to_contact.any? + .row + .col-md-12 + %table.table.table-hover#sponsors + %thead + %th Logo + %th Name + %th Description + %th URL + %th Level + %th Actions + %tbody + - @conference.sponsors.to_contact.each do |sponsor| + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = link_to sponsor.website_url, sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :contact + = link_to 'Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-warning' + - else %p There are no unconfirmed sponsors .row diff --git a/config/routes.rb b/config/routes.rb index 8d2f7099..d361e230 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -121,6 +121,7 @@ Osem::Application.routes.draw do member do patch :confirm patch :cancel + patch :contact end end resources :lodgings, except: [:show] diff --git a/spec/features/sponsor_spec.rb b/spec/features/sponsor_spec.rb index c10a00b8..493e81ed 100644 --- a/spec/features/sponsor_spec.rb +++ b/spec/features/sponsor_spec.rb @@ -26,7 +26,7 @@ feature Sponsor do click_button 'Create Sponsor' expect(flash).to eq('Sponsor successfully created.') - click_link 'Unconfirmed' + click_link 'To contact' within('table#sponsors') do expect(page.has_content?('SUSE')).to be true expect(page.has_content?('The original provider')).to be true From 88a6b2769bae1080a1803f59e8a27b599e3498b4 Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 29 Aug 2017 16:20:21 +0300 Subject: [PATCH 14/15] Remove nil hash objects --- app/controllers/admin/sponsors_controller.rb | 5 +- app/views/admin/sponsors/index.html.haml | 70 ++++++++++---------- app/views/admin/sponsors/show.html.haml | 2 +- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 0d99e807..8bb598d6 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -9,12 +9,15 @@ module Admin end def show + @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } + @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? || value[:boxes].blank? } @sponsor.swag_index = @sponsor.swag.length @sponsor.carrier_index = @sponsor.swag_transportation.length end def edit - @sponsor.swag = @sponsor.swag + @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } + @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? } @sponsor.swag_index = @sponsor.swag.length @sponsor.carrier_index = @sponsor.swag_transportation.length end diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 64366320..d0cbfbea 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -92,13 +92,14 @@ - else %span.fa.fa-times.text-danger %td - - if sponsor.has_swag + - if sponsor.swag.length > 0 - sponsor.swag.each do |key, value| - = value[:type] - ( - = value[:quantity] - ) - %br + - unless value[:type].blank? + = value[:type] + ( + = value[:quantity] + ) + %br %td = check_box_tag @conference.short_title, sponsor.id, sponsor.swag_received, @@ -163,7 +164,7 @@ = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), method: :patch, class: 'btn btn-mini btn-warning' #to_contact.tab-pane - - if @conference.sponsors.to_contact.any? + - if @conference.sponsors.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -175,33 +176,34 @@ %th Level %th Actions %tbody - - @conference.sponsors.to_contact.each do |sponsor| - %tr - %td - = image_tag(sponsor.picture.thumb.url, width: '20%') - %td - = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) - %td - = truncate(sponsor.description) - %td - = link_to sponsor.website_url, sponsor.website_url - %td - = sponsor.sponsorship_level.title - %td - .btn-group - = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-mini btn-primary' - = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } - - if sponsor.transition_possible? :confirm - = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-success' - - if sponsor.transition_possible? :contact - = link_to 'Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-default' - - if sponsor.transition_possible? :cancel - = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-warning' + - @conference.sponsors.each do |sponsor| + - if sponsor.state =='to_contact' + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = link_to sponsor.website_url, sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :contact + = link_to 'Mark as Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-warning' - else %p There are no unconfirmed sponsors diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 7186ab4e..169c23b2 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -74,7 +74,7 @@ off_text: 'No' } - - if @sponsor.has_swag + - if @sponsor.swag.length > 0 %tr %td.col-md-2 %b Swag's Type From 4810aa22f68f9b11f73b128d42799415fea9b175 Mon Sep 17 00:00:00 2001 From: nasia Date: Thu, 31 Aug 2017 22:04:12 +0300 Subject: [PATCH 15/15] Add responsible and fix how hashes are stored --- app/controllers/admin/sponsors_controller.rb | 15 ++++++--------- app/models/sponsor.rb | 5 +++-- app/views/admin/sponsors/edit.html.haml | 17 +++++++++++++++++ app/views/admin/sponsors/index.html.haml | 2 +- app/views/admin/sponsors/show.html.haml | 16 ++++++++++++++-- .../20170822173332_add_swags_to_sponsors.rb | 1 + db/schema.rb | 1 + 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 8bb598d6..4356f8ca 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -8,16 +8,9 @@ module Admin authorize! :index, Sponsor.new(conference_id: @conference.id) end - def show - @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } - @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? || value[:boxes].blank? } - @sponsor.swag_index = @sponsor.swag.length - @sponsor.carrier_index = @sponsor.swag_transportation.length - end + def show; end def edit - @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } - @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? } @sponsor.swag_index = @sponsor.swag.length @sponsor.carrier_index = @sponsor.swag_transportation.length end @@ -39,6 +32,9 @@ module Admin def update if @sponsor.update_attributes(sponsor_params) + @sponsor.update_attribute(:swag, @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? }) + @sponsor.update_attribute(:swag_transportation, @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? }) + redirect_to admin_conference_sponsor_path( conference_id: @conference.short_title, id: @sponsor.id), notice: 'Sponsor successfully updated.' @@ -124,7 +120,8 @@ module Admin def sponsor_params params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id, :paid, :has_swag, :swag_received, :address, :vat, :has_banner, :swag_index, :carrier_index, :amount, - swag: [:type, :quantity], swag_transportation: [:carrier_name, :tracking_number, :boxes]) + responsibe: [:responsible_name, :responsible_email], swag: [:type, :quantity], + swag_transportation: [:carrier_name, :tracking_number, :boxes]) end def sponsorship_level_required diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index f1cd2dca..08678904 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -6,9 +6,11 @@ class Sponsor < ActiveRecord::Base serialize :swag, Hash serialize :swag_transportation, Hash + serialize :responsibe, Hash attr_accessor :type, :quantity, :swag_index, :carrier_index, - :carrier_name, :tracking_number, :boxes + :carrier_name, :tracking_number, :boxes, + :responsible_name, :responsible_email has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } @@ -18,7 +20,6 @@ class Sponsor < ActiveRecord::Base scope :confirmed, -> { where(state: 'confirmed') } scope :contacted, -> { where(state: 'contacted') } - scope :to_contact, -> { where(state: 'to_contact') } state_machine initial: :to_contact do state :to_contact diff --git a/app/views/admin/sponsors/edit.html.haml b/app/views/admin/sponsors/edit.html.haml index d4c0645f..4948ba26 100644 --- a/app/views/admin/sponsors/edit.html.haml +++ b/app/views/admin/sponsors/edit.html.haml @@ -9,6 +9,15 @@ = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| = f.input :name = f.input :amount, as: :number, label: 'Donation amount' + %b Sponsorship paid? + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.paid, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[paid]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + = f.input :responsible_name, label: 'Responsible\'s name', hint: 'The person with whom you are in contact', input_html: { name: 'sponsor[responsibe][responsible_name]', value: @sponsor.responsibe[:responsible_name] } + = f.input :responsible_name, label: 'Responsible\'s email', input_html: { name: 'sponsor[responsibe][responsible_email]', value: @sponsor.responsibe[:responsible_email] } = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } } = f.input :picture = f.input :website_url @@ -26,6 +35,14 @@ = render partial: 'swag_fields', locals: {f: f, index: index, type_value: value[:type].to_s, quantity_value: value[:quantity].to_i} = render partial: 'swag_fields', locals: {f: f, index: @sponsor.swag_index, type_value: nil, quantity_value: nil} + %b Swag received? + = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received, + method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=", + class: 'switch-checkbox', data: { size: 'small', + off_color: 'warning', + on_text: 'Yes', + off_text: 'No' } + - @sponsor.swag_transportation.each_with_index do |(key, value), index| = render partial: 'carrier_fields', locals: {f: f, index: index, name_value: value[:carrier_name].to_s, tracking_value: value[:tracking_number].to_s, boxes_value: value[:boxes]} = render partial: 'carrier_fields', locals: {f: f, index: @sponsor.carrier_index, name_value: nil, tracking_value: nil, boxes_value: nil} diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index d0cbfbea..c485ff61 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -40,7 +40,7 @@ %td = sponsor.amount %td - - if sponsor.payed + - if sponsor.paid %span.fa.fa-check.text-success - else %span.fa.fa-times.text-danger diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 169c23b2..26ee3c85 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -29,6 +29,18 @@ off_color: 'warning', on_text: 'Yes', off_text: 'No' } + - unless @sponsor.responsibe[:responsible_name].blank? + %tr + %td.col-md-2 + %b Responsible's name + %td + = @sponsor.responsibe[:responsible_name] + - unless @sponsor.responsibe[:responsible_email].blank? + %tr + %td.col-md-2 + %b Responsible's email + %td + = @sponsor.responsibe[:responsible_email] - if @sponsor.description? %tr %td.col-md-2 @@ -74,7 +86,7 @@ off_text: 'No' } - - if @sponsor.swag.length > 0 + - if @sponsor.swag.any? %tr %td.col-md-2 %b Swag's Type @@ -101,7 +113,7 @@ .row .col-md-12 %table.table - - if @sponsor.carrier_index > 0 + - if @sponsor.swag_transportation.any? %tr %td.col-md-2 %b Courrier's name diff --git a/db/migrate/20170822173332_add_swags_to_sponsors.rb b/db/migrate/20170822173332_add_swags_to_sponsors.rb index f6fad91e..adf0c363 100644 --- a/db/migrate/20170822173332_add_swags_to_sponsors.rb +++ b/db/migrate/20170822173332_add_swags_to_sponsors.rb @@ -10,5 +10,6 @@ class AddSwagsToSponsors < ActiveRecord::Migration add_column :sponsors, :swag, :text add_column :sponsors, :swag_transportation, :text add_column :sponsors, :state, :string + add_column :sponsors, :responsibe, :text end end diff --git a/db/schema.rb b/db/schema.rb index 4e484104..4f6d5f98 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -478,6 +478,7 @@ ActiveRecord::Schema.define(version: 20170822173332) do t.text "swag" t.text "swag_transportation" t.string "state" + t.text "responsibe" end create_table "sponsorship_levels", force: :cascade do |t|