aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-27 00:27:28 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-27 01:50:47 +0100
commit8cac49181e39a3a4b74555e12ad4688a345467f8 (patch)
treec3bec8fc22b7f1d2f37c6f218b4a5c345f990c08
parentb127a972d43c6069bd054c6b0ad7fbf316c7e788 (diff)
downloadecs2-8cac49181e39a3a4b74555e12ad4688a345467f8.tar.gz
ecs2-8cac49181e39a3a4b74555e12ad4688a345467f8.zip
Add reset action button.
Add new reset action to admin participant. Also introduced action buttons (delete and reset).
-rw-r--r--app/controllers/admin/participants_controller.rb45
-rw-r--r--app/helpers/admin/participants_helper.rb49
-rw-r--r--app/models/message.rb6
-rw-r--r--app/models/participant.rb18
-rw-r--r--app/views/admin/participants/list.html.haml19
-rw-r--r--app/views/layouts/application.html.erb7
-rw-r--r--config/ecs_config.yml3
-rw-r--r--config/initializers/ecs_00.rb1
-rw-r--r--config/routes.rb2
-rw-r--r--test/functional/admin/participants_controller_test.rb2
10 files changed, 131 insertions, 21 deletions
diff --git a/app/controllers/admin/participants_controller.rb b/app/controllers/admin/participants_controller.rb
index f8c195e..e6babf9 100644
--- a/app/controllers/admin/participants_controller.rb
+++ b/app/controllers/admin/participants_controller.rb
@@ -23,7 +23,7 @@ class Admin::ParticipantsController < ApplicationController
include Admin::Helper
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
- verify :method => [ :post, :put, :delete ], :only => [ :destroy, :create, :update, :destroy_participant ],
+ verify :method => [ :post, :put, :delete ], :only => [ :destroy, :create, :update, :destroy_participant, :reset ],
:add_flash => { :notice => "Failed to execute last action" },
:redirect_to => :admin_participants_path
@@ -35,11 +35,11 @@ class Admin::ParticipantsController < ApplicationController
list
render :action => 'list'
end
-
- def list
+
+ def list
@list_participants_anonymous_count = Participant.all.count - Participant.without_anonymous.count
@participants = case params[:anonymous]
- when "true"
+ when "true"
@list_anonymous=true
@list_participants_count = Participant.all.count
Participant.find(:all).uniq
@@ -52,12 +52,20 @@ class Admin::ParticipantsController < ApplicationController
@list_participants_count = Participant.all.count - @list_participants_anonymous_count
Participant.without_anonymous.uniq
end
+ @action_buttons = case params[:actionbuttons]
+ when "true"
+ true
+ when "false"
+ false
+ else
+ false
+ end
end
-
+
def show
@participant = Participant.find(params[:id])
end
-
+
def new
@participant = Participant.new
@organizations = Organization.find(:all, :order => :id)
@@ -80,7 +88,16 @@ class Admin::ParticipantsController < ApplicationController
@participant = Participant.find(params[:id])
@organizations = Organization.find(:all, :order => :id)
end
-
+
+ def reset
+ @participant = Participant.find(params[:id])
+ @participant.destroy_receiver_messages
+ @participant.destroy_sender_messages
+ @participant.destroy_events
+ flash[:notice] = "Successfully cleared all sent and received messages and events of participant \"#{CGI.escapeHTML @participant.name}\"."
+ redirect_to_admin_participants_path
+ end
+
def update
params[:participant][:community_ids] ||= []
@organizations = Organization.find(:all, :order => :id)
@@ -124,9 +141,20 @@ class Admin::ParticipantsController < ApplicationController
create_membership(params[:c_id], params[:id])
redirect_to admin_participant_communities_path(params[:id])
end
-
+
private
+ def redirect_to_admin_participants_path
+ queryparams={}
+ if params[:anonymous]
+ queryparams[:anonymous]=true
+ end
+ if params[:actionbuttons]
+ queryparams[:actionbuttons]=true
+ end
+ redirect_to admin_participants_path(queryparams)
+ end
+
# Generate destroyed events for all messages unconnected in respect to the
# leaving communities.
def generate_destroyed_events_by_leaving_a_community(participant, messages )
@@ -145,5 +173,4 @@ private
end
leaved_messages.flatten.compact.uniq
end
-
end
diff --git a/app/helpers/admin/participants_helper.rb b/app/helpers/admin/participants_helper.rb
index d6245e7..6d90ed5 100644
--- a/app/helpers/admin/participants_helper.rb
+++ b/app/helpers/admin/participants_helper.rb
@@ -18,6 +18,8 @@
module Admin::ParticipantsHelper
+ @queryparams = [[:list_anonymous,:anonymous], [:action_buttons, :actionbuttons]]
+
# adds an empty identity object to the p.identities collection. This object
# ist still not saved. This collection is reused in the form.fields_for method.
# (form.fields_for :identities ...)
@@ -28,4 +30,51 @@ module Admin::ParticipantsHelper
end
end
+ def button_to_reset(participant, list_anonymous, action_buttons)
+ button_to_reset = "button_to 'Reset', reset_admin_participant_path(:id => participant,#{(list_anonymous)?":anonymous => true":":anonymous => false"}"
+ button_to_reset += ", #{(action_buttons)?":actionbuttons => true":":actionbuttons => false"})"
+ button_to_reset += ", :title => 'All messages and events of \"#{h participant.name}\" participant will be deleted. #{(ECS_CONFIG["admin"]["confirm_actions"])?"":"There will be no confirmation !"}'"
+ button_to_reset += ", #{(action_buttons)?":disabled => false":":disabled => true"}"
+ button_to_reset += ", :confirm => 'Are you sure?'" if ECS_CONFIG["admin"]["confirm_actions"]
+ eval button_to_reset
+ end
+
+ def button_to_delete(participant, list_anonymous, action_buttons)
+ button_to_delete = "button_to 'Delete', admin_participant_path(:id => participant,#{(list_anonymous)?":anonymous => true":":anonymous => false"}"
+ button_to_delete += ", #{(action_buttons)?":actionbuttons => true":":actionbuttons => false"})"
+ button_to_delete +=", :method => :delete"
+ button_to_delete +=", :title => 'The \"#{h participant.name}\" participant will be deleted. #{(ECS_CONFIG["admin"]["confirm_actions"])?"":"There will be no confirmation !"}'"
+ button_to_delete += ", #{(action_buttons)?":disabled => false":":disabled => true"}"
+ button_to_delete += ", :confirm => 'Are you sure?'" if ECS_CONFIG["admin"]["confirm_actions"]
+ eval button_to_delete
+ end
+
+ def link_to_actions_toggle_on_off(list_anonymous, action_buttons)
+ Rails.logger.info "Admin::ParticipantsHelper#link_to_actions_toggle_on_off actionbuttons = #{action_buttons}"
+ link = "link_to #{(action_buttons)?'\'off\'':'\'on\''}, admin_participants_path(#{(list_anonymous)?":anonymous => true":":anonymous => false"}"
+ link +=", #{(action_buttons)?":actionbuttons => false":":actionbuttons => true"})"
+ unless action_buttons
+ session[:link_to_actions_toggle_on_off] = false
+ end
+ if not session[:link_to_actions_toggle_on_off] and action_buttons
+ session[:link_to_actions_toggle_on_off] = true
+ unless ECS_CONFIG["admin"]["confirm_actions"]
+ flash.now[:notice] = "Action buttons operate in NON CONFIRMATION mode, .i.e. pressing a delete or reset button just do its job without any confirmation. You have been warned ! To change this behaviour, just set \"admin->confirm_actions\" to \"true\" in \"config/ecs_config.yml\"."
+ end
+ end
+ eval link
+ end
+
+ def link_to_anonymous_toggle_on_off(list_anonymous, action_buttons)
+ end
+
+ def toggle_query_param(queryparam)
+ end
+
+ def link_to_toggle_on_off(ontext, offtext, list_anonymous, action_buttons)
+ #link = "link_to #{(action_buttons)?\'offtext\':\'ontext\'}, admin_participants_path(#{(list_anonymous)?":anonymous => true":":anonymous => false"}"
+ #link +=", #{(action_buttons)?":actionbuttons => false":":actionbuttons => true"})"
+ #eval link
+ end
+
end
diff --git a/app/models/message.rb b/app/models/message.rb
index f7f3d24..7cfb417 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -32,11 +32,13 @@ class Message < ActiveRecord::Base
named_scope :for_participant_receiver, lambda {|participant| {
:joins => {:membership_messages => {:membership => :participant}},
:order => "id ASC",
- :conditions => {:participants => {:id => participant.id}}}}
+ :conditions => {:participants => {:id => participant.id}},
+ :readonly => false}}
named_scope :for_participant_sender, lambda {|participant| {
:order => "id ASC",
- :conditions => {:sender => participant.id}}}
+ :conditions => {:sender => participant.id},
+ :readonly => false}}
named_scope :for_not_removed, lambda { {
:order => "id ASC",
diff --git a/app/models/participant.rb b/app/models/participant.rb
index 2252aa7..5fc363c 100644
--- a/app/models/participant.rb
+++ b/app/models/participant.rb
@@ -73,6 +73,24 @@ class Participant < ActiveRecord::Base
only_anonymous.order_id_asc.reduced_attributes
end
+ def destroy_receiver_messages
+ Message.for_participant_receiver(self).each do |m|
+ m.destroy_as_receiver(self)
+ end
+ end
+
+ def destroy_sender_messages
+ Message.for_participant_sender(self).each do |m|
+ m.destroy_as_sender
+ end
+ end
+
+ def destroy_events
+ self.events.each do |e|
+ e.destroy
+ end
+ end
+
def mainparticipant?
if not anonymousparticipant? and subparticipant.nil?
true
diff --git a/app/views/admin/participants/list.html.haml b/app/views/admin/participants/list.html.haml
index 0d426ce..0bf37db 100644
--- a/app/views/admin/participants/list.html.haml
+++ b/app/views/admin/participants/list.html.haml
@@ -15,7 +15,7 @@
You should have received a copy of the GNU Affero General Public
License along with ECS. If not, see <http://www.gnu.org/licenses/>.
-
+
%h1.box1 Listing Participants (#{@list_participants_count.to_s})
@@ -34,7 +34,7 @@
%th.box2 Description (optional):
%th.box2 Self-<br/>routing:
%th.box2 Events:
- %th.box2(align="center") Operations:
+ %th.box2(align="center")= "Links, Actions(#{link_to_actions_toggle_on_off(@list_anonymous, @action_buttons)})"
%tr
- @participants.group_by(&:organization_id).sort{|x,y| Organization.find(x[0]).abrev.downcase <=> Organization.find(y[0]).abrev.downcase}.each do |orgid,participants|
@@ -46,12 +46,19 @@
- else
%td= Organization.find(orgid).abrev
%td.center= participant.id
- %td= participant.name
+ %td= h participant.name
%td= truncate(participant.description, :length => 80)
%td.center= check_box_tag "participant[community_selfrouting]",1,participant.community_selfrouting, :disabled => true
%td.center= check_box_tag "participant[events_]",1,participant.events_, :disabled => true
%td
- = link_to 'Show', admin_participant_path(:id => participant)
- = link_to 'Edit', edit_admin_participant_path(:id => participant)
- = link_to 'Destroy', admin_participant_path(:id => participant),:confirm => 'Are you sure?', :method => :delete
+ %table
+ %tr
+ %td
+ = link_to 'Show', admin_participant_path(:id => participant)
+ = link_to 'Edit', edit_admin_participant_path(:id => participant)
+ &nbsp;&nbsp;
+ %td
+ = button_to_reset(participant, @list_anonymous, @action_buttons)
+ %td
+ = button_to_delete(participant, @list_anonymous, @action_buttons)
- org_printed= true
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 085269b..1d7404a 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -35,7 +35,12 @@ License along with ECS. If not, see <http://www.gnu.org/licenses/>.
</div>
<%= render(:partial => "shared/main_menu_line") %>
<div id="main">
- <p style="color: green"><%= flash[:notice] %></p>
+ <% if flash[:notice] -%>
+ <div id="notice">
+ <%= flash[:notice] %>
+ </div>
+ <!-- <p style="color: green"><%= flash[:notice] %></p> -->
+ <% end -%>
<%= yield %>
</div>
</body>
diff --git a/config/ecs_config.yml b/config/ecs_config.yml
index b3af8fe..77cebb0 100644
--- a/config/ecs_config.yml
+++ b/config/ecs_config.yml
@@ -1,4 +1,5 @@
participants:
allow_anonymous: false
allow_events: true # for database migration
-
+admin:
+ confirm_actions: false
diff --git a/config/initializers/ecs_00.rb b/config/initializers/ecs_00.rb
index 6aa5db3..c750fc5 100644
--- a/config/initializers/ecs_00.rb
+++ b/config/initializers/ecs_00.rb
@@ -37,3 +37,4 @@ end
ECS_CONFIG["participants"]["allow_anonymous"] = false unless defined? ECS_CONFIG["participants"]["allow_anonymous"]
ECS_CONFIG["participants"]["allow_events"] = true unless defined? ECS_CONFIG["participants"]["allow_events"]
+ECS_CONFIG["admin"]["confirm_actions"] = true unless defined? ECS_CONFIG["admin"]["confirm_actions"]
diff --git a/config/routes.rb b/config/routes.rb
index 1b68e1a..4e9b72b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -20,7 +20,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace(:admin) do |admin|
- admin.resources :participants
+ admin.resources :participants, :member => { :reset => :post }
admin.resources :communities, :has_many => :participants
admin.resources :organizations
admin.resources :ressources
diff --git a/test/functional/admin/participants_controller_test.rb b/test/functional/admin/participants_controller_test.rb
index b9133a9..a521ea6 100644
--- a/test/functional/admin/participants_controller_test.rb
+++ b/test/functional/admin/participants_controller_test.rb
@@ -39,7 +39,7 @@ class Admin::ParticipantsControllerTest < ActionController::TestCase
assert_difference('Participant.count') do
post :create, params
end
- assert_equal('Participant was successfully created.',flash[:notice])
+ assert_equal('Participant "testclient" was successfully created.',flash[:notice])
assert_equal(communities(:wuv).id, Participant.find_by_name("testclient").communities.first.id)
assert_equal(1,Participant.find_by_name("testclient").memberships.first.membership_messages.count)
end