Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature issue entry association diff #1289

Open
wants to merge 9 commits into
base: feature/issue-entry-association
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions app/assets/stylesheets/tylium/modules/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@
}
}

.btn-link {
background-color: transparent;
border: none;
color: $linkColor;
padding: 0;
text-decoration: none;

&:active,
&:focus,
&:hover,
&:not(:disabled):not(.disabled):active {
background-color: transparent;
box-shadow: none !important;
color: $linkColorHover;
}
}

.btn-placeholder {
align-items: center;
background-color: $primaryColor;
Expand Down
18 changes: 8 additions & 10 deletions app/assets/stylesheets/tylium/modules/_modals.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.modal {

.modal-dialog {
max-width: 560px;
&:not(.modal-lg, .modal-xl) {
max-width: 560px;
}

.modal-content {
font-size: 0.9rem;

.modal-body {

.add_multiple_nodes_form {
display: none;

.add_multiple_nodes_error {
display: none;
color: #b94a48;
Expand Down Expand Up @@ -49,7 +49,6 @@
}

&#modal_delete_node {

ul {
list-style: disc;
padding-left: 30px;
Expand All @@ -70,7 +69,7 @@
text-decoration: underline !important;
}
}

.invalid-selection {
cursor: not-allowed;
}
Expand Down Expand Up @@ -109,13 +108,12 @@
}

&#try-pro {

.modal-dialog {
max-width: 80%;

.modal-body {
height: 80vh;

iframe {
border: none;
top: 0;
Expand All @@ -125,7 +123,7 @@
width: 100%;
}
}

.modal-header h5 span {
color: $primaryColor;
}
Expand Down
53 changes: 53 additions & 0 deletions app/services/diffed_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class DiffedContent
attr_reader :source, :target

def initialize(source, target)
@source = source
@target = target

normalize_content(@source)
normalize_content(@target)
end

def diff
Differ.format = :html
differ_result = Differ.diff_by_word(source.content, target.content)
aapomm marked this conversation as resolved.
Show resolved Hide resolved

output = highlighted_string(differ_result)

{ source: output[1], target: output[0] }
end

def changed?
source.updated_at != target.updated_at &&
source.content != target.content
end

private

def normalize_content(record)
fields = record.fields.except('id', 'plugin', 'plugin_id')

record.content =
fields.map do |field, value|
"#[#{field}]#\n#{value.gsub("\r",'')}\n"
end.join("\n")
end

def highlighted_string(differ_result)
[:delete, :insert].map do |highlight_type|
result_str = differ_result.dup.to_s

case highlight_type
when :delete
result_str.gsub!(/<del class="differ">(.*?)<\/del>/m, '<mark>\1</mark>')
result_str.gsub!(/<ins class="differ">(.*?)<\/ins>/m, '')
when :insert
result_str.gsub!(/<ins class="differ">(.*?)<\/ins>/m, '<mark>\1</mark>')
result_str.gsub!(/<del class="differ">(.*?)<\/del>/m, '')
end

result_str.html_safe
end
end
end
33 changes: 33 additions & 0 deletions spec/services/diffed_content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'

describe DiffedContent do
let(:issue1) { create(:issue, text: "#[Title]#\nIssue1\n") }
let(:issue2) { create(:issue, text: "#[Title]#\nIssue2\n") }

subject { described_class.new(issue1, issue2) }

describe '#diff' do
it 'returns the diff' do
expect(subject.diff).to eq({
source: "#[Title]#\n<mark>Issue1</mark>\n",
target: "#[Title]#\n<mark>Issue2</mark>\n"
})
end
end

describe '#changed?' do
context 'source and target does not match' do
it 'returns true' do
issue1.update text: 'test', updated_at: Time.now + 1.day
expect(subject.changed?).to eq true
end
end

context 'source and target matches' do
it 'returns false' do
issue1.update text: issue2.content
expect(subject.changed?).to eq false
end
end
end
end