diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee index cd4e90bc3..3eb53e6d2 100644 --- a/app/assets/javascripts/legislation.js.coffee +++ b/app/assets/javascripts/legislation.js.coffee @@ -4,7 +4,7 @@ App.Legislation = $('#js-toggle-debate').on click: -> $('#debate-show').toggle() - + $('#js-toggle-small-debate').on click: -> $('#debate-show').toggle() diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee index 7617c5004..510bf83ec 100644 --- a/app/assets/javascripts/markdown_editor.js.coffee +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -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") - diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 807a202d5..979963d12 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -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; diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 5b23736d7..39a45da93 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -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; } diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 6f5069763..c97165e2a 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -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 diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index ab346e802..99f401f7b 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,4 +1,6 @@ class NotificationsController < ApplicationController + include CustomUrlsHelper + before_action :authenticate_user! after_action :mark_as_read, only: :show skip_authorization_check diff --git a/app/helpers/custom_urls_helper.rb b/app/helpers/custom_urls_helper.rb new file mode 100644 index 000000000..1519e771e --- /dev/null +++ b/app/helpers/custom_urls_helper.rb @@ -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 diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index ae3dc432d..4d44f14eb 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -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 diff --git a/app/models/comment_notifier.rb b/app/models/comment_notifier.rb index 3cceb5c15..68b350e6b 100644 --- a/app/models/comment_notifier.rb +++ b/app/models/comment_notifier.rb @@ -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 diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index a29a93ea4..36a774f23 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -63,20 +63,22 @@ <%= f.label :body %> <%= t('admin.legislation.draft_versions.form.use_markdown') %> -
-
-
Consul | Editando Versión 3 del proceso Licencias urbanísticas, declaraciones
+
+
<%= t('admin.legislation.draft_versions.form.title_html', draft_version_title: @draft_version.title, process_title: @process.title ) %>
-
- <%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %> -
+
+ <%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %> +
<%= link_to "#", class: 'fullscreen-toggle' do %> - <%= t("admin.legislation.draft_versions.form.fullscreen_toggle")%> + " + data-open-text="<%= t("admin.legislation.draft_versions.form.close_text_editor")%>"> + <%= t("admin.legislation.draft_versions.form.launch_text_editor")%> + <% end %>
-
+
<%= f.text_area :body, label: false, placeholder: t('admin.legislation.draft_versions.form.body_placeholder') %>
diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 4f33d45ef..8844fca38 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -1,12 +1,12 @@
-
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments_count) %>
+
<%= t('legislation.annotations.comments.comments_count', count: annotation.comments.roots.count) %>
<%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> <% end %>
- <% annotation.comments.roots.limit(5).each do |comment| %> + <% annotation.comments.roots.sort_by_newest.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>

<%= truncate comment.body, length: 250 %>

@@ -36,11 +36,35 @@ <% end %>
+ + diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb index 75d8f35a0..8074f6040 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -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 %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 1392aa75e..f73e9857e 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -245,7 +245,9 @@ en: form: error: Error form: - fullscreen_toggle: Toggle full screen + title_html: 'Editing %{draft_version_title} from the process %{process_title}' + 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. diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 368b32c2a..cb1643149 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -245,7 +245,9 @@ es: form: error: Error form: - fullscreen_toggle: Pantalla completa + title_html: 'Editando %{draft_version_title} del proceso %{process_title}' + 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 diff --git a/config/routes.rb b/config/routes.rb index 774efb37c..f5b65420e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,6 +114,7 @@ Rails.application.routes.draw do resources :annotations do get :search, on: :collection get :comments + post :new_comment end end end diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index e1088f24f..439d18d0c 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -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 diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 3a78cd61b..c80ec55f4 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index d0f303743..fc6a1b88f 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -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 diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 5fbc51736..08ba7d3a7 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -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