#276: updated UI of platforms, some refactoring

This commit is contained in:
Vokhmin Alexey V 2013-08-23 22:58:29 +04:00
parent b0880a2595
commit 55bc1a8096
13 changed files with 133 additions and 31 deletions

View File

@ -56,6 +56,15 @@ class Platforms::PlatformsController < Platforms::BaseController
end end
end end
def regenerate_metadata
if @platform.regenerate
flash[:notice] = I18n.t('flash.platform.saved')
else
flash[:error] = I18n.t('flash.platform.save_error')
end
redirect_to edit_platform_path(@platform)
end
def change_visibility def change_visibility
if @platform.change_visibility if @platform.change_visibility
flash[:notice] = I18n.t("flash.platform.saved") flash[:notice] = I18n.t("flash.platform.saved")

View File

@ -122,6 +122,7 @@ class Ability
can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)} can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)} can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)}
can(:clear, Platform) {|platform| owner?(platform) && platform.personal?} can(:clear, Platform) {|platform| owner?(platform) && platform.personal?}
can(:regenerate_metadata, Platform) {|platform| owner?(platform) || local_admin?(platform)}
can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform}
can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)}
@ -161,7 +162,7 @@ class Ability
end end
# Shared cannot rights for all users (registered, admin) # Shared cannot rights for all users (registered, admin)
cannot :destroy, Platform, :platform_type => 'personal' cannot [:regenerate_metadata, :destroy], Platform, :platform_type => 'personal'
cannot [:create, :destroy], Repository, :platform => {:platform_type => 'personal'}, :name => 'main' cannot [:create, :destroy], Repository, :platform => {:platform_type => 'personal'}, :name => 'main'
cannot [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, :platform => {:platform_type => 'personal'} cannot [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, :platform => {:platform_type => 'personal'}

View File

@ -0,0 +1,27 @@
module RegenerationStatus
def human_regeneration_status
self.class::HUMAN_REGENERATION_STATUSES[last_regenerated_status] || :no_data
end
def human_status
self.class::HUMAN_STATUSES[status] || :no_data
end
READY = 0
WAITING_FOR_REGENERATION = 100
REGENERATING = 200
HUMAN_STATUSES = {
READY => :ready,
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
REGENERATING => :regenerating
}
HUMAN_REGENERATION_STATUSES = {
AbfWorker::BaseObserver::COMPLETED => :completed,
AbfWorker::BaseObserver::FAILED => :failed,
AbfWorker::BaseObserver::CANCELED => :canceled
}.freeze
end

View File

@ -1,16 +1,10 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
class Platform < ActiveRecord::Base class Platform < ActiveRecord::Base
include RegenerationStatus
VISIBILITIES = %w(open hidden) VISIBILITIES = %w(open hidden)
NAME_PATTERN = /[\w\-\.]+/ NAME_PATTERN = /[\w\-\.]+/
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
READY = RepositoryStatus::READY
WAITING_FOR_REGENERATION = RepositoryStatus::WAITING_FOR_REGENERATION
REGENERATING = RepositoryStatus::REGENERATING
HUMAN_STATUSES = { READY => :ready,
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
REGENERATING => :regenerating
}.freeze
belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
belongs_to :owner, :polymorphic => true belongs_to :owner, :polymorphic => true
@ -77,19 +71,18 @@ class Platform < ActiveRecord::Base
end end
event :regenerate do event :regenerate do
transition :waiting_for_regeneration => :regenerating
transition :ready => :waiting_for_regeneration, :if => lambda{ |p| p.main? } transition :ready => :waiting_for_regeneration, :if => lambda{ |p| p.main? }
end end
event :start_regeneration do
transition :waiting_for_regeneration => :regenerating
end
HUMAN_STATUSES.each do |code,name| HUMAN_STATUSES.each do |code,name|
state name, :value => code state name, :value => code
end end
end end
def human_status
HUMAN_STATUSES[status]
end
def clear def clear
system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*")
end end

View File

@ -1,8 +1,7 @@
class RepositoryStatus < ActiveRecord::Base class RepositoryStatus < ActiveRecord::Base
READY = 0 include RegenerationStatus
WAITING_FOR_RESIGN = 100
WAITING_FOR_REGENERATION = 200 WAITING_FOR_RESIGN = 300
REGENERATING = 300
PUBLISH = 400 PUBLISH = 400
RESIGN = 500 RESIGN = 500
WAITING_FOR_RESIGN_AFTER_PUBLISH = 600 WAITING_FOR_RESIGN_AFTER_PUBLISH = 600
@ -13,11 +12,8 @@ class RepositoryStatus < ActiveRecord::Base
WAITING_FOR_RESIGN_AND_REGENERATION = 1100 WAITING_FOR_RESIGN_AND_REGENERATION = 1100
HUMAN_STATUSES = { HUMAN_STATUSES = HUMAN_STATUSES.clone.merge({
READY => :ready,
WAITING_FOR_RESIGN => :waiting_for_resign, WAITING_FOR_RESIGN => :waiting_for_resign,
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
REGENERATING => :regenerating,
PUBLISH => :publish, PUBLISH => :publish,
RESIGN => :resign, RESIGN => :resign,
WAITING_FOR_RESIGN_AFTER_PUBLISH => :waiting_for_resign_after_publish, WAITING_FOR_RESIGN_AFTER_PUBLISH => :waiting_for_resign_after_publish,
@ -26,7 +22,7 @@ class RepositoryStatus < ActiveRecord::Base
WAITING_FOR_REGENERATION_AFTER_RESIGN => :waiting_for_regeneration_after_resign, WAITING_FOR_REGENERATION_AFTER_RESIGN => :waiting_for_regeneration_after_resign,
WAITING_FOR_RESIGN_AND_REGENERATION_AFTER_PUBLISH => :waiting_for_resign_and_regeneration_after_publish, WAITING_FOR_RESIGN_AND_REGENERATION_AFTER_PUBLISH => :waiting_for_resign_and_regeneration_after_publish,
WAITING_FOR_RESIGN_AND_REGENERATION => :waiting_for_resign_and_regeneration WAITING_FOR_RESIGN_AND_REGENERATION => :waiting_for_resign_and_regeneration
}.freeze }).freeze
belongs_to :platform belongs_to :platform
belongs_to :repository belongs_to :repository
@ -34,7 +30,7 @@ class RepositoryStatus < ActiveRecord::Base
validates :repository_id, :platform_id, :presence => true validates :repository_id, :platform_id, :presence => true
validates :repository_id, :uniqueness => {:scope => :platform_id} validates :repository_id, :uniqueness => {:scope => :platform_id}
attr_accessible :last_regenerated_at, :last_regenerated_status, :platform_id, :repository_id, :status attr_accessible :platform_id, :repository_id
scope :platform_ready, where(:platforms => {:status => READY}).joins(:platform) scope :platform_ready, where(:platforms => {:status => READY}).joins(:platform)
scope :for_regeneration, platform_ready.where(:status => WAITING_FOR_REGENERATION) scope :for_regeneration, platform_ready.where(:status => WAITING_FOR_REGENERATION)
@ -84,8 +80,4 @@ class RepositoryStatus < ActiveRecord::Base
end end
end end
def human_status
HUMAN_STATUSES[status]
end
end end

View File

@ -15,6 +15,22 @@
:class => 'button' :class => 'button'
.both .both
- if can? :regenerate_metadata, @platform
.hr
%h3= t('layout.platforms.metadata')
.leftside
.rightside= link_to t('layout.regeneration_statuses.regenerate_metadata'), regenerate_metadata_platform_path(@platform), :method => :put, :confirm => t('layout.confirm'), :class => 'button'
.both
.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
- if can? :destroy, @platform - if can? :destroy, @platform
.hr .hr
.leftside= t("layout.platforms.delete_warning") .leftside= t("layout.platforms.delete_warning")

View File

@ -28,6 +28,7 @@ module Rosa
# Custom directories with classes and modules you want to be autoloadable. # Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras) # config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/app/presenters) config.autoload_paths += %W(#{config.root}/app/presenters)
config.autoload_paths += %W(#{config.root}/app/models/concerns)
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named. # :all can be used as a placeholder for all plugins not explicitly named.

View File

@ -52,6 +52,7 @@ en:
change_visibility_from_hidden: Change status to "Public" change_visibility_from_hidden: Change status to "Public"
change_visibility_from_open: Change status to "Private" change_visibility_from_open: Change status to "Private"
confirm_change_visibility: Are you sure you want to change visibility of this platform? confirm_change_visibility: Are you sure you want to change visibility of this platform?
metadata: Metadata for Software Center
flash: flash:
platform: platform:

View File

@ -52,6 +52,7 @@ ru:
change_visibility_from_hidden: Сменить статус на "Публичный" change_visibility_from_hidden: Сменить статус на "Публичный"
change_visibility_from_open: Сменить статус на "Приватный" change_visibility_from_open: Сменить статус на "Приватный"
confirm_change_visibility: Вы уверены, что хотите сменить статус этой платформы? confirm_change_visibility: Вы уверены, что хотите сменить статус этой платформы?
metadata: Метаданные для Software Center
flash: flash:
platform: platform:

View File

@ -0,0 +1,30 @@
en:
layout:
regeneration_statuses:
regenerate_metadata: Regenerate metadata
statuses:
no_data: No data
ready: No actions
waiting_for_regeneration: Waiting for regeneration metadata
regenerating: Regeneration of metadata
waiting_for_resign: Waiting for resign of packages
publish: Publish
resign: Resign of packages
waiting_for_resign_after_publish: Publish, waiting for resign of packages
waiting_for_resign_after_regeneration: Regeneration of metadata, waiting for resign of packages
waiting_for_regeneration_after_publish: Publish, waiting for regeneration metadata
waiting_for_regeneration_after_resign: Resign of packages, waiting for regeneration metadata
waiting_for_resign_and_regeneration_after_publish: Publish, waiting for resign of packages and regeneration metadata
waiting_for_resign_and_regeneration: Waiting for resign of packages and regeneration metadata
last_regenerated_statuses:
no_data: No data
completed: Completed succesfully
failed: Completed not succesfully
canceled: Canceled
activerecord:
attributes:
regeneration_status:
last_regenerated_at: Last regeneration of metadata
last_regenerated_status: Last status of regeneration metadata
status: Current status

View File

@ -0,0 +1,30 @@
ru:
layout:
regeneration_statuses:
regenerate_metadata: Регенерировать метаданные
statuses:
no_data: Нет данных
ready: Нет действий
waiting_for_regeneration: Ожидание регенерации методанных
regenerating: Идет регенерация методанных
waiting_for_resign: Ожидание подписи пакетов
publish: Идет публикация
resign: Идет подпись пакетов
waiting_for_resign_after_publish: Идет публикация, ожидание подписи пакетов
waiting_for_resign_after_regeneration: Идет регенерация методанных, ожидание подписи пакетов
waiting_for_regeneration_after_publish: Идет публикация, ожидание регенерации методанных
waiting_for_regeneration_after_resign: Идет подпись пакетов, ожидание регенерации методанных
waiting_for_resign_and_regeneration_after_publish: Идет публикация, ожидание подписи пакетов и регенерации методанных
waiting_for_resign_and_regeneration: Ожидание подписи пакетов и регенерации методанных
last_regenerated_statuses:
no_data: Нет данных
completed: Завершена успешно
failed: Завершена с ошибкой
canceled: Отменена
activerecord:
attributes:
regeneration_status:
last_regenerated_at: Последняя регенерация методанных
last_regenerated_status: Статус последней регенерации методанных
status: Текущее состояние

View File

@ -152,6 +152,7 @@ Rosa::Application.routes.draw do
resources :platforms do resources :platforms do
resources :private_users, :except => [:show, :destroy, :update] resources :private_users, :except => [:show, :destroy, :update]
member do member do
put :regenerate_metadata
put :clear put :clear
get :clone get :clone
get :members get :members

View File

@ -335,7 +335,7 @@ module AbfWorker
}.map{ |k, v| "#{k}=#{v}" }.join(' ') }.map{ |k, v| "#{k}=#{v}" }.join(' ')
statuses.each(&:start_regeneration) statuses.each(&:start_regeneration)
platform.regenerate platform.start_regeneration
Resque.push( Resque.push(
'publish_worker_default', 'publish_worker_default',
'class' => 'AbfWorker::PublishWorkerDefault', 'class' => 'AbfWorker::PublishWorkerDefault',