Refactoring task queue partials

parent 8673a70f
...@@ -23,18 +23,20 @@ module TasksHelper ...@@ -23,18 +23,20 @@ module TasksHelper
[task.action_name, target].join(" ") [task.action_name, target].join(" ")
end end
def task_note_link_html(task) def task_target_link_html(task)
link_to task_note_target_path(task) do link_to task_target_path(task) do
"##{task.target_iid}" "##{task.target_iid}"
end end
end end
def task_note_target_path(task) def task_target_path(task)
anchor = dom_id(task.note) if task.note.present?
polymorphic_path([task.project.namespace.becomes(Namespace), polymorphic_path([task.project.namespace.becomes(Namespace),
task.project, task.target], anchor: dom_id(task.note)) task.project, task.target], anchor: anchor)
end end
def task_note(text, options = {}) def task_body(text, options = {})
text = first_line_in_markdown(text, 150, options) text = first_line_in_markdown(text, 150, options)
sanitize(text, tags: %w(a img b pre code p span)) sanitize(text, tags: %w(a img b pre code p span))
end end
......
...@@ -50,12 +50,12 @@ class Task < ActiveRecord::Base ...@@ -50,12 +50,12 @@ class Task < ActiveRecord::Base
end end
end end
def body? def body
target.respond_to? :title if note.present?
note.note
else
target.title
end end
def note_text
note.try(:note)
end end
def target_iid def target_iid
......
.task-title
%span.author_name= link_to_author task
%span.task_label{class: task.action_name}
= task_action_name(task)
%strong= link_to "##{task.target_iid}", [task.project.namespace.becomes(Namespace), task.project, task.target]
&middot; #{time_ago_with_tooltip(task.created_at)}
- if task.pending?
.task-actions.pull-right
= link_to 'Done', [:dashboard, task], method: :delete, class: 'btn'
- if task.body?
.task-body
.task-note
= task.target.title
.task-title
%span.author_name
= link_to_author task
%span.task_label{class: task.action_name}
= task_action_name(task)
= task_note_link_html(task)
&middot; #{time_ago_with_tooltip(task.created_at)}
- if task.pending?
.task-actions.pull-right
= link_to 'Done', [:dashboard, task], method: :delete, class: 'btn'
.task-body
.task-note
.md
= task_note(task.note_text, project: task.project)
- note = task.note
- if note.attachment.url
- if note.attachment.image?
= link_to note.attachment.url, target: '_blank' do
= image_tag note.attachment.url, class: 'note-image-attach'
- else
= link_to note.attachment.url, target: "_blank", class: 'note-file-attach' do
%i.fa.fa-paperclip
= note.attachment_identifier
%li{class: "task task-#{task.done? ? 'done' : 'pending'}", id: dom_id(task) } %li{class: "task task-#{task.done? ? 'done' : 'pending'}", id: dom_id(task) }
.task-item{class: "#{task.body? ? 'task-block' : 'task-inline' }"} .task-item{class: 'task-block'}
= image_tag avatar_icon(task.author_email, 40), class: "avatar s40", alt:'' = image_tag avatar_icon(task.author_email, 40), class: 'avatar s40', alt:''
- if task.note.present? .task-title
= render 'note', task: task %span.author_name
- else = link_to_author task
= render 'common', task: task %span.task_label
= task_action_name(task)
= task_target_link_html(task)
&middot; #{time_ago_with_tooltip(task.created_at)}
- if task.pending?
.task-actions.pull-right
= link_to 'Done', [:dashboard, task], method: :delete, class: 'btn'
.task-body
.task-note
.md
= task_body(task.body, project: task.project)
...@@ -51,35 +51,21 @@ describe Task, models: true do ...@@ -51,35 +51,21 @@ describe Task, models: true do
end end
end end
describe '#body?' do describe '#body' do
let(:issue) { build(:issue) }
before do before do
subject.target = issue subject.target = build(:issue, title: 'Bugfix')
end
it 'returns true when target respond to title' do
expect(subject.body?).to eq true
end
it 'returns false when target does not respond to title' do
allow(issue).to receive(:respond_to?).with(:title).and_return(false)
expect(subject.body?).to eq false
end
end end
describe '#note_text' do it 'returns target title when note is blank' do
it 'returns nil when note is blank' do
subject.note = nil subject.note = nil
expect(subject.note_text).to be_nil expect(subject.body).to eq 'Bugfix'
end end
it 'returns note when note is present' do it 'returns note when note is present' do
subject.note = build(:note, note: 'quick fix') subject.note = build(:note, note: 'quick fix')
expect(subject.note_text).to eq 'quick fix' expect(subject.body).to eq 'quick fix'
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment