gamification_plugin.rb
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class GamificationPlugin < Noosfero::Plugin
def self.plugin_name
"Gamification Plugin"
end
def self.plugin_description
_("Gamification Plugin")
end
def self.settings(environment)
Noosfero::Plugin::Settings.new(environment, GamificationPlugin)
end
def user_data_extras
proc do
current_person.present? ? {:gamification_plugin => {:points => current_person.points, :badges => current_person.badges, :level => current_person.level}} : {}
end
end
# Override initial rules with environment specific rules
def self.gamification_set_rules(environment)
Merit::AppPointRules.clear
Merit::AppBadgeRules.clear
Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules)
Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules)
end
def application_controller_filters
[{
:type => 'before_filter', :method_name => 'gamification_set_rules',
:options => {}, :block => proc { GamificationPlugin.gamification_set_rules(environment) }
}]
end
def body_ending
proc do
if current_person.present? && response.status == 200
badges = current_person.badges.notification_pending.all
current_person.sash.notify_all_badges_from_user
render :file => 'gamification/display_notifications', :locals => {:badges => badges}
else
''
end
end
end
def stylesheet?
true
end
def js_files
['jquery.noty.packaged.min.js', 'jquery.easypiechart.min.js', 'main.js', 'admin.js']
end
def self.extra_blocks
{ GamificationPlugin::RankingBlock => {}}
end
def self.api_mount_points
[GamificationPlugin::API]
end
ActionDispatch::Reloader.to_prepare do
Merit.setup do |config|
config.checks_on_each_request = false
config.user_model_name = 'Profile'
config.current_user_method = 'current_person'
config.add_observer 'Merit::PointTrackObserver'
config.add_observer 'Merit::RankObserver'
Merit::PointRules.setup
end
require_dependency 'merit_ext'
end
end