-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add a tag diff to /(node|way|relation)/:id/history #6995
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
Open
stillhart
wants to merge
1
commit into
openstreetmap:master
Choose a base branch
from
stillhart:historydiff
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module TagDiffHelper | ||
| def tag_diff(new_tags, old_tags) | ||
| new_tags ||= {} | ||
| old_tags ||= {} | ||
|
|
||
| (new_tags.keys | old_tags.keys).sort.filter_map do |key| | ||
| if new_tags.key?(key) && old_tags.key?(key) | ||
| { :type => "modified", :key => key, :old_value => old_tags[key], :new_value => new_tags[key] } if new_tags[key] != old_tags[key] | ||
| elsif new_tags.key?(key) | ||
| { :type => "added", :key => key, :old_value => nil, :new_value => new_tags[key] } | ||
| else | ||
| { :type => "removed", :key => key, :old_value => old_tags[key], :new_value => nil } | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <%# locals: (new_element:, old_element:) %> | ||
| <% if old_element %> | ||
| <% diffs = tag_diff(new_element.tags, old_element.tags) %> | ||
| <% if diffs.any? %> | ||
| <details class="mb-3 border-bottom border-secondary-subtle pb-3"> | ||
| <summary class="text-secondary"><%= t("browse.tag_diff.summary", :old_version => old_element.version, :new_version => new_element.version) %></summary> | ||
| <div class="border border-secondary-subtle rounded overflow-hidden mt-2"> | ||
| <table class="table mb-0 browse-tag-list align-middle table-sm"> | ||
| <tbody> | ||
| <% diffs.each do |diff| %> | ||
| <% case diff[:type] %> | ||
| <% when "added" %> | ||
| <tr class="table-secondary"> | ||
| <th scope="row" class="py-1 border-secondary-subtle fw-normal table-success" dir="auto"><span class="visually-hidden"><%= t("browse.tag_diff.type.added") %>:</span><%= format_key(diff[:key]) %> </th> | ||
| <td class="py-1 border-secondary-subtle border-start table-success" dir="auto"><%= format_value(diff[:key], diff[:new_value]) %></td> | ||
| </tr> | ||
| <% when "removed" %> | ||
| <tr class="table-secondary"> | ||
| <th scope="row" class="py-1 border-secondary-subtle fw-normal table-danger" dir="auto"><span class="visually-hidden"><%= t("browse.tag_diff.type.removed") %>:</span><%= format_key(diff[:key]) %> </th> | ||
| <td class="py-1 border-secondary-subtle border-start table-danger" dir="auto"><%= format_value(diff[:key], diff[:old_value]) %></td> | ||
| </tr> | ||
| <% when "modified" %> | ||
| <tr class="table-secondary"> | ||
| <th scope="row" rowspan="2" class="py-1 border-secondary-subtle fw-normal" dir="auto"><span class="visually-hidden"><%= t("browse.tag_diff.type.modified") %>:</span><%= format_key(diff[:key]) %> </th> | ||
| <td class="py-1 border-secondary-subtle border-start table-success text-secondary" dir="auto"><span class="visually-hidden"><%= t("browse.tag_diff.status.new") %>:</span><%= format_value(diff[:key], diff[:new_value]) %></td> | ||
| </tr> | ||
| <tr class="table-secondary"> | ||
| <td class="py-1 border-secondary-subtle border-start table-danger text-secondary" dir="auto"><span class="visually-hidden"><%= t("browse.tag_diff.status.old") %>:</span><%= format_value(diff[:key], diff[:old_value]) %></td> | ||
| </tr> | ||
| <% end %> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </details> | ||
| <% end %> | ||
| <% end %> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| class TagDiffHelperTest < ActionView::TestCase | ||
| def test_tag_diff | ||
| old_tags = { "highway" => "trunk", "maxspeed" => "50", "ref" => "A1" } | ||
| new_tags = { "highway" => "tertiary", "name" => "Main St", "ref" => "A1" } | ||
|
|
||
| diffs = tag_diff(new_tags, old_tags) | ||
|
|
||
| assert_equal 3, diffs.length | ||
|
|
||
| assert_equal "highway", diffs[0][:key] | ||
| assert_equal "modified", diffs[0][:type] | ||
| assert_equal "trunk", diffs[0][:old_value] | ||
| assert_equal "tertiary", diffs[0][:new_value] | ||
|
|
||
| assert_equal "maxspeed", diffs[1][:key] | ||
| assert_equal "removed", diffs[1][:type] | ||
| assert_equal "50", diffs[1][:old_value] | ||
|
|
||
| assert_equal "name", diffs[2][:key] | ||
| assert_equal "added", diffs[2][:type] | ||
| assert_equal "Main St", diffs[2][:new_value] | ||
|
|
||
| assert_nil(diffs.find { |d| d[:key] == "ref" }) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A possible downside of the collapsible design is that the find in page function in some browsers1 won’t be able to find the contents until you manually go through opening each section. I have a hunch that people use this page as a sort of blame view. After all, that’s the main advantage of keeping everything on this one history page instead of relegating the diff to the version page or a separate diff page.
Footnotes
For example, Firefox only started finding in closed
<details>elements in 139.0. ↩There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am the sort of person who is continually annoyed by not being able to find text in a page for reasons such as this one 😬