From 66ac45efc8869a8d0ee31474fbc6abc7a6ed6ec6 Mon Sep 17 00:00:00 2001 From: nasia Date: Wed, 17 May 2017 13:31:27 +0300 Subject: [PATCH 1/5] Introduce Booths to OSEM --- app/controllers/booths_controller.rb | 83 +++++++++++++++++++ app/models/booth.rb | 16 ++++ app/models/booth_request.rb | 10 +++ app/models/conference.rb | 1 + app/models/user.rb | 4 +- app/views/booths/_form.html.haml | 28 +++++++ app/views/booths/edit.html.haml | 7 ++ app/views/booths/index.html.haml | 29 +++++++ app/views/booths/new.html.haml | 5 ++ app/views/booths/show.html.haml | 24 ++++++ db/migrate/20170516190048_create_booths.rb | 14 ++++ .../20170530112510_create_booth_requests.rb | 11 +++ db/schema.rb | 23 +++++ test/factories/booth_requests.rb | 7 ++ test/models/booth_request_test.rb | 7 ++ 15 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 app/controllers/booths_controller.rb create mode 100644 app/models/booth.rb create mode 100644 app/models/booth_request.rb create mode 100644 app/views/booths/_form.html.haml create mode 100644 app/views/booths/edit.html.haml create mode 100644 app/views/booths/index.html.haml create mode 100644 app/views/booths/new.html.haml create mode 100644 app/views/booths/show.html.haml create mode 100644 db/migrate/20170516190048_create_booths.rb create mode 100644 db/migrate/20170530112510_create_booth_requests.rb create mode 100644 test/factories/booth_requests.rb create mode 100644 test/models/booth_request_test.rb diff --git a/app/controllers/booths_controller.rb b/app/controllers/booths_controller.rb new file mode 100644 index 00000000..e739eb3a --- /dev/null +++ b/app/controllers/booths_controller.rb @@ -0,0 +1,83 @@ +class BoothsController < ApplicationController + before_action :set_booth, only: [:show, :edit, :update, :destroy] + + # GET /booths + # GET /booths.json + def index + @booths = Booth.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @booths } + end + end + + # GET /booths/1 + # GET /booths/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.json { render json: @booth } + end + end + + # GET /booths/new + def new + @booth = Booth.new + end + + # GET /booths/1/edit + def edit + end + + # POST /booths + # POST /booths.json + def create + @booth = Booth.new(booth_params) + + respond_to do |format| + if @booth.save + format.html { redirect_to @booth, notice: 'Booth was successfully created.' } + format.json { render json: @booth, status: :created } + else + format.html { render action: 'new' } + format.json { render json: @booth.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /booths/1 + # PATCH/PUT /booths/1.json + def update + respond_to do |format| + if @booth.update(booth_params) + format.html { redirect_to @booth, notice: 'Booth was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @booth.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /booths/1 + # DELETE /booths/1.json + def destroy + @booth.destroy + respond_to do |format| + format.html { redirect_to booths_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_booth + @booth = Booth.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def booth_params + params.require(:booth).permit(:title, :conference_id, :description, :state, :reasoning, :logo_link) + end +end diff --git a/app/models/booth.rb b/app/models/booth.rb new file mode 100644 index 00000000..8dffe88e --- /dev/null +++ b/app/models/booth.rb @@ -0,0 +1,16 @@ +class Booth < ActiveRecord::Base + belongs_to :conference + has_many :booth_requests + has_many :users, through: :booth_requests + + validate :title, + uniqueness: { case_sensitive: fasle}, + presence: true + + validates :description, + :reasoning, + :state, + :logo_link + :conference_id, + presence: true +end diff --git a/app/models/booth_request.rb b/app/models/booth_request.rb new file mode 100644 index 00000000..d29c88fd --- /dev/null +++ b/app/models/booth_request.rb @@ -0,0 +1,10 @@ +class BoothRequest < ActiveRecord::Base + belongs_to :booth + belongs_to :user + + validates :booth, + :user, + :role, + presence: true + +end diff --git a/app/models/conference.rb b/app/models/conference.rb index f58c50ed..07940180 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -24,6 +24,7 @@ class Conference < ActiveRecord::Base has_many :supporters, through: :ticket_purchases, source: :user has_many :tickets, dependent: :destroy has_many :resources, dependent: :destroy + has_many :booths, dependent: :destroy has_many :lodgings, dependent: :destroy has_many :registrations, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 4be77fe8..8b0224fa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -50,11 +50,13 @@ class User < ActiveRecord::Base has_many :votes, dependent: :destroy has_many :voted_events, through: :votes, source: :events has_many :subscriptions, dependent: :destroy + has_many :booth_requests + has_many :booths, through: :users_booths accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } scope :active, -> { where(is_disabled: false) } - + validates :email, presence: true validates :username, diff --git a/app/views/booths/_form.html.haml b/app/views/booths/_form.html.haml new file mode 100644 index 00000000..4f85e0f1 --- /dev/null +++ b/app/views/booths/_form.html.haml @@ -0,0 +1,28 @@ += form_for @booth do |f| + - if @booth.errors.any? + #error_explanation + %h2= "#{pluralize(@booth.errors.count, "error")} prohibited this booth from being saved:" + %ul + - @booth.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :title + = f.text_field :title + .field + = f.label :conference_id + = f.number_field :conference_id + .field + = f.label :description + = f.text_area :description + .field + = f.label :state + = f.text_field :state + .field + = f.label :reasoning + = f.text_area :reasoning + .field + = f.label :logo_link + = f.text_field :logo_link + .actions + = f.submit 'Save' diff --git a/app/views/booths/edit.html.haml b/app/views/booths/edit.html.haml new file mode 100644 index 00000000..222d6c97 --- /dev/null +++ b/app/views/booths/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing booth + += render 'form' + += link_to 'Show', @booth +\| += link_to 'Back', booths_path diff --git a/app/views/booths/index.html.haml b/app/views/booths/index.html.haml new file mode 100644 index 00000000..2554b986 --- /dev/null +++ b/app/views/booths/index.html.haml @@ -0,0 +1,29 @@ +%h1 Listing booths + +%table + %tr + %th Title + %th Conference + %th Description + %th State + %th Reasoning + %th Logo link + %th + %th + %th + + - @booths.each do |booth| + %tr + %td= booth.title + %td= booth.conference_id + %td= booth.description + %td= booth.state + %td= booth.reasoning + %td= booth.logo_link + %td= link_to 'Show', booth + %td= link_to 'Edit', edit_booth_path(booth) + %td= link_to 'Destroy', booth, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Booth', new_booth_path diff --git a/app/views/booths/new.html.haml b/app/views/booths/new.html.haml new file mode 100644 index 00000000..3a84ba98 --- /dev/null +++ b/app/views/booths/new.html.haml @@ -0,0 +1,5 @@ +%h1 New booth + += render 'form' + += link_to 'Back', booths_path diff --git a/app/views/booths/show.html.haml b/app/views/booths/show.html.haml new file mode 100644 index 00000000..5c076aca --- /dev/null +++ b/app/views/booths/show.html.haml @@ -0,0 +1,24 @@ +%p#notice= notice + +%p + %b Title: + = @booth.title +%p + %b Conference: + = @booth.conference_id +%p + %b Description: + = @booth.description +%p + %b State: + = @booth.state +%p + %b Reasoning: + = @booth.reasoning +%p + %b Logo link: + = @booth.logo_link + += link_to 'Edit', edit_booth_path(@booth) +\| += link_to 'Back', booths_path diff --git a/db/migrate/20170516190048_create_booths.rb b/db/migrate/20170516190048_create_booths.rb new file mode 100644 index 00000000..3b155bc8 --- /dev/null +++ b/db/migrate/20170516190048_create_booths.rb @@ -0,0 +1,14 @@ +class CreateBooths < ActiveRecord::Migration + def change + create_table :booths do |t| + t.string :title + t.text :description + t.text :reasoning + t.string :state + t.string :logo_link + t.integer :conference_id + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20170530112510_create_booth_requests.rb b/db/migrate/20170530112510_create_booth_requests.rb new file mode 100644 index 00000000..75e73a93 --- /dev/null +++ b/db/migrate/20170530112510_create_booth_requests.rb @@ -0,0 +1,11 @@ +class CreateBoothRequests < ActiveRecord::Migration + def change + create_table :booth_requests do |t| + t.references :booth, index: true, foreign_key: true + t.references :user, index: true, foreign_key: true + t.string :role + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9772066a..4e7366a2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. + ActiveRecord::Schema.define(version: 20170531094819) do create_table "ahoy_events", force: :cascade do |t| @@ -31,6 +32,28 @@ ActiveRecord::Schema.define(version: 20170531094819) do t.datetime "updated_at" end + create_table "booth_requests", force: :cascade do |t| + t.integer "booth_id" + t.integer "user_id" + t.string "role" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "booth_requests", ["booth_id"], name: "index_booth_requests_on_booth_id" + add_index "booth_requests", ["user_id"], name: "index_booth_requests_on_user_id" + + create_table "booths", force: :cascade do |t| + t.string "title" + t.text "description" + t.text "reasoning" + t.string "state" + t.string "logo_link" + t.integer "conference_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "campaigns", force: :cascade do |t| t.integer "conference_id" t.string "name" diff --git a/test/factories/booth_requests.rb b/test/factories/booth_requests.rb new file mode 100644 index 00000000..9a035c3c --- /dev/null +++ b/test/factories/booth_requests.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :booth_request do + booth nil + user nil + role "MyString" + end +end diff --git a/test/models/booth_request_test.rb b/test/models/booth_request_test.rb new file mode 100644 index 00000000..c775f191 --- /dev/null +++ b/test/models/booth_request_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BoothRequestTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 7ee9b2966a3852f7beec61153ed89115b9eb175d Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 6 Jun 2017 21:36:18 +0300 Subject: [PATCH 2/5] Introduce Call for Booths --- app/controllers/call_for_booths_controller.rb | 83 +++++++++++++++++++ app/models/booth.rb | 2 +- app/models/call_for_booth.rb | 22 +++++ app/models/conference.rb | 3 +- app/views/call_for_booths/_form.html.haml | 19 +++++ app/views/call_for_booths/edit.html.haml | 7 ++ app/views/call_for_booths/index.html.haml | 23 +++++ app/views/call_for_booths/new.html.haml | 5 ++ app/views/call_for_booths/show.html.haml | 15 ++++ config/routes.rb | 3 + .../20170606182954_create_call_for_booths.rb | 11 +++ test/factories/booth_requests.rb | 7 -- test/models/booth_request_test.rb | 7 -- 13 files changed, 191 insertions(+), 16 deletions(-) create mode 100644 app/controllers/call_for_booths_controller.rb create mode 100644 app/models/call_for_booth.rb create mode 100644 app/views/call_for_booths/_form.html.haml create mode 100644 app/views/call_for_booths/edit.html.haml create mode 100644 app/views/call_for_booths/index.html.haml create mode 100644 app/views/call_for_booths/new.html.haml create mode 100644 app/views/call_for_booths/show.html.haml create mode 100644 db/migrate/20170606182954_create_call_for_booths.rb delete mode 100644 test/factories/booth_requests.rb delete mode 100644 test/models/booth_request_test.rb diff --git a/app/controllers/call_for_booths_controller.rb b/app/controllers/call_for_booths_controller.rb new file mode 100644 index 00000000..16d38a33 --- /dev/null +++ b/app/controllers/call_for_booths_controller.rb @@ -0,0 +1,83 @@ +class CallForBoothsController < ApplicationController + before_action :set_call_for_booth, only: [:show, :edit, :update, :destroy] + + # GET /call_for_booths + # GET /call_for_booths.json + def index + @call_for_booths = CallForBooth.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @call_for_booths } + end + end + + # GET /call_for_booths/1 + # GET /call_for_booths/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.json { render json: @call_for_booth } + end + end + + # GET /call_for_booths/new + def new + @call_for_booth = CallForBooth.new + end + + # GET /call_for_booths/1/edit + def edit + end + + # POST /call_for_booths + # POST /call_for_booths.json + def create + @call_for_booth = CallForBooth.new(call_for_booth_params) + + respond_to do |format| + if @call_for_booth.save + format.html { redirect_to @call_for_booth, notice: 'Call for booth was successfully created.' } + format.json { render json: @call_for_booth, status: :created } + else + format.html { render action: 'new' } + format.json { render json: @call_for_booth.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /call_for_booths/1 + # PATCH/PUT /call_for_booths/1.json + def update + respond_to do |format| + if @call_for_booth.update(call_for_booth_params) + format.html { redirect_to @call_for_booth, notice: 'Call for booth was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @call_for_booth.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /call_for_booths/1 + # DELETE /call_for_booths/1.json + def destroy + @call_for_booth.destroy + respond_to do |format| + format.html { redirect_to call_for_booths_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_call_for_booth + @call_for_booth = CallForBooth.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def call_for_booth_params + params.require(:call_for_booth).permit(:start_date, :end_date, :booth_limit) + end +end diff --git a/app/models/booth.rb b/app/models/booth.rb index 8dffe88e..59e1a734 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -3,7 +3,7 @@ class Booth < ActiveRecord::Base has_many :booth_requests has_many :users, through: :booth_requests - validate :title, + validates :title, uniqueness: { case_sensitive: fasle}, presence: true diff --git a/app/models/call_for_booth.rb b/app/models/call_for_booth.rb new file mode 100644 index 00000000..0f16cdcd --- /dev/null +++ b/app/models/call_for_booth.rb @@ -0,0 +1,22 @@ +class CallForBooth < ActiveRecord::Base + belongs_to :conference + + validates :start_date, :end_date, :booth_limit, presence: true + validate :before_end_of_conference + validate :start_date_before_end_date + + private + + def before_end_of_conference + errors + .add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date) + + errors + .add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date) + end + + def start_date_before_end_date + errors + .add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date + end +end diff --git a/app/models/conference.rb b/app/models/conference.rb index 07940180..fd62c7bb 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -16,6 +16,7 @@ class Conference < ActiveRecord::Base has_one :splashpage, dependent: :destroy has_one :contact, dependent: :destroy has_one :registration_period, dependent: :destroy + has_one :call_for_booths, dependent: :destroy has_one :email_settings, dependent: :destroy has_one :program, dependent: :destroy has_one :venue, dependent: :destroy @@ -24,7 +25,7 @@ class Conference < ActiveRecord::Base has_many :supporters, through: :ticket_purchases, source: :user has_many :tickets, dependent: :destroy has_many :resources, dependent: :destroy - has_many :booths, dependent: :destroy + has_many :booths, dependent: :destroy has_many :lodgings, dependent: :destroy has_many :registrations, dependent: :destroy diff --git a/app/views/call_for_booths/_form.html.haml b/app/views/call_for_booths/_form.html.haml new file mode 100644 index 00000000..61331987 --- /dev/null +++ b/app/views/call_for_booths/_form.html.haml @@ -0,0 +1,19 @@ += form_for @call_for_booth do |f| + - if @call_for_booth.errors.any? + #error_explanation + %h2= "#{pluralize(@call_for_booth.errors.count, "error")} prohibited this call_for_booth from being saved:" + %ul + - @call_for_booth.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :start_date + = f.date_select :start_date + .field + = f.label :end_date + = f.date_select :end_date + .field + = f.label :booth_limit + = f.number_field :booth_limit + .actions + = f.submit 'Save' diff --git a/app/views/call_for_booths/edit.html.haml b/app/views/call_for_booths/edit.html.haml new file mode 100644 index 00000000..f6ef190c --- /dev/null +++ b/app/views/call_for_booths/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing call_for_booth + += render 'form' + += link_to 'Show', @call_for_booth +\| += link_to 'Back', call_for_booths_path diff --git a/app/views/call_for_booths/index.html.haml b/app/views/call_for_booths/index.html.haml new file mode 100644 index 00000000..767c67b8 --- /dev/null +++ b/app/views/call_for_booths/index.html.haml @@ -0,0 +1,23 @@ +%h1 Listing call_for_booths + +%table + %tr + %th Start date + %th End date + %th Booth limit + %th + %th + %th + + - @call_for_booths.each do |call_for_booth| + %tr + %td= call_for_booth.start_date + %td= call_for_booth.end_date + %td= call_for_booth.booth_limit + %td= link_to 'Show', call_for_booth + %td= link_to 'Edit', edit_call_for_booth_path(call_for_booth) + %td= link_to 'Destroy', call_for_booth, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Call for booth', new_call_for_booth_path diff --git a/app/views/call_for_booths/new.html.haml b/app/views/call_for_booths/new.html.haml new file mode 100644 index 00000000..b8f9c3eb --- /dev/null +++ b/app/views/call_for_booths/new.html.haml @@ -0,0 +1,5 @@ +%h1 New call_for_booth + += render 'form' + += link_to 'Back', call_for_booths_path diff --git a/app/views/call_for_booths/show.html.haml b/app/views/call_for_booths/show.html.haml new file mode 100644 index 00000000..69b4e773 --- /dev/null +++ b/app/views/call_for_booths/show.html.haml @@ -0,0 +1,15 @@ +%p#notice= notice + +%p + %b Start date: + = @call_for_booth.start_date +%p + %b End date: + = @call_for_booth.end_date +%p + %b Booth limit: + = @call_for_booth.booth_limit + += link_to 'Edit', edit_call_for_booth_path(@call_for_booth) +\| += link_to 'Back', call_for_booths_path diff --git a/config/routes.rb b/config/routes.rb index ccca3511..c5889406 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Osem::Application.routes.draw do + if ENV['OSEM_ICHAIN_ENABLED'] == 'true' devise_for :users, controllers: { registrations: :registrations } else @@ -30,6 +31,7 @@ Osem::Application.routes.draw do resources :conferences do resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] + resources :booths resources :event_schedules, only: [:create, :update, :destroy] get 'commercials/render_commercial' => 'commercials#render_commercial' resources :commercials, only: [:index, :create, :update, :destroy] @@ -52,6 +54,7 @@ Osem::Application.routes.draw do resources :rooms, except: [:show] end resource :registration_period + resource :call_for_booths resource :program do resource :cfp resources :tracks diff --git a/db/migrate/20170606182954_create_call_for_booths.rb b/db/migrate/20170606182954_create_call_for_booths.rb new file mode 100644 index 00000000..fe4e6f3c --- /dev/null +++ b/db/migrate/20170606182954_create_call_for_booths.rb @@ -0,0 +1,11 @@ +class CreateCallForBooths < ActiveRecord::Migration + def change + create_table :call_for_booths do |t| + t.date :start_date + t.date :end_date + t.integer :booth_limit + + t.timestamps null: false + end + end +end diff --git a/test/factories/booth_requests.rb b/test/factories/booth_requests.rb deleted file mode 100644 index 9a035c3c..00000000 --- a/test/factories/booth_requests.rb +++ /dev/null @@ -1,7 +0,0 @@ -FactoryGirl.define do - factory :booth_request do - booth nil - user nil - role "MyString" - end -end diff --git a/test/models/booth_request_test.rb b/test/models/booth_request_test.rb deleted file mode 100644 index c775f191..00000000 --- a/test/models/booth_request_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class BoothRequestTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end From 9103f511a78ecf0589b585f5b993fcbe20a00228 Mon Sep 17 00:00:00 2001 From: nasia Date: Sat, 10 Jun 2017 15:17:19 +0300 Subject: [PATCH 3/5] Create tests for models --- app/models/call_for_booth.rb | 2 ++ spec/models/booth_spec.rb | 24 ++++++++++++++++++++++++ spec/models/call_for_booth_spec.rb | 15 +++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 spec/models/booth_spec.rb create mode 100644 spec/models/call_for_booth_spec.rb diff --git a/app/models/call_for_booth.rb b/app/models/call_for_booth.rb index 0f16cdcd..321ca2b9 100644 --- a/app/models/call_for_booth.rb +++ b/app/models/call_for_booth.rb @@ -1,6 +1,8 @@ class CallForBooth < ActiveRecord::Base belongs_to :conference + has_one :conference + validates :start_date, :end_date, :booth_limit, presence: true validate :before_end_of_conference validate :start_date_before_end_date diff --git a/spec/models/booth_spec.rb b/spec/models/booth_spec.rb new file mode 100644 index 00000000..04e6bf3f --- /dev/null +++ b/spec/models/booth_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe 'Booth' do + subject { create(:booth) } + let!(:conference) { create(:conference) } + + describe 'validation' do + it 'has a valid factory' do + expect(build(:booth)).to be_valid + end + + it { is_expected.to validate_presence_of(:conference) } + + it 'is not valid without a title' do + should validate_presence_of(:title) + end + end + + describe 'association' do + it { is_expected.to belong_to(:conference) } + it { is_expected.to have_many(:booth_requests) } + end + +end diff --git a/spec/models/call_for_booth_spec.rb b/spec/models/call_for_booth_spec.rb new file mode 100644 index 00000000..a9a07254 --- /dev/null +++ b/spec/models/call_for_booth_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe CallForBooth do + it 'has a valid factory' do + expect(build(:call_for_booths)).to be_valid + end + + it 'is not valid without a start_date' do + should validate_presence_of(:start_date) + end + + it 'is not valid without an end_date' do + should validate_presence_of(:end_date) + end +end From 318c0d15a4d0c3bf22e94b532a581cd69f6fd3a6 Mon Sep 17 00:00:00 2001 From: nasia Date: Sat, 10 Jun 2017 23:50:31 +0300 Subject: [PATCH 4/5] Refactor admin/call_for_booth controller --- app/controllers/admin/booths_controller.rb | 21 +++++++ .../admin/call_for_booths_controller.rb | 55 +++++++++++++++++++ app/controllers/booths_controller.rb | 12 ---- app/models/booth.rb | 4 +- app/models/call_for_booth.rb | 2 - app/views/admin/booths/_form.html.haml | 28 ++++++++++ app/views/admin/booths/edit.html.haml | 7 +++ app/views/admin/booths/index.html.haml | 29 ++++++++++ app/views/admin/booths/new.html.haml | 5 ++ app/views/admin/booths/show.html.haml | 24 ++++++++ .../call_for_booths/_form.html.haml | 0 .../call_for_booths/edit.html.haml | 0 .../call_for_booths/index.html.haml | 0 .../{ => admin}/call_for_booths/new.html.haml | 0 .../call_for_booths/show.html.haml | 0 .../20170606182954_create_call_for_booths.rb | 1 + db/schema.rb | 12 +++- 17 files changed, 182 insertions(+), 18 deletions(-) create mode 100644 app/controllers/admin/booths_controller.rb create mode 100644 app/controllers/admin/call_for_booths_controller.rb create mode 100644 app/views/admin/booths/_form.html.haml create mode 100644 app/views/admin/booths/edit.html.haml create mode 100644 app/views/admin/booths/index.html.haml create mode 100644 app/views/admin/booths/new.html.haml create mode 100644 app/views/admin/booths/show.html.haml rename app/views/{ => admin}/call_for_booths/_form.html.haml (100%) rename app/views/{ => admin}/call_for_booths/edit.html.haml (100%) rename app/views/{ => admin}/call_for_booths/index.html.haml (100%) rename app/views/{ => admin}/call_for_booths/new.html.haml (100%) rename app/views/{ => admin}/call_for_booths/show.html.haml (100%) diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb new file mode 100644 index 00000000..65f6f9f6 --- /dev/null +++ b/app/controllers/admin/booths_controller.rb @@ -0,0 +1,21 @@ +module Admin + class Admin::BoothsController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource :booth, through: :conference + + def index + @booths = @conference.booths + end + + def show; end + + def new; end + + def create; end + + def update; end + + def destroy; end + + end +end diff --git a/app/controllers/admin/call_for_booths_controller.rb b/app/controllers/admin/call_for_booths_controller.rb new file mode 100644 index 00000000..39fee8eb --- /dev/null +++ b/app/controllers/admin/call_for_booths_controller.rb @@ -0,0 +1,55 @@ +module Admin + class CallForBoothsController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource through: :conference, singleton: true + + def show; end + + + def new + @call_for_booth = CallForBooth.new(conference: @conference) + end + + def edit; end + + def create + @call_for_booth = @conference.call_for_booth.build(call_for_booth_params) + + if @call_for_booth.save + redirect_to admin_conference_call_for_booth_path, + notice: "Call for booths successfully created." + else + flash[:error] = "Creating the call for booths failed. #{@call_for_booth.errors.full_messages.join('. ')}." + render :new + end + end + + def update + @call_for_booth = @conference.call_for_booth + @call_for_booth.assign_attributes(call_for_booth_params) + + if @call_for_booth.update_attributes(call_for_booth_params) + redirect_to admin_conference_call_for_booth_path(@conference.short_title), + notice: 'Call for booths successfully updated.' + else + flash.now[:error] = "Updating call for booths failed. #{@call_for_booth.errors.to_a.join('. ')}." + render :new + end + end + + def destroy + if @call_for_booth.destroy + redirect_to admin_conference_call_for_booth_path, notice: 'Call for Booths successfully deleted.' + else + redirect_to admin_conference_call_for_booth_path, error: 'An error prohibited this Call for Booths from being destroyed: '\ + "#{@call_for_booth.errors.full_messages.join('. ')}." + end + end + + private + + def call_for_booth_params + params.require(:call_for_booth).permit(:start_date, :end_date, :booth_limit) + end + end +end diff --git a/app/controllers/booths_controller.rb b/app/controllers/booths_controller.rb index e739eb3a..232150a5 100644 --- a/app/controllers/booths_controller.rb +++ b/app/controllers/booths_controller.rb @@ -2,22 +2,18 @@ class BoothsController < ApplicationController before_action :set_booth, only: [:show, :edit, :update, :destroy] # GET /booths - # GET /booths.json def index @booths = Booth.all respond_to do |format| format.html # index.html.erb - format.json { render json: @booths } end end # GET /booths/1 - # GET /booths/1.json def show respond_to do |format| format.html # show.html.erb - format.json { render json: @booth } end end @@ -31,42 +27,34 @@ class BoothsController < ApplicationController end # POST /booths - # POST /booths.json def create @booth = Booth.new(booth_params) respond_to do |format| if @booth.save format.html { redirect_to @booth, notice: 'Booth was successfully created.' } - format.json { render json: @booth, status: :created } else format.html { render action: 'new' } - format.json { render json: @booth.errors, status: :unprocessable_entity } end end end # PATCH/PUT /booths/1 - # PATCH/PUT /booths/1.json def update respond_to do |format| if @booth.update(booth_params) format.html { redirect_to @booth, notice: 'Booth was successfully updated.' } - format.json { head :no_content } else format.html { render action: 'edit' } - format.json { render json: @booth.errors, status: :unprocessable_entity } end end end # DELETE /booths/1 - # DELETE /booths/1.json def destroy @booth.destroy respond_to do |format| format.html { redirect_to booths_url } - format.json { head :no_content } end end diff --git a/app/models/booth.rb b/app/models/booth.rb index 59e1a734..35ea1a42 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -4,13 +4,13 @@ class Booth < ActiveRecord::Base has_many :users, through: :booth_requests validates :title, - uniqueness: { case_sensitive: fasle}, + uniqueness: { case_sensitive: false }, presence: true validates :description, :reasoning, :state, - :logo_link + :logo_link, :conference_id, presence: true end diff --git a/app/models/call_for_booth.rb b/app/models/call_for_booth.rb index 321ca2b9..0f16cdcd 100644 --- a/app/models/call_for_booth.rb +++ b/app/models/call_for_booth.rb @@ -1,8 +1,6 @@ class CallForBooth < ActiveRecord::Base belongs_to :conference - has_one :conference - validates :start_date, :end_date, :booth_limit, presence: true validate :before_end_of_conference validate :start_date_before_end_date diff --git a/app/views/admin/booths/_form.html.haml b/app/views/admin/booths/_form.html.haml new file mode 100644 index 00000000..4f85e0f1 --- /dev/null +++ b/app/views/admin/booths/_form.html.haml @@ -0,0 +1,28 @@ += form_for @booth do |f| + - if @booth.errors.any? + #error_explanation + %h2= "#{pluralize(@booth.errors.count, "error")} prohibited this booth from being saved:" + %ul + - @booth.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label :title + = f.text_field :title + .field + = f.label :conference_id + = f.number_field :conference_id + .field + = f.label :description + = f.text_area :description + .field + = f.label :state + = f.text_field :state + .field + = f.label :reasoning + = f.text_area :reasoning + .field + = f.label :logo_link + = f.text_field :logo_link + .actions + = f.submit 'Save' diff --git a/app/views/admin/booths/edit.html.haml b/app/views/admin/booths/edit.html.haml new file mode 100644 index 00000000..222d6c97 --- /dev/null +++ b/app/views/admin/booths/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing booth + += render 'form' + += link_to 'Show', @booth +\| += link_to 'Back', booths_path diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml new file mode 100644 index 00000000..74287f50 --- /dev/null +++ b/app/views/admin/booths/index.html.haml @@ -0,0 +1,29 @@ +%h1 Listing booths + +%table + %tr + %th Title + %th Conference + %th Description + %th State + %th Reasoning + %th Logo link + %th + %th + %th + + - @booths.each do |booth| + %tr + %td= booth.title + %td= booth.conference_id + %td= booth.description + %td= booth.state + %td= booth.reasoning + %td= booth.logo_link + %td= link_to 'Show', booth + %td= link_to 'Edit', edit_booth_path(booth) + %td= link_to 'Destroy', booth, :method => :delete, :data => { :confirm => 'Are you sure?' } + +%br + += link_to 'New Booth', new_admin_conference_booth_path diff --git a/app/views/admin/booths/new.html.haml b/app/views/admin/booths/new.html.haml new file mode 100644 index 00000000..3a84ba98 --- /dev/null +++ b/app/views/admin/booths/new.html.haml @@ -0,0 +1,5 @@ +%h1 New booth + += render 'form' + += link_to 'Back', booths_path diff --git a/app/views/admin/booths/show.html.haml b/app/views/admin/booths/show.html.haml new file mode 100644 index 00000000..5c076aca --- /dev/null +++ b/app/views/admin/booths/show.html.haml @@ -0,0 +1,24 @@ +%p#notice= notice + +%p + %b Title: + = @booth.title +%p + %b Conference: + = @booth.conference_id +%p + %b Description: + = @booth.description +%p + %b State: + = @booth.state +%p + %b Reasoning: + = @booth.reasoning +%p + %b Logo link: + = @booth.logo_link + += link_to 'Edit', edit_booth_path(@booth) +\| += link_to 'Back', booths_path diff --git a/app/views/call_for_booths/_form.html.haml b/app/views/admin/call_for_booths/_form.html.haml similarity index 100% rename from app/views/call_for_booths/_form.html.haml rename to app/views/admin/call_for_booths/_form.html.haml diff --git a/app/views/call_for_booths/edit.html.haml b/app/views/admin/call_for_booths/edit.html.haml similarity index 100% rename from app/views/call_for_booths/edit.html.haml rename to app/views/admin/call_for_booths/edit.html.haml diff --git a/app/views/call_for_booths/index.html.haml b/app/views/admin/call_for_booths/index.html.haml similarity index 100% rename from app/views/call_for_booths/index.html.haml rename to app/views/admin/call_for_booths/index.html.haml diff --git a/app/views/call_for_booths/new.html.haml b/app/views/admin/call_for_booths/new.html.haml similarity index 100% rename from app/views/call_for_booths/new.html.haml rename to app/views/admin/call_for_booths/new.html.haml diff --git a/app/views/call_for_booths/show.html.haml b/app/views/admin/call_for_booths/show.html.haml similarity index 100% rename from app/views/call_for_booths/show.html.haml rename to app/views/admin/call_for_booths/show.html.haml diff --git a/db/migrate/20170606182954_create_call_for_booths.rb b/db/migrate/20170606182954_create_call_for_booths.rb index fe4e6f3c..d6fdd9b5 100644 --- a/db/migrate/20170606182954_create_call_for_booths.rb +++ b/db/migrate/20170606182954_create_call_for_booths.rb @@ -4,6 +4,7 @@ class CreateCallForBooths < ActiveRecord::Migration t.date :start_date t.date :end_date t.integer :booth_limit + t.references :conference t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 4e7366a2..ea9c99d9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,8 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20170531094819) do +ActiveRecord::Schema.define(version: 20170606182954) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -54,6 +53,15 @@ ActiveRecord::Schema.define(version: 20170531094819) do t.datetime "updated_at", null: false end + create_table "call_for_booths", force: :cascade do |t| + t.date "start_date" + t.date "end_date" + t.integer "booth_limit" + t.integer "conference_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "campaigns", force: :cascade do |t| t.integer "conference_id" t.string "name" From 98e0a256064eeb99b17184864b876e033facde91 Mon Sep 17 00:00:00 2001 From: nasia Date: Sun, 18 Jun 2017 23:33:54 +0300 Subject: [PATCH 5/5] Modify views for booths --- app/controllers/admin/booths_controller.rb | 67 +++++++++++++++- app/models/booth.rb | 33 ++++++++ app/models/booth_request.rb | 2 + .../booths/_change_state_dropdown.html.haml | 25 ++++++ app/views/admin/booths/_form.html.haml | 43 ++++------- app/views/admin/booths/edit.html.haml | 4 - app/views/admin/booths/index.html.haml | 76 ++++++++++++------- app/views/admin/booths/new.html.haml | 2 +- app/views/admin/booths/show.html.haml | 42 +++++----- config/routes.rb | 14 +++- 10 files changed, 220 insertions(+), 88 deletions(-) create mode 100644 app/views/admin/booths/_change_state_dropdown.html.haml diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index 65f6f9f6..c946e274 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -3,19 +3,80 @@ module Admin load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :booth, through: :conference + def index @booths = @conference.booths end def show; end - def new; end + def new + @booth = Booth.new(conference: @conference) + end - def create; end + def create + @booth = @conference.booths.build(booth_params) - def update; end + if @booth.save + redirect_to admin_conference_booths_path, + notice: "Booth successfully created." + else + flash[:error] = "Creating booth failed. #{@booth.errors.full_messages.join('. ')}." + render :new + end + end + + def edit; end + + def update + @booth = @conference.booths + @booth.assign_attributes(booth_params) + + + if @booth.update_attributes(booth_params) + redirect_to admin_conference_booths_path, + notice: "Successfully updated booth for #{@booth.title}." + else + flash[:error] = "An error prohibited the Booth for #{@booth.title} "\ + "#{@booth.errors.full_messages.join('. ')}." + render :edit + end + end def destroy; end + def accept + update_state(:accept, 'Booth accepted!') + end + + def to_accept + update_state(:to_accept, 'Booth to accept') + end + + def reject + update_state(:rejected, 'Booth rejected') + end + + def reset + update_state(:reset, 'Booth is submitted') + end + + private + + def update_state(transition, notice) + alert = @booth.update_state(transition, notice) + + if alert.blank? + flash[:notice] = notice + redirect_back_or_to(admin_conference_booths_path(conference_id: @conference.short_title)) && return + else + flash[:error] = alert + return redirect_back_or_to(admin_conference_booths_path(conference_id: @conference.short_title)) && return + end + end + + def booth_params + params.require(:booth).permit(:title, :description, :reasoning, :state, :logo_link, :conference_id) + end end end diff --git a/app/models/booth.rb b/app/models/booth.rb index 35ea1a42..f68d31d7 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -1,4 +1,6 @@ class Booth < ActiveRecord::Base + include ActiveRecord::Transitions + belongs_to :conference has_many :booth_requests has_many :users, through: :booth_requests @@ -13,4 +15,35 @@ class Booth < ActiveRecord::Base :logo_link, :conference_id, presence: true + + state_machine initial: :submitted do + state :submitted + state :withdrawn + state :to_accept + state :accepted + state :rejected + + event :restart do + transitions to: :submitted, from: [:withdrawn] + end + event :withdrawn do + transitions to: :withdrawn, from: [:submitted, :to_accept, :accepted] + end + event :to_accept do + transitions to: :to_accept, from: [:submitted, :rejected, :accepted] + end + event :accept do + transitions to: :accepted, from: [:submitted, :to_accept] + end + event :reject do + transitions to: :rejected, from: [:submitted] + end + event :reset do + transitions to: :submitted, from: [:to_accept] + end + end + + def transition_possible?(transition) + self.class.state_machine.events_for(current_state).include?(transition) + end end diff --git a/app/models/booth_request.rb b/app/models/booth_request.rb index d29c88fd..91099bc6 100644 --- a/app/models/booth_request.rb +++ b/app/models/booth_request.rb @@ -7,4 +7,6 @@ class BoothRequest < ActiveRecord::Base :role, presence: true + ROLES = [%w[Submitter submitter], %w[Responsible responsible], %w[Secondary secondary]] + end diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml new file mode 100644 index 00000000..2225de76 --- /dev/null +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -0,0 +1,25 @@ +- if booth.transition_possible? :accept + %li= link_to 'Accept booth', + accept_admin_conference_booth_path(@conference.short_title, booth), + method: :patch, id: "accept_booth_#{booth.id}" + +- if booth.transition_possible? :reject + %li= link_to 'Reject booth', + reject_admin_conference_booth_path(@conference.short_title, booth), + method: :patch, confirm: 'Are you sure?', id: "reject_booth_#{booth.id}" + + +- if booth.transition_possible? :restart + %li= link_to 'Start review', + restart_admin_conference_booth_path(@conference.short_title, booth), + method: :patch, id: "restart_booth_#{booth.id}" + +- if booth.transition_possible? :to_accept + %li= link_to 'To accept booth', + to_accept_admin_conference_booth_path(@conference.short_title, booth), + method: :patch, id: "to_accept_booth_#{booth.id}" + +- if booth.transition_possible? :cancel + %li= link_to 'Cancel booth', + cancel_admin_conference_booth_path(@conference.short_title, booth), + method: :patch, id: "cancel_booth_#{booth.id}" diff --git a/app/views/admin/booths/_form.html.haml b/app/views/admin/booths/_form.html.haml index 4f85e0f1..500ce632 100644 --- a/app/views/admin/booths/_form.html.haml +++ b/app/views/admin/booths/_form.html.haml @@ -1,28 +1,17 @@ -= form_for @booth do |f| - - if @booth.errors.any? - #error_explanation - %h2= "#{pluralize(@booth.errors.count, "error")} prohibited this booth from being saved:" - %ul - - @booth.errors.full_messages.each do |msg| - %li= msg +.row + .col-md-12 + .page-header + %title Request a Booth +.row + .col-md-8 + = semantic_form_for(@booth, url: admin_conference_booths_path(@conference.short_title), html: {multipart: true}) do |f| + = f.input :title, as: :string, required: true + = f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true + = f.input :reasoning, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, required: true + = f.input :logo_link, as: :string, required: true - .field - = f.label :title - = f.text_field :title - .field - = f.label :conference_id - = f.number_field :conference_id - .field - = f.label :description - = f.text_area :description - .field - = f.label :state - = f.text_field :state - .field - = f.label :reasoning - = f.text_area :reasoning - .field - = f.label :logo_link - = f.text_field :logo_link - .actions - = f.submit 'Save' + %p.text-right + - if @booth.new_record? + = f.submit 'Create Booth Request', class: 'btn btn-success' + - else + = f.submit 'Update Booth Request', class: 'btn btn-success' diff --git a/app/views/admin/booths/edit.html.haml b/app/views/admin/booths/edit.html.haml index 222d6c97..d614398b 100644 --- a/app/views/admin/booths/edit.html.haml +++ b/app/views/admin/booths/edit.html.haml @@ -1,7 +1,3 @@ %h1 Editing booth = render 'form' - -= link_to 'Show', @booth -\| -= link_to 'Back', booths_path diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml index 74287f50..43db4b1a 100644 --- a/app/views/admin/booths/index.html.haml +++ b/app/views/admin/booths/index.html.haml @@ -1,29 +1,47 @@ -%h1 Listing booths - -%table - %tr - %th Title - %th Conference - %th Description - %th State - %th Reasoning - %th Logo link - %th - %th - %th - - - @booths.each do |booth| - %tr - %td= booth.title - %td= booth.conference_id - %td= booth.description - %td= booth.state - %td= booth.reasoning - %td= booth.logo_link - %td= link_to 'Show', booth - %td= link_to 'Edit', edit_booth_path(booth) - %td= link_to 'Destroy', booth, :method => :delete, :data => { :confirm => 'Are you sure?' } - -%br - -= link_to 'New Booth', new_admin_conference_booth_path +.row + .col-md-12 + .page-header + %h1 + Booths + = "(#{@booths.length})" if @booths.any? + .pull-right + - if can? :create, Booth + =link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-default btn-info' + %p.text-muted + All the booth requests +.row + .col-md-12 + .margin-event-table + %table.table.table-striped.table-bordered.table-hover.datatable + %thead + %th + %b ID + %th + %b Title + %th + %b Submitter + %th + %b Responsible + %th + %b Secondary Responsible + %th + %b State + - @booths.each do |booth| + %tr + %td + = booth.id + %td + = link_to booth.title, admin_conference_booth_path(@conference.short_title, booth) + %td + a + %td + b + %td + c + %td + .btn-group + %button{ type: 'button', class: 'btn btn-link dropdown-toggle', 'data-toggle' => 'dropdown' } + = booth.state.humanize + %span.caret + %ul.dropdown-menu{ role: 'menu' } + = render 'change_state_dropdown', booth: booth diff --git a/app/views/admin/booths/new.html.haml b/app/views/admin/booths/new.html.haml index 3a84ba98..f6dd2fc4 100644 --- a/app/views/admin/booths/new.html.haml +++ b/app/views/admin/booths/new.html.haml @@ -2,4 +2,4 @@ = render 'form' -= link_to 'Back', booths_path += link_to 'Back', admin_conference_booths_path diff --git a/app/views/admin/booths/show.html.haml b/app/views/admin/booths/show.html.haml index 5c076aca..77dd180c 100644 --- a/app/views/admin/booths/show.html.haml +++ b/app/views/admin/booths/show.html.haml @@ -1,24 +1,20 @@ -%p#notice= notice +.row + .col-md-12 + %h3 + = @booth.title + .btn-group.pull-right + = link_to 'Edit', edit_admin_conference_booth_path(@conference.short_title, @booth), class: 'btn btn-mini btn-primary' -%p - %b Title: - = @booth.title -%p - %b Conference: - = @booth.conference_id -%p - %b Description: - = @booth.description -%p - %b State: - = @booth.state -%p - %b Reasoning: - = @booth.reasoning -%p - %b Logo link: - = @booth.logo_link - -= link_to 'Edit', edit_booth_path(@booth) -\| -= link_to 'Back', booths_path +.row + .col-md-12 + %table.table + %tr + %td.col-md-2 + %b Description + %td + = @booth.description + %tr + %td.col-md-2 + %b Reasoning + %td + = @booth.reasoning diff --git a/config/routes.rb b/config/routes.rb index c5889406..ec6392df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,13 +31,25 @@ Osem::Application.routes.draw do resources :conferences do resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] - resources :booths + resources :event_schedules, only: [:create, :update, :destroy] get 'commercials/render_commercial' => 'commercials#render_commercial' resources :commercials, only: [:index, :create, :update, :destroy] get '/volunteers_list' => 'volunteers#show' get '/volunteers' => 'volunteers#index', as: 'volunteers_info' patch '/volunteers' => 'volunteers#update', as: 'volunteers_update' + patch '/booths' => 'booths#update' + + resources :booths do + member do + patch :accept + patch :restart + patch :withdrawn + patch :to_accept + patch :reject + patch :reset + end + end resources :registrations, except: [:create, :new] do member do