diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..13946ec --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'acts_as_list' +gem 'activemodel-serializers-xml' \ No newline at end of file diff --git a/app/controllers/custom_workflows_controller.rb b/app/controllers/custom_workflows_controller.rb index 592f56a..e17bd6d 100644 --- a/app/controllers/custom_workflows_controller.rb +++ b/app/controllers/custom_workflows_controller.rb @@ -1,8 +1,32 @@ class CustomWorkflowsController < ApplicationController layout 'admin' - before_filter :require_admin - before_filter :find_workflow, :only => [:show, :edit, :update, :destroy, :export, :change_status] + before_action :require_admin + before_action :find_workflow, only: [:show, :edit, :update, :destroy, :export, :change_status, :reorder] + + def reorder + from = @workflow.position + to = params[:custom_workflow][:position].to_i + CustomWorkflow.transaction do + CustomWorkflow.find_each do |wf| + if wf.position == from + wf.update_attribute :position, to + elsif wf.position >= to && wf.position < from + # Move up + wf.update_attribute :position, wf.position + 1 + elsif wf.position <= to && wf.position > from + # Move down + wf.update_attribute :position, wf.position - 1 + end + end + end + respond_to do |format| + format.html + format.js { + render inline: "location.replace('#{custom_workflows_path}');" + } + end + end def index @workflows = CustomWorkflow.includes(:projects).all @@ -52,14 +76,30 @@ class CustomWorkflowsController < ApplicationController end def create - @workflow = CustomWorkflow.new(params[:custom_workflow]) + @workflow = CustomWorkflow.new + @workflow.before_save = params[:custom_workflow][:before_save] + @workflow.after_save = params[:custom_workflow][:after_save] + @workflow.name = params[:custom_workflow][:name] + @workflow.description = params[:custom_workflow][:description] + @workflow.position = CustomWorkflow.count + 1 + @workflow.is_for_all = params[:custom_workflow][:is_for_all].present? + @workflow.author = params[:custom_workflow][:author] + @workflow.active = params[:custom_workflow][:active] + @workflow.observable = params[:custom_workflow][:observable] + @workflow.shared_code = params[:custom_workflow][:shared_code] + @workflow.before_add = params[:custom_workflow][:before_add] + @workflow.after_add = params[:custom_workflow][:after_add] + @workflow.before_remove = params[:custom_workflow][:before_remove] + @workflow.after_remove = params[:custom_workflow][:after_remove] + @workflow.before_destroy = params[:custom_workflow][:before_destroy] + @workflow.after_destroy = params[:custom_workflow][:after_destroy] respond_to do |format| if params.has_key?(:commit) && @workflow.save flash[:notice] = l(:notice_successful_create) cookies[:custom_workflows_author] = @workflow.author format.html { redirect_to(custom_workflows_path) } else - format.html { render :action => "new" } + format.html { render action: :new } end end end @@ -70,26 +110,38 @@ class CustomWorkflowsController < ApplicationController flash[:notice] = l(:notice_successful_status_change) format.html { redirect_to(custom_workflows_path) } else - format.html { render :action => :edit } + format.html { render action: :edit } end end end def update respond_to do |format| - @workflow.assign_attributes(params[:custom_workflow]) + @workflow.before_save = params[:custom_workflow][:before_save] + @workflow.after_save = params[:custom_workflow][:after_save] + @workflow.name = params[:custom_workflow][:name] + @workflow.description = params[:custom_workflow][:description] + @workflow.is_for_all = params[:custom_workflow][:is_for_all].present? + @workflow.author = params[:custom_workflow][:author] + @workflow.active = params[:custom_workflow][:active] + @workflow.shared_code = params[:custom_workflow][:shared_code] + @workflow.before_add = params[:custom_workflow][:before_add] + @workflow.after_add = params[:custom_workflow][:after_add] + @workflow.before_remove = params[:custom_workflow][:before_remove] + @workflow.after_remove = params[:custom_workflow][:after_remove] + @workflow.before_destroy = params[:custom_workflow][:before_destroy] + @workflow.after_destroy = params[:custom_workflow][:after_destroy] if params.has_key?(:commit) && @workflow.save flash[:notice] = l(:notice_successful_update) format.html { redirect_to(custom_workflows_path) } else - format.html { render :action => :edit } + format.html { render action: :edit } end end end def destroy @workflow.destroy - respond_to do |format| flash[:notice] = l(:notice_successful_delete) format.html { redirect_to(custom_workflows_path) } diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 52c1586..86e1212 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -14,7 +14,6 @@ class CustomWorkflow < ActiveRecord::Base COLLECTION_OBSERVABLES = [:group_users, :issue_attachments, :project_attachments, :wiki_page_attachments] SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content, :time_entry, :version] - attr_protected :id has_and_belongs_to_many :projects acts_as_list @@ -104,7 +103,7 @@ class CustomWorkflow < ActiveRecord::Base def validate_syntax_for(object, event) object.instance_eval(read_attribute(event)) if respond_to?(event) && read_attribute(event) - rescue WorkflowError => e + rescue WorkflowError => _ rescue Exception => e errors.add event, :invalid_script, :error => e end diff --git a/app/views/custom_workflows/_form.html.erb b/app/views/custom_workflows/_form.html.erb index 6c8b84a..3ee7cfe 100644 --- a/app/views/custom_workflows/_form.html.erb +++ b/app/views/custom_workflows/_form.html.erb @@ -9,7 +9,7 @@ CustomWorkflow::OBSERVABLES.collect {|o| [l("custom_workflow_observable_#{o}"), o]}, {}, :onchange => 'this.form.submit()', :disabled => !@workflow.new_record? %>
-<%= f.text_area :description, :cols => 40, :rows => 5 %>
+<%= f.text_area :description, cols: 40, rows: 5 , class: 'wiki-edit' %>
<% if @workflow.has_projects_association? %><%= f.check_box :is_for_all, :onclick => "checkAndDisable('custom_workflow_enabled_projects', this.checked);", :label => :field_enabled_for_all_projects %>
<% end %> @@ -44,69 +44,73 @@ <% when :shared %> <%= f.text_area :shared_code, :cols => 40, :rows => 20, :wrap => 'off', :class => 'custom_workflow_script' %> <% when *CustomWorkflow::COLLECTION_OBSERVABLES %> - <%= render :layout => 'layouts/collapsible', - :locals => { - :collapsed => (not (@workflow.before_add.present? or @workflow.after_add.present? or @workflow.errors[:base].present?)), - :label => l(:label_add_workflows)} do %> -