Skip to content
Open
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
3 changes: 2 additions & 1 deletion app/controllers/release_log_configurations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ReleaseLogConfigurationsController < ReleaseLogsBaseController
include ReleaseLogsHelper

layout 'admin'
unloadable

helper :release_logs
Expand Down Expand Up @@ -53,7 +54,7 @@ def load_configuration
end

def load_dependencies
@valid_project_selections = Project.all - ReleaseLogConfiguration.all.map(&:project)
@valid_project_selections = Project.all
@release_log_queues = ReleaseLogQueue.all
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/release_log_queues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ReleaseLogQueuesController < ReleaseLogsBaseController
layout 'admin'
unloadable

include ReleaseLogsHelper
Expand Down
27 changes: 24 additions & 3 deletions app/controllers/release_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ReleaseLogsController < ReleaseLogsBaseController
before_filter :load_project
before_filter :authorize
before_filter :load_configuration
before_filter :load_dependencies
before_filter :load_versions
before_filter :load_release_log, :only => [:edit, :show, :update, :destroy, :clone, :send_notification]

def index
Expand Down Expand Up @@ -44,7 +46,8 @@ def clone
:description => release_log.description,
:send_email_notification => release_log.send_email_notification,
:release_upon_publish => release_log.release_upon_publish,
:released_at => release_log.released_at
:released_at => release_log.released_at,
:hotfix => release_log.hotfix

@release_log.release_log_entries = release_log.release_log_entries.map do |entry|
ReleaseLogEntry.new :issue_id => entry.issue_id,
Expand Down Expand Up @@ -102,7 +105,11 @@ def save_release_log
should_publish = params[:publish] && !@release_log.published?

unless params[:release_date].blank? || params[:release_hour].blank? || params[:release_minutes].blank?
release_date = Date.parse(params[:release_date]).in_time_zone
if Rails::VERSION::MAJOR >= 4
release_date = Date.parse(params[:release_date]).in_time_zone
else
release_date = Date.parse(params[:release_date]).to_time_in_current_zone
end
release_date = User.current.time_zone.present? ? release_date.in_time_zone(User.current.time_zone) : (release_date.utc? ? release_date.localtime : release_date)
release_date = release_date.change(:hour => params[:release_hour].to_i, :min => params[:release_minutes].to_i)
@release_log.released_at = release_date
Expand All @@ -116,7 +123,7 @@ def save_release_log
release_log_entry.release_log = @release_log
end

@release_log.title = @release_log.queue_title_for_release_log if @project.queue_release_log_enabled?
@release_log.title = @release_log.queue_title_for_release_log if @release_log.release_log_queue and @release_log.release_log_queue.title_template?

if should_publish
@release_log.publish(User.current)
Expand Down Expand Up @@ -176,7 +183,10 @@ def release_log_params
if Rails::VERSION::MAJOR >= 4
params.require(:release_log).permit(:title,
:description,
:release_log_queue_id,
:version_id,
:send_email_notification,
:hotfix,
:release_upon_publish,
:release_date,
:release_hour,
Expand Down Expand Up @@ -228,6 +238,17 @@ def load_configuration
end
end

def load_dependencies
@release_log_queues = ReleaseLogQueue.joins('RIGHT JOIN release_log_configurations ON release_log_configurations.release_log_queue_id=release_log_queues.id').where('release_log_configurations.enabled = 1 AND release_log_configurations.project_id = :project', :project => @project.id)
end

def load_versions
# Small bug here, either all versions are loaded, or only open version are loaded
# If only open versions are loaded, on edit if the edited version is not open, it is changed
#@versions = @project.shared_versions.where(:status => ['open', 'locked'])
@versions = @project.shared_versions
end

def load_release_log
@release_log = ReleaseLog.find(params[:id])
end
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/release_logs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ def release_logs_help_for(entry, options = {})
def user_date(date)
User.current.time_zone.present? ? date.in_time_zone(User.current.time_zone) : (date.utc? ? date.localtime : date)
end

def options_from_collection_for_select_with_attributes(collection, value_method, text_method, attr_name, attr_field, selected = nil)
options = collection.map do |element|
[element.send(text_method), element.send(value_method), attr_name => element.send(attr_field)]
end

selected, disabled = extract_selected_and_disabled(selected)
select_deselect = {}
select_deselect[:selected] = extract_values_from_collection(collection, value_method, selected)
select_deselect[:disabled] = extract_values_from_collection(collection, value_method, disabled)
options_for_select(options, select_deselect)
end
end
14 changes: 8 additions & 6 deletions app/models/release_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReleaseLog < ActiveRecord::Base
acts_as_attachable :view_permission => :view_project_release_logs,
:delete_permission => :manage_project_release_logs

before_save :assign_to_release_log_queue
#before_save :assign_to_release_log_queue

### Scopes ###
scope :for_project, lambda { |project| where(:project_id => project.id) }
Expand Down Expand Up @@ -86,6 +86,7 @@ class ReleaseLog < ActiveRecord::Base
validates :release_log_entries, :association_count => { :minimum => 1 }
validates :rollback_reason, :presence => { :if => 'rolled_back_at.present?' }
validates :cancellation_reason, :presence => { :if => 'cancelled_at.present?' }
validate :release_log_queue_id
validate :unique_issues

def created_on
Expand Down Expand Up @@ -127,7 +128,8 @@ def status

def queue_title_for_release_log
date = release_upon_publish ? DateTime.now : (released_at.presence || DateTime.now)
project.release_log_configuration.release_log_queue.generate_title(project, date)
version = Version.find(version_id) if version_id?
ReleaseLogQueue.find(release_log_queue_id).generate_title(project, date, version)
end

def publish(user)
Expand All @@ -141,10 +143,10 @@ def publish(user)

protected

def assign_to_release_log_queue
proj = self.project || Project.find(self.project_id)
self.release_log_queue_id = proj.release_log_configuration.release_log_queue.id if proj.release_log_configuration.present? && proj.release_log_configuration.release_log_queue.present?
end
# def assign_to_release_log_queue
# proj = self.project || Project.find(self.project_id)
# self.release_log_queue_id = proj.release_log_configuration.release_log_queue.id if proj.release_log_configuration.present? && proj.release_log_configuration.release_log_queue.present?
# end

def unique_issues
issues = release_log_entries.select{ |entry| !entry.marked_for_destruction? }.map(&:issue_id).compact
Expand Down
2 changes: 1 addition & 1 deletion app/models/release_log_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ReleaseLogConfiguration < ActiveRecord::Base
scope :enabled, lambda { where(:enabled => true) }
scope :for_project, lambda { |project_id| where(:project_id => project_id) }

validates :project_id, :presence => true, :uniqueness => true
validates :project_id, :presence => true, :uniqueness => { scope: :release_log_queue_id }
validates :email_notification_recipients, :presence => { :unless => 'release_log_queue_id.present?' }, :multiple_email_addresses => true

def enabled?
Expand Down
14 changes: 11 additions & 3 deletions app/models/release_log_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class ReleaseLogQueue < ActiveRecord::Base
:project_name => lambda { |project| project.name }
}.freeze

VERSION_INTERPOLATIONS = {
:version => lambda { |version| version.name }
}.freeze

has_many :release_log_entry_categories, :dependent => :destroy, :inverse_of => :release_log_queue
has_many :release_log_notifications, :dependent => :nullify, :inverse_of => :release_log_queue
has_many :release_logs, :dependent => :nullify, :inverse_of => :release_log_queue
Expand All @@ -32,13 +36,13 @@ class ReleaseLogQueue < ActiveRecord::Base
:length => { :maximum => 255 },
:uniqueness => true

validates :title_template, :presence => true, :length => { :maximum => 255 }
validates :title_template, :length => { :maximum => 255 }

validates :email_notification_recipients, :presence => true, :multiple_email_addresses => true
validates :email_notification_recipients, :multiple_email_addresses => true

validate :title_template_syntax

def generate_title(project = Project.new(:name => 'TestProject'), date = Date.today)
def generate_title(project = Project.new(:name => 'TestProject'), date = Date.today, version = Version.new(:name => 'TestVersion'))
return nil unless title_template.present?

title = DATE_INTERPOLATIONS.to_a.inject(title_template) do |title, interpolation|
Expand All @@ -48,6 +52,10 @@ def generate_title(project = Project.new(:name => 'TestProject'), date = Date.to
PROJECT_INTERPOLATIONS.to_a.inject(title) do |title, interpolation|
title.gsub("{{#{interpolation[0]}}}", interpolation[1].call(project))
end

VERSION_INTERPOLATIONS.to_a.inject(title) do |title, interpolation|
title.gsub("{{#{interpolation[0]}}}", interpolation[1].call(version))
end
end

def recipient_addresses
Expand Down
2 changes: 1 addition & 1 deletion app/views/release_log_entries/_issue_release_log.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<%= format_time release_log.released_at %>
<%= issue_failed_release_info(release_log).html_safe %> -
<strong>
<%= link_to release_log.title, release_log_path(release_log, :project_id => release_log.project.identifier), :target => '_blank' %>
<%= link_to [release_log.title, release_log.release_log_queue.name].join(' - '), release_log_path(release_log, :project_id => release_log.project.identifier), :target => '_blank' %>
</strong>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<h1 style="font-size: 16px; font-weight: bold; background: #075490; border: 1px solid #084B8A; color: #fff; padding: 10px; margin-bottom: 5px;">
<%= @release_log.title %> - <%= @release_log.project.name %> - <%= release_logs_label_for(:release_publish_notification) %></h1>
<br/>
<%= @release_log.title %> - <%= @release_log.project.name %> - <%= release_logs_label_for(:release_publish_notification) %>

<% if @release_log.hotfix %>
- <span style="color: #ff8000;"><%= release_logs_label_for(:hotfix) %></span>
<% end %>
</h1>

<span style="font-size: 14px;">
<% future = !@release_log.release_upon_publish && @release_log.released_at.present? && @release_log.released_at >= Time.current
date = future ? release_logs_label_for(:date_on, :date => "#{user_date(@release_log.released_at).strftime('%A')}, #{format_time(@release_log.released_at)}") : release_logs_label_for(:shortly) %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/release_log_queues/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</p>

<p>
<%= form.text_field :title_template, :required => true %>
<%= form.text_field :title_template %>
</p>

<p>
<%= form.text_area :email_notification_recipients, :rows => 5, :required => true %>
<%= form.text_area :email_notification_recipients, :rows => 5 %>
<br />
<span class="release-log-info">
<%= release_logs_help_for(:configuration_recipients)%>
Expand Down
24 changes: 18 additions & 6 deletions app/views/release_logs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@
<legend><strong><%= release_logs_label_for(:properties) %></strong></legend>

<div class="tabular">
<% unless @project.release_log_enabled? && @project.release_log_configuration.release_log_queue.present? %>
<p>
<%= form.text_field :title, :required => true, :class => 'wide' %>
</p>
<% end %>
<p>
<%= form.text_field :title, :required => true, :class => 'wide' %>
</p>

<p>
<%= form.select :version_id,
options_from_collection_for_select(@versions, :id, :name, release_log.version_id) %>
</p>

<p>
<%= form.select :release_log_queue_id,
options_from_collection_for_select_with_attributes(@release_log_queues, :id, :name, 'data-title-template', :title_template, release_log.release_log_queue_id) %>
</p>

<p>
<%= form.check_box :hotfix %>
</p>

<p>
<%= form.text_area :description,
Expand Down Expand Up @@ -51,7 +63,7 @@

<% released_at = (User.current.time_zone.present? ? @release_log.released_at.in_time_zone(User.current.time_zone) : (@release_log.released_at.utc? ? @release_log.released_at.localtime : @release_log.released_at)) if @release_log.released_at.present? %>

<%= text_field_tag :release_date,
<%= date_field_tag :release_date,
released_at.try(:to_date),
:no_label => true %>
<%= calendar_for('release_date') %>
Expand Down
12 changes: 9 additions & 3 deletions app/views/release_logs/_release_log_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</tr>

<tr>
<th><%= release_logs_label_for(:id) %></th>
<th><%= release_logs_label_for(:queue) %></th>
<% if all_mode %>
<th><%= release_logs_label_for(:project) %></th>
<% end %>
Expand All @@ -38,7 +38,13 @@

<tr>
<td class="release-log-id">
<strong><%= link_to release_log.id, release_log_path(release_log, :project_id => release_log.project.identifier) %></strong>
<strong><%= link_to release_log.release_log_queue.nil? ? release_log.id : release_log.release_log_queue.name, release_log_path(release_log, :project_id => release_log.project.identifier) %></strong>
<% if release_log.hotfix %>
<span class="release-log-hotfix">
<br />
(<%= release_logs_label_for(:hotfix) %>)
</span>
<% end %>
</td>

<% if all_mode %>
Expand Down Expand Up @@ -104,4 +110,4 @@
</tbody>
</table>

<p class="pagination"><%= pagination_links_full @release_log_pages, @release_log_count %></p>
<span class="pagination"><%= pagination_links_full @release_log_pages, @release_log_count %></span>
6 changes: 5 additions & 1 deletion app/views/release_logs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
can_manage = User.current.allowed_to?(:manage_project_release_logs, @project)
%>

<h2><%= @release_log.title %> - <%= @release_log.status.titleize %></h2>
<h2><%= @release_log.title %> <%= if !@release_log.release_log_queue.nil? then ['-',@release_log.release_log_queue.name].join(' ') end %> - <%= @release_log.status.titleize %></h2>

<% if @release_log.hotfix %>
<h3><span style="color: #ff8000;"><%= release_logs_label_for(:hotfix_title) %></span></h3>
<% end %>

<div class="details">
<% if can_manage %>
Expand Down
25 changes: 25 additions & 0 deletions assets/javascripts/release-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ jQuery(document).ready(function () {
}
};

var setFieldVisibility = function () {
var $title_template = $('#release_log_release_log_queue_id option:selected').data('title-template');
if ($title_template) {
$('#release_log_title').parent('p').hide();
if ($title_template.indexOf('{{version}}') >= 0) {
$('#release_log_version_id').parent('p').show();
}
else {
$('#release_log_version_id').parent('p').hide();
}
}
else {
$('#release_log_title').parent('p').show();
$('#release_log_version_id').parent('p').hide();
}
};

setFieldVisibility();

$('#add-new-release-log').on('click', function (event) {
event.preventDefault();

Expand Down Expand Up @@ -144,4 +163,10 @@ jQuery(document).ready(function () {
$container.find('.preview-content').html('');
$container.hide();
});

$('#release_log_release_log_queue_id').on('change', function (event) {
event.preventDefault();

setFieldVisibility();
});
});
2 changes: 2 additions & 0 deletions assets/stylesheets/release-logs.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ td.release-log-entry-note-column { text-align: justify !important; }
.release-log-entry-field-container .splitcontentleft { width: 30% !important; }
.release-log-entry-field-container .splitcontentright { width: 68% !important; }

.release-log-hotfix { color: #ff8000; }

.release-log-action-container { display: none; margin-top: 60px; clear: both;}
.preview-release-log { margin-left: 10px; }
#release_preview_log_container { display: none; margin-top: 20px; }
Expand Down
Loading