From 126523c7bd011c2b17297b8722aecd39de8d3a55 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Mon, 19 Aug 2013 15:26:47 +0200 Subject: [PATCH] Email notifications of the root folder --- app/controllers/dmsf_controller.rb | 38 ++++++--- app/models/dmsf_file.rb | 1 + app/models/dmsf_folder.rb | 1 + app/views/dmsf/_path.html.erb | 8 -- app/views/dmsf/show.html.erb | 80 +++++++++++-------- app/views/dmsf_mailer/files_updated.html.erb | 43 +++++----- .../dmsf_mailer/files_updated.text.html.rhtml | 25 ------ .../files_updated.text.plain.rhtml | 6 -- .../workflow_notification.html.erb | 23 ++---- app/views/dmsf_upload/upload_files.html.erb | 10 ++- db/migrate/20130819013955_update_projects.rb | 28 +++++++ 11 files changed, 140 insertions(+), 123 deletions(-) delete mode 100644 app/views/dmsf/_path.html.erb delete mode 100644 app/views/dmsf_mailer/files_updated.text.html.rhtml delete mode 100644 app/views/dmsf_mailer/files_updated.text.plain.rhtml create mode 100644 db/migrate/20130819013955_update_projects.rb diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 936c6052..9e940e5a 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -203,26 +203,46 @@ class DmsfController < ApplicationController redirect_to :controller => "dmsf", :action => "show", :id => @project end - def notify_activate - if @folder.notification + def notify_activate + if((@folder && @folder.notification) || (@folder.nil? && @project.dmsf_notification)) flash[:warning] = l(:warning_folder_notifications_already_activated) else - @folder.notify_activate + if @folder + @folder.notify_activate + else + @project.dmsf_notification = true + @project.save + end flash[:notice] = l(:notice_folder_notifications_activated) end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + if params[:current] + redirect_to params[:current] + elsif @folder + redirect_to({:controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @folder.folder}) + else + redirect_to({:controller => 'dmsf', :action => 'show', :id => @project}) + end end def notify_deactivate - if !@folder.notification + if((@folder && !@folder.notification) || (@folder.nil? && !@project.dmsf_notification)) flash[:warning] = l(:warning_folder_notifications_already_deactivated) else - @folder.notify_deactivate + if @folder + @folder.notify_deactivate + else + @project.dmsf_notification = false + @project.save + end flash[:notice] = l(:notice_folder_notifications_deactivated) end - redirect_to params[:current] ? params[:current] : - {:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder.folder} + if params[:current] + redirect_to params[:current] + elsif @folder + redirect_to({:controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @folder.folder}) + else + redirect_to({:controller => 'dmsf', :action => 'show', :id => @project}) + end end diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index ca5b7461..216383ad 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -157,6 +157,7 @@ class DmsfFile < ActiveRecord::Base def notify? return true if self.notification return true if folder && folder.notify? + return true if !folder && self.project.dmsf_notification return false end diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 8ab595e2..45103f67 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -115,6 +115,7 @@ class DmsfFolder < ActiveRecord::Base def notify? return true if self.notification return true if folder && folder.notify? + return true if !folder && self.project.dmsf_notification return false end diff --git a/app/views/dmsf/_path.html.erb b/app/views/dmsf/_path.html.erb deleted file mode 100644 index a937bff4..00000000 --- a/app/views/dmsf/_path.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= link_to(l(:link_documents), {:controller => "dmsf", :action => "show", :id=> @project }) %> -<% path.each do |path_element| %> - / - <%= link_to(h(path_element.title), {:controller => "dmsf", :action => "show", :id=> @project, :folder_id => path_element}) %> - <% if path_element.notification %> - <%= image_tag("notify.png", :plugin => "redmine_dmsf", :title => l(:title_notifications_active)) %> - <% end %> -<% end %> diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index bc4309aa..cb5be56a 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -1,40 +1,56 @@ <% html_title(l(:dmsf)) %>
- <% if User.current.allowed_to?(:folder_manipulation, @project) %> - <% if !@folder.nil? && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) %> - <% if @folder.locked? %> - <% unless @folder.unlockable? %> - <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_folder_parent_locked, :name => @folder.folder.lock.reverse[0].folder.title)) unless @folder.nil?%> - <% else %> - <%= link_to_function(image_tag("unlock.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'unlock', :id => @project, :folder_id => @folder, :current => request.url)}')", - :title => l(:title_unlock_folder)) unless @folder.nil?%> - <% end %> - <% else %> - <%= link_to_function(image_tag("lock.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'lock', :id => @project, :folder_id => @folder, :current => request.url)}')", - :title => l(:title_lock_folder)) unless @folder.nil?%> - <% end %> - <% end %> - <% if @folder.nil? %> -   - <%= link_to("", {:action => "edit_root", :id => @project}, - :title => l(:link_edit, :title => l(:link_documents)), :class => "icon icon-edit") %> - <% elsif (!@folder.nil? && !@folder.locked_for_user? ) %> -   - <%= link_to("", {:action => "edit", :id => @project, :folder_id => @folder }, - :title => l(:link_edit, :title => h(@folder.title)), :class => "icon icon-edit") %> - <% end %> -   - <%= link_to("", {:action => "new", :id => @project, :parent_id => @folder }, - :title => l(:link_create_folder), :class => "icon icon-add") unless (!@folder.nil? && @folder.locked_for_user?) %> - <% end %> + <% if User.current.allowed_to?(:folder_manipulation, @project) %> + <% if @folder.nil? %> +   + <%= link_to('', {:action => 'edit_root', :id => @project}, + :title => l(:link_edit, :title => l(:link_documents)), :class => 'icon icon-edit') %> + <% elsif (@folder && !@folder.locked_for_user? ) %> +   + <%= link_to('', {:action => 'edit', :id => @project, :folder_id => @folder }, + :title => l(:link_edit, :title => h(@folder.title)), :class => 'icon icon-edit') %> + <% end %> + <% if @folder && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)) %> + <% if @folder.locked? %> + <% unless @folder.unlockable? %> + <%= image_tag('locked.png', :plugin => :redmine_dmsf, :title => l(:title_folder_parent_locked, :name => @folder.folder.lock.reverse[0].folder.title)) unless @folder.nil?%> + <% else %> + <%= link_to_function(image_tag('unlock.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'unlock', :id => @project, :folder_id => @folder, :current => request.url)}')", + :title => l(:title_unlock_folder)) if @folder %> + <% end %> + <% else %> + <%= link_to_function(image_tag('lock.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'lock', :id => @project, :folder_id => @folder, :current => request.url)}')", + :title => l(:title_lock_folder)) if @folder %> + <% end %> + <% end %> + <% unless @folder %> +   + <% if @project.dmsf_notification %> + <%= link_to_function(image_tag('notify.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:action => 'notify_deactivate', :id => @project)}')", + :title => l(:title_notifications_active_deactivate)) %> + <% else %> + <%= link_to_function(image_tag('notifynot.png', :plugin => :redmine_dmsf), + "manipulation_link('#{url_for(:action => 'notify_activate', :id => @project)}')", + :title => l(:title_notifications_not_active_activate)) %> + <% end %> + <% end %> +   + <%= link_to('', {:action => 'new', :id => @project, :parent_id => @folder }, + :title => l(:link_create_folder), :class => 'icon icon-add') unless (@folder && @folder.locked_for_user?) %> + <% end %>
-<% path = @folder.nil? ? [] : @folder.dmsf_path %> -

- <%= render(:partial => 'path', :locals => {:path => path}) %> +

+ <% path = @folder ? @folder.dmsf_path : [] %> + <%= link_to l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> @project } %> + <% path.each do |path_element| %> + / + <%= link_to h(path_element.title), {:controller => 'dmsf', :action => 'show', :id=> @project, :folder_id => path_element} %> + <% end %>

diff --git a/app/views/dmsf_mailer/files_updated.html.erb b/app/views/dmsf_mailer/files_updated.html.erb index 5c6c2bc0..aa38a991 100644 --- a/app/views/dmsf_mailer/files_updated.html.erb +++ b/app/views/dmsf_mailer/files_updated.html.erb @@ -1,25 +1,18 @@ - - - - - - - User <%= link_to(h(@user), {:only_path => false, :controller => "users", :action => "show", :id => @user }) %> - actualized DMSF files in project <%= @project.name %>: - <% @files.each do |file| %> -

- <%= link_to(h(file.dmsf_path_str), - {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file, - :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(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? %> -
    <%= h(file.last_revision.comment) %> - <% end %> -

- <% end %> - - \ No newline at end of file +User <%= link_to(h(@user), {:only_path => false, :controller => "users", :action => "show", :id => @user }) %> +actualized DMSF files in project <%= @project.name %>: +<% @files.each do |file| %> +

+ <%= link_to(h(file.dmsf_path_str), + {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file, + :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(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? %> +
    <%= h(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 deleted file mode 100644 index 5c6c2bc0..00000000 --- a/app/views/dmsf_mailer/files_updated.text.html.rhtml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - User <%= link_to(h(@user), {:only_path => false, :controller => "users", :action => "show", :id => @user }) %> - actualized DMSF files in project <%= @project.name %>: - <% @files.each do |file| %> -

- <%= link_to(h(file.dmsf_path_str), - {:only_path => false, :controller => "dmsf_files", :action => "show", :id => file, - :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(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? %> -
    <%= h(file.last_revision.comment) %> - <% end %> -

- <% end %> - - \ No newline at end of file diff --git a/app/views/dmsf_mailer/files_updated.text.plain.rhtml b/app/views/dmsf_mailer/files_updated.text.plain.rhtml deleted file mode 100644 index fcd0ea79..00000000 --- a/app/views/dmsf_mailer/files_updated.text.plain.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -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(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/workflow_notification.html.erb b/app/views/dmsf_mailer/workflow_notification.html.erb index 9741cca8..765e5d40 100644 --- a/app/views/dmsf_mailer/workflow_notification.html.erb +++ b/app/views/dmsf_mailer/workflow_notification.html.erb @@ -1,15 +1,8 @@ - - - - - - -

Dear user,

-

- <%= @text1 %> -

-

- <%= @text2 %> -

- - \ No newline at end of file +

Dear user,

+

+ <%= @text1 %> +

+

+ <%= @text2 %> +

+ \ No newline at end of file diff --git a/app/views/dmsf_upload/upload_files.html.erb b/app/views/dmsf_upload/upload_files.html.erb index 38a1532b..4a43f9b1 100644 --- a/app/views/dmsf_upload/upload_files.html.erb +++ b/app/views/dmsf_upload/upload_files.html.erb @@ -3,9 +3,13 @@
-<% path = @folder.nil? ? [] : @folder.dmsf_path %> -

- <%= render(:partial => '/dmsf/path', :locals => {:path => path}) %> +

+ <% path = @folder ? @folder.dmsf_path : [] %> + <%= link_to l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> @project } %> + <% path.each do |path_element| %> + / + <%= link_to h(path_element.title), {:controller => 'dmsf', :action => 'show', :id=> @project, :folder_id => path_element} %> + <% end %>

diff --git a/db/migrate/20130819013955_update_projects.rb b/db/migrate/20130819013955_update_projects.rb new file mode 100644 index 00000000..c41f2e2d --- /dev/null +++ b/db/migrate/20130819013955_update_projects.rb @@ -0,0 +1,28 @@ +# 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 UpdateProjects < ActiveRecord::Migration + def self.up + # DMSF - project's root folder notification + add_column :projects, :dmsf_notification, :boolean + end + + def self.down + remove_column :porojects, :dmsf_notification + end +end \ No newline at end of file