diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
index c4d0b576..4f0ba6aa 100644
--- a/app/controllers/tasks_controller.rb
+++ b/app/controllers/tasks_controller.rb
@@ -19,6 +19,7 @@ def new
@projects = Project.all
@tags = Tag.all
@task_states = TaskState.all
+ @task.description = params[:desc_header]
project_id = params[:project_id]
unless project_id.nil?
@@ -41,6 +42,10 @@ def create
if @task.save!
flash[:success] = "タスクを追加しました"
+ matched = task_params[:description].match(/\[AI([0-9]+)\]/)
+ if matched != nil
+ ActionItem.find(matched[1]).update(task_url: tasks_path + "/" + @task.id.to_s)
+ end
redirect_to tasks_path
else
redirect_back fallback_location: new_task_path
diff --git a/app/models/action_item.rb b/app/models/action_item.rb
new file mode 100644
index 00000000..7d295f50
--- /dev/null
+++ b/app/models/action_item.rb
@@ -0,0 +1,13 @@
+class ActionItem < ApplicationRecord
+ after_create :set_uid
+
+ def uid
+ "%04d" % self.id
+ end
+
+ private
+
+ def set_uid
+ self.update(uid: uid)
+ end
+end
diff --git a/app/models/document.rb b/app/models/document.rb
index 933a3b01..af04fde8 100644
--- a/app/models/document.rb
+++ b/app/models/document.rb
@@ -8,4 +8,18 @@ class Document < ApplicationRecord
validates :end_at, presence: true
validates :location, presence: true
#validates :project, presence: true
+ before_validation :add_unique_action_item_marker
+
+ def add_unique_action_item_marker
+ desc = ""
+ self.description.each_line {|line|
+ matched = line.match(/-->\((.+)\)/)
+ if matched != nil
+ @action_item = ActionItem.create(task_url: nil)
+ line.gsub!(/-->\(.+\)/, "-->(#{matched[1]} !#{@action_item.uid})")
+ end
+ desc += line
+ }
+ self.description = desc
+ end
end
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index 8e225f14..861f3d19 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -10,8 +10,24 @@
所属プロジェクト:
<%= link_to_if @document.project&.name, @document.project&.name, @document.project %>
文書内容
-
- <%== JayFlavoredMarkdownConverter.new(@document.description).content %>
+
+ <% desc = JayFlavoredMarkdownConverter.new(@document.description).content %>
+ <% desc.each_line do |line| %>
+ <% matched = line.match(/\([^ ]+ !([0-9]+)\)/) %>
+ <% if matched != nil %>
+ <%== $` %>
+ <% task_url = ActionItem.find_by(uid:matched[1].to_i).task_url %>
+ <% if task_url != nil %>
+ <%= link_to matched[0], task_url.to_s %>
+ <% else %>
+ <% message = "Created from [AI#{matched[1]}](#{request.url})" %>
+ <%= link_to matched[0], new_task_path(desc_header: message) %>
+ <% end %>
+ <%== $' %>
+ <% else %>
+ <%== line %>
+ <% end %>
+ <% end %>
diff --git a/app/views/tasks/show.html.erb b/app/views/tasks/show.html.erb
index 418f936f..0ba2b9da 100644
--- a/app/views/tasks/show.html.erb
+++ b/app/views/tasks/show.html.erb
@@ -20,7 +20,16 @@
説明
- <%= @task.description %>
+ <% @task.description.each_line do |line| %>
+ <% matched = line.match(/\((.+)\)/) %>
+ <% if matched != nil %>
+ <%== $` %>
+ <%= link_to matched[0], matched[1] %>
+ <%== $' %>
+ <% else %>
+ <%== line %>
+ <% end %>
+ <% end %>
diff --git a/db/migrate/20221006041706_create_action_items.rb b/db/migrate/20221006041706_create_action_items.rb
new file mode 100644
index 00000000..a6ee000e
--- /dev/null
+++ b/db/migrate/20221006041706_create_action_items.rb
@@ -0,0 +1,10 @@
+class CreateActionItems < ActiveRecord::Migration[6.1]
+ def change
+ create_table :action_items do |t|
+ t.integer :uid
+ t.string :task_url
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d95b7e13..08afda81 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_11_07_082503) do
+ActiveRecord::Schema.define(version: 2022_10_06_041706) do
+
+ create_table "action_items", force: :cascade do |t|
+ t.integer "uid"
+ t.string "task_url"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ end
create_table "api_tokens", force: :cascade do |t|
t.string "secret"
@@ -58,15 +65,6 @@
t.datetime "updated_at", precision: 6, null: false
end
- create_table "task_tag_relations", force: :cascade do |t|
- t.integer "task_id", null: false
- t.integer "tag_id", null: false
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["tag_id"], name: "index_task_tag_relations_on_tag_id"
- t.index ["task_id"], name: "index_task_tag_relations_on_task_id"
- end
-
create_table "task_tags", force: :cascade do |t|
t.integer "task_id"
t.integer "tag_id"
@@ -86,22 +84,12 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "tag_id"
- t.index ["project_id"], name: "index_tasks_on_project_id"
- t.index ["tag_id"], name: "index_tasks_on_tag_id"
t.integer "task_state_id"
t.index ["project_id"], name: "index_tasks_on_project_id"
+ t.index ["tag_id"], name: "index_tasks_on_tag_id"
t.index ["task_state_id"], name: "index_tasks_on_task_state_id"
end
- create_table "tasks_tags", force: :cascade do |t|
- t.integer "task_id", null: false
- t.integer "tag_id", null: false
- t.datetime "created_at", precision: 6, null: false
- t.datetime "updated_at", precision: 6, null: false
- t.index ["tag_id"], name: "index_tasks_tags_on_tag_id"
- t.index ["task_id"], name: "index_tasks_tags_on_task_id"
- end
-
create_table "users", force: :cascade do |t|
t.string "name"
t.string "screen_name"
@@ -121,14 +109,10 @@
add_foreign_key "documents", "users", column: "creator_id", on_delete: :cascade
add_foreign_key "projects", "users"
add_foreign_key "projects", "users", on_delete: :cascade
- add_foreign_key "task_tag_relations", "tags"
- add_foreign_key "task_tag_relations", "tasks"
add_foreign_key "tasks", "projects"
add_foreign_key "tasks", "projects", on_delete: :cascade
add_foreign_key "tasks", "tags"
add_foreign_key "tasks", "task_states"
add_foreign_key "tasks", "users", column: "assigner_id", on_delete: :cascade
add_foreign_key "tasks", "users", column: "creator_id", on_delete: :cascade
- add_foreign_key "tasks_tags", "tags"
- add_foreign_key "tasks_tags", "tasks"
end
diff --git a/test/fixtures/action_items.yml b/test/fixtures/action_items.yml
new file mode 100644
index 00000000..ab150e95
--- /dev/null
+++ b/test/fixtures/action_items.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ task_url: /1
+
+two:
+ task_url: /1
diff --git a/test/models/action_item_test.rb b/test/models/action_item_test.rb
new file mode 100644
index 00000000..f0b108e7
--- /dev/null
+++ b/test/models/action_item_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class ActionItemTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end