diff --git a/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js b/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js index 92c9a6b3a..8c44e1961 100644 --- a/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js +++ b/app/assets/javascripts/angularjs/controllers/project_schedule_controller.js @@ -1,17 +1,36 @@ RosaABF.controller('ProjectScheduleController', ['$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.project_id = null; + // See: Modules::Models::Autostart::AUTOSTART_STATUSES + $scope.statuses = { + '0': 'autostart_statuses.0', + '1': 'autostart_statuses.1', + '2': 'autostart_statuses.2' + }; + $scope.project = null; + $scope.owner = null; - $scope.update = function() { + $scope.items = []; + + + $scope.init = function(name_with_owner) { + var arr = name_with_owner.split('/'); + $scope.owner = arr[0]; + $scope.project = arr[1]; + } + + $scope.updateStatus = function() { $http.put( - Routes.project_path($scope.platform_id), + Routes.project_path($scope.owner, $scope.project), {project: {autostart_status: $scope.autostart_status}, format: 'json'} ); - } + } + + $scope.updateSchedule = function(obj) { + $http.put( + Routes.project_schedule_path($scope.owner, $scope.project), + {enabled: obj.enabled, auto_publish: obj.auto_publish, repository_id: obj.repository_id, format: 'json'} + ); + } + }]); \ No newline at end of file diff --git a/app/assets/javascripts/angularjs/locales.js.erb b/app/assets/javascripts/angularjs/locales.js.erb index 92b133047..5af849eab 100644 --- a/app/assets/javascripts/angularjs/locales.js.erb +++ b/app/assets/javascripts/angularjs/locales.js.erb @@ -13,6 +13,9 @@ var _locales = { ], 'platform.automatic_metadata_regeneration.day': 'Раз в день', 'platform.automatic_metadata_regeneration.week': 'Раз в неделю', + 'autostart_statuses.0': 'Раз в 12 часов', + 'autostart_statuses.1': 'Раз в день', + 'autostart_statuses.2': 'Раз в неделю', <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> }, <%I18n.locale = :en%> @@ -27,6 +30,9 @@ var _locales = { ], 'platform.automatic_metadata_regeneration.day': 'Once a day', 'platform.automatic_metadata_regeneration.week': 'Once a week', + 'autostart_statuses.0': 'Once a 12 hours', + 'autostart_statuses.1': 'Once a day', + 'autostart_statuses.2': 'Once a week', <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> } }; \ No newline at end of file diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 5dbdc4381..c3eec9c55 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -67,17 +67,40 @@ class Projects::ProjectsController < Projects::BaseController def update params[:project].delete(:maintainer_id) if params[:project][:maintainer_id].blank? - if @project.update_attributes(params[:project]) - flash[:notice] = t('flash.project.saved') - redirect_to @project - else - @project.save - flash[:error] = t('flash.project.save_error') - flash[:warning] = @project.errors.full_messages.join('. ') - render action: :edit + respond_to do |format| + format.html do + if @project.update_attributes(params[:project]) + flash[:notice] = t('flash.project.saved') + redirect_to @project + else + @project.save + flash[:error] = t('flash.project.save_error') + flash[:warning] = @project.errors.full_messages.join('. ') + render action: :edit + end + end + format.json do + if @project.update_attributes(params[:project]) + render json: { notice: I18n.t('flash.project.saved') }.to_json + else + render json: { error: I18n.t('flash.project.save_error') }.to_json, status: 422 + end + end end end + def schedule + p_to_r = @project.project_to_repositories.where(repository_id: params[:repository_id]).first + unless p_to_r.repository.publish_without_qa + authorize! :local_admin_manage, p_to_r.repository.platform + end + p_to_r.user_id = current_user.id + p_to_r.enabled = params[:enabled].present? + p_to_r.auto_publish = params[:auto_publish].present? + p_to_r.save + render json: { notice: I18n.t('flash.project.saved') }.to_json + end + def destroy @project.destroy flash[:notice] = t("flash.project.destroyed") diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 034f00ee5..a023fa618 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -19,6 +19,22 @@ module ProjectsHelper end.sort_by{ |f| f[:uname] } end + def available_project_to_repositories(project) + project.project_to_repositories.includes(repository: :platform).select do |p_to_r| + p_to_r.repository.publish_without_qa ? true : can?(:local_admin_manage, p_to_r.repository.platform) + end.sort_by do |p_to_r| + "#{p_to_r.repository.platform.name}/#{p_to_r.repository.name}" + end.map do |p_to_r| + { + repository_name: "#{p_to_r.repository.platform.name}/#{p_to_r.repository.name}", + repository_path: platform_repository_path(p_to_r.repository.platform, p_to_r.repository), + auto_publish: p_to_r.auto_publish?, + enabled: p_to_r.enabled?, + repository_id: p_to_r.repository_id + } + end.to_a.to_json + end + def repositories_grouped_by_platform groups = {} Platform.accessible_by(current_ability, :related).order(:name).each do |platform| diff --git a/app/models/ability.rb b/app/models/ability.rb index 074f6e922..f7e22d199 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -66,7 +66,7 @@ class Ability can [:read, :archive, :membered, :get_id], Project, owner_type: 'Group', owner_id: user_group_ids can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project} can(:write, Project) {|project| local_writer? project} # for grack - can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members], Project do |project| + can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members, :schedule], Project do |project| local_admin? project end can(:fork, Project) {|project| can? :read, project} diff --git a/app/models/project.rb b/app/models/project.rb index c76e0f435..d48788372 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -324,7 +324,7 @@ class Project < ActiveRecord::Base bl.arch_id = arch_id bl.project_version = p.project_version_for(platform, platform) bl.user = user - bl.auto_publish = p_to_r.auto_publish == 'true' + bl.auto_publish = p_to_r.auto_publish? bl.save_to_repository = repository bl.include_repos = [repository.id, platform.repositories.main.first.try(:id)].uniq.compact end diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 206e79e99..d2e0194eb 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -17,6 +17,14 @@ class ProjectToRepository < ActiveRecord::Base store_accessor :autostart_options, field end + def enabled? + ['true', true].include?(enabled) + end + + def auto_publish? + ['true', true].include?(auto_publish) + end + protected def one_project_in_platform_repositories diff --git a/app/views/projects/projects/edit.html.haml b/app/views/projects/projects/edit.html.haml index e31f8e927..f9f023461 100644 --- a/app/views/projects/projects/edit.html.haml +++ b/app/views/projects/projects/edit.html.haml @@ -7,13 +7,28 @@ .hr %h3= t("layout.projects.build_schedule") -= form_for @project, html: { class: :form, multipart: true, 'ng-controller' => 'ProjectScheduleController', 'ng-init' => "project_id = #{@project.id}" } do |f| - / .leftlist= f.label :default_platforms - / .rightlist= f.select :default_platforms, Platform.main.map{ |p| [p.name, p.id] }, {include_blank: true}, multiple: true, size: 5 - / .both +%div{ 'ng-controller' => 'ProjectScheduleController', 'ng-init' => "init('#{@project.name_with_owner}')" } - .leftlist= f.label :autostart_status - .rightlist= f.select :autostart_status, Project::AUTOSTART_STATUSES.collect{|status| [Project.human_autostart_status(status), status]}, {include_blank: true, selected: @project.autostart_status} + .leftlist= t('activerecord.attributes.project.autostart_status') + .rightlist + %select{ 'ng-options' => 'k as (v | i18n) for (k, v) in statuses', 'ng-model' => 'autostart_status', 'ng-change' => 'updateStatus()', 'ng-init' => "autostart_status = '#{@project.autostart_status}'" } + %option{ value: '' } + .both + + %table#myTable.tablesorter{cellspacing: "0", cellpadding: "0"} + %thead + %tr + %th= t('activerecord.attributes.repository.name') + %th= t('activerecord.attributes.build_list.auto_publish') + %th= t('activerecord.attributes.project_to_repository.enabled') + %tbody{'ng-init' => "items = #{available_project_to_repositories(@project)}"} + %tr{'ng-repeat' => "item in items"} + %td + %a{'ng-href' => '{{item.repository_path}}'} {{item.repository_name}} + %td + %input{type: 'checkbox', 'ng-model' => "item.auto_publish", 'ng-change' => 'updateSchedule(item)'} + %td + %input{type: 'checkbox', 'ng-model' => "item.enabled", 'ng-change' => 'updateSchedule(item)'} .both .hr diff --git a/config/locales/models/project_to_repository.en.yml b/config/locales/models/project_to_repository.en.yml index 553d2e8f3..6714d6819 100644 --- a/config/locales/models/project_to_repository.en.yml +++ b/config/locales/models/project_to_repository.en.yml @@ -1,5 +1,8 @@ en: activerecord: + attributes: + project_to_repository: + enabled: Enabled errors: project_to_repository: project: Project already exists in platform \ No newline at end of file diff --git a/config/locales/models/project_to_repository.ru.yml b/config/locales/models/project_to_repository.ru.yml index 503a54f54..d31822ba9 100644 --- a/config/locales/models/project_to_repository.ru.yml +++ b/config/locales/models/project_to_repository.ru.yml @@ -1,5 +1,8 @@ ru: activerecord: + attributes: + project_to_repository: + enabled: Включено errors: project_to_repository: project: Проект уже присутствует в платформе diff --git a/config/routes.rb b/config/routes.rb index bd2c6874e..e5d3ac13e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -341,6 +341,7 @@ Rosa::Application.routes.draw do post '/preview' => 'projects#preview', as: 'md_preview' post 'refs_list' => 'projects#refs_list', as: 'refs_list' get '/pull_requests/:issue_id/add_line_comments(.:format)' => "comments#new_line", as: :new_line_pull_comment + put 'schedule' => 'projects#schedule' end # Resource