Approval workflow step name #629

This commit is contained in:
Karel Picman 2017-01-04 13:14:27 +01:00
parent 7e1f2f49b0
commit 29fc493661
10 changed files with 71 additions and 11 deletions

View File

@ -277,7 +277,7 @@ class DmsfWorkflowsController < ApplicationController
end
def new_step
@steps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq
@steps = @dmsf_workflow.dmsf_workflow_steps.group(:step).to_a
respond_to do |format|
format.html
@ -301,6 +301,7 @@ class DmsfWorkflowsController < ApplicationController
ws.step = step
ws.user_id = user.id
ws.operator = operator
ws.name = params[:name]
if ws.save
@dmsf_workflow.dmsf_workflow_steps << ws
else

View File

@ -50,7 +50,7 @@ module DmsfWorkflowsHelper
options = Array.new
options << [l(:dmsf_new_step), 0]
steps.each do |step|
options << [step.to_s, step]
options << [step.name.present? ? step.name : step.step.to_s, step.step]
end
options_for_select(options, 0)
end

View File

@ -26,6 +26,7 @@ class DmsfWorkflowStep < ActiveRecord::Base
validates :user_id, :presence => true
validates :operator, :presence => true
validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
validates_length_of :name, :maximum => 30
OPERATOR_OR = 0
OPERATOR_AND = 1

View File

@ -42,6 +42,7 @@
<div class="tab-content" id="tab-content-members">
<table class="list">
<thead><tr>
<th></th>
<th><%= l(:label_dmsf_workflow_step) %></th>
<th><%= l(:label_user) %> </th>
<th><%= l(:label_action) %></th>
@ -54,12 +55,14 @@
<td class="id"/>
<td/>
<td/>
<td/>
<td><%= DmsfWorkflowStepAction.workflow_str(0) %></td>
<td class="dmsf_note"></td>
<td/>
</tr>
<tr id="step-1" class="odd">
<td class="id"></td>
<td/>
<td><%= link_to_user User.find_by_id(revision.dmsf_workflow_assigned_by) if revision.dmsf_workflow_assigned_by %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_ASSIGN) %></td>
@ -68,17 +71,21 @@
</tr>
<tr id="step-2" class="even">
<td class="id"></td>
<td/>
<td><%= link_to_user User.find_by_id(revision.dmsf_workflow_started_by) if revision.dmsf_workflow_started_by %></td>
<td><%= DmsfWorkflowStepAction.action_str(DmsfWorkflowStepAction::ACTION_START) %></td>
<td><%= DmsfWorkflowStepAction.workflow_str(DmsfWorkflowStepAction::ACTION_START) if revision.dmsf_workflow_started_by %></td>
<td class="dmsf_note"></td>
<td><%= format_time(revision.dmsf_workflow_started_at) if revision.dmsf_workflow_started_at %></td>
</tr>
<% sql = "SELECT c.action, c.note, c.created_at, c.author_id, a.user_id, s.step FROM dmsf_workflow_step_actions c RIGHT JOIN dmsf_workflow_step_assignments a ON a.id = c.dmsf_workflow_step_assignment_id RIGHT JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY s.step, c.action DESC, c.created_at" %>
<% result = DmsfWorkflowStep.connection.exec_query sql %>
<% sql = "SELECT c.action, c.note, c.created_at, c.author_id, a.user_id, s.step, s.name FROM dmsf_workflow_step_actions c RIGHT JOIN dmsf_workflow_step_assignments a ON a.id = c.dmsf_workflow_step_assignment_id RIGHT JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY s.step, s.id, c.action DESC, c.created_at" %>
<% result = DmsfWorkflowStep.connection.exec_query sql %>
<% last_step = 0 %>
<% result.each_with_index do |row, i| %>
<tr id="step-<%= i + 3 %> " class="<%= cycle 'odd', 'even' %>">
<td class="id"><%= row['step'] %></td>
<td class="id"><%= row['step'] unless row['step'] == last_step %></td>
<% last_step = row['step'] %>
<td class="name"><%= row['name'] %></td>
<td><%= link_to_user User.find_by_id(row['author_id'].present? ? row['author_id'] : row['user_id']) %></td>
<td><%= DmsfWorkflowStepAction.action_str(row['action']) %></td>
<td>

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
@ -33,5 +33,10 @@
<fieldset class="box">
<legend><%= l(:label_dmsf_workflow_step) %></legend>
<%= select_tag 'step', dmsf_workflow_steps_options_for_select(@steps),
:id => 'selected_step', :style => "width:100px" %>
</fieldset>
:id => 'selected_step', :onchange => "$('#dmsf_step_name').toggle(this.value == 0);" %>
<span id="dmsf_step_name">
&nbsp;
<%= label_tag 'name', l(:field_name) %>
<%= text_field_tag 'name', nil, :maxlength => 30 %>
</span>
</fieldset>

View File

@ -44,6 +44,7 @@
<% if steps.any? %>
<table class="list steps">
<thead><tr>
<th></th>
<th><%= l(:label_dmsf_workflow_step) %></th>
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
<th></th>
@ -52,6 +53,8 @@
<% steps.each do |i|%>
<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| %>

View File

@ -0,0 +1,29 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class AddNameToAppovalWorkflowStep < ActiveRecord::Migration
def up
add_column :dmsf_workflow_steps, :name, :string, :limit => 30, :null => true
end
def down
remove_column :dmsf_links, :external_url
end
end

View File

@ -3,6 +3,7 @@ wfs2:
id: 2
dmsf_workflow_id: 1
step: 2
name: '2nd step'
user_id: 2
operator: 1
@ -10,6 +11,7 @@ wfs1:
id: 1
dmsf_workflow_id: 1
step: 1
name: '1st step'
user_id: 1
operator: 0
@ -31,5 +33,6 @@ wfs5:
id: 5
dmsf_workflow_id: 1
step: 3
name: '3rd step'
user_id: 2
operator: 1

View File

@ -196,12 +196,14 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
def test_add_step
assert_difference 'DmsfWorkflowStep.count', +1 do
post :add_step, :commit => l(:dmsf_or), :step => 1, :id => @wf1.id, :user_ids => [@user_non_member.id]
post :add_step, :commit => l(:dmsf_or), :step => 1, :name => '1st step', :id => @wf1.id,
:user_ids => [@user_non_member.id]
end
assert_response :success
ws = DmsfWorkflowStep.order('id DESC').first
assert_equal @wf1.id, ws.dmsf_workflow_id
assert_equal 1, ws.step
assert_equal '1st step', ws.name
assert_equal @user_non_member.id, ws.user_id
assert_equal DmsfWorkflowStep::OPERATOR_OR, ws.operator
end

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
@ -44,6 +44,7 @@ class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
wfs = DmsfWorkflowStep.new
wfs.dmsf_workflow_id = 1
wfs.step = 2
wfs.name = '2nd step'
wfs.user_id = 3
wfs.operator = 1
assert wfs.save, wfs.errors.full_messages.to_sentence
@ -51,13 +52,15 @@ class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
def test_update
@wfs1.dmsf_workflow_id = 2
@wfs1.step = 2
@wfs1.step = 2
@wfs1.name = '2nd step'
@wfs1.user_id = 2
@wfs1.operator = 2
assert @wfs1.save, @wfs1.errors.full_messages.to_sentence
@wfs1.reload
assert_equal 2, @wfs1.dmsf_workflow_id
assert_equal 2, @wfs1.step
assert_equal '2nd step', @wfs1.name
assert_equal 2, @wfs1.user_id
assert_equal 2, @wfs1.operator
end
@ -93,6 +96,12 @@ class DmsfWorkflowStepTest < RedmineDmsf::Test::UnitTest
assert !@wfs2.save
assert_equal 1, @wfs2.errors.count
end
def test_validate_name_length
@wfs1.name = 'a' * 31
assert !@wfs1.save
assert_equal 1, @wfs1.errors.count
end
def test_destroy
assert DmsfWorkflowStepAssignment.where(:dmsf_workflow_step_id => @wfs2.id).all.count > 0