From 0b40abb821739fb7706e26eafa33c69dc06ba7a3 Mon Sep 17 00:00:00 2001
From: Karel Picman
Date: Thu, 9 May 2013 12:17:12 +0200
Subject: [PATCH 01/10] Approval workflows copied fron 1.5.0 devel
---
app/controllers/dmsf_workflows_controller.rb | 171 ++++++++++++++++++
app/helpers/dmsf_workflows_helper.rb | 45 +++++
app/models/dmsf_workflow.rb | 110 +++++++++++
app/models/dmsf_workflow_step.rb | 37 ++++
app/models/dmsf_workflow_step_action.rb | 24 +++
app/models/dmsf_workflow_step_assignment.rb | 26 +++
app/views/dmsf_workflows/_action.html.erb | 33 ++++
app/views/dmsf_workflows/_main.html.erb | 32 ++++
app/views/dmsf_workflows/_steps.html.erb | 81 +++++++++
app/views/dmsf_workflows/action.html.erb | 1 +
app/views/dmsf_workflows/action.js.erb | 3 +
app/views/dmsf_workflows/add_step.html.erb | 1 +
.../autocomplete_for_user.js.erb | 1 +
app/views/dmsf_workflows/edit.html.erb | 1 +
app/views/dmsf_workflows/index.html.erb | 1 +
app/views/dmsf_workflows/log.html.erb | 1 +
app/views/dmsf_workflows/new.html.erb | 12 ++
app/views/dmsf_workflows/remove_step.html.erb | 1 +
.../dmsf_workflows/reorder_steps.html.erb | 1 +
assets/images/ticket_go.png | Bin 0 -> 608 bytes
assets/javascripts/dmsf.css | 50 +++++
assets/stylesheets/dmsf.css | 5 +
config/locales/en.yml | 17 ++
config/routes.rb | 13 ++
.../20120822100401_create_dmsf_workflows.rb | 13 ++
...120822100402_create_dmsf_workflow_steps.rb | 15 ++
...3_create_dmsf_workflow_step_assignments.rb | 17 ++
...00404_create_dmsf_workflow_step_actions.rb | 17 ++
init.rb | 13 ++
lib/redmine_dmsf/patches/project_patch.rb | 2 +-
.../patches/project_tabs_extended.rb | 5 +-
test/fixtures/dmsf_workflow_step_actions.yml | 22 +++
.../dmsf_workflow_step_assignments.yml | 6 +
test/fixtures/dmsf_workflow_steps.yml | 21 +++
test/fixtures/dmsf_workflows.yml | 8 +
.../dmsf_workflow_controller_test.rb | 171 ++++++++++++++++++
test/unit/dmsf_workflow_step_action_test.rb | 60 ++++++
.../dmsf_workflow_step_assignment_test.rb | 53 ++++++
test/unit/dmsf_workflow_step_test.rb | 76 ++++++++
test/unit/dmsf_workflow_test.rb | 54 ++++++
40 files changed, 1217 insertions(+), 3 deletions(-)
create mode 100644 app/controllers/dmsf_workflows_controller.rb
create mode 100644 app/helpers/dmsf_workflows_helper.rb
create mode 100644 app/models/dmsf_workflow.rb
create mode 100644 app/models/dmsf_workflow_step.rb
create mode 100644 app/models/dmsf_workflow_step_action.rb
create mode 100644 app/models/dmsf_workflow_step_assignment.rb
create mode 100644 app/views/dmsf_workflows/_action.html.erb
create mode 100644 app/views/dmsf_workflows/_main.html.erb
create mode 100644 app/views/dmsf_workflows/_steps.html.erb
create mode 100644 app/views/dmsf_workflows/action.html.erb
create mode 100644 app/views/dmsf_workflows/action.js.erb
create mode 100644 app/views/dmsf_workflows/add_step.html.erb
create mode 100644 app/views/dmsf_workflows/autocomplete_for_user.js.erb
create mode 100644 app/views/dmsf_workflows/edit.html.erb
create mode 100644 app/views/dmsf_workflows/index.html.erb
create mode 100644 app/views/dmsf_workflows/log.html.erb
create mode 100644 app/views/dmsf_workflows/new.html.erb
create mode 100644 app/views/dmsf_workflows/remove_step.html.erb
create mode 100644 app/views/dmsf_workflows/reorder_steps.html.erb
create mode 100644 assets/images/ticket_go.png
create mode 100644 assets/javascripts/dmsf.css
create mode 100644 db/migrate/20120822100401_create_dmsf_workflows.rb
create mode 100644 db/migrate/20120822100402_create_dmsf_workflow_steps.rb
create mode 100644 db/migrate/20120822100403_create_dmsf_workflow_step_assignments.rb
create mode 100644 db/migrate/20120822100404_create_dmsf_workflow_step_actions.rb
create mode 100644 test/fixtures/dmsf_workflow_step_actions.yml
create mode 100644 test/fixtures/dmsf_workflow_step_assignments.yml
create mode 100644 test/fixtures/dmsf_workflow_steps.yml
create mode 100644 test/fixtures/dmsf_workflows.yml
create mode 100644 test/functional/dmsf_workflow_controller_test.rb
create mode 100644 test/unit/dmsf_workflow_step_action_test.rb
create mode 100644 test/unit/dmsf_workflow_step_assignment_test.rb
create mode 100644 test/unit/dmsf_workflow_step_test.rb
create mode 100644 test/unit/dmsf_workflow_test.rb
diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb
new file mode 100644
index 00000000..34ca0555
--- /dev/null
+++ b/app/controllers/dmsf_workflows_controller.rb
@@ -0,0 +1,171 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 DmsfWorkflowsController < ApplicationController
+ unloadable
+ layout :workflows_layout
+
+ before_filter :find_workflow, :except => [:create, :new, :index]
+ before_filter :find_project
+ before_filter :authorize_global, :except => [:action, :new_action]
+
+ def index
+ if @project
+ @workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => @project.id), :per_page => 25
+ else
+ @workflow_pages, @workflows = paginate DmsfWorkflow.where(:project_id => nil), :per_page => 25
+ end
+ end
+
+ def action
+ end
+
+ def new_action
+ logger.info '>>>>>>>>>>>>>>>>>>>>>>> YES!'
+ end
+
+ def log
+ end
+
+ def new
+ @workflow = DmsfWorkflow.new
+ end
+
+ def create
+ @workflow = DmsfWorkflow.new(:name => params[:dmsf_workflow][:name], :project_id => params[:project_id])
+ if request.post? && @workflow.save
+ flash[:notice] = l(:notice_successful_create)
+ if @project
+ redirect_to settings_project_path(@project, :tab => 'dmsf')
+ else
+ redirect_to dmsf_workflows_path
+ end
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if request.put? && @workflow.update_attributes({:name => params[:dmsf_workflow][:name]})
+ flash[:notice] = l(:notice_successful_update)
+ if @project
+ redirect_to settings_project_path(@project, :tab => 'dmsf')
+ else
+ redirect_to dmsf_workflows_path
+ end
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ begin
+ @workflow.destroy
+ rescue
+ flash[:error] = l(:error_unable_delete_dmsf_workflow)
+ end
+ if @project
+ redirect_to settings_project_path(@project, :tab => 'dmsf')
+ else
+ redirect_to dmsf_workflows_path
+ end
+ end
+
+ def autocomplete_for_user
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def add_step
+ if request.post?
+ users = User.find_all_by_id(params[:user_ids])
+ if params[:step] == '0'
+ if @workflow.steps.count > 0
+ step = @workflow.steps.last + 1
+ else
+ step = 1
+ end
+ else
+ step = params[:step].to_i
+ end
+ operator = 1 ? params[:commit] == l(:dmsf_and) : 0
+ users.each do |user|
+ @workflow.dmsf_workflow_steps << DmsfWorkflowStep.new(
+ :dmsf_workflow_id => @workflow.id,
+ :step => step,
+ :user_id => user.id,
+ :operator => operator)
+ end
+ @workflow.save
+ end
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def remove_step
+ if request.delete?
+ DmsfWorkflowStep.where(:dmsf_workflow_id => @workflow.id, :step => params[:step]).each do |ws|
+ @workflow.dmsf_workflow_steps.delete(ws)
+ end
+ @workflow.dmsf_workflow_steps.each do |ws|
+ n = ws.step.to_i
+ if n > params[:step].to_i
+ ws.step = n - 1
+ ws.save
+ end
+ end
+ end
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def reorder_steps
+ if request.put?
+ @workflow.reorder_steps params[:step].to_i, params[:workflow_step][:move_to]
+ end
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ private
+
+ def find_workflow
+ @workflow = DmsfWorkflow.find_by_id(params[:id])
+ end
+
+ def find_project
+ if @workflow
+ @project = @workflow.project
+ elsif params[:project_id].present?
+ @project = Project.find_by_id params[:project_id]
+ end
+ end
+
+ def workflows_layout
+ find_workflow
+ find_project
+ @project ? 'base' : 'admin'
+ end
+end
diff --git a/app/helpers/dmsf_workflows_helper.rb b/app/helpers/dmsf_workflows_helper.rb
new file mode 100644
index 00000000..c61c2ac5
--- /dev/null
+++ b/app/helpers/dmsf_workflows_helper.rb
@@ -0,0 +1,45 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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.
+
+module DmsfWorkflowsHelper
+
+ def render_principals_for_new_dmsf_workflow_users(workflow)
+ scope = User.active.sorted.like(params[:q])
+ principal_count = scope.count
+ principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
+ principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
+
+ s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals')
+
+ links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
+ link_to text, autocomplete_for_user_dmsf_workflow_path(workflow, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
+ }
+
+ s + content_tag('p', links, :class => 'pagination')
+ end
+
+ def dmsf_workflow_steps_options_for_select(steps)
+ options = Array.new
+ options << [l(:dmsf_new_step), 0]
+ steps.each do |step|
+ options << [step.to_s, step]
+ end
+ options_for_select(options, 0)
+ end
+
+end
diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb
new file mode 100644
index 00000000..cb214588
--- /dev/null
+++ b/app/models/dmsf_workflow.rb
@@ -0,0 +1,110 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 DmsfWorkflow < ActiveRecord::Base
+ belongs_to :project
+
+ has_many :dmsf_workflow_steps, :dependent => :destroy
+
+ validates_uniqueness_of :name
+ validates :name, :presence => true
+ validates_length_of :name, :maximum => 255
+
+ def self.workflows(project)
+ project ? where(:project_id => project) : where('project_id IS NULL')
+ end
+
+ def project
+ @project = Project.find_by_id(project_id) unless @project
+ @project
+ end
+
+ def to_s
+ name
+ end
+
+ def approvals(step)
+ wa = Array.new
+ dmsf_workflow_steps.each do |s|
+ if s.step == step
+ wa << s
+ end
+ end
+ wa.sort_by { |obj| -obj.operator }
+ end
+
+ def steps
+ ws = Array.new
+ dmsf_workflow_steps.each do |s|
+ unless ws.include? s.step
+ ws << s.step
+ end
+ end
+ ws.sort
+ end
+
+ def reorder_steps(step, move_to)
+ case move_to
+ when 'highest'
+ unless step == 1
+ dmsf_workflow_steps.each do |ws|
+ if ws.step < step
+ ws.update_attribute('step', ws.step + 1)
+ elsif ws.step == step
+ ws.update_attribute('step', 1)
+ end
+ end
+ end
+ when 'higher'
+ unless step == 1
+ dmsf_workflow_steps.each do |ws|
+ if ws.step == step - 1
+ ws.update_attribute('step', step)
+ elsif ws.step == step
+ ws.update_attribute('step', step - 1)
+ end
+ end
+ end
+ when 'lower'
+ unless step == steps.count
+ dmsf_workflow_steps.each do |ws|
+ if ws.step == step + 1
+ ws.update_attribute('step', step)
+ elsif ws.step == step
+ ws.update_attribute('step', step + 1)
+ end
+ end
+ end
+ when 'lowest'
+ size = steps.count
+ unless step == size
+ dmsf_workflow_steps.each do |ws|
+ if ws.step > step
+ ws.update_attribute('step', ws.step - 1)
+ elsif ws.step == step
+ ws.update_attribute('step', size)
+ end
+ end
+ end
+ end
+ end
+
+ def delegates
+ User.all
+ end
+end
\ No newline at end of file
diff --git a/app/models/dmsf_workflow_step.rb b/app/models/dmsf_workflow_step.rb
new file mode 100644
index 00000000..4d33a284
--- /dev/null
+++ b/app/models/dmsf_workflow_step.rb
@@ -0,0 +1,37 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 DmsfWorkflowStep < ActiveRecord::Base
+ belongs_to :workflow
+
+ has_many :dmsf_workflow_step_assignments, :dependent => :destroy
+
+ validates :dmsf_workflow_id, :presence => true
+ validates :step, :presence => true
+ validates :user_id, :presence => true
+ validates :operator, :presence => true
+ validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
+
+ def soperator
+ operator == 1 ? l(:dmsf_and) : l(:dmsf_or)
+ end
+
+ def user
+ User.find(user_id)
+ end
+end
\ No newline at end of file
diff --git a/app/models/dmsf_workflow_step_action.rb b/app/models/dmsf_workflow_step_action.rb
new file mode 100644
index 00000000..bdc10ee1
--- /dev/null
+++ b/app/models/dmsf_workflow_step_action.rb
@@ -0,0 +1,24 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 DmsfWorkflowStepAction < ActiveRecord::Base
+ belongs_to :dmsf_workflow_step_assignment
+
+ validates :dmsf_workflow_step_assignment_id, :presence => true
+ validates :action, :presence => true
+end
\ No newline at end of file
diff --git a/app/models/dmsf_workflow_step_assignment.rb b/app/models/dmsf_workflow_step_assignment.rb
new file mode 100644
index 00000000..1ffc5250
--- /dev/null
+++ b/app/models/dmsf_workflow_step_assignment.rb
@@ -0,0 +1,26 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 DmsfWorkflowStepAssignment < ActiveRecord::Base
+ belongs_to :dmsf_workflow_step
+
+ has_many :dmsf_workflow_step_actions, :dependent => :destroy
+
+ validates :dmsf_workflow_step_id, :presence => true
+ validates :dmsf_file_revision_id, :presence => true
+end
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/_action.html.erb b/app/views/dmsf_workflows/_action.html.erb
new file mode 100644
index 00000000..99b49e6e
--- /dev/null
+++ b/app/views/dmsf_workflows/_action.html.erb
@@ -0,0 +1,33 @@
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/_steps.html.erb b/app/views/dmsf_workflows/_steps.html.erb
new file mode 100644
index 00000000..70afad2a
--- /dev/null
+++ b/app/views/dmsf_workflows/_steps.html.erb
@@ -0,0 +1,81 @@
+<% if @workflow.project %>
+
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/action.html.erb b/app/views/dmsf_workflows/action.html.erb
new file mode 100644
index 00000000..d1a62773
--- /dev/null
+++ b/app/views/dmsf_workflows/action.html.erb
@@ -0,0 +1 @@
+
WorkflowController#action
diff --git a/app/views/dmsf_workflows/action.js.erb b/app/views/dmsf_workflows/action.js.erb
new file mode 100644
index 00000000..107ab390
--- /dev/null
+++ b/app/views/dmsf_workflows/action.js.erb
@@ -0,0 +1,3 @@
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'action', :locals => {:workflow => @workflow}) %>');
+showModal('ajax-modal', '400px');
+$('#ajax-modal').addClass('new-action');
diff --git a/app/views/dmsf_workflows/add_step.html.erb b/app/views/dmsf_workflows/add_step.html.erb
new file mode 100644
index 00000000..88143721
--- /dev/null
+++ b/app/views/dmsf_workflows/add_step.html.erb
@@ -0,0 +1 @@
+<%= render 'steps' %>
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/autocomplete_for_user.js.erb b/app/views/dmsf_workflows/autocomplete_for_user.js.erb
new file mode 100644
index 00000000..e74e6b4c
--- /dev/null
+++ b/app/views/dmsf_workflows/autocomplete_for_user.js.erb
@@ -0,0 +1 @@
+$('#users').html('<%= escape_javascript(render_principals_for_new_dmsf_workflow_users(@workflow)) %>');
diff --git a/app/views/dmsf_workflows/edit.html.erb b/app/views/dmsf_workflows/edit.html.erb
new file mode 100644
index 00000000..88143721
--- /dev/null
+++ b/app/views/dmsf_workflows/edit.html.erb
@@ -0,0 +1 @@
+<%= render 'steps' %>
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/index.html.erb b/app/views/dmsf_workflows/index.html.erb
new file mode 100644
index 00000000..6dce40e9
--- /dev/null
+++ b/app/views/dmsf_workflows/index.html.erb
@@ -0,0 +1 @@
+<%= render 'main' %>
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/log.html.erb b/app/views/dmsf_workflows/log.html.erb
new file mode 100644
index 00000000..6231320b
--- /dev/null
+++ b/app/views/dmsf_workflows/log.html.erb
@@ -0,0 +1 @@
+
WorkflowController#log
diff --git a/app/views/dmsf_workflows/new.html.erb b/app/views/dmsf_workflows/new.html.erb
new file mode 100644
index 00000000..d2f0103f
--- /dev/null
+++ b/app/views/dmsf_workflows/new.html.erb
@@ -0,0 +1,12 @@
+
<%= submit_tag(l(:submit_create)) %>
+
<% end %>
<% end %>
diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb
index a0263f83..edd3573f 100644
--- a/app/views/dmsf_files/show.html.erb
+++ b/app/views/dmsf_files/show.html.erb
@@ -101,11 +101,13 @@
<%= label_tag("", l(:label_workflow) + ":") %>
- <%= case revision.workflow
- when 1 then l(:option_workflow_waiting_for_approval)
- when 2 then l(:option_workflow_approved)
- else l(:option_workflow_none)
- end %>
+ <%= #case revision.workflow
+ # when 1 then l(:option_workflow_waiting_for_approval)
+ # when 2 then l(:option_workflow_approved)
+ # else l(:option_workflow_none)
+ # end
+ revision.workflow_str
+ %>
<%= label_tag("", l(:label_workflow) + ":") %>
- <%= case upload.workflow
- when 1 then l(:option_workflow_waiting_for_approval)
- when 2 then l(:option_workflow_approved)
- else l(:option_workflow_none)
- end %>
+ <%= #case upload.workflow
+ # when 1 then l(:option_workflow_waiting_for_approval)
+ # when 2 then l(:option_workflow_approved)
+ # else l(:option_workflow_none)
+ # end
+ upload.workflow_str
+ %>
<% end %>
diff --git a/app/views/dmsf_workflows/action.js.erb b/app/views/dmsf_workflows/action.js.erb
index 107ab390..b4294050 100644
--- a/app/views/dmsf_workflows/action.js.erb
+++ b/app/views/dmsf_workflows/action.js.erb
@@ -1,3 +1,3 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'action', :locals => {:workflow => @workflow}) %>');
showModal('ajax-modal', '400px');
-$('#ajax-modal').addClass('new-action');
+$('#ajax-modal').addClass('new-action');
\ No newline at end of file
diff --git a/app/views/dmsf_workflows/new_action.js.erb b/app/views/dmsf_workflows/new_action.js.erb
new file mode 100644
index 00000000..92d31fd2
--- /dev/null
+++ b/app/views/dmsf_workflows/new_action.js.erb
@@ -0,0 +1,2 @@
+$('#ajax-modal').modal('hide').empty();
+window.location.reload();
\ No newline at end of file
diff --git a/assets/images/draft.png b/assets/images/draft.png
new file mode 100644
index 0000000000000000000000000000000000000000..6902ab0cc75af10f160eb1b5f143c77b7f6dc3f8
GIT binary patch
literal 461
zcmV;;0W$uHP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01m?d01m?e$8V@)00007bV*G`2i*k^
z2puUwI-kD)00B)&L_t(2&vlSbCeG^&Ux!%-(Xnern{Y$XAYxD5tvASz>`=aPP7H}U6
zM7x^M8>$U|ZLq?p3BlH}4M6JD0pRdl@#NA4K(A{iSQ((0p}*4rpu1f$+@b@})~wT_
z>&0l=(_8+h;CbwwDaWI%V&+OYU)U~JuG(|?Z~Q=FE#<`G1Ik$w>X)7lgM)L2!LUJn
zl^~J6!M=ZW#GhKn03Sdk+{pM)D*&PuBNcl9{_KF!FDOrX`(+=XY;WUU;S@KTJzb
zm+jlMr*tV|6r{Ac(J{&{|QmLNSH00000NkvXXu0mjf
DQQ6Jc
literal 0
HcmV?d00001
diff --git a/assets/javascripts/dmsf.css b/assets/javascripts/dmsf.css
deleted file mode 100644
index 72eaa000..00000000
--- a/assets/javascripts/dmsf.css
+++ /dev/null
@@ -1,50 +0,0 @@
-/* An image next to the approval workflow item in the administration menu */
-#admin-menu a.workflow { background-image: url(../images/ticket_go.png); }
-
-.dmsf-entity-container {
- padding: 0% 2%;
-}
-
-.dmsf-entity-container .dmsf-entity {
- padding: 5px;
- line-height: 28px;
-}
-
-li.dmsf-entity-file,
-li.dmsf-entity-folder {
- border: 1px solid #628DB6;
- border-width: 1px 0;
- list-style: none;
- zoom: 1;
- overflow: hidden;
-}
-
-.dmsf-entity-container .dmsf-entity .dmsf-col {
- float: left;
- padding-top: 1px;
-}
-
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-name {
- width: 30%;
-}
-
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-cat {
- width: 15%;
-}
-
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-lock {
- width: 5%;
-}
-
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-size {
- width: 10%;
-}
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-modified {
- width: 10%;
-}
-.dmsf-entity-container .dmsf-entity .dmsf-col.dmsf-entity-action {
- width: 20%;
-}
-
-#users_for_delegate {height: 200px; overflow:auto;}
-#users_for_delegate label {display: block;}
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 41a96af5..bf4019e4 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -55,7 +55,7 @@ en:
:title_locked_by_user: "Locked by %{user}"
:title_locked_by_you: "Locked by you"
:title_waiting_for_approval: "Waiting for Approval"
- :title_approved: "Approved"
+ :title_approved: "Approved"
:title_unlock_file: "Unlock to allow changes for other members"
:title_lock_file: "Lock to prevent changes for other members"
:submit_download: "Download"
@@ -95,9 +95,7 @@ en:
:info_changed_by_user: "%{changed} by %{user}"
:label_filename: "Filename"
:label_version: "Version"
- :label_workflow: "Workflow"
- :option_workflow_waiting_for_approval: "Waiting for approval"
- :option_workflow_approved: "Approved"
+ :label_workflow: "Workflow"
:option_workflow_none: "None"
:label_mime: "Mime"
:label_size: "Size"
@@ -223,5 +221,8 @@ en:
label_dmsf: DMSF
label_dmsf_wokflow_action_approve: Approve
label_dmsf_wokflow_action_reject: Reject
- label_dmsf_wokflow_action_delegate: 'Delegate to:'
+ label_dmsf_wokflow_action_delegate: 'Delegate to'
message_dmsf_wokflow_note: Your note...
+ title_draft: Draft
+ title_rejected: Rejected
+ label_dmsf_wokflow_action_start: Start workflow
\ No newline at end of file
diff --git a/db/migrate/20120822100401_create_dmsf_workflows.rb b/db/migrate/20120822100401_create_dmsf_workflows.rb
index c6f20b9a..fbb00c29 100644
--- a/db/migrate/20120822100401_create_dmsf_workflows.rb
+++ b/db/migrate/20120822100401_create_dmsf_workflows.rb
@@ -1,3 +1,21 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 CreateDmsfWorkflows < ActiveRecord::Migration
def self.up
create_table :dmsf_workflows do |t|
@@ -5,9 +23,14 @@ class CreateDmsfWorkflows < ActiveRecord::Migration
t.references :project
end
add_index :dmsf_workflows, [:name], :unique => true
+
+ change_table :dmsf_file_revisions do |t|
+ t.references :dmsf_workflow
+ end
end
def self.down
+ remove_column :dmsf_file_revisions, :dmsf_workflow_id
drop_table :dmsf_workflows
end
end
diff --git a/db/migrate/20120822100402_create_dmsf_workflow_steps.rb b/db/migrate/20120822100402_create_dmsf_workflow_steps.rb
index 10c1f313..8d8b3c3a 100644
--- a/db/migrate/20120822100402_create_dmsf_workflow_steps.rb
+++ b/db/migrate/20120822100402_create_dmsf_workflow_steps.rb
@@ -1,3 +1,21 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 CreateDmsfWorkflowSteps < ActiveRecord::Migration
def self.up
create_table :dmsf_workflow_steps do |t|
diff --git a/db/migrate/20120822100403_create_dmsf_workflow_step_assignments.rb b/db/migrate/20120822100403_create_dmsf_workflow_step_assignments.rb
index c62f2b69..aff1e31f 100644
--- a/db/migrate/20120822100403_create_dmsf_workflow_step_assignments.rb
+++ b/db/migrate/20120822100403_create_dmsf_workflow_step_assignments.rb
@@ -1,3 +1,21 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 CreateDmsfWorkflowStepAssignments < ActiveRecord::Migration
def self.up
create_table :dmsf_workflow_step_assignments do |t|
diff --git a/db/migrate/20120822100404_create_dmsf_workflow_step_actions.rb b/db/migrate/20120822100404_create_dmsf_workflow_step_actions.rb
index 77663ab7..e7704c5e 100644
--- a/db/migrate/20120822100404_create_dmsf_workflow_step_actions.rb
+++ b/db/migrate/20120822100404_create_dmsf_workflow_step_actions.rb
@@ -1,3 +1,21 @@
+# Redmine plugin for Document Management System "Features"
+#
+# Copyright (C) 2013 Karel Picman
+#
+# 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 CreateDmsfWorkflowStepActions < ActiveRecord::Migration
def self.up
create_table :dmsf_workflow_step_actions do |t|
diff --git a/init.rb b/init.rb
index 1e78d64a..f864c5d9 100644
--- a/init.rb
+++ b/init.rb
@@ -66,9 +66,9 @@ Redmine::Plugin.register :redmine_dmsf do
menu.push :approvalworkflows, {:controller => 'dmsf_workflows', :action => 'index'}, :caption => :label_dmsf_workflow_plural
end
- # Adds javascript and stylesheet tags for project tree view
+ # Adds stylesheet tag
class DmsfViewListener < Redmine::Hook::ViewListener
- def view_layouts_base_html_head(context)
+ def view_layouts_base_html_head(context)
stylesheet_link_tag('dmsf', :plugin => :redmine_dmsf)
end
end
From 64d8c521df3a6c162c76026629f444b22bf6b77c Mon Sep 17 00:00:00 2001
From: Karel Picman
Date: Fri, 24 May 2013 14:25:36 +0200
Subject: [PATCH 04/10] Assigning of approval workflows to revisions
---
app/controllers/dmsf_controller.rb | 18 +++-
app/controllers/dmsf_workflows_controller.rb | 68 ++++++++++----
app/helpers/dmsf_workflows_helper.rb | 21 ++++-
app/models/dmsf_file_revision.rb | 27 +++---
app/models/dmsf_workflow.rb | 52 ++++++++---
app/models/dmsf_workflow_step.rb | 14 +--
app/models/dmsf_workflow_step_action.rb | 1 +
app/views/dmsf/show.html.erb | 87 ++++++++++--------
.../dmsf_files/_file_new_revision.html.erb | 2 +-
app/views/dmsf_files/show.html.erb | 71 ++++++--------
app/views/dmsf_mailer/files_updated.html.erb | 2 +-
app/views/dmsf_mailer/files_updated.text.erb | 2 +-
.../dmsf_mailer/files_updated.text.html.rhtml | 2 +-
.../files_updated.text.plain.rhtml | 2 +-
app/views/dmsf_upload/_upload_file.html.erb | 15 +--
.../dmsf_upload/_upload_file_locked.html.erb | 8 +-
app/views/dmsf_workflows/_action.html.erb | 26 ++----
app/views/dmsf_workflows/_assign.html.erb | 21 +++++
app/views/dmsf_workflows/_steps.html.erb | 4 +-
app/views/dmsf_workflows/action.html.erb | 1 -
app/views/dmsf_workflows/assign.js.erb | 3 +
.../autocomplete_for_user.html.erb | 1 +
.../autocomplete_for_user.js.erb | 1 -
assets/images/approve.png | Bin 535 -> 0 bytes
assets/images/approved.png | Bin 262 -> 752 bytes
assets/images/askforapproval.png | Bin 641 -> 0 bytes
assets/images/draft.png | Bin 461 -> 459 bytes
assets/images/none.png | Bin 0 -> 776 bytes
assets/images/rejected.png | Bin 0 -> 631 bytes
assets/images/waiting_for_approval.png | Bin 0 -> 630 bytes
assets/images/waitingforapproval.png | Bin 412 -> 0 bytes
assets/images/workflowdisabled.png | Bin 1392 -> 0 bytes
assets/stylesheets/dmsf.css | 28 +++++-
config/locales/en.yml | 9 +-
config/routes.rb | 5 +-
init.rb | 10 +-
36 files changed, 309 insertions(+), 192 deletions(-)
create mode 100644 app/views/dmsf_workflows/_assign.html.erb
delete mode 100644 app/views/dmsf_workflows/action.html.erb
create mode 100644 app/views/dmsf_workflows/assign.js.erb
create mode 100644 app/views/dmsf_workflows/autocomplete_for_user.html.erb
delete mode 100644 app/views/dmsf_workflows/autocomplete_for_user.js.erb
delete mode 100644 assets/images/approve.png
delete mode 100644 assets/images/askforapproval.png
create mode 100644 assets/images/none.png
create mode 100644 assets/images/rejected.png
create mode 100644 assets/images/waiting_for_approval.png
delete mode 100644 assets/images/waitingforapproval.png
delete mode 100644 assets/images/workflowdisabled.png
diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb
index 579ca759..211f4d4b 100644
--- a/app/controllers/dmsf_controller.rb
+++ b/app/controllers/dmsf_controller.rb
@@ -255,8 +255,22 @@ class DmsfController < ApplicationController
redirect_to params[:current] ? params[:current] :
{:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
end
-
-
+
+ def assign
+ end
+
+ def assignment
+ revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
+ if revision
+ revision.set_workflow(params[:dmsf_workflow_id], params[:action])
+ revision.assign_workflow(params[:dmsf_workflow_id])
+ if request.post? && revision.save
+ flash[:notice] = l(:notice_successful_create)
+ end
+ end
+ redirect_to params[:current] ? params[:current] :
+ {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder}
+ end
private
diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb
index 33bb5806..9416ea3b 100644
--- a/app/controllers/dmsf_workflows_controller.rb
+++ b/app/controllers/dmsf_workflows_controller.rb
@@ -20,9 +20,9 @@ class DmsfWorkflowsController < ApplicationController
unloadable
layout :workflows_layout
- before_filter :find_workflow, :except => [:create, :new, :index]
- before_filter :find_project
- before_filter :authorize_global, :except => [:action, :new_action]
+ before_filter :find_workflow, :except => [:create, :new, :index, :assign, :assignment]
+ before_filter :find_project, :except => [:start]
+ before_filter :authorize_global #, :except => [:action, :new_action]
def index
if @project
@@ -35,18 +35,40 @@ class DmsfWorkflowsController < ApplicationController
def action
end
- def new_action
- action = DmsfWorkflowStepAction.new(
- :dmsf_workflow_step_assignment_id => params[:dmsf_workflow_step_assignment_id],
- :action => params[:step_action],
- :note => params[:note])
- if request.post? && action.save
- @workflow.try_finish params[:dmsf_file_revision_id]
- flash[:notice] = l(:notice_successful_create)
- end
- # TODO: Refresh the page!
+ def new_action
+ if params[:commit] == l(:submit_commit)
+ action = DmsfWorkflowStepAction.new(
+ :dmsf_workflow_step_assignment_id => params[:dmsf_workflow_step_assignment_id],
+ :action => params[:step_action],
+ :note => params[:note])
+ if request.post?
+ if action.save
+ @workflow.try_finish params[:dmsf_file_revision_id], action, params[:user_id]
+ flash[:notice] = l(:notice_successful_update)
+ else
+ flash[:error] = l(:error_empty_note)
+ end
+ end
+ end
redirect_to :back
end
+
+ def assign
+ end
+
+ def assignment
+ if params[:commit] == l(:button_assign)
+ revision = DmsfFileRevision.find_by_id params[:dmsf_file_revision_id]
+ if revision
+ revision.set_workflow(params[:dmsf_workflow_id], params[:action])
+ revision.assign_workflow(params[:dmsf_workflow_id])
+ if request.post? && revision.save
+ flash[:notice] = l(:notice_successful_update)
+ end
+ end
+ end
+ redirect_to :back
+ end
def log
end
@@ -87,7 +109,8 @@ class DmsfWorkflowsController < ApplicationController
def destroy
begin
- @workflow.destroy
+ @workflow.destroy
+ flash[:notice] = l(:notice_successful_delete)
rescue
flash[:error] = l(:error_unable_delete_dmsf_workflow)
end
@@ -98,10 +121,8 @@ class DmsfWorkflowsController < ApplicationController
end
end
- def autocomplete_for_user
- respond_to do |format|
- format.js
- end
+ def autocomplete_for_user
+ render :layout => false
end
def add_step
@@ -158,6 +179,17 @@ class DmsfWorkflowsController < ApplicationController
end
end
+ def start
+ revision = DmsfFileRevision.find_by_id(params[:dmsf_file_revision_id])
+ if revision
+ revision.set_workflow(@workflow.id, params[:action])
+ if request.post? && revision.save
+ flash[:notice] = l(:notice_successful_update)
+ end
+ end
+ redirect_to :back
+ end
+
private
def find_workflow
diff --git a/app/helpers/dmsf_workflows_helper.rb b/app/helpers/dmsf_workflows_helper.rb
index 65a9371d..690e109d 100644
--- a/app/helpers/dmsf_workflows_helper.rb
+++ b/app/helpers/dmsf_workflows_helper.rb
@@ -18,19 +18,24 @@
module DmsfWorkflowsHelper
- def render_principals_for_new_dmsf_workflow_users(workflow)
- scope = User.active.sorted.like(params[:q])
+ def render_principals_for_new_dmsf_workflow_users(workflow, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
+ scope = workflow.delegates(params[:q], dmsf_workflow_step_assignment_id, dmsf_file_revision_id, nil)
principal_count = scope.count
- principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
+ principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page']
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
- s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals')
+ if dmsf_workflow_step_assignment_id
+ s = content_tag('div', principals_radio_button_tags('step_action', principals), :id => 'users_for_delegate')
+ else
+ s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'users')
+ end
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
link_to text, autocomplete_for_user_dmsf_workflow_path(workflow, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
}
s + content_tag('p', links, :class => 'pagination')
+ s.html_safe
end
def dmsf_workflow_steps_options_for_select(steps)
@@ -50,4 +55,12 @@ module DmsfWorkflowsHelper
end
options_for_select(options, :selected => dmsf_workflow_id)
end
+
+ def principals_radio_button_tags(name, principals)
+ s = ''
+ principals.each do |principal|
+ s << "\n"
+ end
+ s.html_safe
+ end
end
diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb
index a28c96be..0ce4c46f 100644
--- a/app/models/dmsf_file_revision.rb
+++ b/app/models/dmsf_file_revision.rb
@@ -156,19 +156,22 @@ class DmsfFileRevision < ActiveRecord::Base
return new_revision
end
- def workflow_str
- str = ''
- if dmsf_workflow_id
+ def workflow_str(name)
+ if name && dmsf_workflow_id
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
str = "#{wf.name} - " if wf
+ else
+ str = ''
end
case workflow
- when 1
+ when DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
str + l(:title_waiting_for_approval)
- when 2
+ when DmsfWorkflow::STATE_APPROVED
str + l(:title_approved)
- when 3
+ when DmsfWorkflow::STATE_DRAFT
str + l(:title_draft)
+ when DmsfWorkflow::STATE_REJECTED
+ str + l(:title_rejected)
else
str
end
@@ -178,21 +181,21 @@ class DmsfFileRevision < ActiveRecord::Base
if User.current.allowed_to?(:file_approval, self.file.project)
unless dmsf_workflow_id.blank?
self.dmsf_workflow_id = dmsf_workflow_id
- if commit == l(:label_dmsf_wokflow_action_start)
- self.workflow = 1 # Waiting for approval
+ if commit == 'start'
+ self.workflow = DmsfWorkflow::STATE_WAITING_FOR_APPROVAL # Waiting for approval
else
- self.workflow = 3 # Draft
- end
+ self.workflow = DmsfWorkflow::STATE_DRAFT # Draft
+ end
end
end
end
def assign_workflow(dmsf_workflow_id)
if User.current.allowed_to?(:file_approval, self.file.project)
- if self.workflow == 1 # Waiting for approval
+ #if self.workflow == DmsfWorkflow::STATE_DRAFT # Waiting for approval
wf = DmsfWorkflow.find_by_id(dmsf_workflow_id)
wf.assign(self.id) if wf && self.id
- end
+ #end
end
end
diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb
index 74708290..7b995ee3 100644
--- a/app/models/dmsf_workflow.rb
+++ b/app/models/dmsf_workflow.rb
@@ -42,7 +42,7 @@ class DmsfWorkflow < ActiveRecord::Base
def to_s
name
- end
+ end
def approvals(step)
wa = Array.new
@@ -109,9 +109,24 @@ class DmsfWorkflow < ActiveRecord::Base
end
end
end
-
- def delegates
- User.all
+
+ def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id, project_id)
+ if project_id
+ sql = ['id IN (SELECT user_id FROM members WHERE project_id = ?', project_id]
+ elsif dmsf_workflow_step_assignment_id && dmsf_file_revision_id
+ sql = [
+ 'id NOT IN (SELECT a.user_id FROM dmsf_workflow_step_assignments a WHERE id = ?) AND id IN (SELECT m.user_id FROM members m JOIN dmsf_file_revisions r ON m.project_id = r.project_id WHERE r.id = ?)',
+ dmsf_workflow_step_assignment_id,
+ dmsf_file_revision_id]
+ else
+ sql = '1=1'
+ end
+
+ unless q.nil? || q.empty?
+ User.active.sorted.where(sql).like(q)
+ else
+ User.active.sorted.where(sql)
+ end
end
def get_free_assignment(user, dmsf_file_revision_id)
@@ -130,17 +145,28 @@ class DmsfWorkflow < ActiveRecord::Base
end
end
- def try_finish(dmsf_file_revision_id)
+ def try_finish(dmsf_file_revision_id, action, user_id)
res = nil
- steps = DmsfWorkflowStep.where(:dmsf_workflow_id => self.id).all
- steps.each do |step|
- res = step.result dmsf_file_revision_id
- unless step.finished? dmsf_file_revision_id
- return
- end
+ case action.action
+ when DmsfWorkflowStepAction::ACTION_APPROVE
+ steps = DmsfWorkflowStep.where(:dmsf_workflow_id => self.id).all
+ steps.each do |step|
+ res = step.result dmsf_file_revision_id
+ unless step.finished? dmsf_file_revision_id
+ return
+ end
+ end
+ when DmsfWorkflowStepAction::ACTION_REJECT
+ res = DmsfWorkflow::STATE_REJECTED
+ when DmsfWorkflowStepAction::ACTION_DELEGATE
+ assignment = DmsfWorkflowStepAssignment.find_by_id(action.dmsf_workflow_step_assignment_id)
+ assignment.update_attribute(:user_id, user_id) if assignment
+ end
+
+ if res
+ revision = DmsfFileRevision.find_by_id dmsf_file_revision_id
+ revision.update_attribute(:workflow, res) if revision
end
- revision = DmsfFileRevision.find_by_id dmsf_file_revision_id
- revision.update_attribute(:workflow, res) if revision && res
end
end
\ No newline at end of file
diff --git a/app/models/dmsf_workflow_step.rb b/app/models/dmsf_workflow_step.rb
index de8baa72..52458ed6 100644
--- a/app/models/dmsf_workflow_step.rb
+++ b/app/models/dmsf_workflow_step.rb
@@ -77,14 +77,16 @@ class DmsfWorkflowStep < ActiveRecord::Base
:dmsf_workflow_step_id => self.id,
:dmsf_file_revision_id => dmsf_file_revision_id,
:user_id => user.id).first
- actions = DmsfWorkflowStepAction.where(
- :dmsf_workflow_step_assignment_id => assignment.id).all
- actions.each do |action|
- if action && action.is_finished?
- return
+ if assignment
+ actions = DmsfWorkflowStepAction.where(
+ :dmsf_workflow_step_assignment_id => assignment.id).all
+ actions.each do |action|
+ if action && action.is_finished?
+ return
+ end
end
+ return assignment.id
end
- return assignment.id
end
end
\ No newline at end of file
diff --git a/app/models/dmsf_workflow_step_action.rb b/app/models/dmsf_workflow_step_action.rb
index 9748aa3b..568e4252 100644
--- a/app/models/dmsf_workflow_step_action.rb
+++ b/app/models/dmsf_workflow_step_action.rb
@@ -22,6 +22,7 @@ class DmsfWorkflowStepAction < ActiveRecord::Base
validates :dmsf_workflow_step_assignment_id, :presence => true
validates :action, :presence => true
+ validates :note, :presence => true, :unless => lambda { self.action == DmsfWorkflowStepAction::ACTION_APPROVE }
ACTION_APPROVE = 1
ACTION_REJECT = 2
diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb
index 9702a086..aec9a1c3 100644
--- a/app/views/dmsf/show.html.erb
+++ b/app/views/dmsf/show.html.erb
@@ -65,7 +65,7 @@
<%= link_to_user User.find_by_id(revision.dmsf_workflow_assigned_by) if revision.dmsf_workflow_assigned_by %>
+
Assigned
+
+
<%= format_time(revision.dmsf_workflow_assigned_at) if revision.dmsf_workflow_assigned_at %>
+
+
+
-
+
<%= link_to_user User.find_by_id(revision.dmsf_workflow_started_by) if revision.dmsf_workflow_started_by %>
+
Started
+
+
<%= format_time(revision.dmsf_workflow_started_at) if revision.dmsf_workflow_started_at %>
+
+ <% 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 JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY c.created_at" %>
+ <% result = DmsfWorkflowStep.connection.execute sql %>
+ <% result.each_with_index do |row, i| %>
+
<%= format_time(revision.dmsf_workflow_started_at) if revision.dmsf_workflow_started_at %>
- <% 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 JOIN dmsf_workflow_steps s ON s.id = a.dmsf_workflow_step_id WHERE a.dmsf_file_revision_id = #{revision.id} ORDER BY c.created_at" %>
+ <% 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 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.created_at" %>
<% result = DmsfWorkflowStep.connection.execute sql %>
<% result.each_with_index do |row, i| %>
@@ -32,7 +40,7 @@
<% 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 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.created_at" %>
<% result = DmsfWorkflowStep.connection.execute sql %>
<% result.each_with_index do |row, i| %>
-