Skip to content

Commit

Permalink
Merge branch 'release/0.5.5_patch.5'
Browse files Browse the repository at this point in the history
* release/0.5.5_patch.5:
  #FIX fix trash
  #FIX bad fix
  • Loading branch information
kalashnikovisme committed Jan 10, 2016
2 parents 7b520e4 + ff920a0 commit e200297
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
20 changes: 20 additions & 0 deletions app/controllers/concerns/trash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Concerns
module Trash
def to_trash_param(type)
type.to_s.split('::').map(&:underscore).join '-'
end

def parse_trash_param(param)
type = nil
if param.to_sym.in? trash_models
type = param
else
modules = param.split('-')
if modules.count > 1 && modules.all? { |mod| mod.to_sym.in?(trash_modules) || mod.to_sym.in?(trash_models) }
type = modules.join '/'
end
end
type.camelize.constantize
end
end
end
17 changes: 5 additions & 12 deletions app/controllers/web/admin/trash_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Web::Admin::TrashController < Web::Admin::ApplicationController
include Concerns::Trash

def index
@type = resource_type
@items = resource_type.removed.page(params[:page]).decorate
Expand All @@ -7,27 +9,18 @@ def index
def restore
item = resource_type.find params[:id]
item.restore
redirect_to type_admin_trash_index_path(resource_type)
redirect_to type_admin_trash_index_path to_trash_param resource_type
end

def destroy
item = resource_type.find params[:id]
item.destroy
redirect_to type_admin_trash_index_path(resource_type)
redirect_to type_admin_trash_index_path to_trash_param resource_type
end

private

def resource_type
resource = nil
if params[:type].to_sym.in? trash_models
resource = params[:type]
else
modules = params[:type].split('-')
if modules.count > 1 && modules.all? { |mod| mod.to_sym.in?(trash_modules) || mod.to_sym.in?(trash_models) }
resource = modules.join '/'
end
end
resource.camelize.constantize
parse_trash_param params[:type]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ActivityLines::Corporative::ConfessionDecorator < ApplicationDecorator
decorates_association :member

def short_name
object.member&.decorate.short_name
object.member.decorate.short_name
end

alias name short_name
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/web/admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,5 @@ def to_path(constant)
constant.name.underscore.gsub '/', '_'
end

def to_trash_param(class_name)
class_name.to_s.split('::').map(&:underscore).join '-'
end
include Concerns::Trash
end
3 changes: 2 additions & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Member < User
has_many :events, as: :organizer,
foreign_key: :organizer_id
has_many :news, foreign_key: :user_id
has_many :confessions, class_name: 'ActivityLines::Corporative::Confession'
has_many :confessions, class_name: 'ActivityLines::Corporative::Confession',
dependent: :destroy

validates :first_name, human_name: true,
allow_blank: true
Expand Down
4 changes: 2 additions & 2 deletions app/views/web/admin/trash/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
%td= item.id
%td= item.name
%td.actions
= link_to restore_admin_trash_path(item, type: @type), method: :patch, class: 'btn btn-primary btn-xs' do
= link_to restore_admin_trash_path(item, type: to_trash_param(@type)), method: :patch, class: 'btn btn-primary btn-xs' do
%span.glyphicon.glyphicon-open
= link_to admin_trash_path(item, type: @type), method: :delete, class: 'btn btn-xs btn-danger' do
= link_to admin_trash_path(item, type: to_trash_param(@type)), method: :delete, class: 'btn btn-xs btn-danger' do
%span.glyphicon.glyphicon-remove
= paginate @items, theme: 'twitter-bootstrap-3'

0 comments on commit e200297

Please sign in to comment.