Merge branch 'legislation-module-stable' into 66-sync-scroll-in-markdown-editor

This commit is contained in:
Fernando Blat
2017-01-23 15:08:25 +01:00
19 changed files with 185 additions and 29 deletions

View File

@@ -4,7 +4,7 @@ App.Legislation =
$('#js-toggle-debate').on
click: ->
$('#debate-show').toggle()
$('#js-toggle-small-debate').on
click: ->
$('#debate-show').toggle()

View File

@@ -25,9 +25,15 @@ App.MarkdownEditor =
$(this).find('.fullscreen-toggle').on 'click', ->
$('.markdown-editor').toggleClass('fullscreen')
$('.fullscreen-container').toggleClass('medium-8', 'medium-12')
span = $(this).find('span')
current_html = span.html()
if(current_html == span.data('open-text'))
span.html(span.data('closed-text'))
else
span.html(span.data('open-text'))
if $('.markdown-editor').hasClass('fullscreen')
$('.markdown-editor textarea').height($(window).height() - 100)
else
$('.markdown-editor textarea').height("10em")

View File

@@ -411,6 +411,11 @@ table.investment-projects-summary {
.markdown-editor {
background-color: white;
.markdown-area,
#markdown-preview {
display: none;
}
}
.markdown-editor #markdown-preview {
@@ -437,7 +442,9 @@ table.investment-projects-summary {
// 06. Legislation
// --------------
.edit_legislation_draft_version .row {
margin-bottom: 2rem;
}
.legislation-admin {
.menu .active > a {
background: none;
@@ -595,6 +602,8 @@ table.investment-projects-summary {
}
.fullscreen-container {
text-align: center;
background: #ccdbe6;
.markdown-editor-header,
.markdown-editor-buttons {
@@ -602,12 +611,7 @@ table.investment-projects-summary {
}
a {
@include breakpoint(medium) {
float: right;
}
line-height: 3rem;
line-height: 8rem;
span {
text-decoration: none;
@@ -660,13 +664,28 @@ table.investment-projects-summary {
.fullscreen {
.markdown-area,
#markdown-preview {
display: block;
}
.column {
padding: 0;
}
.fullscreen-container {
text-align: left;
background: $admin-color;
padding: 0.5rem 1rem;
margin-bottom: 0;
a {
line-height: 3rem;
@include breakpoint(medium) {
float: right;
}
}
.markdown-editor-header {
vertical-align: top;

View File

@@ -212,10 +212,18 @@ $epigraph-line-height: rem-calc(22);
cursor: pointer;
display: inline-block;
margin: 0 1rem 1rem 0;
transition: all 0.4s;
border-bottom: 2px solid transparent;
&:first-of-type {
margin-left: 0;
}
&:hover,
&:active,
&:focus {
border-bottom: 2px solid $brand;
}
@media (min-width: 950px) {
margin: 0 0 0 3rem;
@@ -223,6 +231,7 @@ $epigraph-line-height: rem-calc(22);
a,
h4 {
display: block;
color: #6D6D6D;
margin-bottom: 0;
}

View File

@@ -1,7 +1,7 @@
class Legislation::AnnotationsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :authenticate_user!, only: [:create]
before_action :authenticate_user!, only: [:create, :new_comment]
before_action :convert_ranges_parameters, only: [:create]
load_and_authorize_resource :process
@@ -43,6 +43,7 @@ class Legislation::AnnotationsController < ApplicationController
def comments
@annotation = Legislation::Annotation.find(params[:annotation_id])
@comment = @annotation.comments.new
end
def new
@@ -51,6 +52,19 @@ class Legislation::AnnotationsController < ApplicationController
end
end
def new_comment
@draft_version = Legislation::DraftVersion.find(params[:draft_version_id])
@annotation = @draft_version.annotations.find(params[:annotation_id])
@comment = @annotation.comments.new(body: params[:comment][:body], user: current_user)
if @comment.save
@comment = @annotation.comments.new
end
respond_to do |format|
format.js { render :comments }
end
end
private
def annotation_params

View File

@@ -1,4 +1,6 @@
class NotificationsController < ApplicationController
include CustomUrlsHelper
before_action :authenticate_user!
after_action :mark_as_read, only: :show
skip_authorization_check

View File

@@ -0,0 +1,9 @@
module CustomUrlsHelper
def legislation_question_url(question)
legislation_process_question_url(question.process, question)
end
def legislation_annotation_url(annotation)
legislation_process_question_url(annotation.draft_version.process, annotation.draft_version, annotation)
end
end

View File

@@ -20,7 +20,7 @@ module Abilities
can [:read, :changes, :go_to_version], Legislation::DraftVersion
can [:read], Legislation::Question
can [:create], Legislation::Answer
can [:search, :comments, :read, :create], Legislation::Annotation
can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation
end
end
end

View File

@@ -12,7 +12,9 @@ class CommentNotifier
private
def send_comment_email
Mailer.comment(@comment).deliver_later if email_on_comment?
unless @comment.commentable.is_a?(Legislation::Annotation)
Mailer.comment(@comment).deliver_later if email_on_comment?
end
end
def send_reply_email

View File

@@ -63,20 +63,22 @@
<%= f.label :body %>
<small><%= t('admin.legislation.draft_versions.form.use_markdown') %></small>
</div>
<br/>
<div class="markdown-editor">
<div class="small-12 column fullscreen-container">
<div class="markdown-editor-header truncate">Consul | Editando <span class="strong">Versión 3</span> del proceso <span class="strong">Licencias urbanísticas, declaraciones</span></div>
<div class="small-12 medium-8 column fullscreen-container">
<div class="markdown-editor-header truncate"><%= t('admin.legislation.draft_versions.form.title_html', draft_version_title: @draft_version.title, process_title: @process.title ) %></div>
<div class="markdown-editor-buttons">
<%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
</div>
<div class="markdown-editor-buttons">
<%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
</div>
<%= link_to "#", class: 'fullscreen-toggle' do %>
<span><%= t("admin.legislation.draft_versions.form.fullscreen_toggle")%></span> <span class="icon-expand"></span>
<span data-closed-text="<%= t("admin.legislation.draft_versions.form.launch_text_editor")%>"
data-open-text="<%= t("admin.legislation.draft_versions.form.close_text_editor")%>">
<%= t("admin.legislation.draft_versions.form.launch_text_editor")%>
</span>
<% end %>
</div>
<div class="small-12 medium-6 column">
<div class="small-12 medium-6 column markdown-area">
<%= f.text_area :body, label: false, placeholder: t('admin.legislation.draft_versions.form.body_placeholder') %>
</div>
<div id="markdown-preview" class="small-12 medium-6 column">

View File

@@ -1,12 +1,12 @@
<div class="comment-header">
<span class="icon-comment" aria-hidden="true"></span>
<div class="comment-number"><%= t('legislation.annotations.comments.comments_count', count: annotation.comments_count) %></div>
<div class="comment-number"><%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %></div>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %>
<span class="icon-expand" aria-hidden="true"></span>
<% end %>
</div>
<div class="comments-wrapper">
<% annotation.comments.roots.limit(5).each do |comment| %>
<% annotation.comments.roots.sort_by_newest.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>
<div class="comment">
<div class="comment-text">
<p><%= truncate comment.body, length: 250 %></p>
@@ -36,11 +36,35 @@
<% end %>
</div>
<div class="comment-footer">
<% if annotation.comments.roots.count > Legislation::Annotation::COMMENTS_PAGE_SIZE %>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation), class: "button strong" do %>
<%= t('legislation.annotations.comments.see_all') %>
<% end %>
<% end %>
<a class="button strong publish-comment" title="Publicar comentario" href="#">Publicar comentario</a>
<% if @process.open_phase?(:allegations) %>
<a class="button strong publish-comment" href="#"><%= t('legislation.annotations.comments.publish_comment') %></a>
<% end %>
<% if @process.open_phase?(:allegations) %>
<% if user_signed_in? %>
<% css_id = parent_or_commentable_dom_id(nil, annotation) %>
<div id="js-comment-form-annotation" style="display:none" class="comment-form">
<%= form_for @comment, url: legislation_process_draft_version_annotation_new_comment_path(annotation.draft_version.process, annotation.draft_version, annotation), remote: true do |f| %>
<%= label_tag "comment-body-#{css_id}", leave_comment_text(annotation) %>
<%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: false, rows: 8 %>
<%= f.submit comment_button_text(nil, annotation), class: "button" %>
<% end %>
</div>
<% else %>
<div data-alert class="callout primary">
<%= t("legislation.annotations.form.login_to_comment",
signin: link_to(t("legislation.annotations.form.signin"), new_user_session_path),
signup: link_to(t("legislation.annotations.form.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -1,2 +1,17 @@
$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show();
$('a.publish-comment').on({
click: function(e) {
e.preventDefault();
$('a.publish-comment').hide();
$('#js-comment-form-annotation').toggle();
$('#js-comment-form-annotation textarea').focus();
return;
}
});
<% if @comment.errors.any? %>
$('a.publish-comment').hide();
$('#js-comment-form-annotation').toggle();
$('#js-comment-form-annotation textarea').focus();
<% end %>

View File

@@ -245,7 +245,9 @@ en:
form:
error: Error
form:
fullscreen_toggle: Toggle full screen
title_html: 'Editing <span class="strong">%{draft_version_title}</span> from the process <span class="strong">%{process_title}</span>'
launch_text_editor: Launch text editor
close_text_editor: Close text editor
use_markdown: Use Markdown to format the text
hints:
final_version: This version will be published as Final Result for this process. Comments won't be allowed in this version.

View File

@@ -245,7 +245,9 @@ es:
form:
error: Error
form:
fullscreen_toggle: Pantalla completa
title_html: 'Editando <span class="strong">%{draft_version_title}</span> del proceso <span class="strong">%{process_title}</span>'
launch_text_editor: Lanzar editor de texto
close_text_editor: Cerrar editor de texto
use_markdown: Usa Markdown para formatear el texto
hints:
final_version: Será la versión que se publique en Publicación de Resultados. Esta versión no se podrá comentar

View File

@@ -114,6 +114,7 @@ Rails.application.routes.draw do
resources :annotations do
get :search, on: :collection
get :comments
post :new_comment
end
end
end

View File

@@ -86,10 +86,14 @@ feature 'Admin legislation draft versions' do
click_link 'Version 1'
click_link 'Launch text editor'
fill_in 'legislation_draft_version_title', with: 'Version 1b'
fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote'
click_button 'Save changes'
within('.fullscreen') do
click_button 'Save changes'
end
expect(page).to have_content 'Version 1b'
end

View File

@@ -517,7 +517,7 @@ feature 'Ballots' do
add_to_ballot(bi1)
within("#budget_investment_#{bi2.id}") do
find("div.ballot").hover
find("div.ballot").trigger("mouseover")
expect(page).to have_content('Price is higher than the available amount left')
expect(page).to have_selector('.in-favor a', visible: false)
end
@@ -594,4 +594,4 @@ feature 'Ballots' do
end
end
end
end
end

View File

@@ -171,7 +171,7 @@ feature 'Legislation Draft Versions' do
expect(page).to have_content "this is my annotation"
end
scenario 'Search' do
scenario 'View annotations and comments' do
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}])
annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>12, "end"=>"/p[1]", "endOffset"=>19}])
@@ -185,6 +185,22 @@ feature 'Legislation Draft Versions' do
all(".annotator-hl")[1].trigger('click')
expect(page).to have_content "my other annotation"
end
scenario "Publish new comment for an annotation from comments box" do
draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph)
annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}])
visit legislation_process_draft_version_path(draft_version.process, draft_version)
expect(page).to have_css ".annotator-hl"
first(:css, ".annotator-hl").click
expect(page).to have_content "my annotation"
click_link "Publish Comment"
fill_in "comment[body]", with: "My interesting comment"
click_button "Publish comment"
expect(page).to have_content "My interesting comment"
end
end
context "Annotations page" do

View File

@@ -1,10 +1,17 @@
require 'rails_helper'
feature "Notifications" do
let(:admin_user) { create :user }
let(:administrator) do
create(:administrator, user: admin_user)
admin_user
end
let(:author) { create :user }
let(:user) { create :user }
let(:debate) { create :debate, author: author }
let(:proposal) { create :proposal, author: author }
let(:legislation_question) { create(:legislation_question, author: administrator) }
let(:legislation_annotation) { create(:legislation_annotation, author: author) }
scenario "User commented on my debate", :js do
login_as user
@@ -28,6 +35,28 @@ feature "Notifications" do
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
end
scenario "User commented on my legislation question", :js do
login_as user
visit legislation_process_question_path legislation_question.process, legislation_question
fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I answered your question"
click_button "Publish answer"
within "#comments" do
expect(page).to have_content "I answered your question"
end
logout
login_as administrator
visit root_path
find(".icon-notification").click
expect(page).to have_css ".notification", count: 1
expect(page).to have_content "Someone commented on"
expect(page).to have_xpath "//a[@href='#{notification_path(Notification.last)}']"
end
scenario "Multiple comments on my proposal", :js do
login_as user
visit proposal_path proposal