From 30e70cc5d61c7360df5b3d47a8f4c6a9dd45d08e Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 27 Aug 2017 23:40:32 +0300 Subject: [PATCH] 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