go_gamification 0.0.7 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/go_gamification/hair.png +0 -0
  3. data/app/assets/images/go_gamification/head.png +0 -0
  4. data/app/assets/images/go_gamification/leftArm-jump.png +0 -0
  5. data/app/assets/images/go_gamification/leftArm.png +0 -0
  6. data/app/assets/images/go_gamification/legs-jump.png +0 -0
  7. data/app/assets/images/go_gamification/legs.png +0 -0
  8. data/app/assets/images/go_gamification/rightArm-jump.png +0 -0
  9. data/app/assets/images/go_gamification/rightArm.png +0 -0
  10. data/app/assets/images/go_gamification/torso.png +0 -0
  11. data/app/assets/javascripts/go_gamification/character.js.erb +193 -0
  12. data/app/assets/javascripts/go_gamification/excanvas.js +924 -0
  13. data/app/controllers/gamification/levels_controller.rb +63 -0
  14. data/app/controllers/gamification/rewards_controller.rb +51 -0
  15. data/app/helpers/{go_gamification → gamification}/application_helper.rb +1 -1
  16. data/app/helpers/gamification/rewards_helper.rb +6 -0
  17. data/app/models/application_record.rb +3 -0
  18. data/app/models/gamification.rb +6 -0
  19. data/{lib/go_gamification/concerns/models → app/models/gamification}/goal.rb +3 -7
  20. data/app/models/gamification/level.rb +6 -0
  21. data/app/models/gamification/medal.rb +7 -0
  22. data/{lib/go_gamification/concerns/models → app/models/gamification}/reward.rb +3 -5
  23. data/app/uploaders/{go_gamification → gamification}/image_uploader.rb +1 -1
  24. data/app/views/gamification/levels/_form.html.erb +17 -0
  25. data/app/views/gamification/levels/edit.html.erb +6 -0
  26. data/app/views/gamification/levels/index.html.erb +24 -0
  27. data/app/views/gamification/levels/new.html.erb +5 -0
  28. data/app/views/gamification/levels/show.html.erb +4 -0
  29. data/app/views/{go_gamification → gamification}/rewards/_presentation.html.erb +2 -0
  30. data/app/views/{go_gamification → gamification}/rewards/_reward.html.erb +1 -1
  31. data/app/views/{go_gamification → gamification}/scorings/create.html.erb +0 -0
  32. data/config/initializers/assets.rb +2 -0
  33. data/config/routes.rb +5 -1
  34. data/db/migrate/20171020181447_create_go_gamification_tasks.rb +1 -1
  35. data/db/migrate/20171020181620_create_go_gamification_scorings.rb +2 -2
  36. data/db/migrate/20171020182027_rename_everything.rb +5 -5
  37. data/db/migrate/20171020182119_create_go_gamification_medals.rb +1 -1
  38. data/db/migrate/20171020182210_add_description_to_go_gamification_medals.rb +1 -1
  39. data/db/migrate/20171020182248_rename_go_gamification_tasks_to_goals.rb +3 -3
  40. data/db/migrate/20171020182329_add_seen_at_to_go_gamification_rewards.rb +2 -2
  41. data/db/migrate/20171023230506_create_go_gamification_levels.rb +9 -0
  42. data/lib/go_gamification.rb +1 -3
  43. data/lib/go_gamification/engine.rb +2 -19
  44. data/lib/go_gamification/version.rb +1 -1
  45. metadata +49 -25
  46. data/app/controllers/go_gamification/application_controller.rb +0 -4
  47. data/app/controllers/go_gamification/rewards_controller.rb +0 -7
  48. data/app/helpers/go_gamification/rewards_helper.rb +0 -20
  49. data/app/models/go_gamification/goal.rb +0 -5
  50. data/app/models/go_gamification/medal.rb +0 -5
  51. data/app/models/go_gamification/reward.rb +0 -5
  52. data/lib/go_gamification/activerecord.rb +0 -13
  53. data/lib/go_gamification/checksum.rb +0 -28
  54. data/lib/go_gamification/concerns.rb +0 -6
  55. data/lib/go_gamification/concerns/controllers.rb +0 -3
  56. data/lib/go_gamification/concerns/controllers/rewards_controller.rb +0 -55
  57. data/lib/go_gamification/concerns/models.rb +0 -5
  58. data/lib/go_gamification/concerns/models/medal.rb +0 -13
  59. data/lib/go_gamification/concerns/rewardable.rb +0 -12
  60. 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,4 +1,4 @@
1
- module GoGamification
1
+ module Gamification
2
2
  module ApplicationHelper
3
3
 
4
4
 
@@ -0,0 +1,6 @@
1
+ module Gamification
2
+ module RewardsHelper
3
+
4
+
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,6 @@
1
+ module Gamification
2
+ def self.table_name_prefix
3
+ 'gamification_'
4
+ end
5
+ end
6
+
@@ -1,7 +1,5 @@
1
- module GoGamification::Concerns::Models::Goal
2
- extend ActiveSupport::Concern
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
- ::GoGamification::Reward.create! goal: self, rewardable: subject
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
@@ -0,0 +1,6 @@
1
+ module Gamification
2
+ class Level < ApplicationRecord
3
+ end
4
+ end
5
+
6
+
@@ -0,0 +1,7 @@
1
+ module Gamification
2
+ class Medal < ApplicationRecord
3
+ belongs_to :goal
4
+
5
+ mount_uploader :image, ImageUploader
6
+ end
7
+ end
@@ -1,8 +1,6 @@
1
- module GoGamification::Concerns::Models::Reward
2
- extend ActiveSupport::Concern
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 }
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'carrierwave'
3
3
 
4
- class GoGamification::ImageUploader < CarrierWave::Uploader::Base
4
+ class Gamification::ImageUploader < CarrierWave::Uploader::Base
5
5
 
6
6
  # Include MiniMagick support
7
7
 
@@ -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,6 @@
1
+ <h1>Editing Level</h1>
2
+
3
+ <%= render 'form', level: @level %>
4
+
5
+ <%= link_to 'Show', @level %> |
6
+ <%= link_to 'Back', levels_path %>
@@ -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
+
@@ -0,0 +1,5 @@
1
+ <h1>New Level</h1>
2
+
3
+ <%= render 'form', level: @level %>
4
+
5
+ <%= link_to 'Back', levels_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_level_path(@level) %> |
4
+ <%= link_to 'Back', levels_path %>
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  <% if rewards.any? %>
2
4
  <div class="reward-presentation">
3
5
  <div class="block-content">
@@ -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
 
@@ -0,0 +1,2 @@
1
+ Rails.application.config.assets.precompile += %w( go_gamification/character.js )
2
+ Rails.application.config.assets.precompile += %w( go_gamification/excanvas.js )
data/config/routes.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  Rails.application.routes.draw do
2
- resources :rewards, only: [:create]
2
+ namespace :gamification do
3
+ resources :levels do
4
+
5
+ end
6
+ end
3
7
  end
@@ -1,6 +1,6 @@
1
1
  class CreateGoGamificationTasks < ActiveRecord::Migration[5.1]
2
2
  def change
3
- create_table :go_gamification_tasks do |t|
3
+ create_table :gamification_tasks do |t|
4
4
  t.references :taskable, polymorphic: true, index: true
5
5
  t.integer :points
6
6
 
@@ -1,11 +1,11 @@
1
1
  class CreateGoGamificationScorings < ActiveRecord::Migration[5.1]
2
2
  def change
3
- create_table :go_gamification_scorings do |t|
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 :go_gamification_scorings, [:subjectable_id, :subjectable_type], name: 'index_go_game_score_on_subjectable'
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
- rename_table :go_gamification_scorings, :go_gamification_rewards
4
- rename_column :go_gamification_rewards, :subjectable_id, :rewardable_id
5
- rename_column :go_gamification_rewards, :subjectable_type, :rewardable_type
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 :go_gamification_tasks, :taskable_id, :rewarding_id
8
- rename_column :go_gamification_tasks, :taskable_type, :rewarding_type
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,6 +1,6 @@
1
1
  class CreateGoGamificationMedals < ActiveRecord::Migration[5.1]
2
2
  def change
3
- create_table :go_gamification_medals do |t|
3
+ create_table :gamification_medals do |t|
4
4
  t.references :task, index: true
5
5
  t.string :name
6
6
  t.string :image
@@ -1,5 +1,5 @@
1
1
  class AddDescriptionToGoGamificationMedals < ActiveRecord::Migration[5.1]
2
2
  def change
3
- add_column :go_gamification_medals, :description, :text
3
+ add_column :gamification_medals, :description, :text
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  class RenameGoGamificationTasksToGoals < ActiveRecord::Migration[5.1]
2
2
  def change
3
- rename_table :go_gamification_tasks, :go_gamification_goals
4
- rename_column :go_gamification_rewards, :task_id, :goal_id
5
- rename_column :go_gamification_medals, :task_id, :goal_id
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 :go_gamification_rewards do |t|
3
+ change_table :gamification_rewards do |t|
4
4
  t.datetime :seen_at
5
5
  end
6
6
 
7
- add_index :go_gamification_rewards, :seen_at, name: 'index_go_gamification_rewards_on_seen_at'
7
+ add_index :gamification_rewards, :seen_at, name: 'index_go_gamification_rewards_on_seen_at'
8
8
  end
9
9
  end
@@ -0,0 +1,9 @@
1
+ class CreateGoGamificationLevels < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :gamification_levels do |t|
4
+ t.integer :experience
5
+ t.integer :previous_level_difference
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,4 @@
1
1
  require "go_gamification/engine"
2
- require "go_gamification/concerns"
3
- require "go_gamification/activerecord"
4
- require "go_gamification/checksum"
2
+
5
3
  module GoGamification
6
4
  end
@@ -1,7 +1,6 @@
1
1
  module GoGamification
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace GoGamification
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