add courier info

This commit is contained in:
nasia 2017-08-27 23:40:32 +03:00
parent 792a7fed1c
commit 30e70cc5d6
10 changed files with 146 additions and 95 deletions

View file

@ -11,12 +11,13 @@ module Admin
end end
def show def show
@sponsor.swag_index = @sponsor.swags.length @sponsor.swag_index = @sponsor.swag.length
@sponsor.courier_index = @sponsor.courier_info.length
end end
def edit def edit
@sponsor.swag_index = @sponsor.swags.length @sponsor.swag_index = @sponsor.swag.length
@sponsor.swags = @sponsor.swags @sponsor.courier_index = @sponsor.courier_info.length
end end
def new def new
@ -35,7 +36,6 @@ module Admin
end end
def update def update
if @sponsor.update_attributes(sponsor_params) if @sponsor.update_attributes(sponsor_params)
redirect_to admin_conference_sponsor_path( redirect_to admin_conference_sponsor_path(
conference_id: @conference.short_title, id: @sponsor.id), conference_id: @conference.short_title, id: @sponsor.id),
@ -57,7 +57,7 @@ module Admin
end end
end end
def add_swags() def add_swags
@sponsor.update_attributes(sponsor_params) @sponsor.update_attributes(sponsor_params)
redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor) redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor)
end end
@ -67,7 +67,7 @@ module Admin
if @sponsor.save if @sponsor.save
redirect_to admin_conference_sponsors_path(@conference.short_title), redirect_to admin_conference_sponsors_path(@conference.short_title),
notice: 'Sponsor successfully confirmed!' notice: 'Sponsor successfully confirmed!'
else else
flash[:error] = 'Sponsor couldn\' t be confirmed.' flash[:error] = 'Sponsor couldn\' t be confirmed.'
end end
@ -78,7 +78,7 @@ module Admin
if @sponsor.save if @sponsor.save
redirect_to admin_conference_sponsors_path(@conference.short_title), redirect_to admin_conference_sponsors_path(@conference.short_title),
notice: 'Sponsor successfully canceled' notice: 'Sponsor successfully canceled'
else else
flash[:error] = 'Sponsor couldn\'t be canceled' flash[:error] = 'Sponsor couldn\'t be canceled'
end end
@ -115,7 +115,8 @@ module Admin
def sponsor_params 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,
: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 end
def sponsorship_level_required def sponsorship_level_required

View file

@ -5,7 +5,10 @@ class Sponsor < ActiveRecord::Base
belongs_to :conference belongs_to :conference
serialize :swags, Hash 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 } 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 validates :name, :website_url, :sponsorship_level, presence: true
scope :confirmed, -> { where(state: 'confirmed') } scope :confirmed, -> { where(state: 'confirmed') }
scope :unconfirmed, -> { where(state: 'uncofirmed') } scope :unconfirmed, -> { where(state: 'unconfirmed') }
state_machine initial: :uncofirmed do state_machine initial: :unconfirmed do
state :uncofirmed state :unconfirmed
state :confirmed state :confirmed
event :confirm do event :confirm do
transitions to: :confirmed, from: [:uncofirmed] transitions to: :confirmed, from: [:unconfirmed]
end end
event :cancel do event :cancel do
transitions to: :uncofirmed, from: [:confirmed] transitions to: :unconfirmed, from: [:confirmed]
end end
end end

View file

@ -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 }

View file

@ -1,5 +1,5 @@
.row .row
.col-md-6 .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 .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}

View file

@ -4,7 +4,6 @@
%h1 %h1
Edit Edit
= @sponsor.name = @sponsor.name
= @sponsor.swag_index
.row .row
.col-md-8 .col-md-8
= semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f| = semantic_form_for(@sponsor, url: admin_conference_sponsor_path(@conference.short_title, @sponsor)) do |f|
@ -23,8 +22,13 @@
on_text: 'Yes', on_text: 'Yes',
off_text: 'No' } off_text: 'No' }
- @sponsor.swags.each_with_index do |(key, value), 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: index, type_value: value[:type].to_s, quantity_value: 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: @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 .row
.col-md-8 .col-md-8
= image_tag f.object.picture.thumb.url if f.object.picture? = image_tag f.object.picture.thumb.url if f.object.picture?

View file

@ -13,19 +13,18 @@
%li %li
%a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags %a{'data-toggle' => 'tab', href: '#swags', role: 'tab'} Swags
%li %li
%a{'data-toggle' => 'tab', href: '#uncofirmed', role: 'tab'} Unconfirmed %a{'data-toggle' => 'tab', href: '#unconfirmed', role: 'tab'} Unconfirmed
.tab-content .tab-content
#sponsorship.tab-pane.active #sponsorship.tab-pane.active
- if @conference.sponsors.confirmed.any? - if @conference.sponsors.confirmed.any?
.row .row
.col-md-12 .col-md-12
%table.table.table-hover#sponsors %table.table.table-hover#sponsorship
%thead %thead
%th Logo %th Logo
%th Name %th Name
%th Description %th Payment
%th URL
%th Level %th Level
%th Actions %th Actions
%tbody %tbody
@ -36,9 +35,10 @@
%td %td
= link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor)
%td %td
= truncate(sponsor.description) - if sponsor.payed
%td %span.fa.fa-check.text-success
= sponsor.website_url - else
%span.fa.fa-times.text-danger
%td %td
= sponsor.sponsorship_level.title = sponsor.sponsorship_level.title
%td %td
@ -52,13 +52,14 @@
method: :patch, class: 'btn btn-mini btn-success' method: :patch, class: 'btn btn-mini btn-success'
- if sponsor.transition_possible? :cancel - if sponsor.transition_possible? :cancel
= link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), = 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 #swags.tab-pane
- if @conference.sponsors.confirmed.any? - if @conference.sponsors.confirmed.any?
.row .row
.col-md-12 .col-md-12
%table.table.table-hover#sponsors %table.table.table-hover#swags
%thead %thead
%th Logo %th Logo
%th Name %th Name
@ -71,7 +72,8 @@
- @conference.sponsors.confirmed.each do |sponsor| - @conference.sponsors.confirmed.each do |sponsor|
%tr %tr
%td %td
= image_tag(sponsor.picture.thumb.url, width: '20%') - if sponsor.picture?
= image_tag(sponsor.picture.thumb.url, width: '20%')
%td %td
= link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor)
%td %td
@ -96,7 +98,7 @@
- if sponsor.swag_received - if sponsor.swag_received
%span.fa.fa-check.text-success %span.fa.fa-check.text-success
- else - else
%span.fa.fa-times %span.fa.fa-times.text-danger
%td %td
.btn-group .btn-group
= link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor),
@ -108,47 +110,48 @@
method: :patch, class: 'btn btn-mini btn-success' method: :patch, class: 'btn btn-mini btn-success'
- if sponsor.transition_possible? :cancel - if sponsor.transition_possible? :cancel
= link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), = 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
.tab-content %p No confirmed sponsors yet!
#unconfirmed.tab-pane #unconfirmed.tab-pane
- if @conference.sponsors.unconfirmed.any? - if @conference.sponsors.unconfirmed.any?
.row .row
.col-md-12 .col-md-12
%table.table.table-hover#sponsors %table.table.table-hover#unconfirmed
%thead %thead
%th Logo %th Logo
%th Name %th Name
%th Description %th Description
%th URL %th URL
%th Level %th Level
%th Actions %th Actions
%tbody %tbody
- @conference.sponsors.unconfirmed.each do |sponsor| - @conference.sponsors.unconfirmed.each do |sponsor|
%tr %tr
%td %td
= image_tag(sponsor.picture.thumb.url, width: '20%') = image_tag(sponsor.picture.thumb.url, width: '20%')
%td %td
= link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor)
%td %td
= truncate(sponsor.description) = truncate(sponsor.description)
%td %td
= sponsor.website_url = sponsor.website_url
%td %td
= sponsor.sponsorship_level.title = sponsor.sponsorship_level.title
%td %td
.btn-group .btn-group
= link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor),
method: :get, class: 'btn btn-mini btn-primary' method: :get, class: 'btn btn-mini btn-primary'
= link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), = 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}?" } 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 - if sponsor.transition_possible? :confirm
= link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id),
method: :patch, class: 'btn btn-mini btn-success' method: :patch, class: 'btn btn-mini btn-success'
- if sponsor.transition_possible? :cancel - if sponsor.transition_possible? :cancel
= link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), = 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 There are no unconfirmed sponsors
.row .row
.col-md-12 .col-md-12
= link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right' = link_to 'Add Sponsor', new_admin_conference_sponsor_path(@conference.short_title), class: 'btn btn-primary pull-right'

View file

@ -1,7 +1,8 @@
.row .row
.col-md-12 .col-md-12
%h2 %h2
= image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '') - if @sponsor.picture?
= image_tag(@sponsor.picture.thumb.url, size: '20%', alt: '')
= @sponsor.name = @sponsor.name
.row .row
.col-md-12 .col-md-12
@ -41,6 +42,20 @@
%b Website url %b Website url
%td %td
= link_to @sponsor.website_url, @sponsor.website_url = 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 %tr
%td.col-md-2 %td.col-md-2
%b Has swag? %b Has swag?
@ -75,15 +90,32 @@
= value[:type] = value[:type]
%td %td
= value[:quantity] = value[:quantity]
- if @sponsor.address? %tr
%tr %td.col-md-2
%td.col-md-2 %b Swag Received?
%b Company's address %td
%td = check_box_tag @conference.short_title, @sponsor.id, @sponsor.swag_received,
= @sponsor.address method: :patch, url: "/admin/conferences/#{@conference.short_title}/sponsors/#{@sponsor.id}?sponsor[swag_received]=",
- if @sponsor.vat? class: 'switch-checkbox', data: { size: 'small',
%tr off_color: 'warning',
%td.col-md-2 on_text: 'Yes',
%b Campany's VAT Registration Number off_text: 'No' }
%td .row
= @sponsor.vat .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]

View file

@ -6,8 +6,8 @@ class AddSwagsToSponsors < ActiveRecord::Migration
add_column :sponsors, :address, :string add_column :sponsors, :address, :string
add_column :sponsors, :vat, :string add_column :sponsors, :vat, :string
add_column :sponsors, :has_banner, :boolean, default: false add_column :sponsors, :has_banner, :boolean, default: false
add_column :sponsors, :swags, :text add_column :sponsors, :swag, :text
add_column :sponsors, :courrier_info, :text add_column :sponsors, :courier_info, :text
add_column :sponsors, :state, :string add_column :sponsors, :state, :string
end end
end end

View file

@ -48,11 +48,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do
t.text "reasoning" t.text "reasoning"
t.string "state" t.string "state"
t.string "logo_link" t.string "logo_link"
t.string "website_url"
t.text "submitter_relationship"
t.integer "conference_id" t.integer "conference_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "website_url"
t.text "submitter_relationship"
end end
create_table "campaigns", force: :cascade do |t| create_table "campaigns", force: :cascade do |t|
@ -207,9 +207,6 @@ ActiveRecord::Schema.define(version: 20170822173332) do
t.string "cfp_dates_updated_subject" t.string "cfp_dates_updated_subject"
t.text "program_schedule_public_body" t.text "program_schedule_public_body"
t.text "cfp_dates_updated_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.boolean "send_on_booths_acceptance", default: false
t.string "booths_acceptance_subject" t.string "booths_acceptance_subject"
t.text "booths_acceptance_body" t.text "booths_acceptance_body"
@ -328,8 +325,11 @@ ActiveRecord::Schema.define(version: 20170822173332) do
t.integer "ticket_purchase_id", null: false t.integer "ticket_purchase_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "token"
end end
add_index "physical_tickets", ["token"], name: "index_physical_tickets_on_token", unique: true
create_table "programs", force: :cascade do |t| create_table "programs", force: :cascade do |t|
t.integer "conference_id" t.integer "conference_id"
t.integer "rating", default: 0 t.integer "rating", default: 0
@ -474,8 +474,8 @@ ActiveRecord::Schema.define(version: 20170822173332) do
t.string "address" t.string "address"
t.string "vat" t.string "vat"
t.boolean "has_banner", default: false t.boolean "has_banner", default: false
t.text "swags" t.text "swag"
t.text "courrier_info" t.text "courier_info"
t.string "state" t.string "state"
end end

View file

@ -26,7 +26,8 @@ feature Sponsor do
click_button 'Create Sponsor' click_button 'Create Sponsor'
expect(flash).to eq('Sponsor successfully created.') 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?('SUSE')).to be true
expect(page.has_content?('The original provider')).to be true expect(page.has_content?('The original provider')).to be true
expect(page.has_content?('http://www.suse.com')).to be true expect(page.has_content?('http://www.suse.com')).to be true