From 85c08da7a6f859418865feb706153f4e6fd291a9 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 22 May 2018 19:52:35 +0200 Subject: [PATCH 01/23] Add homepage admin section --- app/controllers/admin/homepage_controller.rb | 12 ++++++++++++ app/controllers/admin/settings_controller.rb | 2 +- app/controllers/admin/widget/base_controller.rb | 10 ++++++++++ app/views/admin/_menu.html.erb | 5 +++++ app/views/admin/homepage/_setting.html.erb | 11 +++++++++++ app/views/admin/homepage/show.html.erb | 11 +++++++++++ app/views/admin/widget/_menu.html.erb | 1 + config/locales/en/settings.yml | 2 +- config/routes/admin.rb | 3 +++ spec/features/home_spec.rb | 4 ++-- 10 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 app/controllers/admin/homepage_controller.rb create mode 100644 app/controllers/admin/widget/base_controller.rb create mode 100644 app/views/admin/homepage/_setting.html.erb create mode 100644 app/views/admin/homepage/show.html.erb create mode 100644 app/views/admin/widget/_menu.html.erb diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb new file mode 100644 index 000000000..1de56b10f --- /dev/null +++ b/app/controllers/admin/homepage_controller.rb @@ -0,0 +1,12 @@ +class Admin::HomepageController < Admin::BaseController + + def show + end + + private + + def load_settings + settings = /feature.homepage.widgets/ + @settings = Setting.select {|setting| setting.key =~ /#{settings}/ } + end +end \ No newline at end of file diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 14dfc6658..5b7147026 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -11,7 +11,7 @@ class Admin::SettingsController < Admin::BaseController def update @setting = Setting.find(params[:id]) @setting.update(settings_params) - redirect_to admin_settings_path, notice: t("admin.settings.flash.updated") + redirect_to request.referer, notice: t("admin.settings.flash.updated") end def update_map diff --git a/app/controllers/admin/widget/base_controller.rb b/app/controllers/admin/widget/base_controller.rb new file mode 100644 index 000000000..1f9aeffc4 --- /dev/null +++ b/app/controllers/admin/widget/base_controller.rb @@ -0,0 +1,10 @@ +class Admin::Widget::BaseController < Admin::BaseController + helper_method :namespace + + private + + def namespace + "admin" + end + +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 134725cda..7336aad77 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -167,6 +167,10 @@ diff --git a/app/views/admin/homepage/_setting.html.erb b/app/views/admin/homepage/_setting.html.erb new file mode 100644 index 000000000..89221e793 --- /dev/null +++ b/app/views/admin/homepage/_setting.html.erb @@ -0,0 +1,11 @@ +
+ <%= form_for(setting, url: admin_setting_path(setting), method: :put) do |f| %> + + <%= f.hidden_field :value, + value: (setting.enabled? ? "" : "active") %> + + <%= f.submit(t("admin.settings.index.features.#{setting.enabled? ? 'disable' : 'enable'}"), + class: "button expanded #{setting.enabled? ? 'hollow alert' : 'success'}", + data: {confirm: t("admin.actions.confirm")}) %> + <% end %> +
\ No newline at end of file diff --git a/app/views/admin/homepage/show.html.erb b/app/views/admin/homepage/show.html.erb new file mode 100644 index 000000000..3da4a9af5 --- /dev/null +++ b/app/views/admin/homepage/show.html.erb @@ -0,0 +1,11 @@ +

Homepage

+ +

The active modules appear in the homepage in the same order as here.

+<% @settings.each do |setting| %> + +
+ <%= t("settings.#{setting.key}") %> +
+ + <%= render "setting", setting: setting %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/widget/_menu.html.erb b/app/views/admin/widget/_menu.html.erb new file mode 100644 index 000000000..08efd87dc --- /dev/null +++ b/app/views/admin/widget/_menu.html.erb @@ -0,0 +1 @@ +<%= render "admin/menu" %> \ No newline at end of file diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index 6d63890c2..1b4444274 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -41,7 +41,7 @@ en: voting_allowed: Voting on investment projects legislation: Legislation user: - recommendations: Recommendeds + recommendations: Recommendations skip_verification: Skip user verification community: Community on proposals and investments map: Proposals and budget investments geolocation diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 6bf380f0c..251a13783 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -179,4 +179,7 @@ namespace :admin do resources :images, only: [:index, :update, :destroy] resources :content_blocks, except: [:show] end + + resource :homepage, controller: :homepage + end diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index 0e26c6711..90a267eea 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Home" do - feature "For not logged users" do + context "For not logged users" do scenario 'Welcome message' do visit root_path @@ -20,7 +20,7 @@ feature "Home" do end - feature "For signed in users" do + context "For signed in users" do feature "Recommended" do From 664e77305cb5f2e1a6078110d17697a3f2190512 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 22 May 2018 19:56:40 +0200 Subject: [PATCH 02/23] Add widget cards to homepage --- app/controllers/admin/homepage_controller.rb | 6 + .../admin/widget/cards_controller.rb | 51 +++++++ app/controllers/welcome_controller.rb | 1 + app/models/widget.rb | 2 + app/models/widget/card.rb | 15 ++ app/views/admin/homepage/_card.html.erb | 22 +++ app/views/admin/homepage/_cards.html.erb | 13 ++ app/views/admin/homepage/show.html.erb | 13 ++ app/views/admin/widget/cards/_form.html.erb | 11 ++ app/views/admin/widget/cards/edit.html.erb | 2 + app/views/admin/widget/cards/new.html.erb | 2 + app/views/welcome/_card.html.erb | 11 ++ app/views/welcome/_cards.html.erb | 5 + app/views/welcome/index.html.erb | 1 + config/routes/admin.rb | 3 + .../20180516091302_create_widget_cards.rb | 15 ++ db/schema.rb | 15 +- spec/factories.rb | 18 +++ spec/features/admin/homepage/homepage_spec.rb | 38 +++++ spec/features/admin/widgets/cards_spec.rb | 132 ++++++++++++++++++ spec/models/widget/card_spec.rb | 37 +++++ 21 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/widget/cards_controller.rb create mode 100644 app/models/widget.rb create mode 100644 app/models/widget/card.rb create mode 100644 app/views/admin/homepage/_card.html.erb create mode 100644 app/views/admin/homepage/_cards.html.erb create mode 100644 app/views/admin/widget/cards/_form.html.erb create mode 100644 app/views/admin/widget/cards/edit.html.erb create mode 100644 app/views/admin/widget/cards/new.html.erb create mode 100644 app/views/welcome/_card.html.erb create mode 100644 app/views/welcome/_cards.html.erb create mode 100644 db/migrate/20180516091302_create_widget_cards.rb create mode 100644 spec/features/admin/homepage/homepage_spec.rb create mode 100644 spec/features/admin/widgets/cards_spec.rb create mode 100644 spec/models/widget/card_spec.rb diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb index 1de56b10f..5d8dad830 100644 --- a/app/controllers/admin/homepage_controller.rb +++ b/app/controllers/admin/homepage_controller.rb @@ -1,6 +1,7 @@ class Admin::HomepageController < Admin::BaseController def show + load_cards end private @@ -9,4 +10,9 @@ class Admin::HomepageController < Admin::BaseController settings = /feature.homepage.widgets/ @settings = Setting.select {|setting| setting.key =~ /#{settings}/ } end + + def load_cards + @cards = ::Widget::Card.body + end + end \ No newline at end of file diff --git a/app/controllers/admin/widget/cards_controller.rb b/app/controllers/admin/widget/cards_controller.rb new file mode 100644 index 000000000..15bb5d49f --- /dev/null +++ b/app/controllers/admin/widget/cards_controller.rb @@ -0,0 +1,51 @@ +class Admin::Widget::CardsController < Admin::BaseController + + def new + @card = ::Widget::Card.new(header: header_card?) + end + + def create + @card = ::Widget::Card.new(card_params) + if @card.save + notice = "Success" + redirect_to admin_homepage_url, notice: notice + else + render :new + end + end + + def edit + @card = ::Widget::Card.find(params[:id]) + end + + def update + @card = ::Widget::Card.find(params[:id]) + if @card.update(card_params) + notice = "Updated" + redirect_to admin_homepage_url, notice: notice + else + render :edit + end + end + + def destroy + @card = ::Widget::Card.find(params[:id]) + @card.destroy + + notice = "Removed" + redirect_to admin_homepage_url, notice: notice + end + + private + + def card_params + params.require(:widget_card).permit(:title, :description, :link_text, :link_url, + :button_text, :button_url, :alignment, :header, + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + end + + def header_card? + params[:header_card].present? + end + +end \ No newline at end of file diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 73b2b3aba..e1a8d3472 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -5,6 +5,7 @@ class WelcomeController < ApplicationController layout "devise", only: [:welcome, :verification] def index + @cards = Widget::Card.body end def welcome diff --git a/app/models/widget.rb b/app/models/widget.rb new file mode 100644 index 000000000..2cf6af02d --- /dev/null +++ b/app/models/widget.rb @@ -0,0 +1,2 @@ +class Widget +end \ No newline at end of file diff --git a/app/models/widget/card.rb b/app/models/widget/card.rb new file mode 100644 index 000000000..fdc41d295 --- /dev/null +++ b/app/models/widget/card.rb @@ -0,0 +1,15 @@ +class Widget + class Card < ActiveRecord::Base + include Imageable + + self.table_name = "widget_cards" + + def self.header + where(header: true) + end + + def self.body + where(header: false).order(:created_at) + end + end +end \ No newline at end of file diff --git a/app/views/admin/homepage/_card.html.erb b/app/views/admin/homepage/_card.html.erb new file mode 100644 index 000000000..d1986d8f7 --- /dev/null +++ b/app/views/admin/homepage/_card.html.erb @@ -0,0 +1,22 @@ + + <%= card.title %> + <%= card.description %> + <%= card.link_text %> + <%= card.link_url %> + + + <% if card.image.present? %> + <%= image_tag(card.image_url(:thumb), + class: "margin", + alt: card.image.title) %> + <% end %> + +
+ <%= link_to "Edit", edit_admin_widget_card_path(card) %> +
+ <%= link_to "Remove", admin_widget_card_path(card), + method: :delete, + data: { confirm: t('admin.actions.confirm') } %> +
+ + \ No newline at end of file diff --git a/app/views/admin/homepage/_cards.html.erb b/app/views/admin/homepage/_cards.html.erb new file mode 100644 index 000000000..e6f2a7eac --- /dev/null +++ b/app/views/admin/homepage/_cards.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + + <% cards.each do |card| %> + <%= render "card", card: card %> + <% end %> +
titletextlink textlinkimageactions
\ No newline at end of file diff --git a/app/views/admin/homepage/show.html.erb b/app/views/admin/homepage/show.html.erb index 3da4a9af5..509cc5e9b 100644 --- a/app/views/admin/homepage/show.html.erb +++ b/app/views/admin/homepage/show.html.erb @@ -1,6 +1,19 @@

Homepage

The active modules appear in the homepage in the same order as here.

+

Cards

+ + +
+ <%= link_to "Create card", new_admin_widget_card_path %> +
+ +
+ <% if @cards.present? %> + <%= render "cards", cards: @cards %> + <% end %> +
+ <% @settings.each do |setting| %>
diff --git a/app/views/admin/widget/cards/_form.html.erb b/app/views/admin/widget/cards/_form.html.erb new file mode 100644 index 000000000..2e8a70295 --- /dev/null +++ b/app/views/admin/widget/cards/_form.html.erb @@ -0,0 +1,11 @@ +<%= form_for [:admin, @card] do |f| %> + <%= f.text_field :title %> + <%= f.text_area :description %> + <%= f.text_field :link_text %> + <%= f.text_field :link_url %> + <%= f.hidden_field :header, value: @card.header? %> +
+ <%= render 'images/nested_image', imageable: @card, f: f %> +
+ <%= f.submit %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/widget/cards/edit.html.erb b/app/views/admin/widget/cards/edit.html.erb new file mode 100644 index 000000000..259dc7b82 --- /dev/null +++ b/app/views/admin/widget/cards/edit.html.erb @@ -0,0 +1,2 @@ +Edit +<%= render "form" %> \ No newline at end of file diff --git a/app/views/admin/widget/cards/new.html.erb b/app/views/admin/widget/cards/new.html.erb new file mode 100644 index 000000000..dae2d7b9f --- /dev/null +++ b/app/views/admin/widget/cards/new.html.erb @@ -0,0 +1,2 @@ +New +<%= render "form" %> \ No newline at end of file diff --git a/app/views/welcome/_card.html.erb b/app/views/welcome/_card.html.erb new file mode 100644 index 000000000..0d8ecdda8 --- /dev/null +++ b/app/views/welcome/_card.html.erb @@ -0,0 +1,11 @@ +
+ <%= card.title %> + <%= card.description %> + <%= link_to card.link_text, card.link_url %> + + <% if card.image.present? %> + <%= image_tag(card.image_url(:large), + class: "margin", + alt: card.image.title) %> + <% end %> +
\ No newline at end of file diff --git a/app/views/welcome/_cards.html.erb b/app/views/welcome/_cards.html.erb new file mode 100644 index 000000000..2e741363f --- /dev/null +++ b/app/views/welcome/_cards.html.erb @@ -0,0 +1,5 @@ +

Cards

+ +<% @cards.all.each do |card| %> + <%= render "card", card: card %> +<% end %> \ No newline at end of file diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 7a55aa263..4c8b0eab9 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -23,6 +23,7 @@
+<%= render "cards" %> <% if feature?("user.recommendations") && (@recommended_debates.present? || @recommended_proposals.present?) %> <%= render "recommended", recommended_debates: @recommended_debates, diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 251a13783..61825aff4 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -182,4 +182,7 @@ namespace :admin do resource :homepage, controller: :homepage + namespace :widget do + resources :cards + end end diff --git a/db/migrate/20180516091302_create_widget_cards.rb b/db/migrate/20180516091302_create_widget_cards.rb new file mode 100644 index 000000000..540523e2e --- /dev/null +++ b/db/migrate/20180516091302_create_widget_cards.rb @@ -0,0 +1,15 @@ +class CreateWidgetCards < ActiveRecord::Migration + def change + create_table :widget_cards do |t| + t.string :title + t.text :description + t.string :link_text + t.string :link_url + t.string :button_text + t.string :button_url + t.boolean :header, default: false + t.string :alignment + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 860378811..c90edc5fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180323190027) do +ActiveRecord::Schema.define(version: 20180519132715) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1223,6 +1223,19 @@ ActiveRecord::Schema.define(version: 20180323190027) do add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree + create_table "widget_cards", force: :cascade do |t| + t.string "title" + t.text "description" + t.string "link_text" + t.string "link_url" + t.string "button_text" + t.string "button_url" + t.boolean "header", default: false + t.string "alignment" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + add_foreign_key "administrators", "users" add_foreign_key "annotations", "legacy_legislations" add_foreign_key "annotations", "users" diff --git a/spec/factories.rb b/spec/factories.rb index cb937e698..448fa8c7f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -962,4 +962,22 @@ LOREM_IPSUM sequence(:body) { |n| "Body #{n}" } end + factory :widget_card, class: 'Widget::Card' do + sequence(:title) { |n| "Title #{n}" } + sequence(:description) { |n| "Description #{n}" } + sequence(:link_text) { |n| "Link text #{n}" } + sequence(:link_url) { |n| "Link url #{n}" } + + trait :header do + header true + sequence(:button_text) { |n| "Button text #{n}" } + sequence(:button_url) { |n| "Button url #{n}" } + sequence(:alignment) { |n| "background" } + end + + after :create do |widget_card| + create(:image, imageable: widget_card) + end + end + end diff --git a/spec/features/admin/homepage/homepage_spec.rb b/spec/features/admin/homepage/homepage_spec.rb new file mode 100644 index 000000000..03aa6733a --- /dev/null +++ b/spec/features/admin/homepage/homepage_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +feature 'Homepage' do + + background do + admin = create(:administrator).user + login_as(admin) + + end + scenario "Cards" do + card1 = create(:widget_card, title: "Card text", + description: "Card description", + link_text: "Link text", + link_url: "consul.dev") + + card2 = create(:widget_card, title: "Card text2", + description: "Card description2", + link_text: "Link text2", + link_url: "consul.dev2") + + visit root_path + + expect(page).to have_css(".card", count: 2) + + within("#widget_card_#{card1.id}") do + expect(page).to have_content("Card text") + expect(page).to have_content("Card description") + expect(page).to have_link("Link text", href: "consul.dev") + expect(page).to have_css("img[alt='#{card1.image.title}']") + end + + within("#widget_card_#{card2.id}") do + expect(page).to have_content("Card text2") + expect(page).to have_content("Card description2") + expect(page).to have_link("Link text2", href: "consul.dev2") + expect(page).to have_css("img[alt='#{card2.image.title}']") + end + end diff --git a/spec/features/admin/widgets/cards_spec.rb b/spec/features/admin/widgets/cards_spec.rb new file mode 100644 index 000000000..57609d0fb --- /dev/null +++ b/spec/features/admin/widgets/cards_spec.rb @@ -0,0 +1,132 @@ +require 'rails_helper' + +feature 'Cards' do + + background do + admin = create(:administrator).user + login_as(admin) + end + + scenario "Create", :js do + visit admin_homepage_path + click_link "Create card" + + fill_in "widget_card_title", with: "Card text" + fill_in "widget_card_description", with: "Card description" + fill_in "widget_card_link_text", with: "Link text" + fill_in "widget_card_link_url", with: "consul.dev" + attach_image_to_card + click_button "Create Card" + + expect(page).to have_content "Success" + expect(page).to have_css(".card", count: 1) + + card = Widget::Card.last + within("#widget_card_#{card.id}") do + expect(page).to have_content "Card text" + expect(page).to have_content "Card description" + expect(page).to have_content "Link text" + expect(page).to have_content "consul.dev" + expect(page).to have_css("img[alt='#{card.image.title}']") + end + end + + scenario "Index" do + 3.times { create(:widget_card) } + + visit admin_homepage_path + + expect(page).to have_css(".card", count: 3) + + cards = Widget::Card.all + cards.each do |card| + expect(page).to have_content card.title + expect(page).to have_content card.description + expect(page).to have_content card.link_text + expect(page).to have_content card.link_url + expect(page).to have_css("img[alt='#{card.image.title}']") + end + end + + scenario "Edit" do + card = create(:widget_card) + + visit admin_homepage_path + + within("#widget_card_#{card.id}") do + click_link "Edit" + end + + fill_in "widget_card_title", with: "Card text updated" + fill_in "widget_card_description", with: "Card description updated" + fill_in "widget_card_link_text", with: "Link text updated" + fill_in "widget_card_link_url", with: "consul.dev updated" + click_button "Update Card" + + expect(page).to have_content "Updated" + + expect(page).to have_css(".card", count: 1) + within("#widget_card_#{Widget::Card.last.id}") do + expect(page).to have_content "Card text updated" + expect(page).to have_content "Card description updated" + expect(page).to have_content "Link text updated" + expect(page).to have_content "consul.dev updated" + end + end + + scenario "Remove", :js do + card = create(:widget_card) + + visit admin_homepage_path + + within("#widget_card_#{card.id}") do + accept_confirm do + click_link "Remove" + end + end + + expect(page).to have_content "Removed" + expect(page).to have_css(".card", count: 0) + end + + context "Header Card" do + + scenario "Create" do + visit admin_homepage_path + click_link "Create header" + + fill_in "widget_card_title", with: "Card text" + fill_in "widget_card_description", with: "Card description" + fill_in "widget_card_link_text", with: "Link text" + fill_in "widget_card_link_url", with: "consul.dev" + click_button "Create Card" + + expect(page).to have_content "Success" + + within("#header") do + expect(page).to have_css(".card", count: 1) + expect(page).to have_content "Card text" + expect(page).to have_content "Card description" + expect(page).to have_content "Link text" + expect(page).to have_content "consul.dev" + end + + within("#cards") do + expect(page).to have_css(".card", count: 0) + end + end + + end + + pending "add image expectactions" + + def attach_image_to_card + click_link "Add image" + image_input = find(".image").find("input[type=file]", visible: false) + attach_file( + image_input[:id], + Rails.root.join('spec/fixtures/files/clippy.jpg'), + make_visible: true) + expect(page).to have_field('widget_card_image_attributes_title', with: "clippy.jpg") + end +end \ No newline at end of file diff --git a/spec/models/widget/card_spec.rb b/spec/models/widget/card_spec.rb new file mode 100644 index 000000000..70c13eafa --- /dev/null +++ b/spec/models/widget/card_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +describe Widget::Card do + + let(:card) { build(:widget_card) } + + context "validations" do + + it "is valid" do + expect(card).to be_valid + end + + end + + describe "#header" do + + it "returns the header card" do + header = create(:widget_card, header: true) + card = create(:widget_card, header: false) + + expect(Widget::Card.header).to eq([header]) + end + end + + describe "#body" do + + it "returns cards for the homepage body" do + header = create(:widget_card, header: true) + card1 = create(:widget_card, header: false, title: "Card 1") + card2 = create(:widget_card, header: false, title: "Card 2") + card3 = create(:widget_card, header: false, title: "Card 3") + + expect(Widget::Card.body).to eq([card1, card2, card3]) + end + end + +end \ No newline at end of file From c7f85c4173d5024161465807e38188ef22487bc7 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 22 May 2018 19:57:52 +0200 Subject: [PATCH 03/23] Add widget header to homepage --- app/controllers/admin/homepage_controller.rb | 5 +++++ app/controllers/welcome_controller.rb | 1 + app/views/admin/homepage/show.html.erb | 11 +++++++++++ app/views/welcome/_header.html.erb | 13 +++++++++++++ app/views/welcome/index.html.erb | 2 ++ spec/features/admin/homepage/homepage_spec.rb | 3 +++ 6 files changed, 35 insertions(+) create mode 100644 app/views/welcome/_header.html.erb diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb index 5d8dad830..a93eb83cd 100644 --- a/app/controllers/admin/homepage_controller.rb +++ b/app/controllers/admin/homepage_controller.rb @@ -1,11 +1,16 @@ class Admin::HomepageController < Admin::BaseController def show + load_header load_cards end private + def load_header + @header = ::Widget::Card.header + end + def load_settings settings = /feature.homepage.widgets/ @settings = Setting.select {|setting| setting.key =~ /#{settings}/ } diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index e1a8d3472..bce56650b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -5,6 +5,7 @@ class WelcomeController < ApplicationController layout "devise", only: [:welcome, :verification] def index + @header = Widget::Card.header.first @cards = Widget::Card.body end diff --git a/app/views/admin/homepage/show.html.erb b/app/views/admin/homepage/show.html.erb index 509cc5e9b..0d6e3fc9f 100644 --- a/app/views/admin/homepage/show.html.erb +++ b/app/views/admin/homepage/show.html.erb @@ -1,8 +1,18 @@

Homepage

The active modules appear in the homepage in the same order as here.

+ + +

Cards

+
+ <%= link_to "Create header", new_admin_widget_card_path(header_card: true) %> +
<%= link_to "Create card", new_admin_widget_card_path %> @@ -14,6 +24,7 @@ <% end %>
+ <% @settings.each do |setting| %>
diff --git a/app/views/welcome/_header.html.erb b/app/views/welcome/_header.html.erb new file mode 100644 index 000000000..610083c5a --- /dev/null +++ b/app/views/welcome/_header.html.erb @@ -0,0 +1,13 @@ +<% if header.present? %> + <%= header.title %> + <%= header.description %> + + <% if header.image.present? %> + <%= image_tag(header.image_url(:large), + class: "margin", + alt: header.image.title) %> + <% end %> + + <%= link_to header.button_text, header.button_url %> + <%= header.alignment %> +<% end %> \ No newline at end of file diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 4c8b0eab9..28e29b786 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -23,7 +23,9 @@
+<%= render "header", header: @header %> <%= render "cards" %> + <% if feature?("user.recommendations") && (@recommended_debates.present? || @recommended_proposals.present?) %> <%= render "recommended", recommended_debates: @recommended_debates, diff --git a/spec/features/admin/homepage/homepage_spec.rb b/spec/features/admin/homepage/homepage_spec.rb index 03aa6733a..4bb1cb31f 100644 --- a/spec/features/admin/homepage/homepage_spec.rb +++ b/spec/features/admin/homepage/homepage_spec.rb @@ -7,6 +7,9 @@ feature 'Homepage' do login_as(admin) end + scenario "Header" do + end + scenario "Cards" do card1 = create(:widget_card, title: "Card text", description: "Card description", From 0e097973cccb225d7593b4ad3dfd473bd41ce373 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 22 May 2018 20:01:06 +0200 Subject: [PATCH 04/23] Add widget feeds to homepage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note there is some funkiness going on with class loadings Had to create a `feed` and `widget_feed` table even though in this first version the Widget::Feed includes only uses ActiveModel instead of ActiveRecord, otherwise some specs failed We’ll figure it out and clean up 😌 --- app/controllers/admin/widget/feed.rb | 4 + app/controllers/welcome_controller.rb | 1 + app/models/widget/feed.rb | 46 +++++++++++ app/views/welcome/_feeds.html.erb | 16 ++++ app/views/welcome/index.html.erb | 1 + db/dev_seeds/settings.rb | 4 + .../20180519132610_create_widget_feeds.rb | 6 ++ db/migrate/20180519132715_create_feeds.rb | 6 ++ db/schema.rb | 6 ++ db/seeds.rb | 5 ++ spec/factories.rb | 8 ++ spec/features/admin/homepage/homepage_spec.rb | 62 +++++++++++++++ spec/models/widget/feed_spec.rb | 77 +++++++++++++++++++ 13 files changed, 242 insertions(+) create mode 100644 app/controllers/admin/widget/feed.rb create mode 100644 app/models/widget/feed.rb create mode 100644 app/views/welcome/_feeds.html.erb create mode 100644 db/migrate/20180519132610_create_widget_feeds.rb create mode 100644 db/migrate/20180519132715_create_feeds.rb create mode 100644 spec/models/widget/feed_spec.rb diff --git a/app/controllers/admin/widget/feed.rb b/app/controllers/admin/widget/feed.rb new file mode 100644 index 000000000..aa3c63664 --- /dev/null +++ b/app/controllers/admin/widget/feed.rb @@ -0,0 +1,4 @@ +class Widget + class Feed < ActiveRecord::Base + end +end \ No newline at end of file diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index bce56650b..1ac4fd51a 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -6,6 +6,7 @@ class WelcomeController < ApplicationController def index @header = Widget::Card.header.first + @feeds = Widget::Feed.active @cards = Widget::Card.body end diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb new file mode 100644 index 000000000..b26097686 --- /dev/null +++ b/app/models/widget/feed.rb @@ -0,0 +1,46 @@ +class Widget + class Feed + include ActiveModel::Model + + KINDS = %w(proposals debates processes) + + attr_accessor :kind + + def initialize(attributes={}) + super + @kind = attributes[:kind] + end + + def active?(kind) + Setting["feature.homepage.widgets.feeds.#{kind}"].present? + end + + def self.active + KINDS.collect do |kind| + feed = new(kind: kind) + feed if feed.active?(kind) + end.compact + end + + def items + send(kind) + end + + def proposals + Proposal.sort_by_hot_score.limit(limit) + end + + def debates + Debate.sort_by_hot_score.limit(limit) + end + + def processes + Legislation::Process.open.limit(limit) + end + + def limit + 3 + end + + end +end \ No newline at end of file diff --git a/app/views/welcome/_feeds.html.erb b/app/views/welcome/_feeds.html.erb new file mode 100644 index 000000000..0f735d5d4 --- /dev/null +++ b/app/views/welcome/_feeds.html.erb @@ -0,0 +1,16 @@ +

Feeds

+ +<% @feeds.each do |feed| %> + +
+ Most active <%= feed.kind %> +
+ + <% feed.items.each do |item| %> +
+ <%= item.title %> +
+
+ <% end %> + +<% end %> \ No newline at end of file diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 28e29b786..a0ef26543 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -24,6 +24,7 @@
<%= render "header", header: @header %> +<%= render "feeds" %> <%= render "cards" %> <% if feature?("user.recommendations") && (@recommended_debates.present? || @recommended_proposals.present?) %> diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 67a110184..6c5d8862d 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -63,4 +63,8 @@ section "Creating Settings" do Setting.create(key: 'map_longitude', value: -3.7) Setting.create(key: 'map_zoom', value: 10) Setting.create(key: 'related_content_score_threshold', value: -0.3) + + Setting['feature.homepage.widgets.feeds.proposals'] = true + Setting['feature.homepage.widgets.feeds.debates'] = true + Setting['feature.homepage.widgets.feeds.processes'] = true end diff --git a/db/migrate/20180519132610_create_widget_feeds.rb b/db/migrate/20180519132610_create_widget_feeds.rb new file mode 100644 index 000000000..d6bb42cb1 --- /dev/null +++ b/db/migrate/20180519132610_create_widget_feeds.rb @@ -0,0 +1,6 @@ +class CreateWidgetFeeds < ActiveRecord::Migration + def change + create_table :widget_feeds do |t| + end + end +end diff --git a/db/migrate/20180519132715_create_feeds.rb b/db/migrate/20180519132715_create_feeds.rb new file mode 100644 index 000000000..c096a5914 --- /dev/null +++ b/db/migrate/20180519132715_create_feeds.rb @@ -0,0 +1,6 @@ +class CreateFeeds < ActiveRecord::Migration + def change + create_table :feeds do |t| + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c90edc5fc..1c4a93747 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -378,6 +378,9 @@ ActiveRecord::Schema.define(version: 20180519132715) do add_index "failed_census_calls", ["user_id"], name: "index_failed_census_calls_on_user_id", using: :btree + create_table "feeds", force: :cascade do |t| + end + create_table "flags", force: :cascade do |t| t.integer "user_id" t.string "flaggable_type" @@ -1236,6 +1239,9 @@ ActiveRecord::Schema.define(version: 20180519132715) do t.datetime "updated_at", null: false end + create_table "widget_feeds", force: :cascade do |t| + end + add_foreign_key "administrators", "users" add_foreign_key "annotations", "legacy_legislations" add_foreign_key "annotations", "users" diff --git a/db/seeds.rb b/db/seeds.rb index fb361c53b..868dec2ad 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -125,3 +125,8 @@ Setting['map_zoom'] = 10 Setting['related_content_score_threshold'] = -0.3 Setting["feature.user.skip_verification"] = 'true' + +Setting['feature.homepage.widgets.feeds.proposals'] = true +Setting['feature.homepage.widgets.feeds.debates'] = true +Setting['feature.homepage.widgets.feeds.processes'] = true + diff --git a/spec/factories.rb b/spec/factories.rb index 448fa8c7f..6910e0f47 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -818,6 +818,11 @@ FactoryBot.define do published false end + trait :open do + start_date 1.week.ago + end_date 1.week.from_now + end + end factory :legislation_draft_version, class: 'Legislation::DraftVersion' do @@ -980,4 +985,7 @@ LOREM_IPSUM end end + factory :widget_feed, class: 'Widget::Feed' do + end + end diff --git a/spec/features/admin/homepage/homepage_spec.rb b/spec/features/admin/homepage/homepage_spec.rb index 4bb1cb31f..2dda511fd 100644 --- a/spec/features/admin/homepage/homepage_spec.rb +++ b/spec/features/admin/homepage/homepage_spec.rb @@ -6,10 +6,72 @@ feature 'Homepage' do admin = create(:administrator).user login_as(admin) + Setting['feature.homepage.widgets.feeds.proposals'] = false + Setting['feature.homepage.widgets.feeds.debates'] = false + Setting['feature.homepage.widgets.feeds.processes'] = false + Setting['feature.user.recommendations'] = false end + + let(:proposals_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.proposals').first } + let(:debates_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.debates').first } + let(:processes_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.processes').first } scenario "Header" do end + context "Feeds" do + + scenario "Proposals" do + 5.times { create(:proposal) } + + visit admin_homepage_path + within("#setting_#{proposals_setting.id}") do + click_button "Enable" + end + + expect(page).to have_content "Value updated" + + visit root_path + + expect(page).to have_content "Most active proposals" + expect(page).to have_css(".proposal", count: 3) + end + + scenario "Debates" do + 5.times { create(:debate) } + + visit admin_homepage_path + within("#setting_#{debates_setting.id}") do + click_button "Enable" + end + + expect(page).to have_content "Value updated" + + visit root_path + + expect(page).to have_content "Most active debates" + expect(page).to have_css(".debate", count: 3) + end + + scenario "Processes" do + 5.times { create(:legislation_process) } + + visit admin_homepage_path + within("#setting_#{processes_setting.id}") do + click_button "Enable" + end + + expect(page).to have_content "Value updated" + + visit root_path + + expect(page).to have_content "Most active processes" + expect(page).to have_css(".legislation_process", count: 3) + end + + xscenario "Deactivate" + + end + scenario "Cards" do card1 = create(:widget_card, title: "Card text", description: "Card description", diff --git a/spec/models/widget/feed_spec.rb b/spec/models/widget/feed_spec.rb new file mode 100644 index 000000000..2411312b9 --- /dev/null +++ b/spec/models/widget/feed_spec.rb @@ -0,0 +1,77 @@ +require 'rails_helper' + +describe Widget::Feed do + + let(:feed) { build(:widget_feed) } + + context "validations" do + it "is valid" do + expect(feed).to be_valid + end + end + + context "kinds" do + + describe "#proposals" do + + it "returns the most active proposals" do + best_proposal = create(:proposal, title: 'Best proposal') + best_proposal.update_column(:hot_score, 10) + + worst_proposal = create(:proposal, title: 'Worst proposal') + worst_proposal.update_column(:hot_score, 2) + + even_worst_proposal = create(:proposal, title: 'Worst proposal') + even_worst_proposal.update_column(:hot_score, 1) + + medium_proposal = create(:proposal, title: 'Medium proposal') + medium_proposal.update_column(:hot_score, 5) + + feed = build(:widget_feed, kind: "proposals") + + expect(feed.proposals).to eq([best_proposal, medium_proposal, worst_proposal]) + end + + end + + describe "#debates" do + + it "returns the most active debates" do + best_debate = create(:debate, title: 'Best debate') + best_debate.update_column(:hot_score, 10) + + worst_debate = create(:debate, title: 'Worst debate') + worst_debate.update_column(:hot_score, 2) + + even_worst_debate = create(:debate, title: 'Worst debate') + even_worst_debate.update_column(:hot_score, 1) + + medium_debate = create(:debate, title: 'Medium debate') + medium_debate.update_column(:hot_score, 5) + + feed = build(:widget_feed, kind: "debates") + + expect(feed.debates).to eq([best_debate, medium_debate, worst_debate]) + end + + end + + describe "#processes" do + + it "returns open processes" do + open_process1 = create(:legislation_process, :open, title: "Open process 1") + open_process2 = create(:legislation_process, :open, title: "Open process 2") + open_process3 = create(:legislation_process, :open, title: "Open process 3") + open_process4 = create(:legislation_process, :open, title: "Open process 4") + past_process = create(:legislation_process, :past, title: "Past process") + + feed = build(:widget_feed, kind: "processes") + + expect(feed.processes).to eq([open_process4, open_process3, open_process2]) + end + + end + + end + +end \ No newline at end of file From 5fe0dd46b963f07b4f5667a75c7a5e19f6305ac3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 22 May 2018 20:01:31 +0200 Subject: [PATCH 05/23] Add homepage configuration for user recomendations --- app/controllers/admin/homepage_controller.rb | 2 ++ spec/features/admin/homepage/homepage_spec.rb | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/controllers/admin/homepage_controller.rb b/app/controllers/admin/homepage_controller.rb index a93eb83cd..ff0c51043 100644 --- a/app/controllers/admin/homepage_controller.rb +++ b/app/controllers/admin/homepage_controller.rb @@ -2,6 +2,7 @@ class Admin::HomepageController < Admin::BaseController def show load_header + load_settings load_cards end @@ -14,6 +15,7 @@ class Admin::HomepageController < Admin::BaseController def load_settings settings = /feature.homepage.widgets/ @settings = Setting.select {|setting| setting.key =~ /#{settings}/ } + @settings << Setting.where(key: 'feature.user.recommendations').first end def load_cards diff --git a/spec/features/admin/homepage/homepage_spec.rb b/spec/features/admin/homepage/homepage_spec.rb index 2dda511fd..67623a2ba 100644 --- a/spec/features/admin/homepage/homepage_spec.rb +++ b/spec/features/admin/homepage/homepage_spec.rb @@ -15,6 +15,9 @@ feature 'Homepage' do let(:proposals_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.proposals').first } let(:debates_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.debates').first } let(:processes_setting) { Setting.where(key: 'feature.homepage.widgets.feeds.processes').first } + let(:user_recommendations) { Setting.where(key: 'feature.user.recommendations').first } + let(:user) { create(:user) } + scenario "Header" do end @@ -101,3 +104,23 @@ feature 'Homepage' do expect(page).to have_css("img[alt='#{card2.image.title}']") end end + + scenario "Recomendations" do + proposal1 = create(:proposal, tag_list: "Sport") + proposal2 = create(:proposal, tag_list: "Sport") + create(:follow, followable: proposal1, user: user) + + visit admin_homepage_path + within("#setting_#{user_recommendations.id}") do + click_button "Enable" + end + + expect(page).to have_content "Value updated" + + login_as(user) + visit root_path + + expect(page).to have_content("Recommendations that may interest you") + end + +end \ No newline at end of file From 50fd540797716ef51b69a2156f8e30becf5e6a4d Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 23 May 2018 17:40:03 +0200 Subject: [PATCH 06/23] Adds styles and missing i18n for admin homepage --- app/assets/stylesheets/admin.scss | 2 +- app/assets/stylesheets/participation.scss | 3 +- app/helpers/admin_helper.rb | 6 +- app/views/admin/_menu.html.erb | 8 +-- app/views/admin/homepage/_card.html.erb | 39 ++++++----- app/views/admin/homepage/_cards.html.erb | 27 ++++---- app/views/admin/homepage/_setting.html.erb | 10 +-- app/views/admin/homepage/show.html.erb | 71 ++++++++++++--------- app/views/admin/widget/cards/_form.html.erb | 28 +++++--- app/views/admin/widget/cards/edit.html.erb | 9 ++- app/views/admin/widget/cards/new.html.erb | 11 +++- app/views/layouts/_admin_header.html.erb | 2 +- config/i18n-tasks.yml | 1 + config/locales/en/activerecord.yml | 5 ++ config/locales/en/admin.yml | 27 ++++++++ config/locales/en/general.yml | 3 + config/locales/es/activerecord.yml | 5 ++ config/locales/es/admin.yml | 27 ++++++++ config/locales/es/general.yml | 3 + 19 files changed, 205 insertions(+), 82 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 5538a2c59..d0367a8c1 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -279,7 +279,7 @@ $sidebar-active: #f4fcd0; } .no-margin-bottom { - margin-bottom: 0 !important; + margin-bottom: 0 !important; } // 02. Sidebar diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 9ecf29802..8a6867565 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -319,7 +319,8 @@ .legislation-process-new, .legislation-process-edit, .milestone-new, -.milestone-edit { +.milestone-edit, +.image-form { @include direct-uploads; } diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index b1f07dd05..c88deba56 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -37,7 +37,11 @@ module AdminHelper end def menu_customization? - ["pages", "images", "content_blocks"].include?(controller_name) + ["pages", "images", "content_blocks"].include?(controller_name) || menu_homepage? + end + + def menu_homepage? + ["homepage", "cards"].include?(controller_name) end def official_level_options diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 7336aad77..e59244e48 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -167,10 +167,10 @@
    > -
  • > - <%= link_to "Homepage", admin_homepage_path %> +
  • > + <%= link_to t("admin.menu.site_customization.homepage"), admin_homepage_path %>
  • - +
  • > <%= link_to t("admin.menu.site_customization.pages"), admin_site_customization_pages_path %>
  • @@ -183,7 +183,7 @@
  • > <%= link_to t("admin.menu.site_customization.content_blocks"), admin_site_customization_content_blocks_path%>
  • - +
diff --git a/app/views/admin/homepage/_card.html.erb b/app/views/admin/homepage/_card.html.erb index d1986d8f7..449bdbad5 100644 --- a/app/views/admin/homepage/_card.html.erb +++ b/app/views/admin/homepage/_card.html.erb @@ -1,22 +1,27 @@ <%= card.title %> <%= card.description %> - <%= card.link_text %> - <%= card.link_url %> - - - <% if card.image.present? %> - <%= image_tag(card.image_url(:thumb), - class: "margin", - alt: card.image.title) %> - <% end %> -
- <%= link_to "Edit", edit_admin_widget_card_path(card) %> -
- <%= link_to "Remove", admin_widget_card_path(card), - method: :delete, - data: { confirm: t('admin.actions.confirm') } %> -
+ <%= card.link_text %>
+ <%= card.link_url %> - \ No newline at end of file + + + + <% if card.image.present? %> + <%= link_to t("admin.shared.show_image"), card.image_url(:large), + title: card.image.title, target: "_blank" %> + <% end %> + + + <%= link_to t("admin.actions.edit"), + edit_admin_widget_card_path(card), + class: "button hollow" %> + + <%= link_to t("admin.actions.delete"), + admin_widget_card_path(card), + method: :delete, + data: { confirm: t('admin.actions.confirm') }, + class: "button hollow alert" %> + + diff --git a/app/views/admin/homepage/_cards.html.erb b/app/views/admin/homepage/_cards.html.erb index e6f2a7eac..ab75445fa 100644 --- a/app/views/admin/homepage/_cards.html.erb +++ b/app/views/admin/homepage/_cards.html.erb @@ -1,13 +1,16 @@ - - - - - - - - - <% cards.each do |card| %> - <%= render "card", card: card %> - <% end %> -
titletextlink textlinkimageactions
\ No newline at end of file + + + <%= t("admin.homepage.cards.title") %> + <%= t("admin.homepage.cards.description") %> + <%= t("admin.homepage.cards.link_text") %> / <%= t("admin.homepage.cards.link_url") %> + <%= t("admin.shared.image") %> + <%= t("admin.shared.actions") %> + + + + <% cards.each do |card| %> + <%= render "card", card: card %> + <% end %> + + diff --git a/app/views/admin/homepage/_setting.html.erb b/app/views/admin/homepage/_setting.html.erb index 89221e793..1398f6951 100644 --- a/app/views/admin/homepage/_setting.html.erb +++ b/app/views/admin/homepage/_setting.html.erb @@ -1,11 +1,11 @@
<%= form_for(setting, url: admin_setting_path(setting), method: :put) do |f| %> - <%= f.hidden_field :value, - value: (setting.enabled? ? "" : "active") %> - + <%= f.hidden_field :value, + value: (setting.enabled? ? "" : "active") %> + <%= f.submit(t("admin.settings.index.features.#{setting.enabled? ? 'disable' : 'enable'}"), - class: "button expanded #{setting.enabled? ? 'hollow alert' : 'success'}", + class: "button #{setting.enabled? ? 'hollow alert' : 'success'}", data: {confirm: t("admin.actions.confirm")}) %> <% end %> -
\ No newline at end of file +
diff --git a/app/views/admin/homepage/show.html.erb b/app/views/admin/homepage/show.html.erb index 0d6e3fc9f..b209a0ec6 100644 --- a/app/views/admin/homepage/show.html.erb +++ b/app/views/admin/homepage/show.html.erb @@ -1,35 +1,48 @@ -

Homepage

+

<%= t("admin.homepage.title") %>

-

The active modules appear in the homepage in the same order as here.

+

<%= t("admin.homepage.description") %>

+

<%= t("admin.homepage.header_title") %>

-

Cards

- -
- <%= link_to "Create header", new_admin_widget_card_path(header_card: true) %> -
- -
- <%= link_to "Create card", new_admin_widget_card_path %> -
- -
- <% if @cards.present? %> - <%= render "cards", cards: @cards %> - <% end %> -
- - -<% @settings.each do |setting| %> - -
- <%= t("settings.#{setting.key}") %> +
+ <%= link_to t("admin.homepage.create_header"), new_admin_widget_card_path(header_card: true), class: "button" %>
- <%= render "setting", setting: setting %> -<% end %> \ No newline at end of file + <% if @header.present? %> + <%= render "cards", cards: @header %> + <% else %> +
+ <%= t("admin.homepage.no_header") %> +
+ <% end %> +
+ +
+ +
+

<%= t("admin.homepage.cards_title") %>

+ +
+ <%= link_to t("admin.homepage.create_card"), new_admin_widget_card_path, class: "button" %> +
+ + <% if @cards.present? %> + <%= render "cards", cards: @cards %> + <% else %> +
+ <%= t("admin.homepage.no_cards") %> +
+ <% end %> +
+ +
+ +<% @settings.each do |setting| %> +
+

<%= t("settings.#{setting.key}") %>

+
+ <%= render "setting", setting: setting %> +
+
+<% end %> diff --git a/app/views/admin/widget/cards/_form.html.erb b/app/views/admin/widget/cards/_form.html.erb index 2e8a70295..ec10bd0f9 100644 --- a/app/views/admin/widget/cards/_form.html.erb +++ b/app/views/admin/widget/cards/_form.html.erb @@ -1,11 +1,23 @@ <%= form_for [:admin, @card] do |f| %> <%= f.text_field :title %> - <%= f.text_area :description %> - <%= f.text_field :link_text %> - <%= f.text_field :link_url %> - <%= f.hidden_field :header, value: @card.header? %> -
- <%= render 'images/nested_image', imageable: @card, f: f %> + + <%= f.text_area :description, rows: 5 %> + +
+ <%= f.text_field :link_text %>
- <%= f.submit %> -<% end %> \ No newline at end of file + +
+ <%= f.text_field :link_url %> +
+ + <%= f.hidden_field :header, value: @card.header? %> + +
+
+ <%= render 'images/nested_image', imageable: @card, f: f %> +
+
+ + <%= f.submit(t("admin.homepage.#{action_name}.#{@card.header? ? 'submit_header' : 'submit_card'}"), class: "button success") %> +<% end %> diff --git a/app/views/admin/widget/cards/edit.html.erb b/app/views/admin/widget/cards/edit.html.erb index 259dc7b82..b9e6045c9 100644 --- a/app/views/admin/widget/cards/edit.html.erb +++ b/app/views/admin/widget/cards/edit.html.erb @@ -1,2 +1,9 @@ -Edit +

+ <% if @card.header? %> + <%= t("admin.homepage.edit.header_title") %> + <% else %> + <%= t("admin.homepage.edit.card_title") %> + <% end %> +

+ <%= render "form" %> \ No newline at end of file diff --git a/app/views/admin/widget/cards/new.html.erb b/app/views/admin/widget/cards/new.html.erb index dae2d7b9f..9e7ee40b2 100644 --- a/app/views/admin/widget/cards/new.html.erb +++ b/app/views/admin/widget/cards/new.html.erb @@ -1,2 +1,9 @@ -New -<%= render "form" %> \ No newline at end of file +

+ <% if @card.header? %> + <%= t("admin.homepage.new.header_title") %> + <% else %> + <%= t("admin.homepage.new.card_title") %> + <% end %> +

+ +<%= render "form" %> diff --git a/app/views/layouts/_admin_header.html.erb b/app/views/layouts/_admin_header.html.erb index ebfe32db9..1e677045f 100644 --- a/app/views/layouts/_admin_header.html.erb +++ b/app/views/layouts/_admin_header.html.erb @@ -16,7 +16,7 @@

- <%= link_to namespaced_root_path do %> + <%= link_to admin_root_path do %> <%= setting['org_name'] %>
<%= namespaced_header_title %> <% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 04adffb48..2ad35f3c1 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -143,6 +143,7 @@ ignore_unused: - 'admin.settings.index.features.*' - 'admin.polls.*.submit_button' - 'admin.booths.*.submit_button' + - 'admin.homepage.*' - 'moderation.comments.index.filter*' - 'moderation.comments.index.order*' - 'moderation.debates.index.filter*' diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 2d5163cb0..b26e0552b 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -245,6 +245,11 @@ en: subject: Subject from: From body: Email content + widget/card: + title: Title + description: Description + link_text: Link text + link_url: Link URL errors: models: user: diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0292df944..809fddec6 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -499,6 +499,7 @@ en: stats: Statistics signature_sheets: Signature Sheets site_customization: + homepage: Homepage pages: Custom Pages images: Custom Images content_blocks: Custom content blocks @@ -958,6 +959,8 @@ en: actions: Actions title: Title description: Description + image: Image + show_image: Show image spending_proposals: index: geozone_filter_all: All zones @@ -1212,3 +1215,27 @@ en: status_draft: Draft status_published: Published locale: Language + homepage: + title: Homepage + description: The active modules appear in the homepage in the same order as here. + header_title: Header + no_header: There is no header. + create_header: Create header + cards_title: Cards + create_card: Create card + no_cards: There is no cards. + cards: + title: Title + description: Description + link_text: Link text + link_url: Link URL + new: + header_title: New header + submit_header: Create header + card_title: New card + submit_card: Create card + edit: + header_title: Edit header + submit_header: Save header + card_title: Edit card + submit_card: Save card diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index d99e5c60a..24f0bdfda 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -845,3 +845,6 @@ en: proposal: "Proposal" debate: "Debate" budget_investment: "Budget investment" + admin/widget: + header: + title: Administration \ No newline at end of file diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index d3a0c776a..0b247f4be 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -241,6 +241,11 @@ es: subject: Asunto from: Enviado por body: Contenido del email + widget/card: + title: Título + description: Descripción + link_text: Texto del enlace + link_url: URL del enlace errors: models: user: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 5d44c9a17..9487996ef 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -499,6 +499,7 @@ es: stats: Estadísticas signature_sheets: Hojas de firmas site_customization: + homepage: Homepage pages: Personalizar páginas images: Personalizar imágenes content_blocks: Personalizar bloques @@ -958,6 +959,8 @@ es: actions: Acciones title: Título description: Descripción + image: Imagen + show_image: Mostrar imagen spending_proposals: index: geozone_filter_all: Todos los ámbitos de actuación @@ -1212,3 +1215,27 @@ es: status_draft: Borrador status_published: Publicada locale: Idioma + homepage: + title: Homepage + description: Los módulos activos aparecerán en la homepage en el mismo orden que aquí. + header_title: Encabezado + create_header: Crear encabezado + no_header: No hay encabezado. + cards_title: Tarjetas + create_card: Crear tarjeta + no_cards: No hay tarjetas. + cards: + title: Título + description: Descripción + link_text: Texto del enlace + link_url: URL del enlace + new: + header_title: Nuevo encabezado + submit_header: Crear encabezado + card_title: Nueva tarjeta + submit_card: Crear tarjeta + edit: + header_title: Editar encabezado + submit_header: Guardar encabezado + card_title: Editar tarjeta + submit_card: Guardar tarjeta diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index eeca5f5d9..81e37d53d 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -844,3 +844,6 @@ es: proposal: "Propuesta" debate: "Debate" budget_investment: "Proyecto de gasto" + admin/widget: + header: + title: Administración \ No newline at end of file From 0ac6531612cbf9cc5b8a55f96a1615e26aea7406 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 23 May 2018 17:41:23 +0200 Subject: [PATCH 07/23] Adds styles for homepage users view --- app/assets/stylesheets/layout.scss | 120 ++++++++++++++---- app/views/welcome/_card.html.erb | 24 ++-- app/views/welcome/_cards.html.erb | 10 +- app/views/welcome/_feeds.html.erb | 26 ++-- app/views/welcome/_header.html.erb | 32 +++-- app/views/welcome/_recommended.html.erb | 10 +- .../welcome/_recommended_carousel.html.erb | 6 +- app/views/welcome/index.html.erb | 56 ++------ config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + 10 files changed, 167 insertions(+), 119 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index bafe9bf0a..4faf2221c 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -23,6 +23,7 @@ // 21. Related content // 22. Images // 23. Maps +// 24. Homepage // // 01. Global styles @@ -2224,17 +2225,17 @@ table { // 19. Recommended Section Home // ---------------------------- -.home-page { - - .push { - display: none; - } -} - .section-recommended { - padding: $line-height * 2 0; + background: #fafafa; + border-bottom: 1px solid $border; + border-top: 1px solid $border; + padding: $line-height 0; h2 { + margin-bottom: 0; + } + + p { margin-bottom: $line-height * 2; } @@ -2258,12 +2259,12 @@ table { .card { .card-section { - padding: $line-height 0; - max-width: rem-calc(300); margin: 0 auto; + max-width: none; + padding: 0; p { - font-size: rem-calc(15); + font-size: $base-font-size; text-align: left; } } @@ -2293,18 +2294,6 @@ table { width: 100%; } - .debates-inner { - border-top: 4px solid $debates; - } - - .proposals-inner { - border-top: 4px solid $proposals; - } - - .budget-investments-inner { - border-top: 4px solid $budget; - } - .debates-inner, .proposals-inner, .budget-investments-inner { @@ -2316,10 +2305,10 @@ table { } h4 { - margin-top: $line-height; - margin-bottom: 0; + margin-top: 0; + margin-bottom: $line-height; font-size: rem-calc(18); - min-height: rem-calc(50); + min-height: 0; } h5 { @@ -2338,9 +2327,21 @@ table { } } + .debates, + .proposals { + + a { + display: block; + margin-top: $line-height; + } + } + .debates-inner, .proposals-inner, .budget-investments-inner { + border: 1px solid $border; + padding: $line-height; + margin-right: $line-height; max-height: rem-calc(500); @include breakpoint(small) { @@ -2575,3 +2576,70 @@ table { color: #525252 !important; } } + +// 24. Homepage +// ------------ + +.home-page { + + a { + + p { + + &.description { + color: $text; + } + } + } + + a:hover { + + h3 { + color: #fff; + } + } +} + +.figure-card { + display: flex; + margin: 0 0 $line-height; + position: relative; + + a { + + h3, + .title { + color: #fff; + } + + &:hover { + text-decoration: none; + } + } + + figcaption { + bottom: 0; + color: #fff; + font-size: rem-calc(36); + line-height: rem-calc(36); + text-transform: uppercase; + padding: $line-height / 4 $line-height / 2; + position: absolute; + width: 100%; + + h3, + .title { + font-size: rem-calc(36); + line-height: rem-calc(36); + } + + span { + background: #fff; + border-radius: rem-calc(4); + color: #000; + display: inline; + font-size: $base-font-size; + padding: rem-calc(4) rem-calc(8); + } + } +} diff --git a/app/views/welcome/_card.html.erb b/app/views/welcome/_card.html.erb index 0d8ecdda8..a3ed3e37c 100644 --- a/app/views/welcome/_card.html.erb +++ b/app/views/welcome/_card.html.erb @@ -1,11 +1,15 @@ -
- <%= card.title %> - <%= card.description %> - <%= link_to card.link_text, card.link_url %> - - <% if card.image.present? %> - <%= image_tag(card.image_url(:large), - class: "margin", - alt: card.image.title) %> +
+ <%= link_to card.link_url do %> +
+ <% if card.image.present? %> + <%= image_tag(card.image_url(:large), alt: card.image.title) %> + <% end %> +
+ LABEL
+

<%= card.title %>

+
+
+

<%= card.description %>

+

<%= card.link_text %>

<% end %> -
\ No newline at end of file +
diff --git a/app/views/welcome/_cards.html.erb b/app/views/welcome/_cards.html.erb index 2e741363f..89596901d 100644 --- a/app/views/welcome/_cards.html.erb +++ b/app/views/welcome/_cards.html.erb @@ -1,5 +1,5 @@ -

Cards

- -<% @cards.all.each do |card| %> - <%= render "card", card: card %> -<% end %> \ No newline at end of file +
+ <% @cards.all.each do |card| %> + <%= render "card", card: card %> + <% end %> +
diff --git a/app/views/welcome/_feeds.html.erb b/app/views/welcome/_feeds.html.erb index 0f735d5d4..9c72efc43 100644 --- a/app/views/welcome/_feeds.html.erb +++ b/app/views/welcome/_feeds.html.erb @@ -1,16 +1,14 @@ -

Feeds

+
+
+ <% @feeds.each do |feed| %> -<% @feeds.each do |feed| %> - -
- Most active <%= feed.kind %> + Most active <%= feed.kind %> + + <% feed.items.each do |item| %> +
+ <%= item.title %> +
+ <% end %> + <% end %>
- - <% feed.items.each do |item| %> -
- <%= item.title %> -
-
- <% end %> - -<% end %> \ No newline at end of file +
diff --git a/app/views/welcome/_header.html.erb b/app/views/welcome/_header.html.erb index 610083c5a..3b49233bc 100644 --- a/app/views/welcome/_header.html.erb +++ b/app/views/welcome/_header.html.erb @@ -1,13 +1,21 @@ <% if header.present? %> - <%= header.title %> - <%= header.description %> - - <% if header.image.present? %> - <%= image_tag(header.image_url(:large), - class: "margin", - alt: header.image.title) %> - <% end %> - - <%= link_to header.button_text, header.button_url %> - <%= header.alignment %> -<% end %> \ No newline at end of file +
+
+
+

<%= header.title %>

+

<%= header.description %>

+
+ <%= link_to header.link_text, header.link_url, class: "button expanded large" %> +
+
+ + <% if header.image.present? %> +
+ <%= image_tag(header.image_url(:large), + class: "margin", + alt: header.image.title) %> +
+ <% end %> +
+
+<% end %> diff --git a/app/views/welcome/_recommended.html.erb b/app/views/welcome/_recommended.html.erb index 67251e749..fece2996a 100644 --- a/app/views/welcome/_recommended.html.erb +++ b/app/views/welcome/_recommended.html.erb @@ -1,8 +1,12 @@ -