Draft Version page

This commit is contained in:
Amaia Castro
2017-01-02 18:01:27 +01:00
parent 1ff6a7b69b
commit 5627b18be2
18 changed files with 245 additions and 63 deletions

View File

@@ -50,8 +50,7 @@
//= require markdown_editor
//= require cocoon
//= require allegations
//= require legislation_debate
//= require legislation_questions
//= require legislation
//= require custom
var initialize_modules = function() {
@@ -76,8 +75,7 @@ var initialize_modules = function() {
App.SocialShare.initialize();
App.MarkdownEditor.initialize();
App.Allegations.initialize();
App.LegislationDebate.initialize();
App.LegislationQuestions.initialize();
App.Legislation.initialize();
};
$(function(){

View File

@@ -0,0 +1,16 @@
App.Legislation =
initialize: ->
$('#js-toggle-debate').on
click: ->
$('#debate-info').toggle()
$('form#new_legislation_answer input.button').hide()
$('form#new_legislation_answer input[type=radio]').on
click: ->
$('form#new_legislation_answer').submit()
$('form#draft_version_go_to_version input.button').hide()
$('form#draft_version_go_to_version select').on
change: ->
$('form#draft_version_go_to_version').submit()

View File

@@ -1,6 +0,0 @@
App.LegislationDebate =
initialize: ->
$('#js-toggle-debate').on
click: ->
$('#debate-info').toggle()

View File

@@ -1,8 +0,0 @@
App.LegislationQuestions =
initialize: ->
$('form#new_legislation_answer input.button').hide()
$('form#new_legislation_answer input[type=radio]').on
click: ->
$('form#new_legislation_answer').submit()

View File

@@ -4,7 +4,6 @@ App.MarkdownEditor =
textarea_content = element.find('textarea').val()
result = md.render(textarea_content)
element.find('#markdown-preview').html(result)
element.find('#markdown-result input').val(result)
initialize: ->
$('.markdown-editor').each ->

View File

@@ -11,4 +11,14 @@ class Legislation::DraftVersionsController < Legislation::BaseController
def changes
@draft_version = @process.draft_versions.find(params[:draft_version_id])
end
def go_to_version
version = @process.draft_versions.find(params[:draft_version_id])
if params[:redirect_action] == 'changes'
redirect_to legislation_process_draft_version_changes_path(@process, version)
else
redirect_to legislation_process_draft_version_path(@process, version)
end
end
end

View File

@@ -10,13 +10,13 @@ class Legislation::DraftVersion < ActiveRecord::Base
validates :body, presence: true
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
def body_in_html
before_save :render_html
def render_html
renderer = Redcarpet::Render::HTML.new(with_toc_data: true)
toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true)
body_html = Redcarpet::Markdown.new(renderer).render(body)
toc = Redcarpet::Markdown.new(toc_renderer).render(body)
return toc, body_html
self.body_html = Redcarpet::Markdown.new(renderer).render(body)
self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body)
end
end

View File

@@ -82,9 +82,6 @@
</div>
<div id="markdown-preview" class="small-12 medium-6 column">
</div>
<div id="markdown-result">
<%= f.hidden_field :body_html, label: false %>
</div>
</div>
</div>

View File

@@ -0,0 +1,19 @@
<div class="legislation-hero legislation-allegation no-margin-top grey-heading">
<div class="row headline">
<div class="small-12 medium-7 column">
<h3><%= process.title %></h3>
</div>
<div class="small-12 medium-4 column right">
<a class="button-subscribed expanded button strong" title="Suscríbete al proceso" data-remote="true" rel="nofollow" data-method="post" href="#">
<span class="icon-checkmark-circle" aria-hidden="true"></span>
<h3>Suscrito</h3>
</a>
</div>
</div>
<div class="center half-gradient">
<a class="button big center button-circle" title="Ver info del proceso">
<span class="icon-angle-down" aria-hidden="true"></span>
</a>
</div>
</div>

View File

@@ -1,14 +1,32 @@
<% provide :title do %><%= "#{@draft_version.title} - #{t('.title')} - #{@process.title}" %><% end %>
<div class="row">
<h2><%= @process.title %></h2>
<h2><%= @draft_version.title %></h2>
<%= render 'process_header', process: @process %>
<div>
<%= link_to t('.see_text'), legislation_process_draft_version_path(@process, @draft_version) %>
<div class="column row">
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
<div class="draft-panels small-12 column row">
<div class="row draft-chooser">
<div class="small-12 medium-9 column">
<h3><%= t('.seeing_changelog_version') %></h3>
<div class="select-box">
<%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %>
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %>
<%= hidden_field_tag "redirect_action", "changes" %>
<%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %>
<% end %>
</div>
<span><%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %></span>
</div>
<div class="small-12 medium-3 column">
<%= link_to t('.see_text'), legislation_process_draft_version_path(@process, @draft_version), title: t('.see_text'), class: "button strong" %>
</div>
</div>
<div>
<div class="row">
<div class="small-12 medium-8 column legislation-changes">
<%= markdown @draft_version.changelog %>
</div>
</div>
</div>
</div>

View File

@@ -1,27 +1,69 @@
<% provide :title do %><%= "#{@draft_version.title} - #{@process.title}" %><% end %>
<div class="row">
<h2><%= link_to @process.title, @process %></h2>
<h2><%= @draft_version.title %></h2>
<%= render 'process_header', process: @process %>
<div>
<%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %>
</div>
<% toc, body = @draft_version.body_in_html %>
<div class="small-12 medium-3 column">
<%= toc.html_safe %>
</div>
<div class="column row">
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %>
<div class="draft-panels small-12 column row">
<div class="row draft-chooser">
<div class="small-12 medium-9 column">
<section data-annotatable-type="legislation_draft_version"
data-annotatable-id="<%= @draft_version.id %>">
<h3><%= t('.seeing_version') %></h3>
<div class="select-box">
<%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %>
<%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %>
<%= submit_tag t('.select_version_submit'), class: "button" %>
<% end %>
<span><%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %></span>
</div>
<span><%= t('.updated_at', date: format_date(@draft_version.updated_at)) %></span>
</div>
<div class="small-12 medium-3 column">
<%= link_to t('.see_comments'), legislation_process_draft_version_annotations_path(@process, @draft_version), title: t('.see_comments'), class: "button strong" %>
</div>
</div>
<div id="legislation_draft_version_body">
<%= body.html_safe %>
<div class="row draft-allegation medium-collapse">
<div class="small-12 calc-index column border-right js-toggle-allegations">
<div class="draft-panel">
<div>
<span class="icon-banner" aria-hidden="true"></span> <span class="panel-title"><%= t('.text_index') %></span>
</div>
</section>
</div>
<div class="draft-index-rotated center">
<span class="panel-title"><%= t('.text_index') %></span>
</div>
<div class="draft-index">
<%= @draft_version.toc_html.html_safe %>
</div>
</div>
<div class="small-12 calc-text column border-right">
<div class="draft-panel">
<div><span class="panel-title"><%= t('.text_body') %></span></div>
</div>
<div class="draft-text">
<%= @draft_version.body_html.html_safe %>
</div>
</div>
<div class="small-12 calc-comments end column js-toggle-allegations">
<div class="draft-panel">
<div>
<span class="icon-comments" aria-hidden="true"></span> <span class="panel-title"><%= t('.text_comments') %></span>
</div>
</div>
<div class="draft-comments-rotated center">
<span class="panel-title"><%= t('.text_comments') %></span>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -226,9 +226,18 @@ en:
draft_versions:
changes:
title: Changes
see_text: See text
seeing_changelog_version: Revision changes summary
see_text: See text draft
show:
see_changes: See changes
seeing_version: You're seeing draft version
select_draft_version: Select draft
select_version_submit: see
updated_at: updated at %{date}
see_changes: see changes summary
see_comments: See all comments
text_index: Index
text_body: Text
text_comments: Comments
processes:
debate:
empty_questions: There aren't any questions

View File

@@ -226,9 +226,18 @@ es:
draft_versions:
changes:
title: Cambios
see_text: Ver texto
seeing_changelog_version: Resumen de cambios de la revisión
see_text: Ver borrador del texto
show:
see_changes: Ver cambios
seeing_version: Estás viendo la revisión
select_draft_version: Seleccionar borrador
select_version_submit: ver
updated_at: actualizada el %{date}
see_changes: ver resumen de cambios
see_comments: Ver todos los comentarios
text_index: Índice
text_body: Texto
text_comments: Comentarios
processes:
debate:
empty_questions: No hay preguntas

View File

@@ -99,6 +99,7 @@ Rails.application.routes.draw do
resources :answers, only: [:create]
end
resources :draft_versions, only: [:show] do
get :go_to_version, on: :collection
get :changes
resources :annotations
end

View File

@@ -0,0 +1,5 @@
class AddTocHtmlToDraftVersions < ActiveRecord::Migration
def change
add_column :legislation_draft_versions, :toc_html, :text
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161229110336) do
ActiveRecord::Schema.define(version: 20161229213217) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -123,10 +123,10 @@ ActiveRecord::Schema.define(version: 20161229110336) do
t.string "visit_id"
t.datetime "hidden_at"
t.integer "flags_count", default: 0
t.datetime "ignored_flag_at"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.datetime "ignored_flag_at"
t.integer "comments_count", default: 0
t.datetime "confirmed_hide_at"
t.integer "cached_anonymous_votes_total", default: 0
@@ -145,6 +145,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
add_index "debates", ["description"], name: "index_debates_on_description", using: :btree
add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
@@ -252,6 +253,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "body_html"
t.text "toc_html"
end
add_index "legislation_draft_versions", ["hidden_at"], name: "index_legislation_draft_versions_on_hidden_at", using: :btree
@@ -394,6 +396,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do
add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree
@@ -566,7 +569,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do
t.boolean "email_digest", default: true
t.boolean "email_on_direct_message", default: true
t.boolean "official_position_badge", default: false
t.datetime "password_changed_at", default: '2016-12-21 17:55:08', null: false
t.datetime "password_changed_at", default: '2016-11-02 13:51:14', null: false
t.boolean "created_from_signature", default: false
end

View File

@@ -87,12 +87,11 @@ feature 'Admin legislation draft versions' do
click_link 'Version 1'
fill_in 'legislation_draft_version_title', with: 'Version 1b'
fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\nParagraph\r\n>Quote'
fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote'
click_button 'Save changes'
expect(page).to have_content 'Version 1b'
expect(draft_version.reload.body_html).to eq("<h1>Version 1 body\\r\\nParagraph\\r\\n&gt;Quote</h1>\r\n")
end
end
end

View File

@@ -6,4 +6,75 @@ RSpec.describe Legislation::DraftVersion, type: :model do
it "should be valid" do
expect(legislation_draft_version).to be_valid
end
it "renders and saves the html from the markdown body field" do
legislation_draft_version.body = body_markdown
legislation_draft_version.save!
expect(legislation_draft_version.body_html).to eq(body_html)
expect(legislation_draft_version.toc_html).to eq(toc_html)
end
def body_markdown
<<-BODY_MARKDOWN
# Title 1
Some paragraph.
A list:
- item 1
- item 2
## Subtitle
Another paragraph.
# Title 2
Something about this.
BODY_MARKDOWN
end
def body_html
<<-BODY_HTML
<h1 id="title-1">Title 1</h1>
<p>Some paragraph.</p>
<p>A list:</p>
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
<h2 id="subtitle">Subtitle</h2>
<p>Another paragraph.</p>
<h1 id="title-2">Title 2</h1>
<p>Something about this.</p>
BODY_HTML
end
def toc_html
<<-TOC_HTML
<ul>
<li>
<a href="#title-1">Title 1</a>
<ul>
<li>
<a href="#subtitle">Subtitle</a>
</li>
</ul>
</li>
<li>
<a href="#title-2">Title 2</a>
</li>
</ul>
TOC_HTML
end
end