From f6c008c79ce036a794c780cd8f01efd303a4234b Mon Sep 17 00:00:00 2001 From: wvengen Date: Sun, 23 Nov 2014 01:22:50 +0100 Subject: [PATCH 1/2] Allow configuration of task periods --- app/models/periodic_task_group.rb | 14 ++++++++++---- app/models/task.rb | 4 ++-- app/views/admin/configs/_tab_tasks.html.haml | 12 ++++++++++++ config/app_config.yml.SAMPLE | 11 ++++++++--- config/locales/en.yml | 6 ++++++ lib/foodsoft_config.rb | 2 ++ lib/tasks/foodsoft.rake | 4 +++- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/models/periodic_task_group.rb b/app/models/periodic_task_group.rb index b92de76c..5e8d2e69 100644 --- a/app/models/periodic_task_group.rb +++ b/app/models/periodic_task_group.rb @@ -1,8 +1,6 @@ class PeriodicTaskGroup < ActiveRecord::Base has_many :tasks, dependent: :destroy - PeriodDays = 7 - def has_next_task? return false if tasks.empty? return false if tasks.first.due_date.nil? @@ -11,13 +9,13 @@ class PeriodicTaskGroup < ActiveRecord::Base def create_next_task template_task = tasks.first - self.next_task_date ||= template_task.due_date + PeriodDays + self.next_task_date ||= template_task.due_date + period_days next_task = template_task.dup next_task.due_date = next_task_date next_task.save - self.next_task_date += PeriodDays + self.next_task_date += period_days self.save end @@ -26,4 +24,12 @@ class PeriodicTaskGroup < ActiveRecord::Base t.update_attribute(:periodic_task_group, nil) end end + + protected + + # @return [Number] Number of days between two periodic tasks + def period_days + # minimum of one to avoid inifite loop when value is invalid + [FoodsoftConfig[:tasks_period_days].to_i, 1].max + end end diff --git a/app/models/task.rb b/app/models/task.rb index d15e0f2c..92bafca9 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -36,8 +36,8 @@ class Task < ActiveRecord::Base end - # find all tasks in the next week (or another number of days) - def self.next_assigned_tasks_for(user, number = 7) + # find all tasks in the period (or another number of days) + def self.next_assigned_tasks_for(user, number = FoodsoftConfig[:tasks_period_days].to_i) user.tasks.undone.where(assignments: {accepted: true}). where(["tasks.due_date >= ? AND tasks.due_date <= ?", Time.now, number.days.from_now]) end diff --git a/app/views/admin/configs/_tab_tasks.html.haml b/app/views/admin/configs/_tab_tasks.html.haml index 180e789a..1df59762 100644 --- a/app/views/admin/configs/_tab_tasks.html.haml +++ b/app/views/admin/configs/_tab_tasks.html.haml @@ -1,3 +1,15 @@ -#= config_use_heading form, :use_tasks do +%fieldset + %label + %h4= t '.periodic_title' + = config_input form, :tasks_period_days do + .input-append + = config_input_field form, :tasks_period_days, as: :numeric, class: 'input-mini' + %span.add-on days + = config_input form, :tasks_upfront_days do + .input-append + = config_input_field form, :tasks_upfront_days, as: :numeric, class: 'input-mini' + %span.add-on days + = config_use_heading form, :use_apple_points do = config_input form, :stop_ordering_under, as: :numeric, input_html: {class: 'input-small'} diff --git a/config/app_config.yml.SAMPLE b/config/app_config.yml.SAMPLE index 12a8f69e..b4603ffb 100644 --- a/config/app_config.yml.SAMPLE +++ b/config/app_config.yml.SAMPLE @@ -55,14 +55,19 @@ default: &defaults # Ordergroups, which have less than 75 apples should not be allowed to make new orders # Comment out this option to activate this restriction - # stop_ordering_under: 75 + #stop_ordering_under: 75 # Comment out to completely hide apple points (be sure to comment stop_ordering_under) - # use_apple_points: false + #use_apple_points: false # ordergroups can only order when their balance is higher than or equal to this # not fully enforced right now, since the check is only client-side - # minimum_balance: 0 + #minimum_balance: 0 + + # how many days there are between two periodic tasks + #tasks_period_days: 7 + # how many days upfront periodic tasks are created + #tasks_upfront_days: 49 # When use_nick is enabled, there will be a nickname field in the user form, # and the option to show a nickname instead of full name to foodcoop members. diff --git a/config/locales/en.yml b/config/locales/en.yml index f7e9c440..795da407 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -237,6 +237,8 @@ en: pdf_title: PDF documents tab_messages: emails_title: Sending email + tab_tasks: + periodic_title: Periodic tasks tabs: title: Configuration update: @@ -467,6 +469,8 @@ en: price_markup: Percentage that is added to the gross price for foodcoop members. stop_ordering_under: Members can only order when they have at least this many apple points. tax_default: Default VAT percentage for new articles. + tasks_period_days: Number of days between two instances of a periodic task. + tasks_upfront_days: How many days upfront to schedule tasks from a periodic task. tolerance_is_costly: Order as much of the member tolerance as possible (compared to only as much needed to fill the last box). Enabling this also includes the tolerance in the total price of the open member order. use_apple_points: When the apple point system is enabled, members are required to do some tasks to be able to keep ordering. use_messages: Allow members to communicate with each other within Foodsoft. @@ -502,6 +506,8 @@ en: pdf_page_size: Page size price_markup: Foodcoop margin stop_ordering_under: Minimum apple points + tasks_period_days: Period + tasks_upfront_days: Create upfront tax_default: Default VAT time_zone: Time zone tolerance_is_costly: Tolerance is costly diff --git a/lib/foodsoft_config.rb b/lib/foodsoft_config.rb index 836f2ef0..d03cd283 100644 --- a/lib/foodsoft_config.rb +++ b/lib/foodsoft_config.rb @@ -226,6 +226,8 @@ class FoodsoftConfig currency_space: true, foodsoft_url: 'https://github.com/foodcoops/foodsoft', contact: {}, # avoid errors when undefined + tasks_period_days: 7, + tasks_upfront_days: 49, # The following keys cannot, by default, be set by foodcoops themselves. protected: { multi_coop_install: true, diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index 1fdd2259..ceb62529 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -40,7 +40,9 @@ 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 + 50 + create_until = Date.today + FoodsoftConfig[:tasks_upfront_days].to_i + 1 + rake_say "creating until #{create_until}" + while tg.next_task_date.nil? or tg.next_task_date < create_until tg.create_next_task end end From 5c78bdde7e3dbe5cd4e9e29fdaff3c9b1ce91776 Mon Sep 17 00:00:00 2001 From: wvengen Date: Sun, 23 Nov 2014 01:42:15 +0100 Subject: [PATCH 2/2] Cleanup old task-related i18n --- app/views/shared/_group_form_fields.html.haml | 15 --------------- config/locales/de.yml | 6 +----- config/locales/en.yml | 10 +++------- config/locales/fr.yml | 6 +----- config/locales/nl.yml | 4 ---- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/app/views/shared/_group_form_fields.html.haml b/app/views/shared/_group_form_fields.html.haml index 8eae4da8..83103d99 100644 --- a/app/views/shared/_group_form_fields.html.haml +++ b/app/views/shared/_group_form_fields.html.haml @@ -8,22 +8,7 @@ - content_for :javascript do :javascript - function toggleWeeklyTaskFields() { - if ($('#workgroup_weekly_task').is(':checked')) { - $('#weekly_task_fields .control-group').show(); - $('#weekly_task_fields input').removeAttr('disabled'); - } else { - $('#weekly_task_fields .control-group').hide(); - $('#weekly_task_fields input').attr('disabled', 'disabled'); - } - } - $(function() { - toggleWeeklyTaskFields(); - $('#workgroup_weekly_task').click(function() { - toggleWeeklyTaskFields(); - }); - $("##{f.object.class.to_s.underscore}_user_tokens").tokenInput("#{users_path(:format => :json)}", { crossDomain: false, prePopulate: $("##{f.object.class.to_s.underscore}_user_tokens").data("pre"), diff --git a/config/locales/de.yml b/config/locales/de.yml index 943056b9..94349051 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -163,7 +163,6 @@ de: workgroup: description: Beschreibung name: Name - next_weekly_tasks_number: Für wieviel Wochen im Voraus sollen Aufgaben erstellt werden? role_admin: Administration role_article_meta: Artikeldatenbank role_finance: Finanzen @@ -185,7 +184,7 @@ de: task: attributes: done: - exclusion: erledigte Aufgaben können nicht wöchentlich wiederholt werden + exclusion: erledigte Aufgaben können nicht wiederholt werden models: article: Artikel article_category: Artikelkategorie @@ -1385,12 +1384,9 @@ de: activated: aktiviert apple_limit: Äpfel-Bestellbeschränkung deactivated: deaktiviert - no_weekly_job: kein wöchentlicher Job definiert - weekly_job: Wöchentlicher Job group_form_fields: search: Suche ... search_user: Nach Nutzerin suchen - title: Wöchentliche Jobs user_not_found: Keine Nutzerin gefunden open_orders: no_open_orders: Derzeit gibt es keine laufenden Bestellungen diff --git a/config/locales/en.yml b/config/locales/en.yml index 795da407..c48fdce4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -163,7 +163,6 @@ en: workgroup: description: Description name: Name - next_weekly_tasks_number: For how many weeks in advance would you like to define tasks? role_admin: Administration role_article_meta: Article database role_finance: Finances @@ -185,7 +184,7 @@ en: task: attributes: done: - exclusion: finished tasks may not be repeated weekly + exclusion: finished tasks may not be repeated models: article: Article article_category: Article category @@ -469,8 +468,8 @@ en: price_markup: Percentage that is added to the gross price for foodcoop members. stop_ordering_under: Members can only order when they have at least this many apple points. tax_default: Default VAT percentage for new articles. - tasks_period_days: Number of days between two instances of a periodic task. - tasks_upfront_days: How many days upfront to schedule tasks from a periodic task. + tasks_period_days: Number of days between two periodic tasks (default 7, which is a week). + tasks_upfront_days: For how many days in advance you would like to schedule periodic tasks. tolerance_is_costly: Order as much of the member tolerance as possible (compared to only as much needed to fill the last box). Enabling this also includes the tolerance in the total price of the open member order. use_apple_points: When the apple point system is enabled, members are required to do some tasks to be able to keep ordering. use_messages: Allow members to communicate with each other within Foodsoft. @@ -1404,12 +1403,9 @@ en: activated: activated apple_limit: Apple points order limit deactivated: deactivated - no_weekly_job: No weekly job defined - weekly_job: Weekly job group_form_fields: search: Search ... search_user: Search user - title: Weekly jobs user_not_found: No user found open_orders: no_open_orders: There are no current orders diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 8958286f..54250e15 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -163,7 +163,6 @@ fr: workgroup: description: Description name: Nom - next_weekly_tasks_number: Combien de temps en avance les boulots doivent ils être annoncés sur le site? role_admin: Administration role_article_meta: Base de données des produits role_finance: Trésorerie @@ -185,7 +184,7 @@ fr: task: attributes: done: - exclusion: répétition hebdomadaire invalide pour un boulot déjà effectué + exclusion: répétition invalide pour un boulot déjà effectué models: article: Article article_category: Catégorie @@ -1398,12 +1397,9 @@ fr: activated: activé apple_limit: Minimum de glands deactivated: désactivé - no_weekly_job: aucun boulot hebdomadaire n'a été défini - weekly_job: Boulot hebdomadaire group_form_fields: search: Recherche... search_user: Rechercher par utilisatrice - title: Boulots hebdomadaires user_not_found: Aucun-e membre ne correspond à ce nom open_orders: no_open_orders: Il n'y a aucune commande en cours en ce moment diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 5d29b9c1..f242f573 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -163,7 +163,6 @@ nl: workgroup: description: Omschrijving name: Naam - next_weekly_tasks_number: Hoeveel weken vooruit moet de taak zichtbaar zijn? role_admin: Beheer role_article_meta: Artikelen role_finance: Financiën @@ -1391,12 +1390,9 @@ nl: activated: actief apple_limit: Appelpunten bestellingslimiet deactivated: inactief - no_weekly_job: geen wekelijkse taak ingesteld - weekly_job: wekelijkse taak group_form_fields: search: Zoeken ... search_user: Gebruiker zoeken - title: Wekelijkse taken user_not_found: Geen gebruiker gevonden open_orders: no_open_orders: Er zijn momenteel geen lopende bestellingen.