From bb73dcac6cdc4d592220317616ce99b5a9b416ad Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 2 Apr 2020 17:26:40 +0100 Subject: [PATCH 1/9] Make CTAs as CMS components --- app/helpers/cms_helper.rb | 8 ++++++++ app/views/partials/ctas/_api.html.erb | 10 +++++----- app/views/partials/ctas/_live-report.html.erb | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 4f71cd5b4..86ebf2c38 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -72,4 +72,12 @@ def get_filtered_pages pages pages end + + def cta_api + @cta_api ||= Comfy::Cms::Page.find_by_slug('cta-api') + end + + def cta_live_report + @cta_live_report ||= Comfy::Cms::Page.find_by_slug('cta-live-report') + end end diff --git a/app/views/partials/ctas/_api.html.erb b/app/views/partials/ctas/_api.html.erb index 4193e1978..97068a7b9 100644 --- a/app/views/partials/ctas/_api.html.erb +++ b/app/views/partials/ctas/_api.html.erb @@ -1,10 +1,10 @@
-

<%= t('ctas.api.title') %>

-

<%= t('ctas.api.intro') %>

- - <%= link_to t('ctas.api.button'), t('ctas.api.url'), target: '_blank', class: 'button--outline-white' %> +

<%= cms_fragment_render(:title, cta_api) %>

+

<%= cms_fragment_render(:summary, cta_api) %>

+ + <%= link_to t('ctas.api.button'), cms_fragment_render(:link, cta_api), target: '_blank', class: 'button--outline-white' %>
-
\ No newline at end of file + diff --git a/app/views/partials/ctas/_live-report.html.erb b/app/views/partials/ctas/_live-report.html.erb index 0a2bfadeb..2b27b273d 100644 --- a/app/views/partials/ctas/_live-report.html.erb +++ b/app/views/partials/ctas/_live-report.html.erb @@ -4,11 +4,11 @@ <%= t('global.status.updated') %>
-

<%= t('ctas.live_report.title') %>

-

<%= t('ctas.live_report.intro') %>

+

<%= cms_fragment_render(:title, cta_live_report) %>

+

<%= cms_fragment_render(:summary, cta_live_report) %>

- <%= link_to t('ctas.live_report.button'), t('ctas.live_report.url'), target: '_blank', class: 'button--accent' %> + <%= link_to t('ctas.live_report.button'), cms_fragment_render(:link, cta_live_report), target: '_blank', class: 'button--accent' %> - \ No newline at end of file + From 172a565b06c9d19f9d26438b6594f556907768ad Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 7 Apr 2020 13:05:34 +0100 Subject: [PATCH 2/9] Refactor CTA to be a custom component --- app/controllers/admin/ctas_controller.rb | 61 +++++++++++++++++++ app/models/cta.rb | 16 +++++ app/views/admin/ctas/_form.html.haml | 10 +++ app/views/admin/ctas/edit.html.haml | 5 ++ app/views/admin/ctas/index.html.haml | 27 ++++++++ app/views/admin/ctas/new.html.haml | 5 ++ app/views/admin/ctas/show.html.haml | 20 ++++++ .../cms/partials/_navigation_inner.html.haml | 2 +- config/routes.rb | 1 + 9 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/ctas_controller.rb create mode 100644 app/models/cta.rb create mode 100644 app/views/admin/ctas/_form.html.haml create mode 100644 app/views/admin/ctas/edit.html.haml create mode 100644 app/views/admin/ctas/index.html.haml create mode 100644 app/views/admin/ctas/new.html.haml create mode 100644 app/views/admin/ctas/show.html.haml diff --git a/app/controllers/admin/ctas_controller.rb b/app/controllers/admin/ctas_controller.rb new file mode 100644 index 000000000..59b5733fa --- /dev/null +++ b/app/controllers/admin/ctas_controller.rb @@ -0,0 +1,61 @@ +class Admin::CtasController < Comfy::Admin::Cms::BaseController + before_action :build_cta, :only => [:new, :create] + before_action :load_cta, :only => [:show, :edit, :update, :destroy] + + def index + @ctas = Cta.page(params[:page]) + end + + def show + render + end + + def new + render + end + + def edit + render + end + + def create + @cta.save! + flash[:success] = 'CTA created' + redirect_to :action => :show, :id => @cta + rescue ActiveRecord::RecordInvalid + flash.now[:danger] = 'Failed to create CTA' + render :action => :new + end + + def update + @cta.update_attributes!(cta_params) + flash[:success] = 'CTA updated' + redirect_to :action => :show, :id => @cta + rescue ActiveRecord::RecordInvalid + flash.now[:danger] = 'Failed to update CTA' + render :action => :edit + end + + def destroy + @cta.destroy + flash[:success] = 'CTA deleted' + redirect_to :action => :index + end + + protected + + def build_cta + @cta = Cta.new(cta_params) + end + + def load_cta + @cta = Cta.find(params[:id]) + rescue ActiveRecord::RecordNotFound + flash[:danger] = 'CTA not found' + redirect_to :action => :index + end + + def cta_params + params.fetch(:cta, {}).permit(:klass, :title, :summary, :url, :updated) + end +end diff --git a/app/models/cta.rb b/app/models/cta.rb new file mode 100644 index 000000000..05d101019 --- /dev/null +++ b/app/models/cta.rb @@ -0,0 +1,16 @@ +class Cta < ActiveRecord::Base + self.table_name = "comfy_cms_cta" + + validates :title, + presence: true, + length: {maximum: 75}, + allow_nil: false + validates :summary, + presence: true, + length: {maximum: 150}, + allow_nil: false + validates :url, + presence: true, + length: {maximum: 255}, + allow_nil: false +end diff --git a/app/views/admin/ctas/_form.html.haml b/app/views/admin/ctas/_form.html.haml new file mode 100644 index 000000000..30580bfb0 --- /dev/null +++ b/app/views/admin/ctas/_form.html.haml @@ -0,0 +1,10 @@ +%p The title may have up to 75 characters and the description may have up to 150. + += form.text_field :klass, maxlength: 75 += form.text_field :title, maxlength: 75 += form.text_field :summary, maxlength: 150 += form.text_field :url, maxlength: 255 += form.check_box :updated + += form.form_group :class => 'form-actions' do + = form.submit :class => 'btn btn-primary' diff --git a/app/views/admin/ctas/edit.html.haml b/app/views/admin/ctas/edit.html.haml new file mode 100644 index 000000000..be148bd36 --- /dev/null +++ b/app/views/admin/ctas/edit.html.haml @@ -0,0 +1,5 @@ +.page-header + %h2 Edit CTA + += comfy_form_with model: @cta, url: {action: :update} do |form| + = render form diff --git a/app/views/admin/ctas/index.html.haml b/app/views/admin/ctas/index.html.haml new file mode 100644 index 000000000..0a3b891be --- /dev/null +++ b/app/views/admin/ctas/index.html.haml @@ -0,0 +1,27 @@ +.page-header + = link_to 'New CTA', new_admin_cta_path, :class => 'btn btn-default pull-right' + %h2= 'CTAs' + += will_paginate @ctas, :theme => 'comfy' + +%table.table.table-hover.table-bordered.wrap + %tr + %th.wrap Class (Max characters: 75) + %th.wrap Title (Max characters: 75) + %th.wrap Summary (Max characters: 150) + %th Url + %th Updated + %th + - @ctas.each do |cta| + %tr + %td.wrap= cta.klass + %td.wrap= cta.title + %td.wrap= cta.summary + %td= cta.url + %td= cta.updated.to_s + %td + .btn-group.btn-group-sm + = link_to 'Edit', edit_admin_cta_path(cta), :class => 'btn btn-default' + = link_to 'Delete', admin_cta_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' + += will_paginate @ctas, :theme => 'comfy' diff --git a/app/views/admin/ctas/new.html.haml b/app/views/admin/ctas/new.html.haml new file mode 100644 index 000000000..df694c35f --- /dev/null +++ b/app/views/admin/ctas/new.html.haml @@ -0,0 +1,5 @@ +.page-header + %h2 New CTA + += comfy_form_with model: @cta, url: {action: :create} do |form| + = render form diff --git a/app/views/admin/ctas/show.html.haml b/app/views/admin/ctas/show.html.haml new file mode 100644 index 000000000..82534ba36 --- /dev/null +++ b/app/views/admin/ctas/show.html.haml @@ -0,0 +1,20 @@ +.page-header + %h2 CTA + +%p + %strong Class: + = @cta.klass +%p + %strong Title: + = @cta.title +%p + %strong Summary: + = @cta.summary +%p + %strong Url: + = @cta.url +%p + %strong Updated: + = @cta.updated.to_s + += link_to 'CTAs', admin_ctas_path, :class => 'btn btn-primary' diff --git a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml b/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml index 19c6936cb..e0bbf1b46 100644 --- a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml +++ b/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml @@ -1,2 +1,2 @@ - %li= active_link_to 'HomeCarouselSlides', admin_home_carousel_slides_path +%li= active_link_to 'CTAs', admin_ctas_path diff --git a/config/routes.rb b/config/routes.rb index ee8c4ed62..baa2b49f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do namespace :admin do resources :home_carousel_slides + resources :ctas end require 'sidekiq/web' From 305107dca0957d5064a937ea7fcde58694450bce Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 7 Apr 2020 14:05:56 +0100 Subject: [PATCH 3/9] Use new CTA component in public interface --- app/helpers/cms_helper.rb | 4 ++-- app/views/partials/ctas/_api.html.erb | 6 +++--- app/views/partials/ctas/_live-report.html.erb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 86ebf2c38..8c30f86da 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -74,10 +74,10 @@ def get_filtered_pages pages end def cta_api - @cta_api ||= Comfy::Cms::Page.find_by_slug('cta-api') + @cta_api ||= Cta.find_by_klass('api') end def cta_live_report - @cta_live_report ||= Comfy::Cms::Page.find_by_slug('cta-live-report') + @cta_live_report ||= Cta.find_by_klass('live-report') end end diff --git a/app/views/partials/ctas/_api.html.erb b/app/views/partials/ctas/_api.html.erb index 97068a7b9..1b8439dda 100644 --- a/app/views/partials/ctas/_api.html.erb +++ b/app/views/partials/ctas/_api.html.erb @@ -1,10 +1,10 @@
-

<%= cms_fragment_render(:title, cta_api) %>

-

<%= cms_fragment_render(:summary, cta_api) %>

+

<%= cta_api.title %>

+

<%= cta_api.summary %>

- <%= link_to t('ctas.api.button'), cms_fragment_render(:link, cta_api), target: '_blank', class: 'button--outline-white' %> + <%= link_to t('ctas.api.button'), cta_api.url, target: '_blank', class: 'button--outline-white' %>
diff --git a/app/views/partials/ctas/_live-report.html.erb b/app/views/partials/ctas/_live-report.html.erb index 2b27b273d..ed3480b7f 100644 --- a/app/views/partials/ctas/_live-report.html.erb +++ b/app/views/partials/ctas/_live-report.html.erb @@ -4,11 +4,11 @@ <%= t('global.status.updated') %>
-

<%= cms_fragment_render(:title, cta_live_report) %>

-

<%= cms_fragment_render(:summary, cta_live_report) %>

+

<%= cta_live_report.title %>

+

<%= cta_live_report.summary %>

- <%= link_to t('ctas.live_report.button'), cms_fragment_render(:link, cta_live_report), target: '_blank', class: 'button--accent' %> + <%= link_to t('ctas.live_report.button'), cta_live_report.url, target: '_blank', class: 'button--accent' %> From 9e50f095d96462e0282c5eb8ad4930a391e3e88d Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 7 Apr 2020 16:37:13 +0100 Subject: [PATCH 4/9] Refactor and rename component --- ...roller.rb => call_to_actions_controller.rb} | 18 +++++++++--------- app/helpers/cms_helper.rb | 4 ++-- app/models/{cta.rb => call_to_action.rb} | 4 ++-- .../{ctas => call_to_actions}/_form.html.haml | 2 +- .../{ctas => call_to_actions}/edit.html.haml | 2 +- .../{ctas => call_to_actions}/index.html.haml | 10 +++++----- .../{ctas => call_to_actions}/new.html.haml | 2 +- .../{ctas => call_to_actions}/show.html.haml | 8 ++++---- .../cms/partials/_navigation_inner.html.haml | 2 +- config/routes.rb | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) rename app/controllers/admin/{ctas_controller.rb => call_to_actions_controller.rb} (62%) rename app/models/{cta.rb => call_to_action.rb} (75%) rename app/views/admin/{ctas => call_to_actions}/_form.html.haml (87%) rename app/views/admin/{ctas => call_to_actions}/edit.html.haml (78%) rename app/views/admin/{ctas => call_to_actions}/index.html.haml (54%) rename app/views/admin/{ctas => call_to_actions}/new.html.haml (78%) rename app/views/admin/{ctas => call_to_actions}/show.html.haml (53%) diff --git a/app/controllers/admin/ctas_controller.rb b/app/controllers/admin/call_to_actions_controller.rb similarity index 62% rename from app/controllers/admin/ctas_controller.rb rename to app/controllers/admin/call_to_actions_controller.rb index 59b5733fa..5eb14a3b2 100644 --- a/app/controllers/admin/ctas_controller.rb +++ b/app/controllers/admin/call_to_actions_controller.rb @@ -1,9 +1,9 @@ -class Admin::CtasController < Comfy::Admin::Cms::BaseController +class Admin::CallToActionsController < Comfy::Admin::Cms::BaseController before_action :build_cta, :only => [:new, :create] before_action :load_cta, :only => [:show, :edit, :update, :destroy] def index - @ctas = Cta.page(params[:page]) + @ctas = CallToAction.page(params[:page]) end def show @@ -20,19 +20,19 @@ def edit def create @cta.save! - flash[:success] = 'CTA created' + flash[:success] = 'Call To Action created' redirect_to :action => :show, :id => @cta rescue ActiveRecord::RecordInvalid - flash.now[:danger] = 'Failed to create CTA' + flash.now[:danger] = 'Failed to create Call To Action' render :action => :new end def update @cta.update_attributes!(cta_params) - flash[:success] = 'CTA updated' + flash[:success] = 'Call To action updated' redirect_to :action => :show, :id => @cta rescue ActiveRecord::RecordInvalid - flash.now[:danger] = 'Failed to update CTA' + flash.now[:danger] = 'Failed to update Call To Action' render :action => :edit end @@ -45,17 +45,17 @@ def destroy protected def build_cta - @cta = Cta.new(cta_params) + @cta = CallToAction.new(cta_params) end def load_cta - @cta = Cta.find(params[:id]) + @cta = CallToAction.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:danger] = 'CTA not found' redirect_to :action => :index end def cta_params - params.fetch(:cta, {}).permit(:klass, :title, :summary, :url, :updated) + params.fetch(:call_to_action, {}).permit(:css_class, :title, :summary, :url, :updated) end end diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 8c30f86da..d4e1a7591 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -74,10 +74,10 @@ def get_filtered_pages pages end def cta_api - @cta_api ||= Cta.find_by_klass('api') + @cta_api ||= CallToAction.find_by_css_class('api') end def cta_live_report - @cta_live_report ||= Cta.find_by_klass('live-report') + @cta_live_report ||= CallToAction.find_by_css_class('live-report') end end diff --git a/app/models/cta.rb b/app/models/call_to_action.rb similarity index 75% rename from app/models/cta.rb rename to app/models/call_to_action.rb index 05d101019..768f86b2b 100644 --- a/app/models/cta.rb +++ b/app/models/call_to_action.rb @@ -1,5 +1,5 @@ -class Cta < ActiveRecord::Base - self.table_name = "comfy_cms_cta" +class CallToAction < ActiveRecord::Base + self.table_name = "comfy_cms_call_to_actions" validates :title, presence: true, diff --git a/app/views/admin/ctas/_form.html.haml b/app/views/admin/call_to_actions/_form.html.haml similarity index 87% rename from app/views/admin/ctas/_form.html.haml rename to app/views/admin/call_to_actions/_form.html.haml index 30580bfb0..8a124b89b 100644 --- a/app/views/admin/ctas/_form.html.haml +++ b/app/views/admin/call_to_actions/_form.html.haml @@ -1,6 +1,6 @@ %p The title may have up to 75 characters and the description may have up to 150. -= form.text_field :klass, maxlength: 75 += form.text_field :css_class, maxlength: 75 = form.text_field :title, maxlength: 75 = form.text_field :summary, maxlength: 150 = form.text_field :url, maxlength: 255 diff --git a/app/views/admin/ctas/edit.html.haml b/app/views/admin/call_to_actions/edit.html.haml similarity index 78% rename from app/views/admin/ctas/edit.html.haml rename to app/views/admin/call_to_actions/edit.html.haml index be148bd36..e4276be8f 100644 --- a/app/views/admin/ctas/edit.html.haml +++ b/app/views/admin/call_to_actions/edit.html.haml @@ -1,5 +1,5 @@ .page-header - %h2 Edit CTA + %h2 Edit Call To Action = comfy_form_with model: @cta, url: {action: :update} do |form| = render form diff --git a/app/views/admin/ctas/index.html.haml b/app/views/admin/call_to_actions/index.html.haml similarity index 54% rename from app/views/admin/ctas/index.html.haml rename to app/views/admin/call_to_actions/index.html.haml index 0a3b891be..6cb9662ba 100644 --- a/app/views/admin/ctas/index.html.haml +++ b/app/views/admin/call_to_actions/index.html.haml @@ -1,6 +1,6 @@ .page-header - = link_to 'New CTA', new_admin_cta_path, :class => 'btn btn-default pull-right' - %h2= 'CTAs' + = link_to 'New Call To Action', new_admin_call_to_action_path, :class => 'btn btn-default pull-right' + %h2= 'Call To Actions' = will_paginate @ctas, :theme => 'comfy' @@ -14,14 +14,14 @@ %th - @ctas.each do |cta| %tr - %td.wrap= cta.klass + %td.wrap= cta.css_class %td.wrap= cta.title %td.wrap= cta.summary %td= cta.url %td= cta.updated.to_s %td .btn-group.btn-group-sm - = link_to 'Edit', edit_admin_cta_path(cta), :class => 'btn btn-default' - = link_to 'Delete', admin_cta_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' + = link_to 'Edit', edit_admin_call_to_action_path(cta), :class => 'btn btn-default' + = link_to 'Delete', admin_call_to_action_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' = will_paginate @ctas, :theme => 'comfy' diff --git a/app/views/admin/ctas/new.html.haml b/app/views/admin/call_to_actions/new.html.haml similarity index 78% rename from app/views/admin/ctas/new.html.haml rename to app/views/admin/call_to_actions/new.html.haml index df694c35f..707e020c4 100644 --- a/app/views/admin/ctas/new.html.haml +++ b/app/views/admin/call_to_actions/new.html.haml @@ -1,5 +1,5 @@ .page-header - %h2 New CTA + %h2 New Call To Action = comfy_form_with model: @cta, url: {action: :create} do |form| = render form diff --git a/app/views/admin/ctas/show.html.haml b/app/views/admin/call_to_actions/show.html.haml similarity index 53% rename from app/views/admin/ctas/show.html.haml rename to app/views/admin/call_to_actions/show.html.haml index 82534ba36..8e668e777 100644 --- a/app/views/admin/ctas/show.html.haml +++ b/app/views/admin/call_to_actions/show.html.haml @@ -1,9 +1,9 @@ .page-header - %h2 CTA + %h2 Call To Action %p - %strong Class: - = @cta.klass + %strong CSS Class: + = @cta.css_class %p %strong Title: = @cta.title @@ -17,4 +17,4 @@ %strong Updated: = @cta.updated.to_s -= link_to 'CTAs', admin_ctas_path, :class => 'btn btn-primary' += link_to 'Call To Actions', admin_call_to_actions_path, :class => 'btn btn-primary' diff --git a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml b/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml index e0bbf1b46..3084f1eea 100644 --- a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml +++ b/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml @@ -1,2 +1,2 @@ %li= active_link_to 'HomeCarouselSlides', admin_home_carousel_slides_path -%li= active_link_to 'CTAs', admin_ctas_path +%li= active_link_to 'CallToActions', admin_call_to_actions_path diff --git a/config/routes.rb b/config/routes.rb index baa2b49f0..c3f059af2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do namespace :admin do resources :home_carousel_slides - resources :ctas + resources :call_to_actions end require 'sidekiq/web' From 8cdc48b03a17dbe4c3a25ae9646e177fc32c94e7 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Tue, 7 Apr 2020 17:50:52 +0100 Subject: [PATCH 5/9] Tidy up link in the side nav --- .../comfy/admin/cms/partials/_navigation_inner.html.erb | 5 +++++ .../comfy/admin/cms/partials/_navigation_inner.html.haml | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 app/views/comfy/admin/cms/partials/_navigation_inner.html.erb delete mode 100644 app/views/comfy/admin/cms/partials/_navigation_inner.html.haml diff --git a/app/views/comfy/admin/cms/partials/_navigation_inner.html.erb b/app/views/comfy/admin/cms/partials/_navigation_inner.html.erb new file mode 100644 index 000000000..336928c89 --- /dev/null +++ b/app/views/comfy/admin/cms/partials/_navigation_inner.html.erb @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml b/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml deleted file mode 100644 index 3084f1eea..000000000 --- a/app/views/comfy/admin/cms/partials/_navigation_inner.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%li= active_link_to 'HomeCarouselSlides', admin_home_carousel_slides_path -%li= active_link_to 'CallToActions', admin_call_to_actions_path From cfc711338840f6f970d63532bedf74399629fd15 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Tue, 7 Apr 2020 18:08:32 +0100 Subject: [PATCH 6/9] Tidy up cms page a bit --- .../admin/call_to_actions/index.html.erb | 33 +++++++++++++++++++ .../admin/call_to_actions/index.html.haml | 27 --------------- .../admin/call_to_actions/show.html.haml | 2 +- db | 2 +- 4 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 app/views/admin/call_to_actions/index.html.erb delete mode 100644 app/views/admin/call_to_actions/index.html.haml diff --git a/app/views/admin/call_to_actions/index.html.erb b/app/views/admin/call_to_actions/index.html.erb new file mode 100644 index 000000000..37eb4c72b --- /dev/null +++ b/app/views/admin/call_to_actions/index.html.erb @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + <% @ctas.each do |cta| %> + + + + + + + + + <% end %> + +
Class (Max characters: 75)Title (Max characters: 75)Summary (Max characters: 150)UrlUpdated
<%= cta.css_class %><%= cta.title %><%= cta.summary %><%= cta.url %><%= cta.updated.to_s %> +
+ <%= link_to 'Edit', edit_admin_call_to_action_path(cta), :class => 'btn btn-outline-secondary' %> + <%= link_to 'Delete', admin_call_to_action_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' %> +
+
\ No newline at end of file diff --git a/app/views/admin/call_to_actions/index.html.haml b/app/views/admin/call_to_actions/index.html.haml deleted file mode 100644 index 6cb9662ba..000000000 --- a/app/views/admin/call_to_actions/index.html.haml +++ /dev/null @@ -1,27 +0,0 @@ -.page-header - = link_to 'New Call To Action', new_admin_call_to_action_path, :class => 'btn btn-default pull-right' - %h2= 'Call To Actions' - -= will_paginate @ctas, :theme => 'comfy' - -%table.table.table-hover.table-bordered.wrap - %tr - %th.wrap Class (Max characters: 75) - %th.wrap Title (Max characters: 75) - %th.wrap Summary (Max characters: 150) - %th Url - %th Updated - %th - - @ctas.each do |cta| - %tr - %td.wrap= cta.css_class - %td.wrap= cta.title - %td.wrap= cta.summary - %td= cta.url - %td= cta.updated.to_s - %td - .btn-group.btn-group-sm - = link_to 'Edit', edit_admin_call_to_action_path(cta), :class => 'btn btn-default' - = link_to 'Delete', admin_call_to_action_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' - -= will_paginate @ctas, :theme => 'comfy' diff --git a/app/views/admin/call_to_actions/show.html.haml b/app/views/admin/call_to_actions/show.html.haml index 8e668e777..b01ca5689 100644 --- a/app/views/admin/call_to_actions/show.html.haml +++ b/app/views/admin/call_to_actions/show.html.haml @@ -17,4 +17,4 @@ %strong Updated: = @cta.updated.to_s -= link_to 'Call To Actions', admin_call_to_actions_path, :class => 'btn btn-primary' += link_to 'View all', admin_call_to_actions_path, :class => 'btn btn-primary' diff --git a/db b/db index 997bd14cb..2a5852e93 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 997bd14cbe4411ce5657d8fd0282f6760bffe653 +Subproject commit 2a5852e93ff823eb1f1537e0c10badf35fed8fce From fc56b7ac1b81bd0750ecde63834883df194cc96d Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Tue, 7 Apr 2020 21:23:15 +0100 Subject: [PATCH 7/9] Refactor and add tests --- .../admin/call_to_actions_controller.rb | 18 +-- .../admin/call_to_actions_controller_test.rb | 107 ++++++++++++++++++ test/factories/call_to_action.rb | 9 ++ test/models/call_to_action_test.rb | 28 +++++ 4 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 test/controllers/admin/call_to_actions_controller_test.rb create mode 100644 test/factories/call_to_action.rb create mode 100644 test/models/call_to_action_test.rb diff --git a/app/controllers/admin/call_to_actions_controller.rb b/app/controllers/admin/call_to_actions_controller.rb index 5eb14a3b2..d95f5bdeb 100644 --- a/app/controllers/admin/call_to_actions_controller.rb +++ b/app/controllers/admin/call_to_actions_controller.rb @@ -21,25 +21,25 @@ def edit def create @cta.save! flash[:success] = 'Call To Action created' - redirect_to :action => :show, :id => @cta + redirect_to action: :show, id: @cta rescue ActiveRecord::RecordInvalid flash.now[:danger] = 'Failed to create Call To Action' - render :action => :new + render action: :new end def update @cta.update_attributes!(cta_params) - flash[:success] = 'Call To action updated' - redirect_to :action => :show, :id => @cta + flash[:success] = 'Call To Action updated' + redirect_to action: :show, id: @cta rescue ActiveRecord::RecordInvalid flash.now[:danger] = 'Failed to update Call To Action' - render :action => :edit + render action: :edit end def destroy @cta.destroy - flash[:success] = 'CTA deleted' - redirect_to :action => :index + flash[:success] = 'Call To Action deleted' + redirect_to action: :index end protected @@ -51,8 +51,8 @@ def build_cta def load_cta @cta = CallToAction.find(params[:id]) rescue ActiveRecord::RecordNotFound - flash[:danger] = 'CTA not found' - redirect_to :action => :index + flash[:danger] = 'Call To Action not found' + redirect_to action: :index end def cta_params diff --git a/test/controllers/admin/call_to_actions_controller_test.rb b/test/controllers/admin/call_to_actions_controller_test.rb new file mode 100644 index 000000000..3a8c47673 --- /dev/null +++ b/test/controllers/admin/call_to_actions_controller_test.rb @@ -0,0 +1,107 @@ +require_relative '../../test_helper' + +class Admin::CallToActionsControllerTest < ActionController::TestCase + + def setup + @cta = FactoryGirl.create(:call_to_action) + @site = ::Comfy::Cms::Site.create(label: 'test', identifier: 'test', hostname: 'localhost') + @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{ComfortableMexicanSofa::AccessControl::AdminAuthentication.username}:#{ComfortableMexicanSofa::AccessControl::AdminAuthentication.password}") + end + + def test_get_index + get :index + assert_response :success + assert assigns(:ctas) + assert_template :index + end + + def test_get_show + get :show, params: {id: @cta} + assert_response :success + assert assigns(:cta) + assert_template :show + end + + def test_get_show_failure + get :show, params: {id: 'invalid'} + assert_response :redirect + assert_redirected_to action: :index + assert_equal 'Call To Action not found', flash[:danger] + end + + def test_get_new + get :new + assert_response :success + assert assigns(:cta) + assert_template :new + end + + def test_get_edit + get :edit, params: {id: @cta} + assert_response :success + assert assigns(:cta) + assert_template :edit + end + + def test_creation + assert_difference 'CallToAction.count' do + post :create, params: { + call_to_action: { + title: 'test title', + summary: 'test summary', + url: 'test url' + } + } + cta = CallToAction.last + assert_response :redirect + assert_redirected_to admin_call_to_action_path(cta) + assert_equal 'Call To Action created', flash[:success] + end + end + + def test_creation_failure + assert_no_difference 'CallToAction.count' do + post :create, params: {call_to_action: {}} + assert_response :success + assert_template :new + assert_equal 'Failed to create Call To Action', flash[:danger] + end + end + + def test_update + put :update, params: { + id: @cta, + call_to_action: { + title: 'Updated' + } + } + assert_response :redirect + assert_redirected_to action: :show, id: @cta + assert_equal 'Call To Action updated', flash[:success] + @cta.reload + assert_equal 'Updated', @cta.title + end + + def test_update_failure + put :update, params: { + id: @cta, + call_to_action: { + title: '' + } + } + assert_response :success + assert_template :edit + assert_equal 'Failed to update Call To Action', flash[:danger] + @cta.reload + refute_equal '', @cta.title + end + + def test_destroy + assert_difference 'CallToAction.count', -1 do + delete :destroy, params: {id: @cta} + assert_response :redirect + assert_redirected_to action: :index + assert_equal 'Call To Action deleted', flash[:success] + end + end +end diff --git a/test/factories/call_to_action.rb b/test/factories/call_to_action.rb new file mode 100644 index 000000000..843774cf3 --- /dev/null +++ b/test/factories/call_to_action.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :call_to_action do + css_class 'css_class' + title 'Title' + summary 'Summary' + url 'URL' + updated false + end +end diff --git a/test/models/call_to_action_test.rb b/test/models/call_to_action_test.rb new file mode 100644 index 000000000..320a8d7a3 --- /dev/null +++ b/test/models/call_to_action_test.rb @@ -0,0 +1,28 @@ +require_relative '../test_helper' + +class CallToActionTest < ActiveSupport::TestCase + + def test_fixtures_validity + CallToAction.all.each do |cta| + assert cta.valid?, cta.errors.inspect + end + end + + def test_validation + cta = CallToAction.new + assert cta.invalid? + assert_equal [:title, :summary, :url], cta.errors.keys + end + + def test_creation + assert_difference 'CallToAction.count' do + CallToAction.create( + css_class: 'css_class', + title: 'test title', + summary: 'test summary', + url: 'test url' + ) + end + end + +end From 5a6c4efaf80357936016de76653d6726e1020e70 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 8 Apr 2020 09:11:42 +0100 Subject: [PATCH 8/9] Refactor views to be html ERB instead of haml --- .../admin/call_to_actions/_form.html.erb | 10 ++++++++ .../admin/call_to_actions/_form.html.haml | 10 -------- app/views/admin/call_to_actions/edit.html.erb | 6 +++++ .../admin/call_to_actions/edit.html.haml | 5 ---- .../admin/call_to_actions/index.html.erb | 5 +--- app/views/admin/call_to_actions/new.html.erb | 6 +++++ app/views/admin/call_to_actions/new.html.haml | 5 ---- app/views/admin/call_to_actions/show.html.erb | 24 +++++++++++++++++++ .../admin/call_to_actions/show.html.haml | 20 ---------------- 9 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 app/views/admin/call_to_actions/_form.html.erb delete mode 100644 app/views/admin/call_to_actions/_form.html.haml create mode 100644 app/views/admin/call_to_actions/edit.html.erb delete mode 100644 app/views/admin/call_to_actions/edit.html.haml create mode 100644 app/views/admin/call_to_actions/new.html.erb delete mode 100644 app/views/admin/call_to_actions/new.html.haml create mode 100644 app/views/admin/call_to_actions/show.html.erb delete mode 100644 app/views/admin/call_to_actions/show.html.haml diff --git a/app/views/admin/call_to_actions/_form.html.erb b/app/views/admin/call_to_actions/_form.html.erb new file mode 100644 index 000000000..efc2e358f --- /dev/null +++ b/app/views/admin/call_to_actions/_form.html.erb @@ -0,0 +1,10 @@ +

The title may have up to 75 characters and the description may have up to 150.

+ +<%= form.text_field :css_class, maxlength: 75 %> +<%= form.text_field :title, maxlength: 75 %> +<%= form.text_field :summary, maxlength: 150 %> +<%= form.text_field :url, maxlength: 255 %> +<%= form.check_box :updated %> +<%= form.form_group class: 'form-actions' do %> + <%= form.submit class: 'btn btn-primary' %> +<% end %> diff --git a/app/views/admin/call_to_actions/_form.html.haml b/app/views/admin/call_to_actions/_form.html.haml deleted file mode 100644 index 8a124b89b..000000000 --- a/app/views/admin/call_to_actions/_form.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -%p The title may have up to 75 characters and the description may have up to 150. - -= form.text_field :css_class, maxlength: 75 -= form.text_field :title, maxlength: 75 -= form.text_field :summary, maxlength: 150 -= form.text_field :url, maxlength: 255 -= form.check_box :updated - -= form.form_group :class => 'form-actions' do - = form.submit :class => 'btn btn-primary' diff --git a/app/views/admin/call_to_actions/edit.html.erb b/app/views/admin/call_to_actions/edit.html.erb new file mode 100644 index 000000000..03be5a6a9 --- /dev/null +++ b/app/views/admin/call_to_actions/edit.html.erb @@ -0,0 +1,6 @@ + +<%= comfy_form_with model: @cta, url: {action: :update} do |form| %> + <%= render form %> +<% end %> diff --git a/app/views/admin/call_to_actions/edit.html.haml b/app/views/admin/call_to_actions/edit.html.haml deleted file mode 100644 index e4276be8f..000000000 --- a/app/views/admin/call_to_actions/edit.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -.page-header - %h2 Edit Call To Action - -= comfy_form_with model: @cta, url: {action: :update} do |form| - = render form diff --git a/app/views/admin/call_to_actions/index.html.erb b/app/views/admin/call_to_actions/index.html.erb index 37eb4c72b..eb36abd57 100644 --- a/app/views/admin/call_to_actions/index.html.erb +++ b/app/views/admin/call_to_actions/index.html.erb @@ -3,8 +3,6 @@

Call To Actions

- - @@ -29,5 +27,4 @@ <% end %> - -
Class (Max characters: 75)
\ No newline at end of file + diff --git a/app/views/admin/call_to_actions/new.html.erb b/app/views/admin/call_to_actions/new.html.erb new file mode 100644 index 000000000..c1ddd25dd --- /dev/null +++ b/app/views/admin/call_to_actions/new.html.erb @@ -0,0 +1,6 @@ + +<%= comfy_form_with model: @cta, url: {action: :create} do |form| %> + <%= render form %> +<% end %> diff --git a/app/views/admin/call_to_actions/new.html.haml b/app/views/admin/call_to_actions/new.html.haml deleted file mode 100644 index 707e020c4..000000000 --- a/app/views/admin/call_to_actions/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -.page-header - %h2 New Call To Action - -= comfy_form_with model: @cta, url: {action: :create} do |form| - = render form diff --git a/app/views/admin/call_to_actions/show.html.erb b/app/views/admin/call_to_actions/show.html.erb new file mode 100644 index 000000000..af53e89ae --- /dev/null +++ b/app/views/admin/call_to_actions/show.html.erb @@ -0,0 +1,24 @@ + +

+ CSS Class: + <%= @cta.css_class %> +

+

+ Title: + <%= @cta.title %> +

+

+ Summary: + <%= @cta.summary %> +

+

+ Url: + <%= @cta.url %> +

+

+ Updated: + <%= @cta.updated.to_s %> +

+<%= link_to 'View all', admin_call_to_actions_path, class: 'btn btn-primary' %> diff --git a/app/views/admin/call_to_actions/show.html.haml b/app/views/admin/call_to_actions/show.html.haml deleted file mode 100644 index b01ca5689..000000000 --- a/app/views/admin/call_to_actions/show.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -.page-header - %h2 Call To Action - -%p - %strong CSS Class: - = @cta.css_class -%p - %strong Title: - = @cta.title -%p - %strong Summary: - = @cta.summary -%p - %strong Url: - = @cta.url -%p - %strong Updated: - = @cta.updated.to_s - -= link_to 'View all', admin_call_to_actions_path, :class => 'btn btn-primary' From 0dcc6d506d9c884abad107ead408e13a5e528a93 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Wed, 8 Apr 2020 09:11:44 +0100 Subject: [PATCH 9/9] Hook up view to cms --- app/views/partials/ctas/_live-report.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/partials/ctas/_live-report.html.erb b/app/views/partials/ctas/_live-report.html.erb index ed3480b7f..086651cd0 100644 --- a/app/views/partials/ctas/_live-report.html.erb +++ b/app/views/partials/ctas/_live-report.html.erb @@ -1,7 +1,9 @@ -
+
- <%= t('global.status.updated') %> + <% if cta_live_report.updated %> + <%= t('global.status.updated') %> + <% end %>

<%= cta_live_report.title %>