Closed Poll: How do you close a poll?


(Burke) #1
  • Duh. Use the button/link on the ______ screen that you overlooked.
  • Change the title from “Poll: Foobar” to “Closed Poll: Foobar”
  • Close the topic.
  • I dunno. Good question.

I love the simplicity of the poll feature (start title with "Poll: " and include a list), but it’s not clear to me how to close the poll. I searched meta.discourse.org and looked at the poll plugin, but didn’t see an answer. I was assuming that I could click on something or make an edit that would show the poll with results in read-only form. It would be nice to be able to close the poll for voting without having to close the topic, since valuable discussion on the topic might continue beyond the time allotted for voting. I know the plugin is early in development, so this feature might not exist yet… or maybe I just missed it.

Update: You can now close a poll by changing the start of the title from "Poll: " to "Closed Poll: " and discussion can continue after voting has ended. :smiley:


(Benjamin Kampmann) #2

https://github.com/discourse/discourse/blob/master/plugins/poll/poll.rb#L139

You can’t vote anymore when the topic was closed. But that is something that in default settings only staff can do afaik.

Aside from that, you are right, there is no way to close a poll atm.


(Bill Ayakatubby) #3

That seems unideal. If the results of the poll need to be discussed, that discussion should be kept in the same topic.


(Burke) #4

Yeah. That was my same feeling. I’m afraid that removing the "Poll: " in the topic would make a mess of the topic (maybe not render it properly and/or lose result counts) as well as lose the information that it’s a poll.

In my opinion, the simplest & cleanest approach would be simply to change the title from “Poll: Foobar” to “Closed Poll: Foobar” and have the plugin render the poll with results in a read-only format at that point, allowing discussion to continue. This would also make it easy to re-open the poll by changing the topic title back.


(Burke) #5

Okay… I’m close. I managed to make it so that changing the title to “Closed Poll: …” will close the poll and make it read-only. The only piece missing is to disable the radio buttons. As it stands, the poll will refuse any new votes, but the radio buttons really should be disabled.

I’m not a ruby programmer, so it’s not obvious to me how to get the PollController to disable the radio buttons. I want to change line 41 of poll_ui.js from this:

  disableRadio: Em.computed.any('poll.post.topic.closed', 'loading'),

to something like this:

  disableRadio: Em.computed.any('poll.is_closed?', 'loading'),

but that ain’t right. The is_closed? method is in ruby on the server and isn’t represented in javascript-land. I can see options getting turned into poll_details for the client, but it’s just a little much for my first day of ruby on rails programming. :slight_smile:

Anyone wanna throw me a bone? Any ruby gurus that could tell me the 1-2 lines needed to get the is_closed? property to the client javascript so I can disable the radio buttons? With that done, I can submit a pull request.

See my changes here.


(Kane York) #6

You want to do something like this:

disableRadio: Em.computed.any('poll.closed', 'loading'),

And in poll.rb line 157:

    def serialize(user)
      return nil if details.nil?
      {options: details, selected: get_vote(user), closed: is_closed?}
    end


(Jeff Atwood) #7

Perhaps @radq can assist on this? I love your idea here:


(Burke) #8

Well. I’m close. After some fiddling, I think something like this may be the trick:

  disableRadio: Em.computed.any('poll.post.poll_details.closed', 'loading'),

If I hardcode closed: 1 in the serialize function and restart the server, it will disable the poll and I get see it within the PollController by adding a line like:

console.log(this.get('poll.post.poll_details.closed'));

However, when I use closed: is_closed? in the serialize function it isn’t working like I expect (the poll isn’t disabled). I know that is_closed is working on the server side, because changing your position on a closed poll is properly prevented (alliteration intended). I was hoping that I could get it, but perhaps I’m in over my head on my first day of ruby programming.

Here’s my poll.rb and poll_us.js. Any suggestions would be appreciated. I’m so close, I can taste it. :smile:


(Sam Saffron) #9

Personally, I think the poll should add an extra button here:


(Burke) #10

How about if that button closed the poll by changing the topic title (e.g., from “Poll:” to “Closed Poll:”)?


(Jeff Atwood) #11

I don’t think it’s a good idea to add a bunch of buttons to the topic.

You create a poll by having the correct topic name, seems logical you can close the poll the same way. In any case you MUST change the title, otherwise people don’t know it’s a closed poll…


(Burke) #12

I finally figured it out. I guess it takes two days to learn ruby. :stuck_out_tongue:

It turns out that this was wrong:

def is_closed?
  @post.topic.closed? || @post.topic.title =~ /^#{I18n.t('poll.closed_prefix')}/i
end

since the regex returns the position 0, which is considered false. This fixed it:

def is_closed?
  @post.topic.closed? || (@post.topic.title =~ /^#{I18n.t('poll.closed_prefix')}/i) === 0
end

In any case, I now have it working and have submitted a pull request.


(Sam Saffron) #13

My big concern here is, how do you teach people about this feature?


(Jeff Atwood) #14

I don’t know, how did you teach people to click a mouse? Or touch a touchscreen?

Creating polls is not exactly the core experience one does hundreds of times a day in a discussion… quite the opposite


(Sam Saffron) #15

First 2 times you create a Poll it could create one of those magic blue hints explaining this or something.

Or, first 2 times you close a poll topic it could present you with help text explaining you have another option.


(Sam Saffron) #16

Also … is it “Closed Poll” or “Poll Closed” or “Poll closed” … I will never remember this.


(Michael Downey) #17

Couldn’t the blue hint box appear as soon as you start a topic with “Poll:” and describe how to set up a poll? And the same hint box could mention how to close the poll. As @sam suggested only the first few times might do the trick.


(Burke) #18

How do you remember that it’s “Poll:” and not “Poll-” or "(Poll) "? :smile: If it becomes a problem, we can use (Closed Poll|Poll Closed) for the closed_prefix so either order would work.

The manual- and button-based approaches aren’t mutually exclusive. We could start with a manual process (just like we have for creating polls now) and a button could be added later to automate the manual process (toggling the title between prefix and closed_prefix).


(Burke) #19

How do people learn to create polls now?


(Sam Saffron) #20

Good question:

Personally I think this will go in Plugin admin section v2. Allow people to read the plugin readme there…

@burke can you update the readme here in light of your change discourse/plugins/poll at master · discourse/discourse · GitHub ?