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 @@
- <%= label_tag("workflow", l(:label_workflow) + ":") %> + <%= label_tag('workflow', l(:label_workflow) + ':') %> <%= select_tag( 'dmsf_workflow_id', dmsf_workflows_for_select(@project, @file.last_revision.dmsf_workflow_id))%> diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb index edd3573f..f1458a6a 100644 --- a/app/views/dmsf_files/show.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -57,7 +57,8 @@
- <%= label_tag("", l(:label_title) + ":") %> - <%= h(revision.title) %> -
+- <%= label_tag("", l(:label_file) + ":") %> - <%= (h(revision.folder.dmsf_path_str) + "/") unless revision.folder.nil? %><%= h(revision.name) %> -
+@@ -94,42 +93,30 @@ <%= textilizable(revision.description) %>
- <%= label_tag("", l(:label_version) + ":") %> - <%= revision.major_version %>.<%= revision.minor_version %> -
-- <%= 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 - revision.workflow_str - %> -
+- <%= label_tag("", l(:label_mime) + ":") %> - <%= h(revision.mime_type) %> -
-- <%= label_tag("", l(:label_size) + ":") %> - <%= number_to_human_size(revision.size) %> -
-+
<%= pagination_links_full @revision_pages, @file.revisions.visible.count %>
diff --git a/app/views/dmsf_mailer/files_updated.html.erb b/app/views/dmsf_mailer/files_updated.html.erb index 545256e2..5c6c2bc0 100644 --- a/app/views/dmsf_mailer/files_updated.html.erb +++ b/app/views/dmsf_mailer/files_updated.html.erb @@ -13,7 +13,7 @@ :download => ""}) %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>, - <%= "#{file.last_revision.workflow_str}," unless file.last_revision.workflow_str.blank? %> + <%= "#{file.last_revision.workflow_str(true)}," unless file.last_revision.workflow_str(true).blank? %> <%= link_to("Details", {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %> diff --git a/app/views/dmsf_mailer/files_updated.text.erb b/app/views/dmsf_mailer/files_updated.text.erb index b78bd7c2..fcd0ea79 100644 --- a/app/views/dmsf_mailer/files_updated.text.erb +++ b/app/views/dmsf_mailer/files_updated.text.erb @@ -1,6 +1,6 @@ User <%= @user %> actualized DMSF files in project <%= @project.name %>: <% @files.each do |file| %> - <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str}" unless file.last_revision.workflow_str.blank? %> + <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str(true)}" unless file.last_revision.workflow_str(true).blank? %> <%= url_for({:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %> comment: <%= file.last_revision.comment %><% end %> <% end %> \ No newline at end of file diff --git a/app/views/dmsf_mailer/files_updated.text.html.rhtml b/app/views/dmsf_mailer/files_updated.text.html.rhtml index 545256e2..5c6c2bc0 100644 --- a/app/views/dmsf_mailer/files_updated.text.html.rhtml +++ b/app/views/dmsf_mailer/files_updated.text.html.rhtml @@ -13,7 +13,7 @@ :download => ""}) %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>, - <%= "#{file.last_revision.workflow_str}," unless file.last_revision.workflow_str.blank? %> + <%= "#{file.last_revision.workflow_str(true)}," unless file.last_revision.workflow_str(true).blank? %> <%= link_to("Details", {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %> diff --git a/app/views/dmsf_mailer/files_updated.text.plain.rhtml b/app/views/dmsf_mailer/files_updated.text.plain.rhtml index b78bd7c2..fcd0ea79 100644 --- a/app/views/dmsf_mailer/files_updated.text.plain.rhtml +++ b/app/views/dmsf_mailer/files_updated.text.plain.rhtml @@ -1,6 +1,6 @@ User <%= @user %> actualized DMSF files in project <%= @project.name %>: <% @files.each do |file| %> - <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str}" unless file.last_revision.workflow_str.blank? %> + <%= file.dmsf_path_str %> (<%= file.name %>), <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %><%= ", #{file.last_revision.workflow_str(true)}" unless file.last_revision.workflow_str(true).blank? %> <%= url_for({:only_path => false, :controller => "dmsf_files", :action => "show", :id => file}) %> <% unless file.last_revision.comment.blank? %> comment: <%= file.last_revision.comment %><% end %> <% end %> \ No newline at end of file diff --git a/app/views/dmsf_upload/_upload_file.html.erb b/app/views/dmsf_upload/_upload_file.html.erb index 4f52aef8..8e56cf62 100644 --- a/app/views/dmsf_upload/_upload_file.html.erb +++ b/app/views/dmsf_upload/_upload_file.html.erb @@ -1,17 +1,4 @@ -<% -#disabled_workflow = [] -#selected_workflow = nil -#unless User.current.allowed_to?(:file_approval, @project) - #disabled_workflow << 2 - #current_workflow = upload.workflow - #if current_workflow == 1 || current_workflow == 2 - #disabled_workflow << nil - #selected_workflow = 1 - #end -#else - #selected_workflow = upload.workflow -#end -%> +<%= 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 - upload.workflow_str - %> + <%= upload.workflow_str true %>
-
- <%= text_field_tag 'user_search', nil %>
+ <%= label_tag 'delegate', l(:label_dmsf_wokflow_action_delegate) %>
+ <%= text_field_tag 'user_search', nil %>
+ <%= javascript_tag "observeSearchfield('user_search', 'users_for_delegate', '#{ escape_javascript autocomplete_for_user_dmsf_workflow_path(@workflow, :dmsf_workflow_step_assignment_id => params[:dmsf_workflow_step_assignment_id], :dmsf_file_revision_id => params[:dmsf_file_revision_id]) }')" %>
+ <%= content_tag('div', principals_radio_button_tags('step_action', @workflow.delegates(nil, params[:dmsf_workflow_step_assignment_id], params[:dmsf_file_revision_id], nil)), :id => 'users_for_delegate') %>
+ <%= label_tag('workflow', l(:label_workflow) + ':') %> + <%= select_tag( + 'dmsf_workflow_id', + dmsf_workflows_for_select(@project, nil))%> +
+ + +<% end %> diff --git a/app/views/dmsf_workflows/_steps.html.erb b/app/views/dmsf_workflows/_steps.html.erb index 70afad2a..2d57c895 100644 --- a/app/views/dmsf_workflows/_steps.html.erb +++ b/app/views/dmsf_workflows/_steps.html.erb @@ -61,10 +61,10 @@