Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/models/action_item.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 18 additions & 2 deletions app/views/documents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@
<p class="text-xl">所属プロジェクト:
<%= link_to_if @document.project&.name, @document.project&.name, @document.project %>
<p class="text-xl block font-bold mb-2">文書内容</p>
<div class="jay_document">
<%== JayFlavoredMarkdownConverter.new(@document.description).content %>
<div class="jay_document">
<% 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 %>
</div>
</p>
</div>
11 changes: 10 additions & 1 deletion app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@

<div class="my-3">
<p class="text-xl block font-bold mb-2">説明</p>
<%= @task.description %>
<% @task.description.each_line do |line| %>
<% matched = line.match(/\((.+)\)/) %>
<% if matched != nil %>
<%== $` %>
<%= link_to matched[0], matched[1] %>
<%== $' %>
<% else %>
<%== line %>
<% end %>
<% end %>
</div>

<div class="my-3">
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20221006041706_create_action_items.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 9 additions & 25 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/action_items.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
task_url: /1

two:
task_url: /1
7 changes: 7 additions & 0 deletions test/models/action_item_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class ActionItemTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end