diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 6c93d693..819c75bd 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -6,51 +6,9 @@ class Workgroup < Group has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC' validates_uniqueness_of :name - validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number, - :if => :weekly_task - validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true, - :if => :weekly_task - validates_length_of :task_description, maximum: 250 validate :last_admin_on_earth, :on => :update before_destroy :check_last_admin_group - def self.weekdays - days = I18n.t('date.day_names') - (0..days.length-1).map {|i| [days[i], i.to_s]} - end - - # Returns an Array with date-objects to represent the next weekly-tasks - def next_weekly_tasks - # our system starts from 0 (sunday) to 6 (saturday) - # get difference between groups weekday and now - diff = self.weekday - Time.now.wday - if diff >= 0 - # weektask is in current week - nextTask = diff.day.from_now - else - # weektask is in the next week - nextTask = (diff + 7).day.from_now - end - # now generate the Array - nextTasks = Array.new - next_weekly_tasks_number.times do - nextTasks << nextTask.to_date - nextTask = 1.week.from_now(nextTask) - end - return nextTasks - end - - def task_attributes(date) - { - :name => task_name, - :description => task_description, - :due_date => date, - :required_users => task_required_users, - :duration => task_duration, - :weekly => true - } - end - protected # Check before destroy a group, if this is the last group with admin role diff --git a/app/views/ordergroups/edit.html.haml b/app/views/ordergroups/edit.html.haml index 3a3eacba..7fec2484 100644 --- a/app/views/ordergroups/edit.html.haml +++ b/app/views/ordergroups/edit.html.haml @@ -45,26 +45,6 @@ = f.label :role_orders %br/ = f.check_box :role_orders - %p - = f.label :weekly_task - %br/ - = f.check_box :weekly_task - %p - = f.label :weekday - %br/ - = f.text_field :weekday - %p - = f.label :task_name - %br/ - = f.text_field :task_name - %p - = f.label :task_description - %br/ - = f.text_field :task_description - %p - = f.label :task_required_users - %br/ - = f.text_field :task_required_users %p = f.label :deleted_at %br/ diff --git a/app/views/ordergroups/index.html.haml b/app/views/ordergroups/index.html.haml index a436cbe1..35c1b4ac 100644 --- a/app/views/ordergroups/index.html.haml +++ b/app/views/ordergroups/index.html.haml @@ -12,11 +12,6 @@ %th Role Article Meta %th Role Finance %th Role Orders - %th Weekly Task - %th Weekday - %th Task Name - %th Task Description - %th Task Required Users %th Deleted At %th Contact Person %th Contact Phone @@ -34,11 +29,6 @@ %td= h ordergroup.role_article_meta %td= h ordergroup.role_finance %td= h ordergroup.role_orders - %td= h ordergroup.weekly_task - %td= h ordergroup.weekday - %td= h ordergroup.task_name - %td= h ordergroup.task_description - %td= h ordergroup.task_required_users %td= h ordergroup.deleted_at %td= h ordergroup.contact_person %td= h ordergroup.contact_phone diff --git a/app/views/shared/_group.html.haml b/app/views/shared/_group.html.haml index eebe4cac..b9b914ce 100644 --- a/app/views/shared/_group.html.haml +++ b/app/views/shared/_group.html.haml @@ -13,13 +13,6 @@ - members = group.users = "(#{members.size})" = members.collect(&:nick).join(", ") - - if group.is_a?(Workgroup) - %dt= t('.weekly_job') + ':' - %dd - - if group.weekly_task - =h "#{group.task_name} am #{weekday(group.weekday)}" - - else - = t '.no_weekly_job' - - else + - unless group.is_a?(Workgroup) %dt= t '.apple_limit' %dd= group.ignore_apple_restriction ? t('.deactivated') : t('.activated') diff --git a/app/views/shared/_group_form_fields.html.haml b/app/views/shared/_group_form_fields.html.haml index f13b0054..44376eaf 100644 --- a/app/views/shared/_group_form_fields.html.haml +++ b/app/views/shared/_group_form_fields.html.haml @@ -3,17 +3,6 @@ = yield -- if f.object.is_a?(Workgroup) - %h3= t '.title' - = f.input :weekly_task - #weekly_task_fields - = f.input :weekday, as: :select, collection: Workgroup.weekdays - = f.input :task_name - = f.input :task_required_users - = f.input :task_duration, :as => :select, :collection => (1..3) - = f.input :task_description, as: :text, input_html: {rows: 5} - = f.input :next_weekly_tasks_number - = f.input :user_tokens, :as => :string, :input_html => { 'data-pre' => f.object.users.map { |u| u.token_attributes }.to_json } diff --git a/app/views/tasks/workgroup.haml b/app/views/tasks/workgroup.haml index a5525d90..b9f81b7f 100644 --- a/app/views/tasks/workgroup.haml +++ b/app/views/tasks/workgroup.haml @@ -1,16 +1,6 @@ - title t('.title', workgroup: @group.name) = render 'nav' -%section.well - %h3= t '.weekly.title' - - if @group.weekly_task - = t('.weekly.desc', weekday: weekday(@group.weekday), task: @group.task_name).html_safe - - else - = t('.weekly.empty').html_safe - - - if @current_user.member_of?(@group) or @current_user.role_admin? - = link_to t('.weekly.edit'), edit_foodcoop_workgroup_path(@group), class: 'btn' - %section %h3= t '.title_all' = render 'list', tasks: @group.open_tasks diff --git a/app/views/workgroups/edit.html.haml b/app/views/workgroups/edit.html.haml index 9346430a..896c8a91 100644 --- a/app/views/workgroups/edit.html.haml +++ b/app/views/workgroups/edit.html.haml @@ -45,26 +45,6 @@ = f.label :role_orders %br/ = f.check_box :role_orders - %p - = f.label :weekly_task - %br/ - = f.check_box :weekly_task - %p - = f.label :weekday - %br/ - = f.text_field :weekday - %p - = f.label :task_name - %br/ - = f.text_field :task_name - %p - = f.label :task_description - %br/ - = f.text_field :task_description - %p - = f.label :task_required_users - %br/ - = f.text_field :task_required_users %p = f.label :deleted_at %br/ diff --git a/app/views/workgroups/index.html.haml b/app/views/workgroups/index.html.haml index ab1ca879..ed688695 100644 --- a/app/views/workgroups/index.html.haml +++ b/app/views/workgroups/index.html.haml @@ -12,11 +12,6 @@ %th Role Article Meta %th Role Finance %th Role Orders - %th Weekly Task - %th Weekday - %th Task Name - %th Task Description - %th Task Required Users %th Deleted At %th Contact Person %th Contact Phone @@ -34,11 +29,6 @@ %td= h workgroup.role_article_meta %td= h workgroup.role_finance %td= h workgroup.role_orders - %td= h workgroup.weekly_task - %td= h workgroup.weekday - %td= h workgroup.task_name - %td= h workgroup.task_description - %td= h workgroup.task_required_users %td= h workgroup.deleted_at %td= h workgroup.contact_person %td= h workgroup.contact_phone diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 59936f79..3f042e65 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -16,21 +16,6 @@ namespace :foodsoft do end end - desc "Create upcoming workgroups tasks (next 3 to 7 weeks)" - task :create_upcoming_weekly_tasks => :environment do - workgroups = Workgroup.where(weekly_task: true) - for workgroup in workgroups - puts "Create weekly tasks for #{workgroup.name}" - # Loop through next tasks weekly tasks method, - # skip the next 3 weeks, to allow manually deleting tasks - workgroup.next_weekly_tasks[3..-1].each do |date| - unless workgroup.tasks.exists?({:due_date => date, :weekly => true}) - workgroup.tasks.create(workgroup.task_attributes(date)) - end - end - end - end - desc "Notify workgroup of upcoming weekly task" task :notify_users_of_weekly_task => :environment do for workgroup in Workgroup.all @@ -55,7 +40,7 @@ namespace :foodsoft do task :create_upcoming_periodic_tasks => :environment do for tg in PeriodicTaskGroup.all if tg.has_next_task? - while tg.next_task_date.nil? or tg.next_task_date < Date.today + 30 + while tg.next_task_date.nil? or tg.next_task_date < Date.today + 50 tg.create_next_task end end