From 7cd16353171d823610fef59c0bb2246ee1747c8f Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 29 Aug 2017 12:04:31 +0300 Subject: [PATCH] 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