Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #71 from akiko-pusu/dev
Browse files Browse the repository at this point in the history
Ready for release v0.1.2
  • Loading branch information
akiko-pusu authored Jun 28, 2016
2 parents 15a7e9a + 9ca009a commit 72ed8f7
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 574 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
40 changes: 40 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-06-01 07:37:41 +0900 using RuboCop version 0.40.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
Metrics/AbcSize:
Max: 55

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 200

# "Line is too long"を無効
Metrics/LineLength:
Enabled: false

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 10

# Avoid methods longer than 10 lines of code
MethodLength:
CountComments: true # count full line comments?
Max: 45

# Aboid Missing top-level module documentation comment.
Documentation:
Enabled: false

EndOfLine:
Enabled: false
12 changes: 12 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ For Redmine 1.x, use the following command:

== Changelog

=== 0.1.2

* Fix style and css selector. (Github: #45)
* Change global banner style for responsive mode. (Github: #68)
* Code refactoring.
* Fix: Prevent deprecation warning. (Github PR: #60) Thanks, Wojciech.
* Refactor: Rename file to prevent conflict (Github #63 / r-labs: 54).
* i18n: Update Italian translation file. (Github: #61 / r-labs: 57) Thanks, R-i-c-k-y.
* i18n: Add Spanish translation file. (Github: #61 / r-labs: 52) Thanks Picazamora!
* i18n: Update Turkish translation file. (Github: #64) Thank you so much, Adnan.
* i18n: Update Portuguese translation file. (Github: #50) Thanks, Guilherme.

=== 0.1.1

* Support Redmine 3.x.
Expand Down
44 changes: 20 additions & 24 deletions app/controllers/banner_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,53 @@ class BannerController < ApplicationController
# NOTE: Authorized user can turn off banner while their in session. (Changed from version 0.0.9)
# If Administrator hope to disable site wide banner, please go to settings page and uncheck
# eabned checkbox.
before_filter :require_login, :only => [:off]
before_filter :find_user, :find_project, :authorize, :except => [ :preview, :off]
before_filter :require_login, only: [:off]
before_filter :find_user, :find_project, :authorize, except: [:preview, :off]

def preview
@text = params[:settings][:banner_description]
render :partial => 'common/preview'
render partial: 'common/preview'
end

#
# Turn off (hide) banner while in user's session.
#
def off
begin
session[:pref_banner_off] = Time.now.to_i
render
rescue Exception => exc
logger.warn("Message for the log file / When off banner #{exc.message}")
render :text => ""
end
session[:pref_banner_off] = Time.now.to_i
render
rescue => e
logger.warn("Message for the log file / When off banner #{e.message}")
render text: ''
end

def project_banner_off
@banner = Banner.find_or_create(@project.id)
@banner.enabled = false
@banner.save
render :text => ""
render text: ''
end

def edit
if (params[:settings] != nil)
unless params[:settings].nil?
@banner = Banner.find_or_create(@project.id)
banner_params = params[:settings] || {}
@banner.update_attributes(banner_params)
@banner.save
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects',
:action => "settings", :id => @project, :tab => 'banner'
end
redirect_to controller: 'projects',
action: 'settings', id: @project, tab: 'banner'
end
end

private

def find_user
@user = User.current
end

def find_project
begin
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end

end
69 changes: 33 additions & 36 deletions app/models/banner.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
class Banner < ActiveRecord::Base
include Redmine::SafeAttributes
unloadable
belongs_to :project

validates_uniqueness_of :project_id
validates :project_id, :presence => true
validates_inclusion_of :display_part, :in=> ['all', 'new_issue', 'overview','overview_and_issues']
validates_inclusion_of :style, :in=> ['info','warn','alert', 'normal', 'nodata']
# project should be stable.
safe_attributes 'banner_description', 'style', 'start_date', 'end_date', 'enabled', 'use_timer', 'display_part'
attr_accessible :enabled, :style, :display_part, :banner_description

def self.find_or_create(project_id)
banner = Banner.where(['project_id = ?', project_id]).first()
unless banner.present?
banner = Banner.new
banner.project_id = project_id
banner.enabled = false

# Set default (Also set default by migration file)
banner.display_part = "all"
banner.style = "info"
banner.save!
end
return banner
end

def enable_banner?
if self.enabled == true && !self.banner_description.blank?
return true
end
return false
end

end
class Banner < ActiveRecord::Base
include Redmine::SafeAttributes
unloadable
belongs_to :project

validates_uniqueness_of :project_id
validates :project_id, presence: true
validates_inclusion_of :display_part, in: %w(all new_issue overview overview_and_issues)
validates_inclusion_of :style, in: %w(info warn alert normal nodata)
# project should be stable.
safe_attributes 'banner_description', 'style', 'start_date', 'end_date', 'enabled', 'use_timer', 'display_part'
attr_accessible :enabled, :style, :display_part, :banner_description

def self.find_or_create(project_id)
banner = Banner.where(['project_id = ?', project_id]).first
unless banner.present?
banner = Banner.new
banner.project_id = project_id
banner.enabled = false

# Set default (Also set default by migration file)
banner.display_part = 'all'
banner.style = 'info'
banner.save!
end
banner
end

def enable_banner?
return true if enabled == true && !banner_description.blank?
false
end
end
13 changes: 8 additions & 5 deletions app/views/banner/_after_top_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<%
-%>
<%= render :partial=>'banner/body_bottom' %>
<%= render 'banner/body_bottom' %>
<script type="text/javascript">
$(document).ready(function(){
$('#banner_area').insertAfter($('#top-menu'));
$(document).ready(function () {
displayTopBanner();
});

$(window).resize(function () {
console.log("resize");
displayTopBanner();
});
</script>

6 changes: 3 additions & 3 deletions app/views/banner/_body_bottom.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
banner_description = Setting.plugin_redmine_banner['banner_description'];
banner_description.force_encoding("UTF-8") if banner_description.respond_to?(:force_encoding)
-%>
<div id="banner_area" class="banner_area global_banner">
<div class="banner_area" class="banner_area global_banner">
<div class="banner banner_<%= Setting.plugin_redmine_banner['type'] %>" id="banner_content">
<%= textilizable banner_description %>
</div>
<div id="banner_edit">
<div class="banner_edit">
<%= link_to l(:button_edit),
{:controller => 'settings', :action => 'plugin', :id => 'redmine_banner'},
{:class => 'icon banner-icon-edit', :title => l(:button_edit)} if User.current.admin? %>
Expand All @@ -24,7 +24,7 @@
</div>

<% if Setting.plugin_redmine_banner['related_link'].present? %>
<div id="banner_more_info">
<div class="banner_more_info">
<%= link_to l(:more_info), Setting.plugin_redmine_banner['related_link'],
{:class => 'icon external', :title => l(:label_more_info)} %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/banner/_project_body_bottom.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
display_part = banner.display_part
return '' unless BannerHelper.is_action_to_display?(@_controller, display_part)
%>
<div id="project_banner_area" class="banner_area">
<div class="project_banner_area" class="banner_area">
<div class="banner banner_<%= banner.style %>" id="banner_content">
<%= textilizable banner.banner_description %>
</div>

<%
<%
if authorize_for(:banner, :edit)
%>
<div id="banner_edit">
<div class="banner_edit">
<%= link_to l(:button_edit),
{:controller => 'projects', :action => "settings", :id => @project, :tab => 'banner'},
{:class => 'icon banner-icon-edit', :title => l(:button_edit)} %>
Expand All @@ -37,6 +37,6 @@ if authorize_for(:banner, :edit)
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#project_banner_area').prependTo('div#content');
$('.project_banner_area').prependTo('div#content');
});
</script>
54 changes: 27 additions & 27 deletions app/views/settings/_redmine_banner.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<%
banner_description = @settings['banner_description'];
banner_description.force_encoding("UTF-8") if banner_description.respond_to?(:force_encoding)
banner_description = @settings['banner_description'];
banner_description.force_encoding("UTF-8") if banner_description.respond_to?(:force_encoding)
%>
<!-- confirmation popup -->
<script type="text/javascript">

$("#plugin").submit(function(event) {
$("#plugin").submit(function(event) {
var confirm_msg = "<%= l(:text_are_you_sure) %>";
var date_range_error_msg = "<%= l(:error_banner_date_range) %>";
if (!checkDateRange(event, confirm_msg, date_range_error_msg)) {
return false;
return false;
} else {
this.submit();
this.submit();
}
});
});
</script>
<p>
<%=content_tag(:label, l(:button_activate))%>
Expand All @@ -34,23 +34,23 @@ $("#plugin").submit(function(event) {
</p>

<p>
<%=content_tag(:label, l(:setting_banner_display_part))%>
<%= select_tag('settings[display_part]',
options_for_select([[l(:label_header_only),'header'],
[l(:label_footer_only),'footer'],[l(:label_both),'both']],@settings['display_part'])) %>
<%=check_box_tag 'settings[display_only_login_page]', true, @settings['display_only_login_page'] == "true" %>
<%=content_tag(:label, l(:setting_banner_display_part))%>
<%= select_tag('settings[display_part]',
options_for_select([[l(:label_header_only),'header'],
[l(:label_footer_only),'footer'],[l(:label_both),'both']],@settings['display_part'])) %>
<%=check_box_tag 'settings[display_only_login_page]', true, @settings['display_only_login_page'] == "true" %>
<%= l(:lalel_check_if_banner_show_only_login_page) %>
</p>

<p>
<%=content_tag(:label, l(:label_banner_message)) %>
<%=text_area_tag 'settings[banner_description]', banner_description, :size =>"40x3",
:class => 'wiki-edit' ,:required => true %><br/>
</p>
<%= wikitoolbar_for "settings_banner_description" %>
<%=text_area_tag 'settings[banner_description]', banner_description, :size =>"40x3",
:class => 'wiki-edit' ,:required => true %><br/>
</p>
<%= wikitoolbar_for "settings_banner_description" %>

<%= preview_link url_for(:controller => 'banner', :action => 'preview'), 'plugin',
target='banner_description_preview' %>
<%= preview_link url_for(:controller => 'banner', :action => 'preview'), 'plugin',
target='banner_description_preview' %>

<div id="banner_description_preview" class="wiki"></div>

Expand All @@ -71,23 +71,23 @@ $("#plugin").submit(function(event) {
<p>
<%=content_tag(:label, l(:label_start_datetime))%>
<%= text_field_tag 'settings[start_ymd]', @start_datetime.strftime("%Y-%m-%d"), :size => 10 %>
<%= select_hour @start_datetime, :prefix => 'settings', :field_name => 'start_hour',
:time_separator => ':', :include_seconds => false %>:
<%= select_hour @start_datetime, :prefix => 'settings', :field_name => 'start_hour',
:time_separator => ':', :include_seconds => false %>:
<%= select_minute @start_datetime, :prefix => 'settings', :field_name => 'start_min', :time_separator => ':', :include_seconds => false %>
<%= calendar_for('settings_start_ymd') %> (exp. 2012-12-31 11:00)
<br/>
</p>

<p>
<%=content_tag(:label, l(:label_end_datetime))%>
<p>
<%=content_tag(:label, l(:label_end_datetime))%>
<%= text_field_tag 'settings[end_ymd]', @end_datetime.strftime("%Y-%m-%d"), :size => 10 %>
<%= select_hour @end_datetime, :prefix => 'settings',:field_name => 'end_hour',
:time_separator => ':', :include_seconds => false,:disabled => !@settings['use_timer'] == "true" %>:
<%= select_minute @end_datetime, :prefix => 'settings',:field_name => 'end_min',
:time_separator => ':', :include_seconds => false,:disabled => !@settings['use_timer'] == "true" %>
<%= select_hour @end_datetime, :prefix => 'settings',:field_name => 'end_hour',
:time_separator => ':', :include_seconds => false,:disabled => !@settings['use_timer'] == "true" %>:
<%= select_minute @end_datetime, :prefix => 'settings',:field_name => 'end_min',
:time_separator => ':', :include_seconds => false,:disabled => !@settings['use_timer'] == "true" %>
<%= calendar_for('settings_end_ymd') %> (exp. 2013-01-01 11:00)
<br/>
</p>
<br/>
</p>
</div>

<p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/settings/plugin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div id="settings">
<%= form_tag({:action => 'plugin'},{:id => :plugin }) do %>
<div class="box tabular">
<%= render :partial => @partial, :locals => {:settings => @settings}%>
<%= render @partial, settings: @settings %>
</div>
<%= submit_tag l(:button_apply) %>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions assets/javascripts/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ function checkDateValue(event, confirm_msg, error_msg) {
}
return true;
}

function displayTopBanner() {
if (window.matchMedia( '(max-width: 899px)' ).matches) {
$('#content').prepend($('.banner_area').first());
} else {
$('.banner_area').first().insertAfter($('#top-menu'));
};
}
Loading

0 comments on commit 72ed8f7

Please sign in to comment.