publiclab / plots2

a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! :balloon:
https://publiclab.org
GNU General Public License v3.0
957 stars 1.83k forks source link

Enable "activities" variant of [notes:grid:TAGNAME] inline tag #5308

Open jywarren opened 5 years ago

jywarren commented 5 years ago

Now that we have inline image grids, like on this page: https://publiclab.org/wiki/coqui#Assemble+the+Coqui

image

...that can be made by inserting the following shortcode into a wiki page: [notes:grid:coqui] (for example),

We should make the Add an activity button appear if we use the alternate syntax:

[activities:grid:coqui]

image

Here's where we show the button:

https://github.com/publiclab/plots2/blob/e7d1315189f3e4b7ad0e1f50c1ed74c1d371c6bf/app/views/grids/_notes.html.erb#L68-L74

And here are lines of code where the current Activities grid is added:

https://github.com/publiclab/plots2/blob/master/app/helpers/application_helper.rb#L84

https://github.com/publiclab/plots2/blob/master/app/models/concerns/node_shared.rb#L190-L221

Here's the thumbnails grid code that would be copied to make an activities thumbnails grid:

https://github.com/publiclab/plots2/blob/master/app/models/concerns/node_shared.rb#L20-L56

We'd love help with this!

digitaldina commented 5 years ago

Hey! I'll take this on :)

grvsachdeva commented 5 years ago

Great!

digitaldina commented 5 years ago

@jywarren just checking if I have this right: we want to make the activities shortcode to display the activity button, link, and note below it that you linked the code snippet to. Should I do this by adding a return that includes the activity button, link, and note below it or do I have to use output += '[insert button code that you lined in that first code snippet]' @gauravano thoughts?

digitaldina commented 5 years ago

@jywarren looking for clarification on my above comment so I can get working on this :)

jywarren commented 5 years ago

Hi! Sorry, i was slow!

I think you should be able to copy in the HTML from the plots2/app/views/grids/_notes.html.erb lines I highlighted into the grid template. But we will also have to make a new shortcode for [activities:grid:coqui] -- make sense? So these new HTML lines would only activate if it were there activities variant of the grid shortcode.

Thanks!

digitaldina commented 5 years ago

@jywarren when I make the new shortcode for the activities for the grid, do I do the same as I did for the button shortcode and just do a return of that html code? Thanks!

jywarren commented 5 years ago

So, I think you'll want to make a copy of the activities_grid method here: https://github.com/publiclab/plots2/blob/master/app/models/concerns/node_shared.rb#L190-L221

called activities_thumbnail_grid -- where you'll change this line:

body.gsub(/(?<![\>])(\<p>)?[notes\:grid\:(\S+)]/) do |_tagname|`

to

body.gsub(/(?<![\>])(\<p>)?[activities\:grid\:(\S+)]/) do |_tagname|`

That way it'll match [activities:grid:______], right? Then you can use the same template but pass in a local parameter to activate the lines showing the button. Kind of like how this segment does for a non-thumbnail grid:

https://github.com/publiclab/plots2/blob/f9be44fd09a7b7eb65656405625571bd2f1d7268/app/models/concerns/node_shared.rb#L217

See how that 'type' local parameter switches on the relevant section of the template? Does this make sense?

jywarren commented 5 years ago

To be honest, we should eventually refactor node_shared.rb because it has a ton of unnecessary redundancy! But let's do things one at a time!

digitaldina commented 5 years ago

@jywarren ohhh I get it now! the local parameter part is what chooses which code to display based on the code you originally linked (_notes.html.erb) and the rest is pretty much the same since this is just another shortcode for creating a activities button instead of using the notes inline tag. I've made additions based on what I understand at #5463 . Thanks for the help!