#757: add logic for enable/disable "auto_create_container" field on UI, some refactoring

This commit is contained in:
Vokhmin Alexey V 2013-02-22 14:20:47 +04:00
parent 38b6375ca3
commit 79d81e9c13
6 changed files with 22 additions and 22 deletions

View File

@ -10,10 +10,12 @@ $(document).ready(function() {
var all_repositories = $('.all_platforms input');
all_repositories.removeAttr('checked');
var use_save_to_repository = $('#build_list_use_save_to_repository');
var auto_create_container = $('#build_list_auto_create_container');
if (build_platform.size() == 0) {
all_repositories.removeAttr('disabled');
use_save_to_repository.removeAttr('disabled');
auto_create_container.removeAttr('checked');
} else {
updateExtraReposAndContainers();
use_save_to_repository.attr('disabled', 'disabled').attr('checked', 'checked');
@ -31,6 +33,7 @@ $(document).ready(function() {
build_list_auto_publish.removeAttr('disabled').attr('checked', 'checked');
} else {
build_list_auto_publish.removeAttr('checked').attr('disabled', 'disabled');
auto_create_container.attr('checked', 'checked');
}
var path = '/build_lists/autocomplete_to_extra_repos_and_containers?platform_id=' + platform_id;

View File

@ -33,11 +33,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController
end
def publish
if @build_list.can_publish_to_repository?
render_json :publish
else
render_validation_error @build_list, t('layout.build_lists.publish_with_extra_fail')
end
render_json :publish
end
def reject_publish

View File

@ -173,12 +173,8 @@ class Projects::BuildListsController < Projects::BaseController
end
if @build_list.save && @build_list.can_publish?
if @build_list.can_publish_to_repository? && @build_list.now_publish
redirect_to :back, :notice => t('layout.build_lists.publish_success')
else
redirect_to :back, :notice => t('layout.build_lists.publish_with_extra_fail')
end
if @build_list.save && @build_list.can_publish? && @build_list.now_publish
redirect_to :back, :notice => t('layout.build_lists.publish_success')
else
redirect_to :back, :notice => t('layout.build_lists.publish_fail')
end

View File

@ -196,8 +196,7 @@ class BuildList < ActiveRecord::Base
end
event :publish do
transition [:success, :failed_publish, :build_published, :tests_failed] => :build_publish,
:if => :can_publish_to_repository?
transition [:success, :failed_publish, :build_published, :tests_failed] => :build_publish
transition [:success, :failed_publish] => :failed_publish
end
@ -275,7 +274,7 @@ class BuildList < ActiveRecord::Base
end
def can_create_container?
(can_publish? || build_publish?) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
[SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
end
#TODO: Share this checking on product owner.
@ -283,8 +282,9 @@ class BuildList < ActiveRecord::Base
build_started? || build_pending?
end
def can_publish?
[SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include? status
def can_publish?(check_only_status = false)
by_status = [SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED].include?(status)
check_only_status ? by_status : (by_status && can_publish_to_repository?)
end
def can_publish_to_repository?
@ -293,7 +293,7 @@ class BuildList < ActiveRecord::Base
end
def can_reject_publish?
can_publish? && !save_to_repository.publish_without_qa && !build_published?
[SUCCESS, FAILED_PUBLISH, TESTS_FAILED].include?(status) && !save_to_repository.publish_without_qa
end
def add_to_queue

View File

@ -151,11 +151,16 @@
- if can?(:publish, @build_list)
- if @build_list.build_published?
= submit_tag t("layout.publish_again"), :confirm => t("layout.publish_again_warning"), :name => 'publish'
- elsif @build_list.can_publish?
- confirm = @build_list.tests_failed? ? t('layout.build_lists.tests_failed') : t('layout.confirm')
- elsif @build_list.can_publish?(true)
- if !@build_list.can_publish_to_repository?
- confirm = t('layout.build_lists.publish_with_extra_fail')
- elsif @build_list.tests_failed?
- confirm = t('layout.build_lists.tests_failed')
- else
- confirm = t('layout.confirm')
= submit_tag t("layout.publish"), :confirm => confirm, :name => 'publish'
- if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish'
- if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish'
- if @build_list.can_create_container? && can?(:create_container, @build_list)
= link_to t("layout.build_lists.create_container"), create_container_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'

View File

@ -17,7 +17,7 @@ module AbfWorker
case status
when COMPLETED
subject.build_success
subject.now_publish if subject.auto_publish?
subject.now_publish if subject.auto_publish? && subject.can_publish?
when FAILED
subject.build_error
item.update_attributes({:status => BuildList::BUILD_ERROR})