Plots2: "Browse other activities" next to "replicate this" prompt

Created on 30 Aug 2016  路  11Comments  路  Source: publiclab/plots2

This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @jywarren to get it labelled.

Or just solve it yourself!


A link next to the button would let people more easily horizontally browse activities:

screenshot 2016-08-30 at 2 13 06 pm

It could go on this line of code, though you should break it up unto multiple lines so it's easier to read:

https://github.com/publiclab/plots2/blob/master/app/views/notes/_responses.html.erb#L8

To determine where the link should lead to, we look for the tagname, and go to the page with a tag such as activities:<tagname>, so:

DrupalTag.where(name: "activities:" + @node.power_tag('activity')).first.nodes.first.path

However, we must account for the possibility that:

  • the DrupalTag doesn't exist and we can't run .first on an empty returned array
  • the DrupalTag does exist but has no nodes (say, they've been deleted) and we can't call .first on an empty .nodes array

So we'll have to add some if statements to protect against that possibility.

But once you have the URL, you can just add it in a link, like <a href="/...">Browser other activities</a>

HTML Ruby enhancement fto-candidate help wanted

All 11 comments

I would like to help with this issue. Can u explain further on how?

Maybe a good place to begin here would be to look over this test, which lays out what we expect to happen in that template:

https://github.com/publiclab/plots2/blob/master/test/integration/node_insert_extras_test.rb#L40-L53

Here, we're adding the tag activity:test for purposes of testing. So we'd then want this new code to also display a link (an <a> tag) pointed at a page which bears the tag activities:test -- that's the idea of this feature.

You could add that expectation to the test and create a PR, which we should expect to fail, initially.

But -- once it does, we can then begin writing the code to get that test to pass -- and we have a clear way to tell when it's working; to run the tests. Make sense?

I think if we take that as our first step, and you create pull request, we can start there and move forward. Sound good?

Thanks!!

Oh, and see how the assert_select statements look for specific HTML elements? That's how we can add the new expectation.

Yeah it sounds great. I will have a look

Oh - or perhaps you'd like to re-start on this one? Thank you!

Yeah I think I should finish this one first.

1081

1083 is the new PR

so the tagname of the URL will be = DrupalTag.where(name: "activities:" + @node.power_tag('activity')).first.nodes.first.path
And how should the rest of the URL and if statements be?

Hi, so the link would be to a node, and that node would have a tag named activities:balloon-mapping for the tagname balloon-mapping.

So we need to know what the tagname is -- we find that out by using the node.power_tag method, which looks up the "value" of the "activity" powertag for the current node for this page:

@node.power_tag('activity')

IF it returns something, we then use the resulting string to search for a tag matching activities:<tagname> -- like activities:balloon-mapping, for example:

DrupalTag.where(name: @node.power_tag('activity'))

IF we find tags there, we want to use the first one returned (since where() returns an array of results, even if there's only one), then find nodes for that tag, using:

tag.nodes.first

So basically at each stage of this, we need to use an if statement to ensure we're not working with a nil or an empty array. Make sense?

I have added the if statements. Cant understand how to add it to the link. I have opened a PR #1090.
Please have a look! Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

first-timers[bot] picture first-timers[bot]  路  3Comments

first-timers[bot] picture first-timers[bot]  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments

RuthNjeri picture RuthNjeri  路  3Comments

keshavsethi picture keshavsethi  路  3Comments