Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create current topic #374

Merged
merged 11 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,38 @@
//= require cookieconsent.min
//= require newsletter_sign_up
//= require google_analytics
//= require jscookie

$(document).on('turbolinks:load', function () {
// Initialize Cookie Bar
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#1d1e21"
},
"button": {
"background": "#4cae18"
}
},
"theme": "classic",
"content": {
"message": "Tento web používa súbory cookie na poskytovanie služieb a analýzu webu. Používaním tohto webu vyjadrujete svoj súhlas s používaním súborov cookie.",
"dismiss": "OK"
},
"showLink": false
})
$(document).on("turbolinks:load", function () {
// Initialize Cookie Bar
window.cookieconsent.initialise({
palette: {
popup: {
background: "#1d1e21",
},
button: {
background: "#4cae18",
},
},
theme: "classic",
content: {
message:
"Tento web používa súbory cookie na poskytovanie služieb a analýzu webu. Používaním tohto webu vyjadrujete svoj súhlas s používaním súborov cookie.",
dismiss: "OK",
},
showLink: false,
});

var activeTopicClose = document.querySelector(".js__active-topic-close");
if (activeTopicClose) {
activeTopicClose.addEventListener("click", function (e) {
e.preventDefault();
Cookies.set("current_topic", activeTopicClose.dataset.key, {
expires: 365,
});
document
.querySelector(".active-topic")
.classList.add("active-topic__hidden");
});
}
});
41 changes: 41 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,44 @@
.notification-subscription-group .govuk-form-group:last-child {
margin-bottom: 0;
}

.active-topic {
background-color: #F3F2F1;
padding: 20px 0;
font-size: 1rem;
}

.active-topic p ,
.active-topic h1,
.active-topic h2,
.active-topic h3,
.active-topic h4,
.active-topic h5,
.active-topic h6 {
margin: 10px 0;
font-size: 1rem;
}

.active-topic p:first-child {
margin-top: 0;
}

.active-topic p:last-child {
margin-bottom: 0;
}

.active-topic__inner {
display: grid;
grid-template-columns: 1fr 100px;
grid-gap: 30px;
}

.active-topic__hidden {
display: none;
}

@media (max-width: 767px) {
.active-topic__inner {
grid-template-columns: 1fr;
}
}
32 changes: 32 additions & 0 deletions app/controllers/admin/current_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Admin::CurrentTopicsController < Admin::AdminController
before_action :set_current_topic, only: [:show, :edit, :update]

def index
current_topic = CurrentTopic.last
return redirect_to edit_admin_current_topic_path(current_topic) if current_topic.present?
redirect_to new_admin_current_topic_path
end

def new
@current_topic = CurrentTopic.new
end

def create
@current_topic = CurrentTopic.new(current_topic_params)
@current_topic.save!
redirect_to admin_current_topics_url
end

def update
@current_topic.update!(current_topic_params)
redirect_to admin_current_topics_url
end

private def set_current_topic
@current_topic = CurrentTopic.find_by!(id: params[:id])
end

private def current_topic_params
params.require(:current_topic).permit(:body, :enabled)
end
end
8 changes: 7 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base
before_action :set_default_metadata
before_action :set_default_metadata, :set_active_current_topic

protected

Expand Down Expand Up @@ -46,4 +46,10 @@ def set_default_metadata
)
)
end

def set_active_current_topic
active_current_topic = CurrentTopic.active
return if active_current_topic.blank? || cookies[:current_topic] == active_current_topic.key
@active_current_topic = active_current_topic
end
end
17 changes: 17 additions & 0 deletions app/models/current_topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CurrentTopic < ApplicationRecord

def key
Digest::MD5.hexdigest updated_at.to_s
end

def self.active
last_current_topic = self.last

return last_current_topic if last_current_topic.present? &&
last_current_topic.body.present? &&
last_current_topic.enabled == true

nil
end

end
30 changes: 30 additions & 0 deletions app/views/admin/current_topics/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= form_with(model: [:admin, current_topic], local: true, builder: AdminFormBuilder) do |form| %>

<div class="app-whitespace-highlight">
<div class="govuk-warning-text">
<span class="govuk-warning-text__icon" aria-hidden="true">!</span>
<strong class="govuk-warning-text__text">
<span class="govuk-warning-text__assistive">Pozor!</span>
Každou aktualizáciou sa užívateľom vynuluje skrytie banneru.
</strong>
</div>
</div>


<% if current_topic.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(current_topic.errors.count, "error") %> prohibited this current topic from being saved</h2>
</div>
<% end %>

<%= form.text_area :body, size: "60x12" %>
<%= form.check_box :enabled %>

<br />

<div class="actions">
<%= form.submit %>
</div>

</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/admin/current_topics/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', current_topic: @current_topic %>
1 change: 1 addition & 0 deletions app/views/admin/current_topics/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form', current_topic: @current_topic %>
12 changes: 12 additions & 0 deletions app/views/components/_active_topic.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="active-topic" role="banner">
<div class="govuk-width-container">
<div class="active-topic__inner">
<div>
<%= @active_current_topic.body.html_safe %>
</div>
<div>
<a href="#" class="js__active-topic-close" data-key="<%= @active_current_topic.key %>">Skryť správu</a>
</div>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<li class="govuk-header__navigation-item govuk-header__navigation-item<%= klass %>">
<%= link_to 'UserJourneys', admin_user_journeys_path, class: 'govuk-header__link' %>
</li>
<% klass = request.fullpath.include?(admin_current_topics_path) ? '--active' : '' %>
<li class="govuk-header__navigation-item govuk-header__navigation-item<%= klass %>">
<%= link_to 'CurrentTopics', admin_current_topics_path, class: 'govuk-header__link' %>
</li>
</ul>
</nav>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<% if content_for?(:before_main_wrapper) %>
<%= yield(:before_main_wrapper) %>
<% else %>
<%= render 'components/active_topic' if @active_current_topic.present? %>
<div class="govuk-width-container">
<%= yield(:before_content) %>

Expand Down
7 changes: 2 additions & 5 deletions app/views/pages/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<% content_for(:before_main_wrapper) do %>
<%= render 'searches/search_box' %>
<%= render 'components/active_topic' if @active_current_topic.present? %>

<main id="main-content" class="govuk-main-wrapper govuk-!-padding-top-0" role="main">
<div class="featured-journeys govuk-!-padding-top-9 govuk-!-padding-bottom-9">
<div class="govuk-width-container">
Expand All @@ -20,11 +22,6 @@
</div>
</div>
</div>
<!-- <div class="govuk-grid-row">-->
<!-- <div id="show-more-container" class="govuk-grid-column-full govuk-!-padding-top-6">-->
<%#= link_to 'Zobraziť viac', '#', class: 'govuk-button', role: 'button', draggable: false %>
<!-- </div>-->
<!-- </div>-->
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
post :reposition, on: :collection
end
resources :apps, except: [:show]
resources :current_topics, except: [:show, :destroy]
resources :pages, except: [:show]
resources :journeys, except: [:show] do
resources :steps, except: [:show] do
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20200919092214_create_current_topic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateCurrentTopic < ActiveRecord::Migration[6.0]
def change
create_table :current_topics do |t|
t.string :body
t.boolean :enabled
t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@
title: "Zaregistrujte sa na DPH",
type: "SimpleTask",
)

CurrentTopic.create!(
key: 'Brexit',
value: 'A Brexit deal has been agreed but needs to be ratified',
enabled: true
)
50 changes: 49 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,38 @@ CREATE TABLE public.ar_internal_metadata (
);


--
-- Name: current_topics; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.current_topics (
id bigint NOT NULL,
body character varying,
enabled boolean,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: current_topics_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.current_topics_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: current_topics_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.current_topics_id_seq OWNED BY public.current_topics.id;


--
-- Name: journeys; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -723,6 +755,13 @@ ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
ALTER TABLE ONLY public.apps ALTER COLUMN id SET DEFAULT nextval('public.apps_id_seq'::regclass);


--
-- Name: current_topics id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.current_topics ALTER COLUMN id SET DEFAULT nextval('public.current_topics_id_seq'::regclass);


--
-- Name: journeys id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -823,6 +862,14 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);


--
-- Name: current_topics current_topics_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.current_topics
ADD CONSTRAINT current_topics_pkey PRIMARY KEY (id);


--
-- Name: journeys journeys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1276,6 +1323,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190915104202'),
('20191209121011'),
('20200316102804'),
('20200316104715');
('20200316104715'),
('20200919092214');


Loading