go_gamification 0.0.7 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/images/go_gamification/hair.png +0 -0
- data/app/assets/images/go_gamification/head.png +0 -0
- data/app/assets/images/go_gamification/leftArm-jump.png +0 -0
- data/app/assets/images/go_gamification/leftArm.png +0 -0
- data/app/assets/images/go_gamification/legs-jump.png +0 -0
- data/app/assets/images/go_gamification/legs.png +0 -0
- data/app/assets/images/go_gamification/rightArm-jump.png +0 -0
- data/app/assets/images/go_gamification/rightArm.png +0 -0
- data/app/assets/images/go_gamification/torso.png +0 -0
- data/app/assets/javascripts/go_gamification/character.js.erb +193 -0
- data/app/assets/javascripts/go_gamification/excanvas.js +924 -0
- data/app/controllers/gamification/levels_controller.rb +63 -0
- data/app/controllers/gamification/rewards_controller.rb +51 -0
- data/app/helpers/{go_gamification → gamification}/application_helper.rb +1 -1
- data/app/helpers/gamification/rewards_helper.rb +6 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/gamification.rb +6 -0
- data/{lib/go_gamification/concerns/models → app/models/gamification}/goal.rb +3 -7
- data/app/models/gamification/level.rb +6 -0
- data/app/models/gamification/medal.rb +7 -0
- data/{lib/go_gamification/concerns/models → app/models/gamification}/reward.rb +3 -5
- data/app/uploaders/{go_gamification → gamification}/image_uploader.rb +1 -1
- data/app/views/gamification/levels/_form.html.erb +17 -0
- data/app/views/gamification/levels/edit.html.erb +6 -0
- data/app/views/gamification/levels/index.html.erb +24 -0
- data/app/views/gamification/levels/new.html.erb +5 -0
- data/app/views/gamification/levels/show.html.erb +4 -0
- data/app/views/{go_gamification → gamification}/rewards/_presentation.html.erb +2 -0
- data/app/views/{go_gamification → gamification}/rewards/_reward.html.erb +1 -1
- data/app/views/{go_gamification → gamification}/scorings/create.html.erb +0 -0
- data/config/initializers/assets.rb +2 -0
- data/config/routes.rb +5 -1
- data/db/migrate/20171020181447_create_go_gamification_tasks.rb +1 -1
- data/db/migrate/20171020181620_create_go_gamification_scorings.rb +2 -2
- data/db/migrate/20171020182027_rename_everything.rb +5 -5
- data/db/migrate/20171020182119_create_go_gamification_medals.rb +1 -1
- data/db/migrate/20171020182210_add_description_to_go_gamification_medals.rb +1 -1
- data/db/migrate/20171020182248_rename_go_gamification_tasks_to_goals.rb +3 -3
- data/db/migrate/20171020182329_add_seen_at_to_go_gamification_rewards.rb +2 -2
- data/db/migrate/20171023230506_create_go_gamification_levels.rb +9 -0
- data/lib/go_gamification.rb +1 -3
- data/lib/go_gamification/engine.rb +2 -19
- data/lib/go_gamification/version.rb +1 -1
- metadata +49 -25
- data/app/controllers/go_gamification/application_controller.rb +0 -4
- data/app/controllers/go_gamification/rewards_controller.rb +0 -7
- data/app/helpers/go_gamification/rewards_helper.rb +0 -20
- data/app/models/go_gamification/goal.rb +0 -5
- data/app/models/go_gamification/medal.rb +0 -5
- data/app/models/go_gamification/reward.rb +0 -5
- data/lib/go_gamification/activerecord.rb +0 -13
- data/lib/go_gamification/checksum.rb +0 -28
- data/lib/go_gamification/concerns.rb +0 -6
- data/lib/go_gamification/concerns/controllers.rb +0 -3
- data/lib/go_gamification/concerns/controllers/rewards_controller.rb +0 -55
- data/lib/go_gamification/concerns/models.rb +0 -5
- data/lib/go_gamification/concerns/models/medal.rb +0 -13
- data/lib/go_gamification/concerns/rewardable.rb +0 -12
- data/lib/go_gamification/concerns/rewarding.rb +0 -7
@@ -0,0 +1,63 @@
|
|
1
|
+
module Gamification
|
2
|
+
class LevelsController < ApplicationController
|
3
|
+
|
4
|
+
before_action :set_level, only: [:show, :edit, :update, :destroy]
|
5
|
+
|
6
|
+
# GET /levels
|
7
|
+
def index
|
8
|
+
@levels = Level.all
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /levels/1
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /levels/new
|
16
|
+
def new
|
17
|
+
@level = Level.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /levels/1/edit
|
21
|
+
def edit
|
22
|
+
end
|
23
|
+
|
24
|
+
# POST /levels
|
25
|
+
def create
|
26
|
+
@level = Level.new(level_params)
|
27
|
+
|
28
|
+
if @level.save
|
29
|
+
redirect_to @level, notice: 'Level was successfully created.'
|
30
|
+
else
|
31
|
+
render :new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# PATCH/PUT /levels/1
|
36
|
+
def update
|
37
|
+
if @level.update(level_params)
|
38
|
+
redirect_to @level, notice: 'Level was successfully updated.'
|
39
|
+
else
|
40
|
+
render :edit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# DELETE /levels/1
|
45
|
+
def destroy
|
46
|
+
@level.destroy
|
47
|
+
redirect_to levels_url, notice: 'Level was successfully destroyed.'
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
# Use callbacks to share common setup or constraints between actions.
|
52
|
+
def set_level
|
53
|
+
@level = Level.find(params[:id])
|
54
|
+
end
|
55
|
+
|
56
|
+
# Only allow a trusted parameter "white list" through.
|
57
|
+
def level_params
|
58
|
+
params.fetch(:level, {})
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Gamification
|
2
|
+
class RewardsController < ApplicationController
|
3
|
+
before_action :verify_checksum
|
4
|
+
|
5
|
+
def create
|
6
|
+
if rewarding.is_a? ::Gamification::Goal
|
7
|
+
rewarding.complete_for rewardable
|
8
|
+
else
|
9
|
+
rewarding.goals.each do |goal|
|
10
|
+
goal.complete_for rewardable
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
respond_to do |format|
|
15
|
+
format.json { render json: {}, status: :created }
|
16
|
+
format.html { redirect_to redirect_url }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def verify_checksum
|
23
|
+
render text: "Invalid checksum", status: :forbidden unless Checksum.verify(params[:checksum],
|
24
|
+
[rewarding.class.name, rewarding.id, rewardable.class.name, rewardable.id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def redirect_url
|
28
|
+
params[:redirect_url] || request.env['HTTP_REFERER']
|
29
|
+
end
|
30
|
+
|
31
|
+
def rewarding
|
32
|
+
rewarding_model.find reward_params[:rewarding_id]
|
33
|
+
end
|
34
|
+
|
35
|
+
def rewardable
|
36
|
+
rewardable_model.find reward_params[:rewardable_id]
|
37
|
+
end
|
38
|
+
|
39
|
+
def rewarding_model
|
40
|
+
reward_params[:rewarding_type].constantize
|
41
|
+
end
|
42
|
+
|
43
|
+
def rewardable_model
|
44
|
+
reward_params[:rewardable_type].constantize
|
45
|
+
end
|
46
|
+
|
47
|
+
def reward_params
|
48
|
+
params.require(:reward).permit(:rewarding_type, :rewarding_id, :rewardable_type, :rewardable_id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
included do
|
1
|
+
module Gamification
|
2
|
+
class Goal < ApplicationRecord
|
5
3
|
belongs_to :rewarding, polymorphic: true
|
6
4
|
has_one :medal, dependent: :destroy
|
7
5
|
has_many :rewards, dependent: :destroy
|
@@ -26,7 +24,7 @@ module GoGamification::Concerns::Models::Goal
|
|
26
24
|
if completed_by? subject
|
27
25
|
raise Completed, "#{self} is already completed for #{subject}"
|
28
26
|
else
|
29
|
-
|
27
|
+
Reward.create! goal: self, rewardable: subject
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
@@ -38,7 +36,5 @@ module GoGamification::Concerns::Models::Goal
|
|
38
36
|
def reward_for rewardable
|
39
37
|
rewards.find_by rewardable: rewardable
|
40
38
|
end
|
41
|
-
|
42
|
-
class Completed < StandardError; end
|
43
39
|
end
|
44
40
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
included do
|
5
|
-
belongs_to :goal, class_name: 'GoGamification::Goal'
|
1
|
+
module Gamification
|
2
|
+
class Reward < ApplicationRecord
|
3
|
+
belongs_to :goal
|
6
4
|
belongs_to :rewardable, polymorphic: true, inverse_of: :rewards
|
7
5
|
|
8
6
|
scope :unseen, -> { where seen_at: nil }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_with(model: level, local: true) do |form| %>
|
2
|
+
<% if level.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(level.errors.count, "error") %> prohibited this level from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% level.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= form.submit %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Levels</h1>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th colspan="3"></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @levels.each do |level| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= link_to 'Show', level %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_level_path(level) %></td>
|
17
|
+
<td><%= link_to 'Destroy', level, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<div class="col-xs-6">
|
3
3
|
<div class="push-5"><%= image_tag reward.medal.image.icon32 %></div>
|
4
4
|
<div class="h5 font-w300 text-muted"><%= reward.medal.name %> - <%= reward.medal.description %></div>
|
5
|
+
<div class="h5 font-w300 text-muted"><%= reward.points %> xp</div>
|
5
6
|
</div>
|
6
7
|
<% end %>
|
7
8
|
|
8
|
-
<div class="points"><%= reward.points %></div>
|
9
9
|
|
File without changes
|
data/config/routes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class CreateGoGamificationScorings < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :gamification_scorings do |t|
|
4
4
|
t.references :task,index: {:name => "index_game_scoring_on_tasks"}
|
5
5
|
t.references :subjectable, polymorphic: true,index: {:name => "index_game_scoring_on_subjectable"}
|
6
6
|
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
|
-
add_index :
|
9
|
+
add_index :gamification_scorings, [:subjectable_id, :subjectable_type], name: 'index_go_game_score_on_subjectable'
|
10
10
|
end
|
11
11
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class RenameEverything < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
|
-
|
4
|
-
rename_column :
|
5
|
-
rename_column :
|
3
|
+
rename_table :gamification_scorings, :gamification_rewards
|
4
|
+
rename_column :gamification_rewards, :subjectable_id, :rewardable_id
|
5
|
+
rename_column :gamification_rewards, :subjectable_type, :rewardable_type
|
6
6
|
|
7
|
-
rename_column :
|
8
|
-
rename_column :
|
7
|
+
rename_column :gamification_tasks, :taskable_id, :rewarding_id
|
8
|
+
rename_column :gamification_tasks, :taskable_type, :rewarding_type
|
9
9
|
end
|
10
10
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class RenameGoGamificationTasksToGoals < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
|
-
rename_table :
|
4
|
-
rename_column :
|
5
|
-
rename_column :
|
3
|
+
rename_table :gamification_tasks, :gamification_goals
|
4
|
+
rename_column :gamification_rewards, :task_id, :goal_id
|
5
|
+
rename_column :gamification_medals, :task_id, :goal_id
|
6
6
|
end
|
7
7
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class AddSeenAtToGoGamificationRewards < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
|
-
change_table :
|
3
|
+
change_table :gamification_rewards do |t|
|
4
4
|
t.datetime :seen_at
|
5
5
|
end
|
6
6
|
|
7
|
-
add_index :
|
7
|
+
add_index :gamification_rewards, :seen_at, name: 'index_go_gamification_rewards_on_seen_at'
|
8
8
|
end
|
9
9
|
end
|
data/lib/go_gamification.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module GoGamification
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
|
4
|
-
initializer :append_migrations do |app|
|
3
|
+
initializer :append_migrations do |app|
|
5
4
|
# This prevents migrations from being loaded twice from the inside of the
|
6
5
|
# gem itself (dummy test app)
|
7
6
|
if app.root.to_s !~ /#{root}/
|
@@ -11,21 +10,5 @@ module GoGamification
|
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
initializer 'go_gamification.action_controller' do |app|
|
15
|
-
ActiveSupport.on_load :action_controller do
|
16
|
-
helper GoGamification::ApplicationHelper
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
initializer 'go_gamification.factories', after: 'factory_girl.set_factory_paths' do
|
21
|
-
FactoryGirl.definition_file_paths << File.expand_path('../../../spec/factories', __FILE__) if defined?(FactoryGirl)
|
22
|
-
end
|
23
|
-
|
24
|
-
config.generators do |g|
|
25
|
-
g.test_framework :rspec, fixture: false
|
26
|
-
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
27
|
-
g.assets false
|
28
|
-
g.helper false
|
29
|
-
end
|
30
13
|
end
|
31
|
-
end
|
14
|
+
end
|