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

View File

@ -43,9 +43,12 @@ class Platforms::PlatformsController < Platforms::BaseController
@admin_uname = params[:admin_uname]
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?
respond_to do |format|
format.html do
if @platform.update_attributes(platform_params)
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
@ -55,6 +58,15 @@ class Platforms::PlatformsController < Platforms::BaseController
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
def regenerate_metadata
if @platform.regenerate

View File

@ -5,6 +5,7 @@ class Platform < ActiveRecord::Base
include Modules::Models::FileStoreClean
include Modules::Models::RegenerationStatus
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
VISIBILITIES = %w(open hidden)
NAME_PATTERN = /[\w\-\.]+/
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
@ -30,6 +31,7 @@ class Platform < ActiveRecord::Base
validates :description, presence: true
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 :distrib_type, presence: true, inclusion: {in: APP_CONFIG['distr_types']}
validate lambda {
@ -63,7 +65,7 @@ class Platform < ActiveRecord::Base
scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION)
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
include Modules::Models::Owner

View File

@ -21,15 +21,25 @@
.leftlist= t('activerecord.attributes.regeneration_status.status')
.rightlist= t("layout.regeneration_statuses.statuses.#{@platform.human_status}")
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_at')
.rightlist= @platform.last_regenerated_at
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_status')
.rightlist= t("layout.regeneration_statuses.last_regenerated_statuses.#{@platform.human_regeneration_status}")
.both
.leftlist= t('activerecord.attributes.regeneration_status.last_regenerated_log_sha1')
.rightlist= link_to_file_store('regeneration.log', @platform.last_regenerated_log_sha1)
.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
.rightside= link_to t('layout.regeneration_statuses.regenerate_metadata'), regenerate_metadata_platform_path(@platform), method: :put, confirm: t('layout.confirm'), class: 'button'
.both

View File

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

View File

@ -92,6 +92,7 @@ ru:
updated_at: Обновлена
distrib_type: Тип дистрибутива
visibility: Статус
automatic_metadata_regeneration: Автоматическая регенерация метаданных
visibility_types:
open: Публичный
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.
ActiveRecord::Schema.define(:version => 20140113215223) do
ActiveRecord::Schema.define(:version => 20140211175858) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -330,6 +330,7 @@ ActiveRecord::Schema.define(:version => 20140113215223) do
t.datetime "last_regenerated_at"
t.integer "last_regenerated_status"
t.string "last_regenerated_log_sha1"
t.string "automatic_metadata_regeneration"
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false

View File

@ -27,6 +27,12 @@ describe Platform do
end
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(:distrib_type) }
it { should have_readonly_attribute(:parent_platform_id) }