Skip to content
This repository was archived by the owner on May 27, 2020. It is now read-only.

Commit e095255

Browse files
author
bach
committed
fixes flash notif, adds requirement in forms and redirects form errors
1 parent 33749bb commit e095255

19 files changed

Lines changed: 79 additions & 68 deletions

app/controllers/availabilities_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,24 @@ def index
2929

3030
def new
3131
@event = Event.find(params[:event_id])
32+
unless Shift.where(event_id: @event.id).any?
33+
flash[:danger] = 'No shift exists to create availability'
34+
redirect_back fallback_location: event_shifts_path(@event)
35+
end
36+
3237
@availability = Availability.new
38+
3339
end
3440

3541
def create
3642
@event = Event.find(params[:event_id])
3743
@availability = Availability.new(availability_params)
3844
if @availability.save
39-
flash[:notice] = 'Availability was successfully saved'
45+
flash[:success] = 'Availability was successfully saved'
4046
@current_user.availabilities << @availability
4147
redirect_to event_shifts_path(@event)
4248
else
43-
flash[:notice] = 'Error creating availability'
49+
flash[:danger] = 'Error creating availability'
4450
render 'new'
4551
end
4652
end
@@ -54,4 +60,4 @@ def show
5460
def availability_params
5561
params.require(:availability).permit(:shift_id, :user_id)
5662
end
57-
end
63+
end

app/controllers/events_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def new
1414
def create
1515
@event = Event.new(event_params)
1616
if @event.save
17-
flash[:notice] = 'Event was successfully created'
17+
flash[:success] = 'Event was successfully created'
1818
redirect_to events_path
1919
else
20-
flash[:notice] = 'Error creating Event'
20+
flash[:danger] = 'Error creating Event'
2121
render 'new'
2222
end
2323
end
@@ -41,10 +41,10 @@ def edit
4141
def update
4242
@event = Event.find(params[:id])
4343
if @event.update(event_params)
44-
flash[:notice] = 'Event was successfully updated'
44+
flash[:success] = 'Event was successfully updated'
4545
redirect_to event_path(@event)
4646
else
47-
flash[:notice] = 'Error updating Event'
47+
flash[:danger] = 'Error updating Event'
4848
render 'edit'
4949
end
5050
end
@@ -55,4 +55,4 @@ def event_params
5555
params.require(:event).permit(:title, :start_date, :end_date)
5656
end
5757

58-
end
58+
end

app/controllers/requirements_controller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ def index
3838
def new
3939
@event = Event.find(params[:event_id])
4040
@requirement = Requirement.new
41+
unless Shift.where(event_id: @event.id).any?
42+
flash[:danger] = 'No Shifts exist to create requirement'
43+
redirect_back fallback_location: event_requirements_path(@event)
44+
end
45+
unless Team.where(event_id: @event.id).any?
46+
flash[:danger] = 'No Teams exist to create requirement'
47+
redirect_back fallback_location: event_requirements_path(@event)
48+
end
4149
end
4250

4351
def create
4452
@event = Event.find(params[:event_id])
4553
@requirement = Requirement.new(requirement_params)
4654
if @requirement.save
47-
flash[:notice] = 'Requirement was successfully created'
55+
flash[:success] = 'Requirement was successfully created'
4856
@event.requirements << @requirement
4957
redirect_to event_requirements_path(@event)
5058
else
51-
flash[:notice] = 'Error creating Event'
59+
flash[:danger] = 'Error creating Requirement'
5260
render 'new'
5361
end
5462
end

app/controllers/schedules_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def update
4747
@event = Event.find(params[:event_id])
4848
@schedule = Schedule.find(params[:id])
4949
if @schedule.update(schedule_params)
50-
flash[:notice] = 'Schedule was successfully updated'
50+
flash[:success] = 'Schedule was successfully updated'
5151
redirect_to event_schedules_path(@event)
5252
else
53-
flash[:notice] = 'Error updating schedule'
53+
flash[:danger] = 'Error updating schedule'
5454
render 'edit'
5555
end
5656
end

app/controllers/shifts_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def create
1818
DateTime.strptime(@shift.start_time.to_s, '%Y-%m-%d %H:%M')
1919
DateTime.strptime(@shift.end_time.to_s, '%Y-%m-%d %H:%M')
2020
if @shift.save
21-
flash[:notice] = 'Shift was successfully created'
21+
flash[:success] = 'Shift was successfully created'
2222
@event.shifts << @shift
2323
redirect_to event_shifts_path(@event)
2424
else
25-
flash[:notice] = 'Error creating Event'
25+
flash[:danger] = 'Error creating Shift'
2626
render 'new'
2727
end
2828
end
@@ -36,10 +36,10 @@ def update
3636
@event = Event.find(params[:event_id])
3737
@shift = Shift.find(params[:id])
3838
if @shift.update(shift_params)
39-
flash[:notice] = 'Team was successfully updated'
39+
flash[:success] = 'Shift was successfully updated'
4040
redirect_to event_shifts_path(@event)
4141
else
42-
flash[:notice] = 'Error updating Shift'
42+
flash[:danger] = 'Error updating Shift'
4343
render 'edit'
4444
end
4545
end
@@ -50,4 +50,4 @@ def shift_params
5050
params.require(:shift).permit(:start_time, :end_time)
5151
end
5252

53-
end
53+
end

app/controllers/teams_applications_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def create
2222
@event = Event.find(params[:event_id])
2323
@teams_application = TeamsApplication.new(teams_application_params)
2424
if @teams_application.save
25-
flash[:notice] = 'Application was successfully created'
25+
flash[:success] = 'Application was successfully created'
2626
@event.teams_applications << @teams_application
2727
@current_user.teams_applications << @teams_application
2828
redirect_to event_teams_path(@event)
2929
else
30-
flash[:notice] = 'Error creating application'
30+
flash[:danger] = 'Error creating application'
3131
render 'new'
3232
end
3333
end

app/controllers/teams_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def create
1616
@event = Event.find(params[:event_id])
1717
@team = Team.new(team_params)
1818
if @team.save
19-
flash[:notice] = 'Team was successfully created'
19+
flash[:success] = 'Team was successfully created'
2020
@event.teams << @team
2121
redirect_to event_teams_path(@event)
2222
else
23-
flash[:notice] = 'Error creating Team'
23+
flash[:danger] = 'Error creating Team'
2424
render 'new'
2525
end
2626
end
@@ -39,10 +39,10 @@ def update
3939
@event = Event.find(params[:event_id])
4040
@team = Team.find(params[:id])
4141
if @team.update(team_params)
42-
flash[:notice] = 'Team was successfully updated'
42+
flash[:success] = 'Team was successfully updated'
4343
redirect_to event_teams_path(@event)
4444
else
45-
flash[:notice] = 'Error updating Team'
45+
flash[:danger] = 'Error updating Team'
4646
render 'edit'
4747
end
4848
end
@@ -53,4 +53,4 @@ def team_params
5353
params.require(:team).permit(:title, :description)
5454
end
5555

56-
end
56+
end

app/javascript/components/radarChart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class radarChart extends Component {
3535
label: '# of application for priority 3',
3636
data: dataPriorityThree,
3737
pointBackgroundColor: '#1FC3B4',
38-
backgroundColor: 'rgb(117, 238, 222, 0.75)',
38+
backgroundColor: 'rgb(117, 238, 222)',
3939
borderColor: '#CAFFF4'
4040
}
4141
]

app/views/availabilities/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
<% end %>
2222
</div>
2323
</div>
24-
<% end %>
24+
<% end %>

app/views/events/edit.html.erb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<div class="container">
1+
<% content_for :top_content do %>
2+
<div class="row">
23
<h1>Edit <%= @event.title %></h1>
34

45
<%= render 'shared/errors', object: @event %>
@@ -7,15 +8,15 @@
78
<%= form_for @event do |f| %>
89
<div class="form-group col-md-6">
910
<%= f.label :title %>
10-
<%= f.text_field :title, class: 'form-control' %>
11+
<%= f.text_field :title, class: 'form-control', required: true %>
1112
</div>
1213
<div class="form-group col-md-6">
1314
<%= f.label :start_date %>
14-
<%= f.date_field :start_date, class: 'form-control' %>
15+
<%= f.date_field :start_date, class: 'form-control', required: true %>
1516
</div>
1617
<div class="form-group col-md-6">
1718
<%= f.label :end_date%>
18-
<%= f.date_field :end_date, class: 'form-control'%>
19+
<%= f.date_field :end_date, class: 'form-control', required: true%>
1920
</div>
2021
<div class="col-md-6">
2122
<%= f.submit "Update", class: 'btn btn-primary' %>
@@ -24,3 +25,4 @@
2425
<% end %>
2526

2627
</div>
28+
<% end %>

0 commit comments

Comments
 (0)