Commit b66a26b6 authored by Tiago Botelho's avatar Tiago Botelho Committed by André Luís

Add system header and footer options to the application appearances

parent 9ae9d46c
...@@ -50,9 +50,19 @@ class Admin::AppearancesController < Admin::ApplicationController ...@@ -50,9 +50,19 @@ class Admin::AppearancesController < Admin::ApplicationController
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def appearance_params def appearance_params
params.require(:appearance).permit( params.require(:appearance).permit(%i(
:title, :description, :logo, :logo_cache, :header_logo, :header_logo_cache, title
:new_project_guidelines, :updated_by description
) logo
logo_cache
header_logo
header_logo_cache
new_project_guidelines
updated_by
header_message
footer_message
background_color
font_color
))
end end
end end
module AppearancesHelper module AppearancesHelper
def header_message(appearance)
return unless appearance.header_message.present?
appearance_message(appearance, :header_message)
end
def footer_message(appearance)
return unless appearance.footer_message.present?
appearance_message(appearance, :footer_message)
end
def appearance_message(appearance, field_sym)
class_names = [field_sym.to_s.dasherize]
class_names << 'with-performance-bar' if performance_bar_enabled?
content_tag :div, class: class_names, style: message_style(appearance) do
icon('bullhorn') << ' ' << render_message(appearance, field_sym)
end
end
def message_style(appearance)
style = ''
if appearance.background_color.present?
style << "background-color: #{appearance.background_color}"
style << '; ' if appearance.font_color.present?
end
if appearance.font_color.present?
style << "color: #{appearance.font_color}"
end
style
end
def render_message(appearance, field)
Banzai.render_field(appearance, field).html_safe
end
def brand_title def brand_title
brand_item&.title.presence || 'GitLab Enterprise Edition' brand_item&.title.presence || 'GitLab Enterprise Edition'
end end
......
...@@ -5,12 +5,19 @@ class Appearance < ActiveRecord::Base ...@@ -5,12 +5,19 @@ class Appearance < ActiveRecord::Base
cache_markdown_field :description cache_markdown_field :description
cache_markdown_field :new_project_guidelines cache_markdown_field :new_project_guidelines
cache_markdown_field :header_message
cache_markdown_field :footer_message
validates :background_color, allow_blank: true, color: true
validates :font_color, allow_blank: true, color: true
validates :logo, file_size: { maximum: 1.megabyte } validates :logo, file_size: { maximum: 1.megabyte }
validates :header_logo, file_size: { maximum: 1.megabyte } validates :header_logo, file_size: { maximum: 1.megabyte }
validate :single_appearance_row, on: :create validate :single_appearance_row, on: :create
default_value_for :background_color, '#E75E40'
default_value_for :font_color, '#FFFFFF'
mount_uploader :logo, AttachmentUploader mount_uploader :logo, AttachmentUploader
mount_uploader :header_logo, AttachmentUploader mount_uploader :header_logo, AttachmentUploader
......
...@@ -18,6 +18,29 @@ ...@@ -18,6 +18,29 @@
.hint .hint
Maximum file size is 1MB. Pages are optimized for a 28px tall header logo Maximum file size is 1MB. Pages are optimized for a 28px tall header logo
%fieldset.system_header_footer
%legend
System header and footer:
.form-group
= f.label :header_message, 'Header message', class: 'control-label'
.col-sm-10
= f.text_area :header_message, placeholder: 'State your message to activate', class: "form-control js-autosize"
.form-group
= f.label :footer_message, 'Footer message', class: 'control-label'
.col-sm-10
= f.text_area :footer_message, placeholder: 'State your message to activate', class: "form-control js-autosize"
.form-group.js-toggle-colors-container
.col-sm-10.col-sm-offset-2
= link_to 'Customize colors', '#', class: 'js-toggle-colors-link'
.form-group.js-toggle-colors-container.hide
= f.label :background_color, "Background Color", class: 'control-label'
.col-sm-10
= f.color_field :background_color, class: "form-control"
.form-group.js-toggle-colors-container.hide
= f.label :font_color, "Font Color", class: 'control-label'
.col-sm-10
= f.color_field :font_color, class: "form-control"
%fieldset.sign-in %fieldset.sign-in
%legend %legend
Sign in/Sign up pages: Sign in/Sign up pages:
......
= footer_message(Appearance.current)
= header_message(Appearance.current)
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
%body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page, project: "#{@project.path if @project}", group: "#{@group.path if @group}", find_file: find_file_path } } %body{ class: "#{user_application_theme} #{@body_class}", data: { page: body_data_page, project: "#{@project.path if @project}", group: "#{@group.path if @group}", find_file: find_file_path } }
= render "layouts/init_auto_complete" if @gfm_form = render "layouts/init_auto_complete" if @gfm_form
= render 'peek/bar' = render 'peek/bar'
= render "layouts/header_message"
= render "layouts/header/default" = render "layouts/header/default"
= render 'layouts/page', sidebar: sidebar, nav: nav = render 'layouts/page', sidebar: sidebar, nav: nav
= render "layouts/footer_message"
= yield :scripts_body = yield :scripts_body
class AddHeaderAndFooterBannersToAppearancesTable < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :appearances, :header_message, :text
add_column :appearances, :header_message_html, :text
add_column :appearances, :footer_message, :text
add_column :appearances, :footer_message_html, :text
add_column :appearances, :background_color, :text
add_column :appearances, :font_color, :text
end
end
...@@ -39,6 +39,12 @@ ActiveRecord::Schema.define(version: 20180327101207) do ...@@ -39,6 +39,12 @@ ActiveRecord::Schema.define(version: 20180327101207) do
t.integer "cached_markdown_version" t.integer "cached_markdown_version"
t.text "new_project_guidelines" t.text "new_project_guidelines"
t.text "new_project_guidelines_html" t.text "new_project_guidelines_html"
t.text "header_message"
t.text "header_message_html"
t.text "footer_message"
t.text "footer_message_html"
t.text "background_color"
t.text "font_color"
end end
create_table "application_settings", force: :cascade do |t| create_table "application_settings", force: :cascade do |t|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment