Edit approval workflow steps #635

This commit is contained in:
Karel Picman 2017-01-17 09:41:43 +01:00
parent 66c5af9d53
commit 2f6fc5cc9d
8 changed files with 168 additions and 15 deletions

View File

@ -384,6 +384,58 @@ class DmsfWorkflowsController < ApplicationController
redirect_to :back
end
def update_step
# Name
if params[:dmsf_workflow].present?
index = params[:step].to_i
name = params[:dmsf_workflow][:name]
if name.present?
step = @dmsf_workflow.dmsf_workflow_steps[index]
step.name = name
unless step.save
flash[:error] = step.errors.full_messages.to_sentence
else
@dmsf_workflow.dmsf_workflow_steps.each do |s|
if s.step == step.step
s.name = step.name
s.save
end
end
end
end
else
# Operators
params[:operator_step].each do |id, operator|
step = DmsfWorkflowStep.find_by_id id
if step
step.operator = operator.to_i
unless step.save
flash[:error] = step.errors.full_messages.to_sentence
end
end
end
end
redirect_to :back
end
def delete_step
step = DmsfWorkflowStep.find_by_id params[:step]
if step
# Safe the name
if step.name.present?
@dmsf_workflow.dmsf_workflow_steps.each do |s|
if s.step == step.step
s.name = step.name
s.save
end
end
end
# Destroy
step.destroy
end
redirect_to :back
end
private
def find_project

View File

@ -2,7 +2,7 @@
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -28,10 +28,14 @@ class DmsfWorkflowStep < ActiveRecord::Base
validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
validates_length_of :name, :maximum => 30
OPERATOR_OR = 0
OPERATOR_AND = 1
OPERATOR_OR = 0.freeze
OPERATOR_AND = 1.freeze
def soperator
DmsfWorkflowStep.soperator(self.operator)
end
def self.soperator(operator)
operator == 1 ? l(:dmsf_and) : l(:dmsf_or)
end

View File

@ -3,7 +3,7 @@
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View File

@ -3,7 +3,7 @@
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -54,18 +54,74 @@
<tr id="step-<%= i %>" class="<%= cycle 'odd', 'even' %> step">
<td class="id"><%= i %></td>
<% index = @dmsf_workflow.dmsf_workflow_steps.order(:id).index{ |s| s.step == i } %>
<td class="name"><%= @dmsf_workflow.dmsf_workflow_steps[index].name if index %></td>
<td class="approval">
<% stps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| (s.step == i) ? s : nil}.compact %>
<% stps.each_with_index do |step, j| %>
<% if (j != 0) || (stps.count > 1) %>
<b><%= step.soperator %></b>
<td class="name">
<span id="step-index-<%= index %>-name"><%= @dmsf_workflow.dmsf_workflow_steps[index].name if index %></span>
<%= form_for(@dmsf_workflow,
:url => update_step_dmsf_workflow_path(:step => index),
:method => :put,
:html => {:id => "step-index-#{index}-name-form", :class => 'hol'}) do |f| %>
<p>
<%= f.text_field(:name, :value => @dmsf_workflow.dmsf_workflow_steps[index].name) %>
</p>
<p>
<%= submit_tag l(:button_change), :class => 'small' %>
<%= link_to_function(
l(:button_cancel),
"$('#step-index-#{index}-name').show(); $('#step-index-#{index}-approvers').show(); $('#step-index-#{index}-name-form').hide(); $('#step-index-#{index}-approvers-form').hide();")
%>
</p>
<% end %>
</td>
<td>
<span id="step-index-<%= index %>-approvers">
<% stps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| (s.step == i) ? s : nil}.compact %>
<% stps.each_with_index do |step, j| %>
<% if (j != 0) || (stps.count > 1) %>
<b><%= step.soperator %></b>
<% end %>
<%= link_to_user step.user %>
<% end %>
<%= link_to_user step.user %>
</span>
<%= form_for(@dmsf_workflow,
:url => update_step_dmsf_workflow_path(:step => index),
:method => :put,
:html => {:id => "step-index-#{index}-approvers-form", :class => 'hol'}) do |f| %>
<div class="dmsf_parent_container">
<% stps.each_with_index do |step, j| %>
<div class="dmsf_child_container">
<label>
<%= radio_button_tag "operator_step[#{step.id}]", DmsfWorkflowStep::OPERATOR_AND,
step.operator == DmsfWorkflowStep::OPERATOR_AND %>
<%= DmsfWorkflowStep.soperator(DmsfWorkflowStep::OPERATOR_AND) %>
</label>
<br/>
<label>
<%= radio_button_tag "operator_step[#{step.id}]", DmsfWorkflowStep::OPERATOR_OR,
step.operator == DmsfWorkflowStep::OPERATOR_OR %>
<%= DmsfWorkflowStep.soperator(DmsfWorkflowStep::OPERATOR_OR) %>
</label>
<br/>
&nbsp;<%= delete_link delete_step_dmsf_workflow_path(:step => step.id) %>
</div>
<div class="dmsf_child_container">
<%= link_to_user step.user %>
</div>
<% end %>
</div>
<p>
<%= submit_tag l(:button_change), :class => 'small' %>
<%= link_to_function(
l(:button_cancel),
"$('#step-index-#{index}-name').show(); $('#step-index-#{index}-approvers').show(); $('#step-index-#{index}-name-form').hide(); $('#step-index-#{index}-approvers-form').hide();")
%>
</p>
<% end %>
</td>
<td class="buttons">
<%= reorder_handle(@dmsf_workflow, :url => url_for(:action => 'edit', :id => @dmsf_workflow, :step => i) ) %>
<%= link_to_function l(:button_edit),
"$('#step-index-#{index}-name').hide(); $('#step-index-#{index}-approvers').hide(); $('#step-index-#{index}-name-form').show(); $('#step-index-#{index}-approvers-form').show();",
:class => 'icon icon-edit' %>
<%= delete_link edit_dmsf_workflow_path(@dmsf_workflow, :step => i) %>
</td>
</tr>

View File

@ -99,7 +99,7 @@
}
.dmsf_workflow {
font-size: 0.8em;
/*font-size: 0.8em;*/
white-space: nowrap;
}
@ -249,3 +249,15 @@
.dmsf_select_version {
max-width: 50px;
}
.dmsf_parent_container {
overflow: hidden;
/*padding: 20px 0px 0px 0px;*/
}
.dmsf_child_container {
float: left;
text-align: left;
/*padding: 0px 10px 0px 0px;
width: 200px;*/
}

View File

@ -133,6 +133,8 @@ RedmineApp::Application.routes.draw do
get 'start'
post 'assignment'
get 'new_step'
put 'update_step'
delete 'delete_step'
end
end

View File

@ -92,7 +92,8 @@ Redmine::Plugin.register :redmine_dmsf do
permission :file_approval,
{:dmsf_workflows => [:action, :new_action, :autocomplete_for_user, :start, :assign, :assignment]}
permission :manage_workflows,
{:dmsf_workflows => [:index, :new, :create, :destroy, :show, :new_step, :add_step, :remove_step, :reorder_steps, :update]}
{:dmsf_workflows => [:index, :new, :create, :destroy, :show, :new_step, :add_step, :remove_step, :reorder_steps,
:update, :update_step, :delete_step]}
end
# Administration menu extension

View File

@ -2,7 +2,7 @@
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -371,4 +371,30 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
assert_response :redirect
end
def test_update_step_name
put :update_step, :id => @wf1, :step => @wfs2.step.to_s, :dmsf_workflow => {:name => 'new_name'}
assert_response :redirect
@wfs2.reload
assert_equal @wfs2.name, 'new_name'
@wfs3.reload
assert_equal @wfs3.name, 'new_name'
end
def test_update_step_operators
put :update_step, :id => @wf1, :step => '1', :operator_step => {@wfs1.id.to_s => DmsfWorkflowStep::OPERATOR_OR.to_s}
assert_response :redirect
@wfs1.reload
assert_equal @wfs1.operator, DmsfWorkflowStep::OPERATOR_OR
end
def test_delete_step
name = @wfs2.name
assert_difference 'DmsfWorkflowStep.count', -1 do
delete :delete_step, :id => @wf1, :step => @wfs2.id
end
@wfs3.reload
assert_equal @wfs3.name, name
assert_response :redirect
end
end