#349: added #automatic_metadata_regeneration to Platform

This commit is contained in:
Vokhmin Alexey V 2014-02-12 00:23:34 +04:00
parent ec40018d9b
commit 6c471c50b1
10 changed files with 74 additions and 15 deletions

View File

@ -0,0 +1,17 @@
RosaABF.controller('AutomaticMetadataRegenerationController', ['$scope', '$http', function($scope, $http) {
// See: Platfrom::AUTOMATIC_METADATA_REGENERATIONS
$scope.items = {
'day': 'platform.automatic_metadata_regeneration.day',
'week': 'platform.automatic_metadata_regeneration.week'
};
$scope.platform_id = null;
$scope.update = function() {
$http.put(
Routes.platform_path($scope.platform_id),
{platform: {automatic_metadata_regeneration: $scope.amr}, format: 'json'}
);
}
}]);

View File

@ -11,6 +11,8 @@ var _locales = {
'Всего %1 тега', 'Всего %1 тега',
'Всего %1 тегов' 'Всего %1 тегов'
], ],
'platform.automatic_metadata_regeneration.day': 'Раз в день',
'platform.automatic_metadata_regeneration.week': 'Раз в неделю',
<%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %>
}, },
<%I18n.locale = :en%> <%I18n.locale = :en%>
@ -23,6 +25,8 @@ var _locales = {
'Total %1 tag', 'Total %1 tag',
'Total %1 tags' 'Total %1 tags'
], ],
'platform.automatic_metadata_regeneration.day': 'Once a day',
'platform.automatic_metadata_regeneration.week': 'Once a week',
<%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %>
} }
}; };

View File

@ -43,16 +43,28 @@ class Platforms::PlatformsController < Platforms::BaseController
@admin_uname = params[:admin_uname] @admin_uname = params[:admin_uname]
platform_params = params[:platform] || {} platform_params = params[:platform] || {}
platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released) platform_params = platform_params.slice(:description, :platform_arch_settings_attributes, :released, :automatic_metadata_regeneration)
platform_params[:owner] = User.find(@admin_id) if @admin_id.present? platform_params[:owner] = User.find(@admin_id) if @admin_id.present?
if @platform.update_attributes(platform_params)
flash[:notice] = I18n.t("flash.platform.saved") respond_to do |format|
redirect_to @platform format.html do
else if @platform.update_attributes(platform_params)
flash[:error] = I18n.t("flash.platform.save_error") flash[:notice] = I18n.t("flash.platform.saved")
flash[:warning] = @platform.errors.full_messages.join('. ') redirect_to @platform
render action: :edit else
flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
render action: :edit
end
end
format.json do
if @platform.update_attributes(platform_params)
render json: { notice: I18n.t("flash.platform.saved") }.to_json
else
render json: { error: I18n.t("flash.platform.save_error") }.to_json, status: 433
end
end
end end
end end

View File

@ -5,6 +5,7 @@ class Platform < ActiveRecord::Base
include Modules::Models::FileStoreClean include Modules::Models::FileStoreClean
include Modules::Models::RegenerationStatus include Modules::Models::RegenerationStatus
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
VISIBILITIES = %w(open hidden) VISIBILITIES = %w(open hidden)
NAME_PATTERN = /[\w\-\.]+/ NAME_PATTERN = /[\w\-\.]+/
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
@ -30,6 +31,7 @@ class Platform < ActiveRecord::Base
validates :description, presence: true validates :description, presence: true
validates :visibility, presence: true, inclusion: {in: VISIBILITIES} validates :visibility, presence: true, inclusion: {in: VISIBILITIES}
validates :automatic_metadata_regeneration, inclusion: {in: AUTOMATIC_METADATA_REGENERATIONS}, allow_blank: true
validates :name, uniqueness: {case_sensitive: false}, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ } validates :name, uniqueness: {case_sensitive: false}, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ }
validates :distrib_type, presence: true, inclusion: {in: APP_CONFIG['distr_types']} validates :distrib_type, presence: true, inclusion: {in: APP_CONFIG['distr_types']}
validate lambda { validate lambda {
@ -63,7 +65,7 @@ class Platform < ActiveRecord::Base
scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION) scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION)
accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes, :automatic_metadata_regeneration
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner include Modules::Models::Owner

View File

@ -21,15 +21,25 @@
.leftlist= t('activerecord.attributes.regeneration_status.status') .leftlist= t('activerecord.attributes.regeneration_status.status')
.rightlist= t("layout.regeneration_statuses.statuses.#{@platform.human_status}") .rightlist= t("layout.regeneration_statuses.statuses.#{@platform.human_status}")
.both .both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_at') .leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_at')
.rightlist= @platform.last_regenerated_at .rightlist= @platform.last_regenerated_at
.both .both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_status') .leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_status')
.rightlist= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}") .rightlist= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}")
.both .both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_log_sha1') .leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_log_sha1')
.rightlist= link_to_file_store('regeneration.log', @platform.last_regenerated_log_sha1) .rightlist= link_to_file_store('regeneration.log', @platform.last_regenerated_log_sha1)
.both .both
.leftlist= t('activerecord.attributes.platform.automatic_metadata_regeneration')
.rightlist{ 'ng-controller' => 'AutomaticMetadataRegenerationController', 'ng-init' => "platform_id = #{@platform.id}" }
%select{ 'ng-options' => 'k as (v | i18n) for (k, v) in items', 'ng-model' => 'amr', 'ng-change' => 'update()', 'ng-init' => "amr = '#{@platform.automatic_metadata_regeneration.to_s}'" }
%option{ value: '' }
.both
.leftside .leftside
.rightside= link_to t('layout.regeneration_statuses.regenerate_metadata'), regenerate_metadata_platform_path(@platform), method: :put, confirm: t('layout.confirm'), class: 'button' .rightside= link_to t('layout.regeneration_statuses.regenerate_metadata'), regenerate_metadata_platform_path(@platform), method: :put, confirm: t('layout.confirm'), class: 'button'
.both .both

View File

@ -92,6 +92,7 @@ en:
updated_at: Updated updated_at: Updated
distrib_type: Source type distrib_type: Source type
visibility: Status visibility: Status
automatic_metadata_regeneration: Automatic metadata regeneration
visibility_types: visibility_types:
open: Public open: Public
hidden: Private hidden: Private

View File

@ -92,6 +92,7 @@ ru:
updated_at: Обновлена updated_at: Обновлена
distrib_type: Тип дистрибутива distrib_type: Тип дистрибутива
visibility: Статус visibility: Статус
automatic_metadata_regeneration: Автоматическая регенерация метаданных
visibility_types: visibility_types:
open: Публичный open: Публичный
hidden: Приватный hidden: Приватный

View File

@ -0,0 +1,5 @@
class AddAutomaticMetadataRegenerationToPlatform < ActiveRecord::Migration
def change
add_column :platforms, :automatic_metadata_regeneration, :string
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140113215223) do ActiveRecord::Schema.define(:version => 20140211175858) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
@ -316,20 +316,21 @@ ActiveRecord::Schema.define(:version => 20140113215223) do
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|
t.string "description" t.string "description"
t.string "name", :null => false t.string "name", :null => false
t.integer "parent_platform_id" t.integer "parent_platform_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "released", :default => false, :null => false t.boolean "released", :default => false, :null => false
t.integer "owner_id" t.integer "owner_id"
t.string "owner_type" t.string "owner_type"
t.string "visibility", :default => "open", :null => false t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false t.string "platform_type", :default => "main", :null => false
t.string "distrib_type", :null => false t.string "distrib_type", :null => false
t.integer "status" t.integer "status"
t.datetime "last_regenerated_at" t.datetime "last_regenerated_at"
t.integer "last_regenerated_status" t.integer "last_regenerated_status"
t.string "last_regenerated_log_sha1" t.string "last_regenerated_log_sha1"
t.string "automatic_metadata_regeneration"
end end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false

View File

@ -27,6 +27,12 @@ describe Platform do
end end
it {should_not allow_value('custom_status').for(:visibility)} it {should_not allow_value('custom_status').for(:visibility)}
['', nil] + Platform::AUTOMATIC_METADATA_REGENERATIONS.each do |value|
it {should allow_value(value).for(:automatic_metadata_regeneration)}
end
it {should_not allow_value('custom_status').for(:visibility)}
it { should have_readonly_attribute(:name) } it { should have_readonly_attribute(:name) }
it { should have_readonly_attribute(:distrib_type) } it { should have_readonly_attribute(:distrib_type) }
it { should have_readonly_attribute(:parent_platform_id) } it { should have_readonly_attribute(:parent_platform_id) }