From c0a31f4849a1ebfa89d2832260dca08fc66ac1a1 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Tue, 10 Sep 2019 09:41:59 +0300 Subject: [PATCH] Demo for acts_as_mentionable --- app/models/issue.rb | 1 + lib/plugins/acts_as_mentionable/init.rb | 5 ++ .../lib/acts_as_mentionable.rb | 55 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 lib/plugins/acts_as_mentionable/init.rb create mode 100644 lib/plugins/acts_as_mentionable/lib/acts_as_mentionable.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index 507574de7..e6d566b36 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -43,6 +43,7 @@ class Issue < ActiveRecord::Base acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed acts_as_customizable acts_as_watchable + acts_as_mentionable :attributes => ['description'] acts_as_searchable :columns => ['subject', "#{table_name}.description"], :preload => [:project, :status, :tracker], :scope => lambda {|options| options[:open_issues] ? self.open : self.all} diff --git a/lib/plugins/acts_as_mentionable/init.rb b/lib/plugins/acts_as_mentionable/init.rb new file mode 100644 index 000000000..248383f3c --- /dev/null +++ b/lib/plugins/acts_as_mentionable/init.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +# Include hook code here +require File.dirname(__FILE__) + '/lib/acts_as_mentionable' +ActiveRecord::Base.send(:include, Redmine::Acts::Mentionable) diff --git a/lib/plugins/acts_as_mentionable/lib/acts_as_mentionable.rb b/lib/plugins/acts_as_mentionable/lib/acts_as_mentionable.rb new file mode 100644 index 000000000..eed31fb77 --- /dev/null +++ b/lib/plugins/acts_as_mentionable/lib/acts_as_mentionable.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2019 Jean-Philippe Lang +# +# 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 Redmine + module Acts + module Mentionable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def acts_as_mentionable(options = {}) + return if self.included_modules.include?(Redmine::Acts::Mentionable::InstanceMethods) + + cattr_accessor :mentionable_attributes + self.mentionable_attributes = options[:attributes] + + send :include, Redmine::Acts::Mentionable::InstanceMethods + + after_save :mentioned_users + end + end + + module InstanceMethods + def self.included(base) + base.extend ClassMethods + end + + def mentioned_users + puts "****"*50 + puts self.saved_changes.inspect + end + + module ClassMethods + end + end + end + end +end -- 2.22.0