From 2ab95cd8b83526bb6287ad459a1da83042861305 Mon Sep 17 00:00:00 2001 From: bcmoore Date: Mon, 17 Apr 2017 11:35:25 -0400 Subject: [PATCH 1/4] fixed parenthesis on type and duration and work name validated --- .../javascripts/controllers/main/DataEntryCtrl.coffee | 5 +++++ app/models/work.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/app/assets/javascripts/controllers/main/DataEntryCtrl.coffee b/app/assets/javascripts/controllers/main/DataEntryCtrl.coffee index 4eba6b2..4add8c7 100644 --- a/app/assets/javascripts/controllers/main/DataEntryCtrl.coffee +++ b/app/assets/javascripts/controllers/main/DataEntryCtrl.coffee @@ -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) -> diff --git a/app/models/work.rb b/app/models/work.rb index 0673f40..e54b1b0 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -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 From a55be9d4e09fa6d07b4a6c932413cf022dd1e490 Mon Sep 17 00:00:00 2001 From: bcmoore Date: Mon, 24 Apr 2017 09:45:45 -0400 Subject: [PATCH 2/4] removed validation for start after today --- app/controllers/works_controller.rb | 15 +++++++++++++++ app/views/people/index.html.erb | 2 ++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index ae4952e..d6110ee 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -49,6 +49,21 @@ def destroy end end + def getAll + @work.id = Work.where(production_id: current_user.person.production_id).where.not(id: self.id).select do |w| + holder = Array.new(5000, hash.new) + used = 0 + if w.fits?(start_datetime) + #format.html { render :new } + #format.json { render json: @work.id } + holder[used] + used += 1 + end + smallHolder = holder[0,used] + format.json { render json: smallHolder } + end + end + private def set_work @work = Work.find(params[:id]) diff --git a/app/views/people/index.html.erb b/app/views/people/index.html.erb index 3ac8f93..c9e09fa 100644 --- a/app/views/people/index.html.erb +++ b/app/views/people/index.html.erb @@ -16,6 +16,8 @@ <%= person.first %> <%= person.last %> + <%= person.cell %> + <%= person.email %> <%= link_to 'Show', person %> <%= link_to 'Edit', edit_person_path(person) %> <%= link_to 'Destroy', person, method: :delete, data: { confirm: 'Are you sure?' } %> From 0cfbb86ba4912d3984f2a6ba820ea517de9f27f6 Mon Sep 17 00:00:00 2001 From: Jonah Roth Date: Mon, 24 Apr 2017 10:19:46 -0400 Subject: [PATCH 3/4] Route that returns all pieces of work fitting a given scheduled piece of work --- .../controllers/main/ScheduleCtrl.coffee | 14 ++++++++--- app/controllers/works_controller.rb | 25 ++++++++++--------- app/models/work.rb | 4 +-- config/routes.rb | 2 ++ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/controllers/main/ScheduleCtrl.coffee b/app/assets/javascripts/controllers/main/ScheduleCtrl.coffee index 4130560..82d7401 100644 --- a/app/assets/javascripts/controllers/main/ScheduleCtrl.coffee +++ b/app/assets/javascripts/controllers/main/ScheduleCtrl.coffee @@ -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 diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index d6110ee..cde1e7f 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -49,18 +49,19 @@ def destroy end end - def getAll - @work.id = Work.where(production_id: current_user.person.production_id).where.not(id: self.id).select do |w| - holder = Array.new(5000, hash.new) - used = 0 - if w.fits?(start_datetime) - #format.html { render :new } - #format.json { render json: @work.id } - holder[used] - used += 1 - end - smallHolder = holder[0,used] - format.json { render json: smallHolder } + 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 diff --git a/app/models/work.rb b/app/models/work.rb index e54b1b0..ca860ef 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -30,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 diff --git a/config/routes.rb b/config/routes.rb index 0e90846..230bd29 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' From 27c0213f5eab04f43203fe3d7065ea1f9b83f2b7 Mon Sep 17 00:00:00 2001 From: Jonah Roth Date: Mon, 24 Apr 2017 10:53:27 -0400 Subject: [PATCH 4/4] Update works_controller.rb that was a dumb mistake --- app/controllers/works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index cde1e7f..cefab5d 100644 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -54,7 +54,7 @@ def all_fits 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 + break if w.id == work.id start_time += w.duration start_time += w.break_duration end