From b6f5295267862e5b65761e3e5b6377bec5f51a4f Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Fri, 6 Mar 2020 13:04:03 +0100 Subject: [PATCH] Add created_by user to Task --- app/controllers/tasks_controller.rb | 1 + app/models/task.rb | 1 + app/views/tasks/show.haml | 4 ++++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/nl.yml | 2 ++ db/migrate/20181205000000_add_user_to_task.rb | 11 +++++++++++ db/schema.rb | 15 ++++++++------- 10 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20181205000000_add_user_to_task.rb diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 04c7f7be..92de0081 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -18,6 +18,7 @@ class TasksController < ApplicationController def create @task = Task.new(current_user_id: current_user.id) + @task.created_by = current_user @task.attributes=(task_params) if params[:periodic] @task.periodic_task_group = PeriodicTaskGroup.new diff --git a/app/models/task.rb b/app/models/task.rb index 5134bec8..b36da935 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -4,6 +4,7 @@ class Task < ApplicationRecord has_many :users, :through => :assignments belongs_to :workgroup belongs_to :periodic_task_group + belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' scope :non_group, -> { where(workgroup_id: nil, done: false) } scope :done, -> { where(done: true) } diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index ba7a36d0..492c2d6a 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -5,6 +5,10 @@ %dl.dl-horizontal %dt= heading_helper Task, :name %dd= @task.name + %dt= heading_helper Task, :created_on + %dd= format_time @task.created_on + %dt= heading_helper Task, :created_by + %dd= show_user @task.created_by - if @task.description.present? %dt= heading_helper Task, :description %dd= simple_format(@task.description) diff --git a/config/locales/de.yml b/config/locales/de.yml index bf140348..d7388ec7 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -167,6 +167,8 @@ de: phone2: Telefon 2 shared_sync_method: Syncronisierungsmethode task: + created_by: Erstellt von + created_on: Erstellt am description: Beschreibung done: Erledigt? due_date: Wann erledigen? diff --git a/config/locales/en.yml b/config/locales/en.yml index 1d86d737..c5bb96e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -179,6 +179,8 @@ en: shared_sync_method: How to synchronize url: Homepage task: + created_by: Created by + created_on: Created at description: Description done: Done? due_date: Due date diff --git a/config/locales/es.yml b/config/locales/es.yml index a5bf5c57..d3c8662d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -144,6 +144,8 @@ es: shared_sync_method: Cómo sincronizar url: Web task: + created_by: Creado por + created_on: Creado en description: Descripción done: Hecho? due_date: Fecha diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6b5fa6da..d048b7bf 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -128,6 +128,8 @@ fr: phone2: Autre téléphone url: Site web task: + created_by: Crée par + created_on: Créé le done: Fait? due_date: Echéance duration: Durée diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 7e0ad0e7..3d0f366e 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -165,6 +165,8 @@ nl: shared_sync_method: Hoe synchroniseren url: Homepage task: + created_by: Gemaakt door + created_on: Gemaakt op description: Beschrijving done: Gedaan? due_date: Voor wanneer? diff --git a/db/migrate/20181205000000_add_user_to_task.rb b/db/migrate/20181205000000_add_user_to_task.rb new file mode 100644 index 00000000..d9ddb11c --- /dev/null +++ b/db/migrate/20181205000000_add_user_to_task.rb @@ -0,0 +1,11 @@ +class AddUserToTask < ActiveRecord::Migration + def change + add_column :tasks, :created_by_user_id, :integer + + reversible do |dir| + dir.up do + change_column :tasks, :description, :text + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ba0d2c58..941a7cad 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -502,16 +502,17 @@ ActiveRecord::Schema.define(version: 20181201000210) do add_index "suppliers", ["name"], name: "index_suppliers_on_name", unique: true, using: :btree create_table "tasks", force: :cascade do |t| - t.string "name", limit: 255, default: "", null: false - t.string "description", limit: 255 + t.string "name", limit: 255, default: "", null: false + t.text "description", limit: 65535 t.date "due_date" - t.boolean "done", default: false + t.boolean "done", default: false t.integer "workgroup_id", limit: 4 - t.datetime "created_on", null: false - t.datetime "updated_on", null: false - t.integer "required_users", limit: 4, default: 1 - t.integer "duration", limit: 4, default: 1 + t.datetime "created_on", null: false + t.datetime "updated_on", null: false + t.integer "required_users", limit: 4, default: 1 + t.integer "duration", limit: 4, default: 1 t.integer "periodic_task_group_id", limit: 4 + t.integer "created_by_user_id", limit: 4 end add_index "tasks", ["due_date"], name: "index_tasks_on_due_date", using: :btree