add to_contact and contacted tabs

This commit is contained in:
nasia 2017-08-29 12:04:31 +03:00
parent 9d2d1c0e5a
commit 7cd1635317
6 changed files with 78 additions and 19 deletions

View file

@ -90,7 +90,7 @@ linters:
- "app/views/admin/splashpages/_form.html.haml" - "app/views/admin/splashpages/_form.html.haml"
- "app/views/admin/splashpages/show.html.haml" - "app/views/admin/splashpages/show.html.haml"
- "app/views/admin/sponsors/_carrier_fields.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/edit.html.haml"
- "app/views/admin/sponsors/index.html.haml" - "app/views/admin/sponsors/index.html.haml"
- "app/views/admin/sponsors/new.html.haml" - "app/views/admin/sponsors/new.html.haml"
@ -273,6 +273,7 @@ linters:
- "app/views/admin/questions/show.html.haml" - "app/views/admin/questions/show.html.haml"
- "app/views/admin/roles/show.html.haml" - "app/views/admin/roles/show.html.haml"
- "app/views/admin/schedules/index.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/sponsorship_levels/index.html.haml"
- "app/views/admin/users/_event_registrations.html.haml" - "app/views/admin/users/_event_registrations.html.haml"
- "app/views/admin/users/show.html.haml" - "app/views/admin/users/show.html.haml"

View file

@ -4,8 +4,6 @@ module Admin
load_and_authorize_resource :sponsor, through: :conference load_and_authorize_resource :sponsor, through: :conference
before_action :sponsorship_level_required, only: [:index, :new] before_action :sponsorship_level_required, only: [:index, :new]
helper_method :add_swags
def index def index
authorize! :index, Sponsor.new(conference_id: @conference.id) authorize! :index, Sponsor.new(conference_id: @conference.id)
end end
@ -58,11 +56,6 @@ module Admin
end end
end end
def add_swags
@sponsor.update_attributes(sponsor_params)
redirect_to edit_admin_conference_sponsor_path(@conference.short_title, @sponsor)
end
def confirm def confirm
@sponsor.confirm! @sponsor.confirm!
@ -85,6 +78,17 @@ module Admin
end end
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 def paid
@sponsor.paid = !@sponsor.paid @sponsor.paid = !@sponsor.paid
if @sponsor.save if @sponsor.save

View file

@ -17,18 +17,24 @@ 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: 'unconfirmed') } scope :contacted, -> { where(state: 'contacted') }
scope :to_contact, -> { where(state: 'to_contact') }
state_machine initial: :unconfirmed do state_machine initial: :to_contact do
state :unconfirmed state :to_contact
state :confirmed state :confirmed
state :contacted
event :confirm do event :confirm do
transitions to: :confirmed, from: [:unconfirmed] transitions to: :confirmed, from: [:to_contact, :contacted]
end end
event :cancel do 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
end end

View file

@ -13,7 +13,9 @@
%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: '#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 .tab-content
#sponsorship.tab-pane.active #sponsorship.tab-pane.active
@ -114,16 +116,20 @@
- 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? :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 - 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-warning' method: :patch, class: 'btn btn-mini btn-warning'
- else - else
%p No confirmed sponsors yet! %p No confirmed sponsors yet!
#unconfirmed.tab-pane #contacted.tab-pane
- if @conference.sponsors.unconfirmed.any? - if @conference.sponsors.contacted.any?
.row .row
.col-md-12 .col-md-12
%table.table.table-hover#sponsors %table.table.table-hover
%thead %thead
%th Logo %th Logo
%th Name %th Name
@ -132,7 +138,7 @@
%th Level %th Level
%th Actions %th Actions
%tbody %tbody
- @conference.sponsors.unconfirmed.each do |sponsor| - @conference.sponsors.contacted.each do |sponsor|
%tr %tr
%td %td
= image_tag(sponsor.picture.thumb.url, width: '20%') = image_tag(sponsor.picture.thumb.url, width: '20%')
@ -156,6 +162,47 @@
- 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-warning' 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 - else
%p There are no unconfirmed sponsors %p There are no unconfirmed sponsors
.row .row

View file

@ -121,6 +121,7 @@ Osem::Application.routes.draw do
member do member do
patch :confirm patch :confirm
patch :cancel patch :cancel
patch :contact
end end
end end
resources :lodgings, except: [:show] resources :lodgings, except: [:show]

View file

@ -26,7 +26,7 @@ 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.')
click_link 'Unconfirmed' click_link 'To contact'
within('table#sponsors') do within('table#sponsors') 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