From 7891efee326d3289a0818ffc31ad459b33c27ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Nov 2018 13:04:20 +0100 Subject: [PATCH 1/6] Add milestones to proposals --- app/models/proposal.rb | 1 + db/dev_seeds/milestones.rb | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index fff616626..aa54827c6 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -20,6 +20,7 @@ class Proposal < ActiveRecord::Base accepted_content_types: [ "application/pdf" ] include EmbedVideosHelper include Relationable + include Milestoneable acts_as_votable acts_as_paranoid column: :hidden_at diff --git a/db/dev_seeds/milestones.rb b/db/dev_seeds/milestones.rb index d3e2ced68..41b3f40ab 100644 --- a/db/dev_seeds/milestones.rb +++ b/db/dev_seeds/milestones.rb @@ -6,17 +6,20 @@ section "Creating default Milestone Statuses" do end section "Creating investment milestones" do - Budget::Investment.find_each do |investment| - rand(1..5).times do - milestone = investment.milestones.build( - publication_date: rand(Date.tomorrow..(Date.current + 3.weeks)), - status_id: Milestone::Status.all.sample - ) - I18n.available_locales.map do |locale| - Globalize.with_locale(locale) do - milestone.description = "Description for locale #{locale}" - milestone.title = I18n.l(Time.current, format: :datetime) - milestone.save! + [Budget::Investment, Proposal].each do |model| + model.find_each do |record| + rand(1..5).times do + milestone = record.milestones.build( + publication_date: Date.tomorrow, + status_id: Milestone::Status.all.sample + ) + + I18n.available_locales.map do |locale| + Globalize.with_locale(locale) do + milestone.description = "Description for locale #{locale}" + milestone.title = I18n.l(Time.current, format: :datetime) + milestone.save! + end end end end From 47702173737366e16439d7e5f3bb2b0b9667dd5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Nov 2018 13:38:06 +0100 Subject: [PATCH 2/6] Add proposals index in admin --- app/controllers/admin/proposals_controller.rb | 12 ++++++ app/views/admin/_menu.html.erb | 9 +++++ app/views/admin/proposals/index.html.erb | 37 +++++++++++++++++++ app/views/admin/proposals/show.html.erb | 0 config/locales/en/admin.yml | 8 ++++ config/locales/es/admin.yml | 8 ++++ config/routes/admin.rb | 2 + spec/features/admin/proposals_spec.rb | 16 ++++++++ .../information_texts_spec.rb | 4 +- 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/proposals_controller.rb create mode 100644 app/views/admin/proposals/index.html.erb create mode 100644 app/views/admin/proposals/show.html.erb create mode 100644 spec/features/admin/proposals_spec.rb diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/proposals_controller.rb new file mode 100644 index 000000000..64b5e3526 --- /dev/null +++ b/app/controllers/admin/proposals_controller.rb @@ -0,0 +1,12 @@ +class Admin::ProposalsController < Admin::BaseController + include FeatureFlags + feature_flag :proposals + + def index + @proposals = Proposal.sort_by_created_at.page(params[:page]) + end + + def show + @proposal = Proposal.find(params[:id]) + end +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 5344c06f8..6e393e805 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -79,6 +79,15 @@ <% end %> + <% if feature?(:proposals) %> +
  • + <%= link_to admin_proposals_path do %> + + <%= t("admin.menu.proposals") %> + <% end %> +
  • + <% end %> + <% messages_sections = %w(newsletters emails_download admin_notifications system_emails) %> <% messages_menu_active = messages_sections.include?(controller_name) %>
  • > diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb new file mode 100644 index 000000000..181674b73 --- /dev/null +++ b/app/views/admin/proposals/index.html.erb @@ -0,0 +1,37 @@ +<% provide(:title) do %> + <%= t("admin.header.title") %> - <%= t("admin.proposals.index.title") %> +<% end %> + +

    <%= t("admin.proposals.index.title") %>

    + +<% if @proposals.any? %> +

    <%= page_entries_info @proposals %>

    + + + + + + + + + + + + + <% @proposals.each do |proposal| %> + + + + + + + <% end %> + +
    <%= t("admin.proposals.index.id") %><%= t("admin.proposals.index.title") %><%= t("admin.proposals.index.author") %><%= t("admin.proposals.index.milestones") %>
    <%= proposal.id %><%= link_to proposal.title, admin_proposal_path(proposal) %><%= proposal.author.username %><%= proposal.milestones.count %>
    + + <%= paginate @proposals %> +<% else %> +
    + <%= t("admin.proposals.index.no_proposals") %> +
    +<% end %> diff --git a/app/views/admin/proposals/show.html.erb b/app/views/admin/proposals/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0fd2a0d56..cd99283ce 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -536,6 +536,7 @@ en: admin: Admin menu banner: Manage banners poll_questions: Questions + proposals: Proposals proposals_topics: Proposals topics budgets: Participatory budgets geozones: Manage geozones @@ -1040,6 +1041,13 @@ en: search: title: Search Organisations no_results: No organizations found. + proposals: + index: + title: Proposals + id: ID + author: Author + milestones: Milestones + no_proposals: There are no proposals. hidden_proposals: index: filter: Filter diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 5798dd0b1..cc0d99b7e 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -532,6 +532,7 @@ es: admin: Menú de administración banner: Gestionar banners poll_questions: Preguntas + proposals: Propuestas proposals_topics: Temas de propuestas budgets: Presupuestos participativos geozones: Gestionar distritos @@ -1036,6 +1037,13 @@ es: search: title: Buscar Organizaciones no_results: No se han encontrado organizaciones. + proposals: + index: + title: Propuestas + id: ID + author: Autor + milestones: Hitos + no_proposals: No hay propuestas. hidden_proposals: index: filter: Filtro diff --git a/config/routes/admin.rb b/config/routes/admin.rb index a6ccf2de3..660d90e3c 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -29,6 +29,8 @@ namespace :admin do end end + resources :proposals, only: [:index, :show] + resources :hidden_proposals, only: :index do member do put :restore diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb new file mode 100644 index 000000000..305db9d6c --- /dev/null +++ b/spec/features/admin/proposals_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +feature "Admin proposals" do + background do + login_as create(:administrator).user + end + + scenario "Index" do + create(:proposal, title: "Make Pluto a planet again") + + visit admin_root_path + within("#side_menu") { click_link "Proposals" } + + expect(page).to have_content "Make Pluto a planet again" + end +end diff --git a/spec/features/admin/site_customization/information_texts_spec.rb b/spec/features/admin/site_customization/information_texts_spec.rb index 454a83526..83e4edb9a 100644 --- a/spec/features/admin/site_customization/information_texts_spec.rb +++ b/spec/features/admin/site_customization/information_texts_spec.rb @@ -21,7 +21,7 @@ feature "Admin custom information texts" do click_link 'Community' expect(page).to have_content 'Access the community' - click_link 'Proposals' + within("#information-texts-tabs") { click_link "Proposals" } expect(page).to have_content 'Create proposal' within "#information-texts-tabs" do @@ -49,7 +49,7 @@ feature "Admin custom information texts" do scenario 'check that tabs are highlight when click it' do visit admin_site_customization_information_texts_path - click_link 'Proposals' + within("#information-texts-tabs") { click_link "Proposals" } expect(find("a[href=\"/admin/site_customization/information_texts?tab=proposals\"].is-active")) .to have_content "Proposals" end From d3f11c3b55f0a8719c08d97b887ae21e85b8b528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Nov 2018 13:57:10 +0100 Subject: [PATCH 3/6] Add search form to proposals admin index --- app/controllers/admin/proposals_controller.rb | 12 ++++++++--- app/views/admin/proposals/index.html.erb | 2 ++ spec/features/admin/proposals_spec.rb | 20 ++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/proposals_controller.rb index 64b5e3526..e76efce21 100644 --- a/app/controllers/admin/proposals_controller.rb +++ b/app/controllers/admin/proposals_controller.rb @@ -1,12 +1,18 @@ class Admin::ProposalsController < Admin::BaseController + include HasOrders + include CommentableActions include FeatureFlags feature_flag :proposals - def index - @proposals = Proposal.sort_by_created_at.page(params[:page]) - end + has_orders %w[created_at] def show @proposal = Proposal.find(params[:id]) end + + private + + def resource_model + Proposal + end end diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb index 181674b73..8a8372713 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/proposals/index.html.erb @@ -5,6 +5,8 @@

    <%= t("admin.proposals.index.title") %>

    <% if @proposals.any? %> + <%= render "/admin/shared/proposal_search", url: admin_proposals_path %> +

    <%= page_entries_info @proposals %>

    diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb index 305db9d6c..1e12c7132 100644 --- a/spec/features/admin/proposals_spec.rb +++ b/spec/features/admin/proposals_spec.rb @@ -5,12 +5,22 @@ feature "Admin proposals" do login_as create(:administrator).user end - scenario "Index" do - create(:proposal, title: "Make Pluto a planet again") + context "Index" do + scenario "Search" do + create(:proposal, title: "Make Pluto a planet again") + create(:proposal, title: "Build a monument to honour CONSUL developers") - visit admin_root_path - within("#side_menu") { click_link "Proposals" } + visit admin_root_path + within("#side_menu") { click_link "Proposals" } - expect(page).to have_content "Make Pluto a planet again" + expect(page).to have_content "Make Pluto a planet again" + expect(page).to have_content "Build a monument" + + fill_in "search", with: "Pluto" + click_button "Search" + + expect(page).to have_content "Make Pluto a planet again" + expect(page).not_to have_content "Build a monument" + end end end From 8c45be788793e18366d5c4decb8aa2490bf3b5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Nov 2018 14:24:51 +0100 Subject: [PATCH 4/6] Show proposal info in admin --- app/assets/stylesheets/admin.scss | 4 -- app/views/admin/proposals/show.html.erb | 9 +++ app/views/proposals/_info.html.erb | 84 ++++++++++++++++++++++++ app/views/proposals/show.html.erb | 87 +------------------------ spec/features/admin/proposals_spec.rb | 9 +++ 5 files changed, 103 insertions(+), 90 deletions(-) create mode 100644 app/views/proposals/_info.html.erb diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index caf81b40b..f08d14fda 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -284,10 +284,6 @@ $sidebar-active: #f4fcd0; .proposal-form { padding-top: 0; } - - .proposal-show { - padding-top: rem-calc(54); - } } .is-featured { diff --git a/app/views/admin/proposals/show.html.erb b/app/views/admin/proposals/show.html.erb index e69de29bb..55eaebfef 100644 --- a/app/views/admin/proposals/show.html.erb +++ b/app/views/admin/proposals/show.html.erb @@ -0,0 +1,9 @@ +<% provide :title do %> + <%= t("admin.header.title") %> - <%= t("admin.menu.proposals") %> - <%= @proposal.title %> +<% end %> + +
    +

    <%= @proposal.title %>

    + + <%= render "proposals/info", proposal: @proposal %> +
    diff --git a/app/views/proposals/_info.html.erb b/app/views/proposals/_info.html.erb new file mode 100644 index 000000000..44d5b76f3 --- /dev/null +++ b/app/views/proposals/_info.html.erb @@ -0,0 +1,84 @@ +
    + <%= render '/shared/author_info', resource: @proposal %> + +  •  + <%= l @proposal.created_at.to_date %> +  •  +   + <%= link_to t("proposals.show.comments", count: @proposal.comments_count), "#comments" %> + + <% if current_user %> +  •  + + <%= render 'proposals/flag_actions', proposal: @proposal %> + + <% end %> + +
    + +<%= render_image(@proposal.image, :large, true) if @proposal.image.present? %> + +
    +

    + <%= t("proposals.show.code") %> + <%= @proposal.code %> +

    + +
    <%= @proposal.summary %>
    + +<% if @proposal.video_url.present? %> +
    +
    +
    +
    +
    +<% end %> + +<%= safe_html_with_links @proposal.description %> + +<% if feature?(:map) && map_location_available?(@proposal.map_location) %> +
    + <%= render_map(@proposal.map_location, "proposal", false, nil) %> +
    +<% end %> + +<% if @proposal.external_url.present? %> + +<% end %> + +<% if @proposal.video_url.present? %> + + +<% end %> + +

    <%= @proposal.question %>

    + +<% if @proposal.retired? %> +
    +

    + <%= t("proposals.show.retired") %>: + <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %> +

    + <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %> +
    +<% end %> + +<% if feature?(:allow_attached_documents) %> + <%= render 'documents/documents', + documents: @proposal.documents, + max_documents_allowed: Proposal.max_documents_allowed %> +<% end %> + +<%= render 'shared/tags', taggable: @proposal %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 2c40a7075..dab5996fb 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -37,93 +37,8 @@ <% end %> -
    - <%= render '/shared/author_info', resource: @proposal %> - -  •  - <%= l @proposal.created_at.to_date %> -  •  -   - <%= link_to t("proposals.show.comments", count: @proposal.comments_count), "#comments" %> - - <% if current_user %> -  •  - - <%= render 'proposals/flag_actions', proposal: @proposal %> - - <% end %> - -
    - - <%= render_image(@proposal.image, :large, true) if @proposal.image.present? %> - -
    -

    - <%= t("proposals.show.code") %> - <%= @proposal.code %> -

    - -
    <%= @proposal.summary %>
    - - <% if @proposal.video_url.present? %> -
    -
    -
    -
    -
    - <% end %> - - <%= safe_html_with_links @proposal.description %> - - <% if feature?(:map) && map_location_available?(@proposal.map_location) %> -
    - <%= render_map(@proposal.map_location, "proposal", false, nil) %> -
    - <% end %> - - <% if @proposal.external_url.present? %> - - <% end %> - - <% if @proposal.video_url.present? %> - - - <% end %> - -

    <%= @proposal.question %>

    - - <% if @proposal.retired? %> -
    -

    - <%= t("proposals.show.retired") %>: - <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %> -

    - <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %> -
    - <% end %> - - <% if feature?(:allow_attached_documents) %> - <%= render 'documents/documents', - documents: @proposal.documents, - max_documents_allowed: Proposal.max_documents_allowed %> - <% end %> - - <%= render 'shared/tags', taggable: @proposal %> - + <%= render "info", proposal: @proposal %> <%= render 'shared/geozone', geozonable: @proposal %> - <%= render 'relationable/related_content', relationable: @proposal %>
    diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb index 1e12c7132..04e382348 100644 --- a/spec/features/admin/proposals_spec.rb +++ b/spec/features/admin/proposals_spec.rb @@ -23,4 +23,13 @@ feature "Admin proposals" do expect(page).not_to have_content "Build a monument" end end + + scenario "Show" do + create(:proposal, title: "Create a chaotic future", summary: "Chaos isn't controlled") + + visit admin_proposals_path + click_link "Create a chaotic future" + + expect(page).to have_content "Chaos isn't controlled" + end end From 2fcbee6261d4b8085ef5947cf441d096597386cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 15 Nov 2018 15:11:36 +0100 Subject: [PATCH 5/6] Manage proposal milestones --- app/controllers/admin/proposal_milestones_controller.rb | 8 ++++++++ app/views/admin/proposals/show.html.erb | 2 ++ app/views/proposals/_filter_subnav.html.erb | 8 ++++++++ app/views/proposals/show.html.erb | 1 + config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + config/locales/val/general.yml | 1 + config/routes/admin.rb | 4 +++- spec/features/admin/proposals_spec.rb | 4 ++++ spec/features/proposals_spec.rb | 4 ++++ 10 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/proposal_milestones_controller.rb diff --git a/app/controllers/admin/proposal_milestones_controller.rb b/app/controllers/admin/proposal_milestones_controller.rb new file mode 100644 index 000000000..3dec8463b --- /dev/null +++ b/app/controllers/admin/proposal_milestones_controller.rb @@ -0,0 +1,8 @@ +class Admin::ProposalMilestonesController < Admin::MilestonesController + + private + + def milestoneable + Proposal.find(params[:proposal_id]) + end +end diff --git a/app/views/admin/proposals/show.html.erb b/app/views/admin/proposals/show.html.erb index 55eaebfef..762c65592 100644 --- a/app/views/admin/proposals/show.html.erb +++ b/app/views/admin/proposals/show.html.erb @@ -7,3 +7,5 @@ <%= render "proposals/info", proposal: @proposal %>
    + +<%= render "admin/milestones/milestones", milestoneable: @proposal %> diff --git a/app/views/proposals/_filter_subnav.html.erb b/app/views/proposals/_filter_subnav.html.erb index 47709c8aa..642d21535 100644 --- a/app/views/proposals/_filter_subnav.html.erb +++ b/app/views/proposals/_filter_subnav.html.erb @@ -21,4 +21,12 @@ <% end %> +
  • + <%= link_to "#tab-milestones" do %> +

    + <%= t("proposals.show.milestones_tab") %> + (<%= @proposal.milestones.count %>) +

    + <% end %> +
  • diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index dab5996fb..fe8f97251 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -140,4 +140,5 @@ <%= render "proposals/notifications" %> + <%= render "milestones/milestones", milestoneable: @proposal %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 25136eecb..20f843999 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -437,6 +437,7 @@ en: flag: This proposal has been flagged as inappropriate by several users. login_to_comment: You must %{signin} or %{signup} to leave a comment. notifications_tab: Notifications + milestones_tab: Milestones retired_warning: "The author considers this proposal should not receive more supports." retired_warning_link_to_explanation: Read the explanation before voting for it. retired: Proposal retired by the author diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 8c2212dae..52308497b 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -437,6 +437,7 @@ es: flag: Esta propuesta ha sido marcada como inapropiada por varios usuarios. login_to_comment: Necesitas %{signin} o %{signup} para comentar. notifications_tab: Notificaciones + milestones_tab: Seguimiento retired_warning: "El autor de esta propuesta considera que ya no debe seguir recogiendo apoyos." retired_warning_link_to_explanation: Revisa su explicación antes de apoyarla. retired: Propuesta retirada por el autor diff --git a/config/locales/val/general.yml b/config/locales/val/general.yml index aa35f48d5..bc014d401 100644 --- a/config/locales/val/general.yml +++ b/config/locales/val/general.yml @@ -434,6 +434,7 @@ val: flag: Esta proposta ha sigut marcada com inapropiada per diversos usuaris. login_to_comment: Necessites %{signin} o %{signup} per a comentar. notifications_tab: Notificacions + milestones_tab: Seguiments retired_warning: "L'autor d'esta proposta considera que ja no ha de seguir recollint avals." retired_warning_link_to_explanation: Revisa la seua explicació abans d'avalar-la. retired: Proposta retirada per l'autor diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 660d90e3c..b37714f47 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -29,7 +29,9 @@ namespace :admin do end end - resources :proposals, only: [:index, :show] + resources :proposals, only: [:index, :show] do + resources :milestones, controller: "proposal_milestones" + end resources :hidden_proposals, only: :index do member do diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb index 04e382348..ddad53d9c 100644 --- a/spec/features/admin/proposals_spec.rb +++ b/spec/features/admin/proposals_spec.rb @@ -5,6 +5,10 @@ feature "Admin proposals" do login_as create(:administrator).user end + it_behaves_like "admin_milestoneable", + :proposal, + "admin_proposal_path" + context "Index" do scenario "Search" do create(:proposal, title: "Make Pluto a planet again") diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index eb8b5c0de..8beb35549 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -3,6 +3,10 @@ require 'rails_helper' feature 'Proposals' do + it_behaves_like "milestoneable", + :proposal, + "proposal_path" + scenario 'Disabled with a feature flag' do Setting['feature.proposals'] = nil expect{ visit proposals_path }.to raise_exception(FeatureFlags::FeatureDisabled) From 1ff6390950123c7afe062e07072c393218534749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 12 Dec 2018 13:41:35 +0100 Subject: [PATCH 6/6] Fix proposal info rendering for managers We were looking for the partial in management/proposals/info instead of proposals/info. --- app/views/proposals/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index fe8f97251..cd9ba74f0 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -37,7 +37,7 @@ <% end %> - <%= render "info", proposal: @proposal %> + <%= render "proposals/info", proposal: @proposal %> <%= render 'shared/geozone', geozonable: @proposal %> <%= render 'relationable/related_content', relationable: @proposal %>