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

Separate question posting form temp fixes #910 #944

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/editor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def post
})
flash[:error] = "The image could not be saved." unless @image.save!
end
redirect_to '/questions/new' if params[:tags] && params[:tags].include?("question:")
end

def rich
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def index
@questions = @questions.order('node.nid DESC')
.paginate(:page => params[:page], :per_page => 30)
end

def new
render "editor/question"
end

def show
if params[:author] && params[:date]
Expand Down
134 changes: 134 additions & 0 deletions app/views/editor/question.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<div class="col-sm-3">

<script>
$D = {
uid: <%= current_user.uid %>,
type: 'note',
warn_image: <%= params[:template] == "question" %>
}
</script>

<%= javascript_include_tag "post" %>
<%= javascript_include_tag "dragdrop" %>

<% if params[:template] == "question" %>
<h4 class="visible-sm">Ask a question</h4>
<div id="research-note-detail" class="hidden-sm">
<h4><i class="fa fa-question-circle"></i> Use this form to ask Question about <b><%= @node.power_tag('question') if @node %></b></h4>
<% if @node && DrupalTag.follower_count(@node.power_tag('question')) > 0 %>
<div class="alert alert-success" role="alert"><%= DrupalTag.follower_count(@node.power_tag('question')) %> people have signed up to answer questions on this topic.</div>
<% end %>
<p>Here you can ask a question to the Public Lab community to help you in your environmental exploration. This is a great space to ask whether a method exists for identifying a possible pollutant, or ask about details of a specific technique for identifying a pollutant.</p>
<p>You can add more tags in the tags section below to further relate your question. You can also change the main tag of the question by renaming the part after <b><i>question:</i></b> tag</p>
<p>New to Public Lab? Take a minute to read the Q &amp; A wiki before posting your question</p>
<h4><a href="//<%= request.host %>/wiki/public-lab-q-and-a">Learn more &raquo;</a></h4>
</div>

<% else %>
<h3 class="visible-md"><i class="fa fa-file"></i> What's a <br />research note?</h3>
<h4 class="hidden-md"><i class="fa fa-file"></i> What's a research note? <a onClick="$('#research-note-detail').toggleClass('visible-sm')">Learn more &raquo;</a><br /></h4>

<div id="research-note-detail" class="hidden-sm hidden-xs">
<p>At Public Lab, we all collaborate to invent and improve open source environmental science tools. <b>Research notes</b> are the primary way we share what we learn, ask questions, pose challenges, and critique one another's work.</p>
<p><b>Research notes can include:</b></p>
<ul>
<li>photos of what you've made</li>
<li>requests for troubleshooting</li>
<li>proposals for new projects</li>
<li>announcements of events</li>
<li>reports from a field test or meetup</li>
<li>etc!</li>
</ul>
<hr />
<p><b><a href="//www.youtube.com/watch?v=rsy__zTTh8c" target="_blank"><i class="fa fa-film"></i> Watch a 30 second video on posting research notes &raquo;</a></b></p>
<hr />
<div class="sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">More</li>
<li><a href="/getting-started">Getting started with Public Lab</a></li>
<li><a href="/wiki/posting-research">About posting research</a></li>
<li><a href="/wiki/authoring-help#Advanced+formatting">Advanced formatting</a></li>
</ul>
</div>
</div>
<% end %>
</div>

<div class="col-sm-9">
<%
if @node && params[:action] != "create"
url = { :controller => "notes", :action => "update", :id => params[:id] }
else
url = { :controller => "notes", :action => "create", :id => params[:id] }
end
%>
<%= form_for @node, :as => :drupal_node, :url => url do |f| %>
<% if f.error_messages != "" %><div class="alert alert-danger"><%= f.error_messages :header_message => "Your note couldn't be saved." %></div><% end %>
<% end %>

<%= form_for @revision, :as => :drupal_node_revision, :url => url, :html => {:class => "form well"} do |f| %>

<% if f.error_messages != "" %><div class="alert alert-danger"><%= f.error_messages :header_message => "Your note couldn't be saved." %></div><% end %>

<%= render :partial => "editor/main_image" %>

<div class="col-md-9 col-md-pull-3">

<% if params[:template] == "question" %>
<h3>Ask a question of the community</h3>
<% else %>
<h3>Share your work</h3>
<% end %>

<div class="form-group">
<input id="title" tabindex="1" name="title" class="form-control" placeholder="<% if params[:template] == "question" %>Ask a question as specifically as possible<% else %>Title your post descriptively<% end %>" value="<%= if @node then @node.title else params[:title] end %>"/>
</div>

<input id="has_main_image" type="hidden" name="has_main_image" value="<% if @node && @node.main_image %>true<% end %>" />
<input id="main_image" type="hidden" name="main_image" value="<% if @node && @node.main_image(:rails) %><%= @node.main_image(:rails).id %><% else %><%= params[:main_image] %><% end %>" />
<input id="node_images" type="hidden" name="node_images" value="" />

<%= render :partial => 'editor/editor' %>

<div class="input-group tags-input">
<span class="input-group-addon"><i class="fa fa-tags"></i></span>
<input autocomplete="off" class="form-control" id="taginput" tabindex="3" name="tags" type="text" <% if params[:tags] || (@node && @node.power_tag('question')) || (@node && @node.tagnames) %>value="<%= params[:tags] || @node.tagnames.join(',') %><%= ','[email protected]_tag('question') if @node && @node.power_tag('question') != '' %>"<% else %>placeholder="balloon-mapping,gulf-coast"<% end %> data-provide="typeahead" />
</div>

<input name="remote" type="hidden" value="true" />

<p class="hide alert alert-warning">Consider adding a lead image to illustrate your post! (see above right)</p>
<br />

<% if current_user.first_time_poster %>
<p class="moderation-notice">Hi! Just letting you know ahead of time that everyone's first posts to this website are <a href='/wiki/moderation'>moderated</a> due to issues we've had with spam. Thanks for your patience!</p>
<% end %>

<a id="publish" tabindex="5" class="publish btn btn-primary btn-lg">Publish</a>
<a tabindex="6" data-previewing-text="Previewing (click to edit)" class="btn btn-default btn-lg preview-btn" onClick="$E.toggle_preview()">Preview</a>

<span style="margin-top:12px;margin-left:8px;" class="checkbox">
<label for="event-input">
<input tabindex="7" onChange="$('#event-info').toggle()" id="event-input" type="checkbox" name="event">
This is an event
</label>
</span>

<div id="event-info" style="display:none;clear:both;padding-top:4px;">
<p><i>An RSVP feature will be added to your note. Please choose a date:</i></p>
<span style="padding-right:0;" class="input-group date">
<input data-provide="datepicker" data-date="<%= DateTime.now.strftime("%m-%d-%Y") %>" data-date-format="mm-dd-yyyy" class="col-md-8 form-control" size="16" type="text" name="date" value="<%= DateTime.now.strftime("%m-%d-%Y") %>" />
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</span>
</div>

</div>

<div style="clear:both;">
<br />
<p class="col-md-12">By publishing, you agree to <a target="_blank" href="/licenses">open source your work</a> so that others may use it.</p>
<br />
</div>

<% end %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@

match 'talk/:id' => 'talk#show'

match 'questions/new' => 'questions#new'
match 'questions' => 'questions#index'
match 'questions/:author/:date/:id' => 'questions#show'
match 'questions/show/:id' => 'questions#show'
Expand Down
8 changes: 5 additions & 3 deletions test/functional/editor_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def setup
tags: 'question:question,one',
template: 'question',
redirect: 'question'
assert_select "h3", "Ask a question of the community"
assert_select "input#taginput[value=?]", "question:question,one"
assert_response :redirect
assert_redirected_to '/questions/new'
# assert_select "h3", "Ask a question of the community"
# assert_select "input#taginput[value=?]", "question:question,one"
end

test "should show title form input if title parameter present" do
Expand All @@ -55,7 +57,7 @@ def setup
title: 'New Question'
assert_response :success
assert_select "input#title" do
assert_select "[value=?]", "New Question"
assert_select "[value=?]", "New Question"
end
end
end
6 changes: 6 additions & 0 deletions test/functional/questions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,10 @@ def setup
assert (questions & expected).present?
assert !(questions & [node(:question2)]).present?
end

test "/questions/new form loads" do
UserSession.create(rusers(:bob))
get :new
assert_response :success
end
end
9 changes: 6 additions & 3 deletions test/integration/login_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ class LoginFlowTest < ActionDispatch::IntegrationTest
username: rusers(:jeff).username,
password: 'secret'
}

follow_redirect!
assert_response :redirect
assert_redirected_to '/questions/new'
assert_equal '/post?tags=question%3Aquestion&template=question&title=What&redirect=question', request.fullpath
assert_select "input#title" do
assert_select "[value=?]", "What"
end
# assert_select "input#title" do
# assert_select "[value=?]", "What"
#end
end

test "should redirect to current page when logging in through the header login" do
Expand Down