From 55bc1a809674d7f19936c1573adfa1b1a65698e8 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 23 Aug 2013 22:58:29 +0400 Subject: [PATCH] #276: updated UI of platforms, some refactoring --- .../platforms/platforms_controller.rb | 9 ++++++ app/models/ability.rb | 3 +- app/models/concerns/regeneration_status.rb | 27 +++++++++++++++++ app/models/platform.rb | 21 +++++-------- app/models/repository_status.rb | 22 +++++--------- app/views/platforms/platforms/edit.html.haml | 16 ++++++++++ config/application.rb | 1 + config/locales/models/platform.en.yml | 1 + config/locales/models/platform.ru.yml | 1 + .../locales/models/regeneration_status.en.yml | 30 +++++++++++++++++++ .../locales/models/regeneration_status.ru.yml | 30 +++++++++++++++++++ config/routes.rb | 1 + .../build_lists_publish_task_manager.rb | 2 +- 13 files changed, 133 insertions(+), 31 deletions(-) create mode 100644 app/models/concerns/regeneration_status.rb create mode 100644 config/locales/models/regeneration_status.en.yml create mode 100644 config/locales/models/regeneration_status.ru.yml diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 5cca06898..695ec7e9b 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -56,6 +56,15 @@ class Platforms::PlatformsController < Platforms::BaseController 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 if @platform.change_visibility flash[:notice] = I18n.t("flash.platform.saved") diff --git a/app/models/ability.rb b/app/models/ability.rb index 94247a47f..f631c29e3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -122,6 +122,7 @@ class Ability 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(: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([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} @@ -161,7 +162,7 @@ class Ability end # 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 [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, :platform => {:platform_type => 'personal'} diff --git a/app/models/concerns/regeneration_status.rb b/app/models/concerns/regeneration_status.rb new file mode 100644 index 000000000..f2e920b49 --- /dev/null +++ b/app/models/concerns/regeneration_status.rb @@ -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 \ No newline at end of file diff --git a/app/models/platform.rb b/app/models/platform.rb index 8afd33134..f77fb7373 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,16 +1,10 @@ # -*- encoding : utf-8 -*- class Platform < ActiveRecord::Base + include RegenerationStatus + VISIBILITIES = %w(open hidden) NAME_PATTERN = /[\w\-\.]+/ - - 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 + HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :owner, :polymorphic => true @@ -77,19 +71,18 @@ class Platform < ActiveRecord::Base end event :regenerate do - transition :waiting_for_regeneration => :regenerating transition :ready => :waiting_for_regeneration, :if => lambda{ |p| p.main? } end + event :start_regeneration do + transition :waiting_for_regeneration => :regenerating + end + HUMAN_STATUSES.each do |code,name| state name, :value => code end end - def human_status - HUMAN_STATUSES[status] - end - def clear system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") end diff --git a/app/models/repository_status.rb b/app/models/repository_status.rb index 3a30d8746..8feaa9cee 100644 --- a/app/models/repository_status.rb +++ b/app/models/repository_status.rb @@ -1,8 +1,7 @@ class RepositoryStatus < ActiveRecord::Base - READY = 0 - WAITING_FOR_RESIGN = 100 - WAITING_FOR_REGENERATION = 200 - REGENERATING = 300 + include RegenerationStatus + + WAITING_FOR_RESIGN = 300 PUBLISH = 400 RESIGN = 500 WAITING_FOR_RESIGN_AFTER_PUBLISH = 600 @@ -13,11 +12,8 @@ class RepositoryStatus < ActiveRecord::Base WAITING_FOR_RESIGN_AND_REGENERATION = 1100 - HUMAN_STATUSES = { - READY => :ready, + HUMAN_STATUSES = HUMAN_STATUSES.clone.merge({ WAITING_FOR_RESIGN => :waiting_for_resign, - WAITING_FOR_REGENERATION => :waiting_for_regeneration, - REGENERATING => :regenerating, PUBLISH => :publish, RESIGN => :resign, 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_RESIGN_AND_REGENERATION_AFTER_PUBLISH => :waiting_for_resign_and_regeneration_after_publish, WAITING_FOR_RESIGN_AND_REGENERATION => :waiting_for_resign_and_regeneration - }.freeze + }).freeze belongs_to :platform belongs_to :repository @@ -34,7 +30,7 @@ class RepositoryStatus < ActiveRecord::Base validates :repository_id, :platform_id, :presence => true 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 :for_regeneration, platform_ready.where(:status => WAITING_FOR_REGENERATION) @@ -84,8 +80,4 @@ class RepositoryStatus < ActiveRecord::Base end end - def human_status - HUMAN_STATUSES[status] - end - -end +end \ No newline at end of file diff --git a/app/views/platforms/platforms/edit.html.haml b/app/views/platforms/platforms/edit.html.haml index 331207f00..146b46625 100644 --- a/app/views/platforms/platforms/edit.html.haml +++ b/app/views/platforms/platforms/edit.html.haml @@ -15,6 +15,22 @@ :class => 'button' .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 .hr .leftside= t("layout.platforms.delete_warning") diff --git a/config/application.rb b/config/application.rb index c51dde67b..7f1004a61 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,6 +28,7 @@ module Rosa # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) 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). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index 45206ae3d..d4722ed81 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -52,6 +52,7 @@ en: change_visibility_from_hidden: Change status to "Public" change_visibility_from_open: Change status to "Private" confirm_change_visibility: Are you sure you want to change visibility of this platform? + metadata: Metadata for Software Center flash: platform: diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index 81b15a8b6..7b8db4de3 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -52,6 +52,7 @@ ru: change_visibility_from_hidden: Сменить статус на "Публичный" change_visibility_from_open: Сменить статус на "Приватный" confirm_change_visibility: Вы уверены, что хотите сменить статус этой платформы? + metadata: Метаданные для Software Center flash: platform: diff --git a/config/locales/models/regeneration_status.en.yml b/config/locales/models/regeneration_status.en.yml new file mode 100644 index 000000000..1b12ff2b3 --- /dev/null +++ b/config/locales/models/regeneration_status.en.yml @@ -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 diff --git a/config/locales/models/regeneration_status.ru.yml b/config/locales/models/regeneration_status.ru.yml new file mode 100644 index 000000000..9acd20dde --- /dev/null +++ b/config/locales/models/regeneration_status.ru.yml @@ -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: Текущее состояние diff --git a/config/routes.rb b/config/routes.rb index 8792dc9bf..bb7e64cea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -152,6 +152,7 @@ Rosa::Application.routes.draw do resources :platforms do resources :private_users, :except => [:show, :destroy, :update] member do + put :regenerate_metadata put :clear get :clone get :members diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index 3b97e51af..25fba3d70 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -335,7 +335,7 @@ module AbfWorker }.map{ |k, v| "#{k}=#{v}" }.join(' ') statuses.each(&:start_regeneration) - platform.regenerate + platform.start_regeneration Resque.push( 'publish_worker_default', 'class' => 'AbfWorker::PublishWorkerDefault',