Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft event dashboard 129621349 #193

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//= require dataTables/jquery.dataTables
//= require jquery.remotipart
//= require jquery-ui/autocomplete
//= require event_autocomplete
//= require materialize-sprockets
//= require social-share-button
//= require_tree .
Expand Down
8 changes: 8 additions & 0 deletions app/assets/javascripts/event_autocomplete.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jQuery ->
$('.add_staff_field').autocomplete
delay: 500
minLength: 1
source: '/lookup_staffs'
select: (event, ui) ->
staffId = ui.item.data
$('#staff_id').val(staffId)
11 changes: 1 addition & 10 deletions app/assets/javascripts/event_staff.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ $(document).ready(function () {
return true;
}
};
$('.add_staff_field').autocomplete({
delay: 500,
minLength: 1,
source: '/lookup_staffs',
select: function (event, ui) {
var staffId = ui.item.data;
$('#staff_id').val(staffId);
}
});
$('.event_staffs').on('click', '.remove_staff', function () {
$(this).parents('.chip').hide('slow', function () {
$(this).remove();
Expand All @@ -92,4 +83,4 @@ $(document).ready(function () {
}
});
});
});
});
73 changes: 73 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;

&:visited {
color: #666;
}

&:hover {
color: #fff;
background-color: #000;
}
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;

h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}

ul li {
font-size: 12px;
list-style: square;
}
}
8 changes: 8 additions & 0 deletions app/assets/stylesheets/welcome.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ input[type=text]:focus:not([readonly]) {

.tabs .tab a {
color: rgb(140, 131, 131);
padding: 10px;
display: block;
width: 100%;
height: 100%;
Expand All @@ -264,8 +265,15 @@ input[type=text]:focus:not([readonly]) {
transition: color 0.28s ease;
}

.tabs .tab .active {
background-color: teal;
color: white;
}

.tabs .tab a:hover { color: #f9c9cb; }

h5.col.s12 { margin: 20px 0; }

footer.page-footer {
position: relative;
z-index: 40;
Expand Down
20 changes: 16 additions & 4 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class EventsController < ApplicationController
:disable,
:generate,
:scan,
:administer_full,
:tickets_report
]
before_action :set_sponsor
before_action :set_roles, only: [:edit, :update, :create, :administer]
before_action :subscription_status, only: [:show]

layout "admin", only: [:tickets, :tickets_report]
layout "admin", only: [:administer, :tickets, :tickets_report]

respond_to :html, :json, :js

Expand All @@ -40,7 +42,6 @@ def show
end

def edit
@roles = Event.get_roles
@highlights = @event.highlights
end

Expand All @@ -60,7 +61,6 @@ def scan
end

def update
@roles = Event.get_roles
@event.event_staffs.delete_all
flash[:notice] = if @event.update(event_params)
update_successful_message("event")
Expand All @@ -71,18 +71,26 @@ def update
end

def create
@roles = Event.get_roles
@event = Event.new(event_params).decorate
@event.manager_profile = current_user.manager_profile
@event.title = @event.title.strip
flash[:notice] = if @event.save
@event.event_staffs.create(
role: 2,
user_id: current_user.id,
event_id: @event.id
)
create_successful_message("event")
else
@event.errors.full_messages.join("; ")
end
respond_with(@event)
end

def administer
@my_events = User.get_team_events(current_user)
end

def tickets
@bookings = current_user.user_tickets_for_event(params[:id])
end
Expand Down Expand Up @@ -149,6 +157,10 @@ def set_sponsor
@sponsors = @event.sponsors.group_by(&:level) if @event
end

def set_roles
@roles = Event.get_roles
end

def subscription_status
@subscribed = Subscription.find_by(
event_id: @event.id,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sponsors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class SponsorsController < ApplicationController
before_action :find_event, :all_sponsors
before_action :find_sponsor, only: [:edit, :update, :destroy]
respond_to :html, :js

layout "admin"
def index
@sponsors = @event.sponsors.group_by(&:level)
Expand Down
62 changes: 62 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class TasksController < ApplicationController
load_and_authorize_resource
before_action :find_event, :all_tasks, :find_task

layout "admin"

def index
end

def show
@task = Task.new
end

def new
@task = @event.tasks.new
end

def create
@task = @event.tasks.new(task_params)
@task.assigner = current_user
@task.event = @event
if @task.save
flash[:success] = create_successful_message("Task")
else
flash[:error] = create_failure_message("Task")
end
end

def edit
end

def update
if @task.update(task_params)
flash[:success] = update_successful_message("task")
else
flash[:error] = update_failure_message("task")
end
end

def destroy
@task.destroy
flash[:success] = delete_successful_message("task")
end

private

def find_event
@event = Event.find_by(id: params[:event_id])
end

def find_task
@my_tasks = Task.where(event_id: @event.id, user_id: current_user.id)
end

def all_tasks
@tasks = @event.tasks
end

def task_params
params.require(:task).permit(:name, :user_id, :completed_status)
end
end
3 changes: 0 additions & 3 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ def index
respond_with @events
end

def about
end

def faq
end

Expand Down
14 changes: 14 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def past_event?(event)
Time.now > event.end_date
end

def manage_events_link
if current_user.event_staffs.exists?
link_to(icon("users") + " My Events Teams", administer_event_path)
end
end

def check_status(event)
if event.enabled
render partial: "events/administered_events", locals: { event: event }
else
"#{event} has been disabled"
end
end

def cummulative_rating(event)
all_ratings ||= event.reviews.map(&:rating).compact
total_rating = all_ratings.reduce(:+)
Expand Down
24 changes: 24 additions & 0 deletions app/helpers/tasks_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module TasksHelper
def can_manage_task(task)
if true
render(
partial: "tasks/manage_task",
locals: { task: task }
)
end
end

def can_add_event_task
if can? :create, Task
render partial: "tasks/add_task"
end
end

def get_name_and_role(staff)
first_name = User.find(staff.user_id).first_name
last_name = User.find(staff.user_id).last_name
last_name ||= ""
role = staff.role.humanize.titleize
first_name + " " + last_name + " (" + role + ")"
end
end
36 changes: 34 additions & 2 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,50 @@ class Ability

def initialize(user)
user ||= User.new
can [:read, :tickets], Event
can [:read, :tickets, :administer], Event
can :read, Sponsor

alias_action :create, :read, :update, to: :cru

if user.event_staffs.present?
can :scan, Event do |event|
user == event.event_staffs.find_by(user_id: user.id, role: 1).user
end
end

staffs = user.event_staffs
if staffs
staffs.each do |staff|
if staff.role == "collaborator"
can :manage, Event, id: staff.event_id
can :manage, Task, event_id: staff.event_id
can :manage, EventStaff, event_id: staff.event_id
can :manage, Sponsor, event_id: staff.event_id
end

if staff.role == "logistics"
can :cru, Event, id: staff.event_id
can :manage, Task, event_id: staff.event_id
can :manage, EventStaff, event_id: staff.event_id
end

if staff.role == "sponsor"
can :read, Event, id: staff.event_id
can :manage, Task, event_id: staff.event_id
can :manage, EventStaff, event_id: staff.event_id
end

next unless %w(event_staff volunteer gate_keeper).include? staff.role
can :read, Event, id: staff.event_id
can :read, Task, event_id: staff.event_id
can :update, Task, event_id: staff.event_id, user_id: user.id
can :read, EventStaff, event_id: staff.event_id
end
end

if user.event_manager?
can :manage, Event, manager_profile_id: user.manager_profile.id
can :manage, Sponsor
user.events.each { |event| can :manage, Sponsor, event_id: event.id }
can :manage, Booking do |booking|
booking.event.manager_profile_id = user.manager_profile.id
end
Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Event < ActiveRecord::Base
has_many :reviews, dependent: :destroy
has_many :subscriptions
has_many :subscribers, through: :subscriptions, source: :user
has_many :tasks

belongs_to :manager_profile
acts_as_tenant(:manager_profile)
Expand Down
Loading