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

Begin converting Map nodes into normal note nodes #4072

Closed
jywarren opened this issue Nov 29, 2018 · 12 comments · Fixed by #11225
Closed

Begin converting Map nodes into normal note nodes #4072

jywarren opened this issue Nov 29, 2018 · 12 comments · Fixed by #11225
Labels
help wanted requires help by anyone willing to contribute refactorization Ruby

Comments

@jywarren
Copy link
Member

We have a range of nodes at https://publiclab.org/maps which are of type map, so node.type == 'map'. See one here: https://publiclab.org/map/chandeleur-islands-louisiana/2010-06-09

Let's migrate them to a simpler form of node, type note - but copy all the extra fields into the note body (actually part of the note's Revision record). We could do this in a migration kind of like this:

Node.where(type: 'map').each do |node|
  revision = node.latest
  text = node.map.field_jpg_url_value
  revision.body = text + node.latest.body
  revision.save
  node.type = 'note'
  node.save({})
end

See how we can use Markdown to display all the relevant data in a simpler format, but still roughly in the arrangement we'd had in the original custom template:

<% if @node.map.authorship %>
<p><b>By</b> <%= @node.map.authorship %></p>
<% else %>
<p><b>Mapped by</b> <%= @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') %></p>
<p><b>Cartographer:</b> <%= @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') %></p>
<p><b>Published by</b> <a href="/profile/<%= @node.author.name %>"><%= @node.author.name %></a></p>
<% end %>
<p><a href="https://maps.google.com/maps?t=h&ll=<%= @node.lat %>,<%= @node.lon %>"><%= @node.lat %> N, <%= @node.lon %> E</a></p>
<p><%= @node.totalviews %> views</p>
<% if @node.map.field_ground_resolution_value %><p><b>Ground resolution: </b><%= @node.map.field_ground_resolution_value %> cm/px</p><% end %>
<p><b>Capture date:</b> <%= @node.map.captured_on.to_s %></p>
<p><b>Publication date:</b> <%= @node.map.published_on.to_s %></p>
<p><b>License:</b> <%= raw @node.map.license %></p>

Let's not forget also the different forms of export we can display:

<a class="btn btn-sm btn-danger" rel="tooltip" title="View the map in a full-screen web viewer" href="https://publiclab.github.io/plots-leaflet-viewer/?tms=<%= @node.map.tms %>&lon=<%= @node.lon %>&lat=<%= @node.lat %>&zoom=17">Web viewer</a>
<a class="btn btn-sm btn-success" rel="tooltip" title="" href="<%= @node.map.field_jpg_url_value %>">JPG (<%= @node.map.field_jpg_filesize_value.to_i %> MB)</a>
<a class="btn btn-sm btn-info" rel="tooltip" title="" href="<%= @node.map.field_geotiff_url_value %>">GeoTiff (<%= @node.map.field_geotiff_filesize_value.to_i %> MB)</a>
<a class="btn btn-sm btn-warning" rel="tooltip" title="Tiled Map Service (for developers)" href="<%= @node.map.field_tms_url_value %>">TMS</a>

Finally, let's embed a map as in the original display, at the top of the body content, using this line:

<iframe style="width:100%;border:none;" height="375" src="https://publiclab.github.io/plots-leaflet-viewer/?tms=<%= @node.map.tms %>&lon=<%= @node.lon %>&lat=<%= @node.lat %>&zoom=<%= @node.map.min_zoom+1 %>"></iframe>

Once we can demonstrate that this works (please upload a screenshot of your script working; you can test it out on the rails console by running it with rails console interactively), we can turn it into a migration like one of these:

https://github.com/publiclab/plots2/blob/master/db/migrate/20180707065151_change_status_of_comments.rb

Follow-ups: removing the maps type code, including ones like this: https://github.com/publiclab/plots2/blob/master/app/models/drupal_content_field_map_editor.rb

and stuff inside https://github.com/publiclab/plots2/blob/master/app/views/map/

This is a bit complex but is a great exercise in Rails-style models and migrations! It'd also help resolve #956

@jywarren
Copy link
Member Author

jywarren commented Dec 2, 2018

Added to GCI!

@oorjitchowdhary
Copy link
Member

@publiclab/mentors if I've understood this correctly, we are trying to convert all the map nodes into normal note nodes and we are integrating maps in all the nodes ... Which means this task is also linked to #4066 .. Am I right?

@jywarren
Copy link
Member Author

jywarren commented Dec 6, 2018 via email

@jywarren
Copy link
Member Author

Noting a great question from the chatroom:

Hi @gaurav2699, thanks, great question. Actually both page and note share the same type, "node" but are displayed differently and have different requirements within the Rails app. You can read about the difference in https://github.com/publiclab/plots2/tree/main/doc/DATA_MODEL.md but I think maps would be notes because they have a publication date and an author. Thank you!!!

@gaurav2699
Copy link
Contributor

Hey @jywarren. I have a doubt, I believe we are deprecating the drupal_content_type_map model, and as mentioned in this issue #956, we are merging the drupal_content_type_map model to the map node body field. Since the body of a node is a text field, how can we merge the content_type_map table in that as it contains several columns? Thank you!

@gaurav2699
Copy link
Contributor

or are we doing it using hashes?

@jywarren
Copy link
Member Author

jywarren commented Apr 5, 2022

Hi @gaurav2699 sorry for my too-late response. We are hoping to simply write out HTML or Markdown for each entry in the drupal_content_type_map model, so actually we can re-use the template code as our migration method for flattening this all into a string:

@node.body += "<p><b>Mapped by</b> #{ @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Cartographer:</b> #{ @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Published by</b> <a href='/profile/#{ @node.author.name }'>#{ @node.author.name }</a></p>"

Does this make sense?

@Forchapeatl
Copy link
Contributor

Forchapeatl commented Apr 9, 2022

Hi @gaurav2699 sorry for my too-late response. We are hoping to simply write out HTML or Markdown for each entry in the drupal_content_type_map model, so actually we can re-use the template code as our migration method for flattening this all into a string:

@node.body += "<p><b>Mapped by</b> #{ @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Cartographer:</b> #{ @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Published by</b> <a href='/profile/#{ @node.author.name }'>#{ @node.author.name }</a></p>"

Does this make sense?

@jywarren , please I'm a bit confused on what is to be done as this code has already been implemented on app/views/map/show.html.erb lines 35 to 40.

@Forchapeatl
Copy link
Contributor

Hi @gaurav2699 sorry for my too-late response. We are hoping to simply write out HTML or Markdown for each entry in the drupal_content_type_map model, so actually we can re-use the template code as our migration method for flattening this all into a string:

@node.body += "<p><b>Mapped by</b> #{ @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Cartographer:</b> #{ @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') }</p>"
@node.body += "<p><b>Published by</b> <a href='/profile/#{ @node.author.name }'>#{ @node.author.name }</a></p>"

Does this make sense?

@jywarren , please I'm a bit confused on what is to be done as this code has already been implemented on app/views/map/show.html.erb lines 35 to 40.

@TildaDares , the above code has already been implemented . please are we to include more entries (trruncate_fields, tms, min_zoom, max_zoom, cartographer_notes, license, notes, published_on, captured_on) of the drupal_content_type_map model at app/views/map/show.html.erb. or are we replacing the word "Map" with "note" of all plots2 files. This is overwhelming , please hep me with this confusion.

@jywarren
Copy link
Member Author

jywarren commented Apr 12, 2022

Sorry, to clarify-- yes, similar code exists on show.html.erb -- however, what were proposing is that we use this very similar code to permanently insert generated HTML into the node body field, and store it that way in the database, so that we can then remove fields like drupal_content_field_mappers and other custom database columns from the database schema. This will simplify our database, as everything will just be plain text rather than a complex set of interconnected tables.

By using the code segment I proposed, we adapt the template code into a database migration, and run it once, to insert all this permanently into the node body field. Although actually now that I think of it, the body field is part of the revision model, not the node model. So we'd have to edit that --

revision = @node.latest
revision.body += "<p><b>Mapped by</b> #{ @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') }</p>"
revision.body += "<p><b>Cartographer:</b> #{ @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') }</p>"
revision.body += "<p><b>Published by</b> <a href='/profile/#{ @node.author.name }'>#{ @node.author.name }</a></p>"
revision.save

Does that make more sense?

@Forchapeatl
Copy link
Contributor

Sorry, to clarify-- yes, similar code exists on show.html.erb -- however, what were proposing is that we use this very similar code to permanently insert generated HTML into the node body field, and store it that way in the database, so that we can then remove fields like drupal_content_field_mappers and other custom database columns from the database schema. This will simplify our database, as everything will just be plain text rather than a complex set of interconnected tables.

By using the code segment I proposed, we adapt the template code into a database migration, and run it once, to insert all this permanently into the node body field. Although actually now that I think of it, the body field is part of the revision model, not the node model. So we'd have to edit that --

revision = @node.latest
revision.body += "<p><b>Mapped by</b> #{ @node.drupal_content_field_mappers.collect(&:field_mappers_value).uniq.join(', ') }</p>"
revision.body += "<p><b>Cartographer:</b> #{ @node.drupal_content_field_map_editor.collect(&:field_map_editor_value).uniq.join(', ') }</p>"
revision.body += "<p><b>Published by</b> <a href='/profile/#{ @node.author.name }'>#{ @node.author.name }</a></p>"
revision.save

Does that make more sense?

It does , thank you.

@ebarry
Copy link
Member

ebarry commented Jul 5, 2022

This is an exciting advancement!~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute refactorization Ruby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants