From 1cdb9e85017a17e4dbee276cd87feaa2aab75932 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Wed, 28 Nov 2012 10:13:54 +0100 Subject: [PATCH 01/17] Outlined new concept for multiple periodically recurring tasks (#3). --- app/models/periodic_task_group.rb | 23 +++++++++++++++++++ app/models/task.rb | 9 ++++++++ app/views/tasks/_form.html.haml | 1 + config/locales/de.yml | 1 + ...21115073715_create_periodic_task_groups.rb | 13 +++++++++++ db/schema.rb | 23 ++++++++++++------- lib/tasks/foodsoft.rake | 11 +++++++++ 7 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 app/models/periodic_task_group.rb create mode 100644 db/migrate/20121115073715_create_periodic_task_groups.rb diff --git a/app/models/periodic_task_group.rb b/app/models/periodic_task_group.rb new file mode 100644 index 00000000..7f0efa1a --- /dev/null +++ b/app/models/periodic_task_group.rb @@ -0,0 +1,23 @@ +class PeriodicTaskGroup < ActiveRecord::Base + has_many :tasks, :inverse_of => :periodic_task_group, :dependent => :destroy + + PeriodDays = 7 + + def has_next_task? + return false if self.tasks.empty? + return false if self.tasks.first.due_date.nil? + return true + end + + def create_next_task + template_task = self.tasks.first + self.next_task_date ||= template_task.due_date + PeriodDays + + next_task = template_task.dup + next_task.due_date = self.next_task_date + next_task.save + + self.next_task_date += PeriodDays + self.save + end +end diff --git a/app/models/task.rb b/app/models/task.rb index a16ada32..69dbb860 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -2,6 +2,7 @@ class Task < ActiveRecord::Base has_many :assignments, :dependent => :destroy has_many :users, :through => :assignments belongs_to :workgroup + belongs_to :periodic_task_group, :inverse_of => :tasks scope :non_group, where(workgroup_id: nil, done: false) scope :done, where(done: true) @@ -45,6 +46,14 @@ class Task < ActiveRecord::Base end end + def periodic + not periodic_task_group.nil? + end + + def periodic=(p) + self.periodic_task_group = PeriodicTaskGroup.new if p == "1" + end + def is_assigned?(user) self.assignments.detect {|ass| ass.user_id == user.id } end diff --git a/app/views/tasks/_form.html.haml b/app/views/tasks/_form.html.haml index 77e96aad..29875af1 100644 --- a/app/views/tasks/_form.html.haml +++ b/app/views/tasks/_form.html.haml @@ -23,6 +23,7 @@ = f.input :required_users = f.association :workgroup = f.input :due_date, as: :date_picker + = f.input :periodic, as: :boolean = f.input :done .form-actions = f.submit class: 'btn' diff --git a/config/locales/de.yml b/config/locales/de.yml index d53e9593..0e487c4d 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -312,6 +312,7 @@ de: required_users: 'Anzahl' due_date: 'Wann erledigen?' workgroup: 'Arbeitsgruppe' + periodic: 'Wöchentlich wiederholen' done: Erledigt? message: sent_to_all: 'An alle Mitglieder schicken' diff --git a/db/migrate/20121115073715_create_periodic_task_groups.rb b/db/migrate/20121115073715_create_periodic_task_groups.rb new file mode 100644 index 00000000..87cf560b --- /dev/null +++ b/db/migrate/20121115073715_create_periodic_task_groups.rb @@ -0,0 +1,13 @@ +class CreatePeriodicTaskGroups < ActiveRecord::Migration + def change + create_table :periodic_task_groups do |t| + t.date :next_task_date + + t.timestamps + end + + change_table :tasks do |t| + t.references :periodic_task_group + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2e795b70..63ab6801 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120929155541) do +ActiveRecord::Schema.define(:version => 20121115073715) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -284,6 +284,12 @@ ActiveRecord::Schema.define(:version => 20120929155541) do add_index "pages", ["permalink"], :name => "index_pages_on_permalink" add_index "pages", ["title"], :name => "index_pages_on_title" + create_table "periodic_task_groups", :force => true do |t| + t.date "next_task_date" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "stock_changes", :force => true do |t| t.integer "delivery_id" t.integer "order_id" @@ -324,17 +330,18 @@ ActiveRecord::Schema.define(:version => 20120929155541) do add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true create_table "tasks", :force => true do |t| - t.string "name", :default => "", :null => false + t.string "name", :default => "", :null => false t.string "description" t.date "due_date" - t.boolean "done", :default => false + t.boolean "done", :default => false t.integer "workgroup_id" - t.boolean "assigned", :default => false - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false - t.integer "required_users", :default => 1 + t.boolean "assigned", :default => false + t.datetime "created_on", :null => false + t.datetime "updated_on", :null => false + t.integer "required_users", :default => 1 t.boolean "weekly" - t.integer "duration", :default => 1 + t.integer "duration", :default => 1 + t.integer "periodic_task_group_id" end add_index "tasks", ["due_date"], :name => "index_tasks_on_due_date" diff --git a/lib/tasks/foodsoft.rake b/lib/tasks/foodsoft.rake index ebfecbc1..8ef1e739 100644 --- a/lib/tasks/foodsoft.rake +++ b/lib/tasks/foodsoft.rake @@ -49,4 +49,15 @@ namespace :foodsoft do end end end + + desc "Create upcoming periodic tasks" + 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 + tg.create_next_task + end + end + end + end end From 71d8f9bde729883669012b1b72733878bd045a1c Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Wed, 12 Jun 2013 10:20:06 +0200 Subject: [PATCH 02/17] Fixed schema.rb. --- db/schema.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index b584b004..59fa21c4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -319,16 +319,9 @@ ActiveRecord::Schema.define(:version => 20121230142516) do t.date "due_date" t.boolean "done", :default => false t.integer "workgroup_id" -<<<<<<< HEAD - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false - t.integer "required_users", :default => 1 -======= - t.boolean "assigned", :default => false t.datetime "created_on", :null => false t.datetime "updated_on", :null => false t.integer "required_users", :default => 1 ->>>>>>> 1cdb9e85017a17e4dbee276cd87feaa2aab75932 t.boolean "weekly" t.integer "duration", :default => 1 t.integer "periodic_task_group_id" From 4037ef12dae5d92e2229bca20a73b1ada7af584c Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Wed, 12 Jun 2013 12:02:13 +0200 Subject: [PATCH 03/17] Users may delete all tasks of a group, i.e. delete the whole group. --- app/controllers/periodic_task_groups_controller.rb | 8 ++++++++ app/helpers/periodic_task_groups_helper.rb | 2 ++ app/views/tasks/show.haml | 3 +++ config/locales/de.yml | 6 +++++- config/routes.rb | 4 ++++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/controllers/periodic_task_groups_controller.rb create mode 100644 app/helpers/periodic_task_groups_helper.rb diff --git a/app/controllers/periodic_task_groups_controller.rb b/app/controllers/periodic_task_groups_controller.rb new file mode 100644 index 00000000..3642cc97 --- /dev/null +++ b/app/controllers/periodic_task_groups_controller.rb @@ -0,0 +1,8 @@ +class PeriodicTaskGroupsController < ApplicationController + def destroy + @task_group = PeriodicTaskGroup.find(params[:id]) + @task_group.destroy + + redirect_to tasks_url, notice: I18n.t('periodic_task_groups.destroy.notice') + end +end diff --git a/app/helpers/periodic_task_groups_helper.rb b/app/helpers/periodic_task_groups_helper.rb new file mode 100644 index 00000000..cf0d9631 --- /dev/null +++ b/app/helpers/periodic_task_groups_helper.rb @@ -0,0 +1,2 @@ +module PeriodicTaskGroupsHelper +end diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index 23b843c7..12094186 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -29,3 +29,6 @@ = link_to t('ui.edit'), edit_task_path(@task), class: 'btn' = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?", class: 'btn btn-danger' + - if @task.periodic + = link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete, + :confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger' diff --git a/config/locales/de.yml b/config/locales/de.yml index 883d6373..5e4c226b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1422,6 +1422,9 @@ de: title: ! '%{title} - Version %{version}' title_version: Version view_current: Aktuelle Version sehen + periodic_task_groups: + destroy: + notice: Aufgaben wurden gelöscht sessions: logged_in: Logged in! logged_out: Logged out! @@ -1517,7 +1520,6 @@ de: task: duration: Wie lange dauert die Aufgabe, 1-3 Stunden required_users: Wieviel Benutzerinnen werden insgesamt benötigt? - periodic: Wöchentlich wiederholen tax: In Prozent, Standard sind 7,0 labels: article: @@ -1609,6 +1611,7 @@ de: due_date: Wann erledigen? duration: Dauer name: Name + periodic: Wöchentlich wiederholen required_users: Anzahl user_list: Verantwortliche workgroup: Arbeitsgruppe @@ -1823,6 +1826,7 @@ de: ui: close: Schließen delete: Löschen + delete_all: Alle löschen edit: Bearbeiten marks: close: ! '×' diff --git a/config/routes.rb b/config/routes.rb index cbcf2828..85905b63 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Foodsoft::Application.routes.draw do + get "periodic_task_groups/destroy" + get "order_comments/new" get "comments/new" @@ -70,6 +72,8 @@ Foodsoft::Application.routes.draw do end end + resources :periodic_task_groups, only: [:destroy] + resources :messages, :only => [:index, :show, :new, :create] namespace :foodcoop do From 6b62fc90d8770d3ad04153f1ee73944926470b71 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Fri, 21 Jun 2013 13:48:48 +0200 Subject: [PATCH 04/17] Now creating periodic task via button --- app/controllers/tasks_controller.rb | 3 +++ app/models/periodic_task_group.rb | 2 +- app/models/task.rb | 8 ++------ app/views/tasks/_form.html.haml | 5 +++-- app/views/tasks/show.haml | 2 +- config/routes.rb | 2 -- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 16fc0f73..c8fbcada 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -18,6 +18,9 @@ class TasksController < ApplicationController def create @task = Task.new(params[:task]) + if params[:periodic] + @task.periodic_task_group = PeriodicTaskGroup.new + end if @task.save redirect_to tasks_url, :notice => I18n.t('tasks.create.notice') else diff --git a/app/models/periodic_task_group.rb b/app/models/periodic_task_group.rb index 7f0efa1a..3e11de9e 100644 --- a/app/models/periodic_task_group.rb +++ b/app/models/periodic_task_group.rb @@ -1,5 +1,5 @@ class PeriodicTaskGroup < ActiveRecord::Base - has_many :tasks, :inverse_of => :periodic_task_group, :dependent => :destroy + has_many :tasks, :dependent => :destroy PeriodDays = 7 diff --git a/app/models/task.rb b/app/models/task.rb index bc974653..aebd54d3 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -2,7 +2,7 @@ class Task < ActiveRecord::Base has_many :assignments, :dependent => :destroy has_many :users, :through => :assignments belongs_to :workgroup - belongs_to :periodic_task_group, :inverse_of => :tasks + belongs_to :periodic_task_group scope :non_group, where(workgroup_id: nil, done: false) scope :done, where(done: true) @@ -47,14 +47,10 @@ class Task < ActiveRecord::Base end end - def periodic + def periodic? not periodic_task_group.nil? end - def periodic=(p) - self.periodic_task_group = PeriodicTaskGroup.new if p == "1" - end - def is_assigned?(user) self.assignments.detect {|ass| ass.user_id == user.id } end diff --git a/app/views/tasks/_form.html.haml b/app/views/tasks/_form.html.haml index 625a5ead..59acab59 100644 --- a/app/views/tasks/_form.html.haml +++ b/app/views/tasks/_form.html.haml @@ -23,8 +23,9 @@ = f.input :required_users = f.association :workgroup = f.input :due_date, as: :date_picker - = f.input :periodic, as: :boolean = f.input :done .form-actions - = f.submit class: 'btn' + = f.submit class: 'btn btn-primary' + - unless @task.id + = f.submit 'Wöchentliche Aufgabe erstellen', name: 'periodic', class: 'btn' = link_to t('ui.or_cancel'), :back diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index 12094186..2d8fa063 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -29,6 +29,6 @@ = link_to t('ui.edit'), edit_task_path(@task), class: 'btn' = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?", class: 'btn btn-danger' - - if @task.periodic + - if @task.periodic? = link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete, :confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger' diff --git a/config/routes.rb b/config/routes.rb index 85905b63..19855380 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,5 @@ Foodsoft::Application.routes.draw do - get "periodic_task_groups/destroy" - get "order_comments/new" get "comments/new" From c52e4827434c2644d34cf799abc8c5c1dbbf78f4 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Fri, 21 Jun 2013 20:54:24 +0200 Subject: [PATCH 05/17] Exclude tasks from groups when changing attributes. --- app/models/task.rb | 7 +++++++ app/views/tasks/_form.html.haml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/task.rb b/app/models/task.rb index aebd54d3..8d17652c 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -18,6 +18,7 @@ class Task < ActiveRecord::Base validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 0 validates_length_of :description, maximum: 250 + before_save :exclude_from_periodic_task_group after_save :update_ordergroup_stats # Find all tasks, for which the current user should be responsible @@ -105,5 +106,11 @@ class Task < ActiveRecord::Base def update_ordergroup_stats(user_ids = self.user_ids) Ordergroup.joins(:users).where(users: {id: user_ids}).each(&:update_stats!) end + + def exclude_from_periodic_task_group + if changed? and not new_record? + self.periodic_task_group = nil + end + end end diff --git a/app/views/tasks/_form.html.haml b/app/views/tasks/_form.html.haml index 59acab59..ba627f7e 100644 --- a/app/views/tasks/_form.html.haml +++ b/app/views/tasks/_form.html.haml @@ -26,6 +26,6 @@ = f.input :done .form-actions = f.submit class: 'btn btn-primary' - - unless @task.id + - if @task.new_record? = f.submit 'Wöchentliche Aufgabe erstellen', name: 'periodic', class: 'btn' = link_to t('ui.or_cancel'), :back From 990397a7f06f68e054a459c8c638d6573670fa0a Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Fri, 21 Jun 2013 22:04:36 +0200 Subject: [PATCH 06/17] Delete only the FOLLOWING tasks. --- .../periodic_task_groups_controller.rb | 8 -------- app/controllers/tasks_controller.rb | 7 ++++++- app/helpers/periodic_task_groups_helper.rb | 2 -- app/models/periodic_task_group.rb | 16 +++++++++++----- app/views/tasks/show.haml | 4 ++-- config/routes.rb | 2 -- 6 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 app/controllers/periodic_task_groups_controller.rb delete mode 100644 app/helpers/periodic_task_groups_helper.rb diff --git a/app/controllers/periodic_task_groups_controller.rb b/app/controllers/periodic_task_groups_controller.rb deleted file mode 100644 index 3642cc97..00000000 --- a/app/controllers/periodic_task_groups_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class PeriodicTaskGroupsController < ApplicationController - def destroy - @task_group = PeriodicTaskGroup.find(params[:id]) - @task_group.destroy - - redirect_to tasks_url, notice: I18n.t('periodic_task_groups.destroy.notice') - end -end diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index c8fbcada..017a9a8a 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -56,7 +56,12 @@ class TasksController < ApplicationController task = Task.find(params[:id]) # Save user_ids to update apple statistics after destroy user_ids = task.user_ids - task.destroy + if params[:periodic] + task.periodic_task_group.exclude_tasks_before(task) + task.periodic_task_group.destroy + else + task.destroy + end task.update_ordergroup_stats(user_ids) redirect_to tasks_url, :notice => I18n.t('tasks.destroy.notice') diff --git a/app/helpers/periodic_task_groups_helper.rb b/app/helpers/periodic_task_groups_helper.rb deleted file mode 100644 index cf0d9631..00000000 --- a/app/helpers/periodic_task_groups_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PeriodicTaskGroupsHelper -end diff --git a/app/models/periodic_task_group.rb b/app/models/periodic_task_group.rb index 3e11de9e..b92de76c 100644 --- a/app/models/periodic_task_group.rb +++ b/app/models/periodic_task_group.rb @@ -1,23 +1,29 @@ class PeriodicTaskGroup < ActiveRecord::Base - has_many :tasks, :dependent => :destroy + has_many :tasks, dependent: :destroy PeriodDays = 7 def has_next_task? - return false if self.tasks.empty? - return false if self.tasks.first.due_date.nil? + return false if tasks.empty? + return false if tasks.first.due_date.nil? return true end def create_next_task - template_task = self.tasks.first + template_task = tasks.first self.next_task_date ||= template_task.due_date + PeriodDays next_task = template_task.dup - next_task.due_date = self.next_task_date + next_task.due_date = next_task_date next_task.save self.next_task_date += PeriodDays self.save end + + def exclude_tasks_before(task) + tasks.where("due_date < '#{task.due_date}'").each do |t| + t.update_attribute(:periodic_task_group, nil) + end + end end diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index 2d8fa063..f2e147c8 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -30,5 +30,5 @@ = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?", class: 'btn btn-danger' - if @task.periodic? - = link_to t('ui.delete_all'), periodic_task_group_path(@task.periodic_task_group), :method => :delete, - :confirm => "Alle Aufgaben dieser wöchentlichen Aufgabe wirklich löschen?", class: 'btn btn-danger' + = link_to 'Aufgabe und folgende löschen', task_path(@task, periodic: true), method: :delete, + confirm: "Diese und alle folgenden wöchentlichen Aufgaben wirklich löschen?", class: 'btn btn-danger' diff --git a/config/routes.rb b/config/routes.rb index 19855380..cbcf2828 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,8 +70,6 @@ Foodsoft::Application.routes.draw do end end - resources :periodic_task_groups, only: [:destroy] - resources :messages, :only => [:index, :show, :new, :create] namespace :foodcoop do From 2e1a3eb47fb876f3663cf2e41139f8aaa54b6879 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Sat, 22 Jun 2013 11:23:08 +0200 Subject: [PATCH 07/17] Removed unused I18n strings. --- config/locales/de.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 5e4c226b..0961913b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1422,9 +1422,6 @@ de: title: ! '%{title} - Version %{version}' title_version: Version view_current: Aktuelle Version sehen - periodic_task_groups: - destroy: - notice: Aufgaben wurden gelöscht sessions: logged_in: Logged in! logged_out: Logged out! @@ -1611,7 +1608,6 @@ de: due_date: Wann erledigen? duration: Dauer name: Name - periodic: Wöchentlich wiederholen required_users: Anzahl user_list: Verantwortliche workgroup: Arbeitsgruppe @@ -1826,7 +1822,6 @@ de: ui: close: Schließen delete: Löschen - delete_all: Alle löschen edit: Bearbeiten marks: close: ! '×' From ef329b564732056726d61feddb019a15762f5255 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Sat, 22 Jun 2013 17:35:45 +0200 Subject: [PATCH 08/17] Added up and down migration for weekly task data. --- app/models/task.rb | 2 +- ...0615073715_create_periodic_task_groups.rb} | 0 .../20130622095040_move_weekly_tasks.rb | 60 +++++++++++++++++++ db/schema.rb | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) rename db/migrate/{20121115073715_create_periodic_task_groups.rb => 20130615073715_create_periodic_task_groups.rb} (100%) create mode 100644 db/migrate/20130622095040_move_weekly_tasks.rb diff --git a/app/models/task.rb b/app/models/task.rb index 8d17652c..453af12b 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -108,7 +108,7 @@ class Task < ActiveRecord::Base end def exclude_from_periodic_task_group - if changed? and not new_record? + if changed? and not new_record? and not changed.include? 'periodic_task_group_id' self.periodic_task_group = nil end end diff --git a/db/migrate/20121115073715_create_periodic_task_groups.rb b/db/migrate/20130615073715_create_periodic_task_groups.rb similarity index 100% rename from db/migrate/20121115073715_create_periodic_task_groups.rb rename to db/migrate/20130615073715_create_periodic_task_groups.rb diff --git a/db/migrate/20130622095040_move_weekly_tasks.rb b/db/migrate/20130622095040_move_weekly_tasks.rb new file mode 100644 index 00000000..7c9cde8f --- /dev/null +++ b/db/migrate/20130622095040_move_weekly_tasks.rb @@ -0,0 +1,60 @@ +class MoveWeeklyTasks < ActiveRecord::Migration + def up + Workgroup.where(weekly_task: true).each do |workgroup| + task_group = PeriodicTaskGroup.create + puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}" + workgroup.tasks.undone.each do |task| + task_group.tasks << task if weekly_task?(workgroup, task) + end + tasks = task_group.tasks.order(:due_date) + task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty? + task_group.save! + puts "Associated #{tasks.count} tasks with group and set next_task_date to #{task_group.next_task_date}" + end + end + + def down + PeriodicTaskGroup.all.each do |task_group| + unless task_group.tasks.empty? + task = task_group.tasks.first + workgroup = task.workgroup + puts "Writing task data of group #{task_group.id} to workgroup #{workgroup.name}" + workgroup_attributes = { + weekly_task: true, + weekday: task.due_date.days_to_week_start(:sunday), + task_name: task.name, + task_description: task.description, + task_required_users: task.required_users, + task_duration: task.duration + } + workgroup.update_attributes workgroup_attributes + task_group.tasks.update_all weekly: true + end + end + end + +private + def weekly_task?(workgroup, task) + group_task = { + weekday: workgroup.weekday, + name: workgroup.task_name, + description: workgroup.task_description, + required_users: workgroup.task_required_users, + duration: workgroup.task_duration, + weekly: true, + done: false, + workgroup_id: workgroup.id + } + task_task = { + weekday: task.due_date.days_to_week_start(:sunday), + name: task.name, + description: task.description, + required_users: task.required_users, + duration: task.duration, + weekly: task.weekly, + done: task.done, + workgroup_id: task.workgroup_id + } + group_task == task_task + end +end diff --git a/db/schema.rb b/db/schema.rb index 59fa21c4..73cb2ef1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121230142516) do +ActiveRecord::Schema.define(:version => 20130622095040) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false From a7fd7a79363149d4b8e4663a985270d6b8ea98df Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Sat, 22 Jun 2013 18:14:11 +0200 Subject: [PATCH 09/17] Removed obsolete code of old workgroup-centric weekly task concept. --- app/models/workgroup.rb | 42 ------------------- app/views/ordergroups/edit.html.haml | 20 --------- app/views/ordergroups/index.html.haml | 10 ----- app/views/shared/_group.html.haml | 9 +--- app/views/shared/_group_form_fields.html.haml | 11 ----- app/views/tasks/workgroup.haml | 10 ----- app/views/workgroups/edit.html.haml | 20 --------- app/views/workgroups/index.html.haml | 10 ----- lib/tasks/foodsoft.rake | 17 +------- 9 files changed, 2 insertions(+), 147 deletions(-) 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 From 577945e59129e66836e0fa241e3d8242015e485c Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Sat, 22 Jun 2013 18:56:17 +0200 Subject: [PATCH 10/17] Add validation for task.done in combination with periodic task. --- app/models/task.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/task.rb b/app/models/task.rb index 453af12b..6f97d277 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- class Task < ActiveRecord::Base has_many :assignments, :dependent => :destroy has_many :users, :through => :assignments @@ -17,6 +18,7 @@ class Task < ActiveRecord::Base validates :required_users, :presence => true validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 0 validates_length_of :description, maximum: 250 + validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic? before_save :exclude_from_periodic_task_group after_save :update_ordergroup_stats From d081a2c66b4e71358c5a7c4d0359debac8d11fd8 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 24 Jun 2013 09:49:06 +0200 Subject: [PATCH 11/17] Validate done/weekly combination only on creation of task. --- app/models/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/task.rb b/app/models/task.rb index 6f97d277..829e2bb2 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -18,7 +18,7 @@ class Task < ActiveRecord::Base validates :required_users, :presence => true validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 0 validates_length_of :description, maximum: 250 - validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic? + validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic?, on: :create before_save :exclude_from_periodic_task_group after_save :update_ordergroup_stats From 3d1faa9ed319814e991a060e87c99582f1771d5f Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 24 Jun 2013 10:36:14 +0200 Subject: [PATCH 12/17] Skip save callback when migrating data. --- app/models/task.rb | 7 +++---- db/migrate/20130622095040_move_weekly_tasks.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/task.rb b/app/models/task.rb index 829e2bb2..d32b8251 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -20,7 +20,7 @@ class Task < ActiveRecord::Base validates_length_of :description, maximum: 250 validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic?, on: :create - before_save :exclude_from_periodic_task_group + before_save :exclude_from_periodic_task_group, if: :changed?, unless: :new_record? after_save :update_ordergroup_stats # Find all tasks, for which the current user should be responsible @@ -110,9 +110,8 @@ class Task < ActiveRecord::Base end def exclude_from_periodic_task_group - if changed? and not new_record? and not changed.include? 'periodic_task_group_id' - self.periodic_task_group = nil - end + self.periodic_task_group = nil + true end end diff --git a/db/migrate/20130622095040_move_weekly_tasks.rb b/db/migrate/20130622095040_move_weekly_tasks.rb index 7c9cde8f..be316c5c 100644 --- a/db/migrate/20130622095040_move_weekly_tasks.rb +++ b/db/migrate/20130622095040_move_weekly_tasks.rb @@ -4,7 +4,7 @@ class MoveWeeklyTasks < ActiveRecord::Migration task_group = PeriodicTaskGroup.create puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}" workgroup.tasks.undone.each do |task| - task_group.tasks << task if weekly_task?(workgroup, task) + task.update_column(:periodic_task_group_id, task_group.id) if weekly_task?(workgroup, task) end tasks = task_group.tasks.order(:due_date) task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty? From abe7c7181da2bfd9a233e54ed9eb43879da4c0a4 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 24 Jun 2013 10:57:42 +0200 Subject: [PATCH 13/17] Remove obsolete columns from database. --- db/schema.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 73cb2ef1..d2a0dc72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130622095040) do +ActiveRecord::Schema.define(:version => 20130624085246) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -143,17 +143,11 @@ ActiveRecord::Schema.define(:version => 20130622095040) do t.boolean "role_article_meta", :default => false, :null => false t.boolean "role_finance", :default => false, :null => false t.boolean "role_orders", :default => false, :null => false - t.boolean "weekly_task", :default => false - t.integer "weekday" - t.string "task_name" - t.string "task_description" - t.integer "task_required_users", :default => 1 t.datetime "deleted_at" t.string "contact_person" t.string "contact_phone" t.string "contact_address" t.text "stats" - t.integer "task_duration", :default => 1 t.integer "next_weekly_tasks_number", :default => 8 t.boolean "ignore_apple_restriction", :default => false end @@ -322,7 +316,6 @@ ActiveRecord::Schema.define(:version => 20130622095040) do t.datetime "created_on", :null => false t.datetime "updated_on", :null => false t.integer "required_users", :default => 1 - t.boolean "weekly" t.integer "duration", :default => 1 t.integer "periodic_task_group_id" end From c27127c745bb2b0122af8db03d878b244f1aed09 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 24 Jun 2013 11:53:52 +0200 Subject: [PATCH 14/17] Added i18n strings. --- app/models/task.rb | 2 +- app/views/tasks/_form.html.haml | 2 +- app/views/tasks/show.haml | 4 ++-- config/locales/de.yml | 20 +++++++++----------- config/locales/en.yml | 9 +++++++++ db/schema.rb | 4 ++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/models/task.rb b/app/models/task.rb index d32b8251..bd2f23d6 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -18,7 +18,7 @@ class Task < ActiveRecord::Base validates :required_users, :presence => true validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 0 validates_length_of :description, maximum: 250 - validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic?, on: :create + validates :done, exclusion: { in: [true] }, if: :periodic?, on: :create before_save :exclude_from_periodic_task_group, if: :changed?, unless: :new_record? after_save :update_ordergroup_stats diff --git a/app/views/tasks/_form.html.haml b/app/views/tasks/_form.html.haml index ba627f7e..95f3b134 100644 --- a/app/views/tasks/_form.html.haml +++ b/app/views/tasks/_form.html.haml @@ -27,5 +27,5 @@ .form-actions = f.submit class: 'btn btn-primary' - if @task.new_record? - = f.submit 'Wöchentliche Aufgabe erstellen', name: 'periodic', class: 'btn' + = f.submit t('.submit.periodic'), name: 'periodic', class: 'btn' = link_to t('ui.or_cancel'), :back diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index f2e147c8..6a57dbad 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -30,5 +30,5 @@ = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => "Die Aufgabe wirklich löschen?", class: 'btn btn-danger' - if @task.periodic? - = link_to 'Aufgabe und folgende löschen', task_path(@task, periodic: true), method: :delete, - confirm: "Diese und alle folgenden wöchentlichen Aufgaben wirklich löschen?", class: 'btn btn-danger' + = link_to t('.delete_group'), task_path(@task, periodic: true), method: :delete, + confirm: t('.confirm_delete_group'), class: 'btn btn-danger' diff --git a/config/locales/de.yml b/config/locales/de.yml index 0961913b..8a8abb73 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -81,6 +81,11 @@ de: too_long: ist zu lang (nicht mehr als %{count} Zeichen) too_short: ist zu kurz (nicht weniger als %{count} Zeichen) wrong_length: hat die falsche Länge (muss genau %{count} Zeichen haben) + models: + task: + attributes: + done: + exclusion: erledigte Aufgaben können nicht wöchentlich wiederholt werden template: body: ! 'Bitte überprüfen Sie die folgenden Felder:' header: @@ -1628,12 +1633,6 @@ de: role_finance: Finanzen role_orders: Bestellverwaltung role_suppliers: Lieferanten - task_description: Beschreibung - task_duration: Vor. Dauer in Stunden - task_name: Name für Job - task_required_users: Benötige Verantwortliche - weekday: Wochentag - weekly_task: Monatlichen Job definieren? 'no': Nein required: mark: ! '*' @@ -1764,6 +1763,8 @@ de: hint: Nach Nutzerin suchen noresult: Keine Nutzerin gefunden placeholder: Suche ... + submit: + periodic: Wöchentliche Aufgabe speichern index: show_group_tasks: Gruppenaufgaben anzeigen title: Aufgaben @@ -1791,6 +1792,8 @@ de: notice: Aufgabenstatus wurde aktualisiert show: accept_task: Aufgabe übernehmen + confirm_delete_group: Diese und alle folgenden wöchentlichen Aufgaben wirklich löschen? + delete_group: Aufgabe und folgende löschen due_date: Fälligkeitsdatum hours: ! '%{count}h' mark_done: Als erledigt markieren @@ -1807,11 +1810,6 @@ de: workgroup: title: Aufgaben für %{workgroup} title_all: Alle Aufgaben der Gruppe - weekly: - desc: ! '

Jeden %{weekday} hat diese Arbeitsgruppe folgenden Job: %{task}

Die Wochenaufgaben werden von der Foodsoft automatisch erstellt. Eintragen müsst Ihr Euch aber selber.

' - edit: Wöchentliche Aufgaben anpassen - empty: Noch keine Wochenaufgaben angelegt. - title: Wöchentliche Aufgaben time: am: vormittags formats: diff --git a/config/locales/en.yml b/config/locales/en.yml index bd34e6d4..1cd4eee9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -81,6 +81,11 @@ en: too_long: is too long (no more than %{count} characters) too_short: is too short (use more than %{count} characters) wrong_length: is the wrong length (has to have exactly %{count} characters) + models: + task: + attributes: + done: + exclusion: finished tasks may not be repeated weekly template: body: ! 'Please check the following fields:' header: @@ -1765,6 +1770,8 @@ en: hint: Search for user noresult: No user found placeholder: Search ... + submit: + periodic: Save weekly task index: show_group_tasks: Show group tasks title: Tasks @@ -1792,6 +1799,8 @@ en: notice: The state of the task has been updated show: accept_task: Accept task + confirm_delete_group: Really delete this and all subsequent tasks? + delete_group: Delete task and subsequent due_date: Due date hours: ! '%{count}h' mark_done: Mark task as done diff --git a/db/schema.rb b/db/schema.rb index d2a0dc72..f81bfae6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -308,10 +308,10 @@ ActiveRecord::Schema.define(:version => 20130624085246) do add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true create_table "tasks", :force => true do |t| - t.string "name", :default => "", :null => false + t.string "name", :default => "", :null => false t.string "description" t.date "due_date" - t.boolean "done", :default => false + t.boolean "done", :default => false t.integer "workgroup_id" t.datetime "created_on", :null => false t.datetime "updated_on", :null => false From 7942ccfae698716b7ab255fffd03fc5990d5cf83 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 24 Jun 2013 12:02:22 +0200 Subject: [PATCH 15/17] Added missing migration files. --- ...20130624084223_remove_weekly_from_tasks.rb | 9 +++++++++ ...24085246_remove_weekly_task_from_groups.rb | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 db/migrate/20130624084223_remove_weekly_from_tasks.rb create mode 100644 db/migrate/20130624085246_remove_weekly_task_from_groups.rb diff --git a/db/migrate/20130624084223_remove_weekly_from_tasks.rb b/db/migrate/20130624084223_remove_weekly_from_tasks.rb new file mode 100644 index 00000000..4fefcb5b --- /dev/null +++ b/db/migrate/20130624084223_remove_weekly_from_tasks.rb @@ -0,0 +1,9 @@ +class RemoveWeeklyFromTasks < ActiveRecord::Migration + def up + remove_column :tasks, :weekly + end + + def down + add_column :tasks, :weekly, :boolean + end +end diff --git a/db/migrate/20130624085246_remove_weekly_task_from_groups.rb b/db/migrate/20130624085246_remove_weekly_task_from_groups.rb new file mode 100644 index 00000000..665651d9 --- /dev/null +++ b/db/migrate/20130624085246_remove_weekly_task_from_groups.rb @@ -0,0 +1,19 @@ +class RemoveWeeklyTaskFromGroups < ActiveRecord::Migration + def up + remove_column :groups, :weekly_task + remove_column :groups, :weekday + remove_column :groups, :task_name + remove_column :groups, :task_description + remove_column :groups, :task_required_users + remove_column :groups, :task_duration + end + + def down + add_column :groups, :task_duration, :integer + add_column :groups, :task_required_users, :integer + add_column :groups, :task_description, :string + add_column :groups, :task_name, :string + add_column :groups, :weekday, :integer + add_column :groups, :weekly_task, :boolean + end +end From e5d790021c77b912ade0d9faffdf501b720fc6c5 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 27 Jun 2013 10:22:22 +0200 Subject: [PATCH 16/17] Add repeated symbol to task list. --- app/views/tasks/_list.haml | 4 ++++ app/views/tasks/show.haml | 5 ++++- config/locales/de.yml | 1 + config/locales/en.yml | 1 + db/schema.rb | 4 ++-- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/views/tasks/_list.haml b/app/views/tasks/_list.haml index a0b2af22..da91cec8 100644 --- a/app/views/tasks/_list.haml +++ b/app/views/tasks/_list.haml @@ -2,6 +2,7 @@ %thead %tr %th= t '.due_date' + %th %th= t '.task' %th{:colspan => '2'} = t '.who' @@ -11,6 +12,9 @@ - done = task.done ? " done" : "" %tr{:class => done } %td= format_date(task.due_date) unless task.due_date.nil? + %td + - if task.periodic? + %i.icon-repeat{title: t('tasks.repeated')} %td= link_to t('.task_format', name: task.name, duration: task.duration), task_path(task) %td = task_assignments task diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index 6a57dbad..8777d15d 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -10,7 +10,10 @@ %dd= simple_format(@task.description) - if @task.due_date.present? %dt= t '.due_date' - %dd= format_date(@task.due_date) + %dd + = format_date(@task.due_date) + - if @task.periodic? + %i.icon-repeat{title: t('tasks.repeated')} %dt= t 'simple_form.labels.task.duration' %dd= t('.hours', count: @task.duration) %dt= t 'simple_form.labels.task.user_list' diff --git a/config/locales/de.yml b/config/locales/de.yml index 8a8abb73..ffd5a82b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1788,6 +1788,7 @@ de: new_task: Neue Aufgabe erstellen new: title: Neue Aufgabe erstellen + repeated: Aufgabe wird wöchentlich wiederholt set_done: notice: Aufgabenstatus wurde aktualisiert show: diff --git a/config/locales/en.yml b/config/locales/en.yml index 1cd4eee9..a2042a46 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1795,6 +1795,7 @@ en: new_task: Create new task new: title: Create new tasks + repeated: Task is repeated weekly set_done: notice: The state of the task has been updated show: diff --git a/db/schema.rb b/db/schema.rb index f81bfae6..d2a0dc72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -308,10 +308,10 @@ ActiveRecord::Schema.define(:version => 20130624085246) do add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true create_table "tasks", :force => true do |t| - t.string "name", :default => "", :null => false + t.string "name", :default => "", :null => false t.string "description" t.date "due_date" - t.boolean "done", :default => false + t.boolean "done", :default => false t.integer "workgroup_id" t.datetime "created_on", :null => false t.datetime "updated_on", :null => false From 65c0b555c247572fcd5f2300d636c7959c83efb4 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 11 Jul 2013 10:30:55 +0200 Subject: [PATCH 17/17] Added warning/ hint when updating periodic task. --- app/controllers/tasks_controller.rb | 7 +++++++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ 3 files changed, 11 insertions(+) diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 017a9a8a..ee4c05cd 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -35,13 +35,20 @@ class TasksController < ApplicationController def edit @task = Task.find(params[:id]) @task.current_user_id = current_user.id + if @task.periodic? + flash.now[:alert] = I18n.t('tasks.edit.warning_periodic').html_safe + end end def update @task = Task.find(params[:id]) + was_periodic = @task.periodic? @task.attributes=(params[:task]) if @task.errors.empty? && @task.save flash[:notice] = I18n.t('tasks.update.notice') + if was_periodic and not @task.periodic? + flash[:notice] = I18n.t('tasks.update.notice_converted') + end if @task.workgroup redirect_to workgroup_tasks_url(workgroup_id: @task.workgroup_id) else diff --git a/config/locales/de.yml b/config/locales/de.yml index ffd5a82b..c2e5f8b9 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1757,6 +1757,7 @@ de: notice: Aufgabe wurde gelöscht edit: title: Aufgabe bearbeiten + warning_periodic: Warnung: Diese Aufgabe ist Teil einer Gruppe von wöchentlichen Aufgaben. Beim Speichern wird sie aus der Gruppe ausgeschlossen und in eine gewöhnliche Aufgabe umgewandelt. error_not_found: Keine Arbeitsgruppe gefunden form: search: @@ -1802,6 +1803,7 @@ de: title: Aufgabe anzeigen update: notice: Aufgabe wurde aktualisiert + notice_converted: Aufgabe wurde aktualisiert und in eine gewöhnliche Aufgabe umgewandelt user: more: Nichts zu tun? %{tasks_link} gibt es bestimmt Arbeit tasks_link: Hier diff --git a/config/locales/en.yml b/config/locales/en.yml index a2042a46..b6b2901a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1764,6 +1764,7 @@ en: notice: Task has been deleted edit: title: Edit task + warning_periodic: Warning: This task is part of a group of weekly tasks. When saving it will be excluded from the group and it will be converted to a regular task. error_not_found: No workgroup found form: search: @@ -1809,6 +1810,7 @@ en: title: Show task update: notice: Task has been updated + notice_converted: Task has been updated and was converted to a regular task user: more: Nothing to do? %{tasks_link} are tasks for sure. tasks_link: Here