Skip to content
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
5 changes: 5 additions & 0 deletions app/assets/javascripts/controllers/main/DataEntryCtrl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
$scope.generate_schedule = () ->
window.location.href = '/#/schedule'

$scope.getWorkType = (wt) ->
if wt.nil?
return ""
else return "(" + wt + ")"

### PEOPLE AND CONFLICTS ###
$scope.people_message = {person: {}}
$scope.people_success = (response) ->
Expand Down
14 changes: 10 additions & 4 deletions app/assets/javascripts/controllers/main/ScheduleCtrl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@
swappable_works

$scope.highlight_all_swappable = (orig_work) ->
for rehearsal in $scope.schedule.rehearsals
for work in rehearsal.works
if work.id in $scope.all_swappable(orig_work)
work.swappable = true
$http({
method: 'GET',
url: '/works/all_fits/' + orig_work.id + '.json'
}).then((response) ->
console.log response.data
for rehearsal in $scope.schedule.rehearsals
for work in rehearsal.works
if work.id in response.data
work.swappable = true
)

$scope.unhighlight_all_swappable = () ->
for rehearsal in $scope.schedule.rehearsals
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ def destroy
end
end

def all_fits
work = Work.find(params[:id])
start_time = work.rehearsal.start_time
rehearsal_works = work.rehearsal.works.order(:sequence_id)
for w in rehearsal_works do
break if w.id == work.id
start_time += w.duration
start_time += w.break_duration
end
works = Work.where(production_id: current_user.person.production_id).where.not(id: work.id).select { |w| w.fits?(start_time) }.map(&:id)

respond_to do |format|
format.json { render json: works }
end
end

private
def set_work
@work = Work.find(params[:id])
Expand Down
12 changes: 10 additions & 2 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ class Work < ApplicationRecord
accepts_nested_attributes_for :person_works, allow_destroy: true
accepts_nested_attributes_for :dependencies, allow_destroy: true

validate :duration_not_zero
validates :name, :duration, presence: true

def called
people
end

def duration_not_zero
errors.add(:duration, "Duration must be at least 1 minute") if
duration < 1
end

# Whether this piece of work can be scheduled at a given start time
# without conflicts.
# TODO Allow for expressing priority, maybe by returning a number instead
Expand All @@ -22,9 +30,9 @@ def fits?(start_datetime)
end

def all_conflicts(start_datetime)
end_datetime = start_time + self.duration.minutes
end_datetime = start_datetime + self.duration.minutes
conflicts = Set.new
work.called.each do |p|
self.called.each do |p|
p.conflicts.each do |c|
unless c.fits?(start_datetime, end_datetime)
conflicts << c
Expand Down
2 changes: 2 additions & 0 deletions app/views/people/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<tr>
<td><%= person.first %></td>
<td><%= person.last %></td>
<td><%= person.cell %></td>
<td><%= person.email %></td>
<td><%= link_to 'Show', person %></td>
<td><%= link_to 'Edit', edit_person_path(person) %></td>
<td><%= link_to 'Destroy', person, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
post 'api/mobile/cell' => 'mobile#cell'
get 'api/mobile/refresh' => 'mobile#refresh'

get 'works/all_fits/:id' => 'works#all_fits'

# TODO: get rid of this
get 'generate' => 'schedules#generate'

Expand Down