Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sudharti/socify
Browse files Browse the repository at this point in the history
  • Loading branch information
scaffeinate committed Jun 14, 2017
2 parents b390919 + f6978a9 commit 000d5fb
Show file tree
Hide file tree
Showing 18 changed files with 389 additions and 79 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
@import "jquery.datetimepicker";
@import "jquery.atwho";
@import "fullcalendar.min";
@import "fontello-embedded";
@import "*";
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

before_filter :configure_permitted_parameters, if: :devise_controller?
before_action :configure_permitted_parameters, if: :devise_controller?

protected
def configure_permitted_parameters
Expand Down
1 change: 0 additions & 1 deletion app/models/Merit

This file was deleted.

7 changes: 3 additions & 4 deletions app/models/badge_rules.rb → app/models/merit/badge_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class BadgeRules
include Merit::BadgeRulesMethods

def initialize

grant_on 'comments#create', badge: 'Jr.Critics', temporary: true, to: :user do |comment|
comment.user.comments.count >= 2
end
comment.user.comments.count >= 2
end
end

# If it creates user, grant badge
# Should be "current_user" after registration for badge to be granted.
Expand All @@ -49,6 +49,5 @@ def initialize
#
# user.name.length > 4
# end
end
end
end
12 changes: 5 additions & 7 deletions app/models/point_rules.rb → app/models/merit/point_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ class PointRules
include Merit::PointRulesMethods

def initialize
score 2, on: 'comments#create', to: [:user]
score 1, on: 'posts#upvote', to: [:user]
score 4, on: 'posts#create', to: [:user]

score 1, on: 'comments#create', to: [:user]


score 5, on: 'post#upvote', to: [:user]


score 3, on: 'post#create', to: [:user]
score 3, on: 'events#create', to: [:user]
score 1, on: 'events#upvote', to: [:user]
# score 10, :on => 'users#create' do |user|
# user.bio.present?
# end
Expand Down
31 changes: 31 additions & 0 deletions app/models/merit/rank_rules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Be sure to restart your server when you modify this file.
#
# 5 stars is a common ranking use case. They are not given at specified
# actions like badges, you should define a cron job to test if ranks are to be
# granted.
#
# +set_rank+ accepts:
# * :+level+ ranking level (greater is better)
# * :+to+ model or scope to check if new rankings apply
# * :+level_name+ attribute name (default is empty and results in 'level'
# attribute, if set it's appended like 'level_#{level_name}')

module Merit
class RankRules
include Merit::RankRulesMethods

def initialize
# set_rank :level => 1, :to => Commiter.active do |commiter|
# commiter.repositories.count > 1 && commiter.followers >= 10
# end
#
# set_rank :level => 2, :to => Commiter.active do |commiter|
# commiter.branches.count > 1 && commiter.followers >= 10
# end
#
# set_rank :level => 3, :to => Commiter.active do |commiter|
# commiter.branches.count > 2 && commiter.followers >= 20
# end
end
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
has_merit
has_merit
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
Expand Down
14 changes: 13 additions & 1 deletion app/views/shared/_user_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@
<%= @user.location %>
</h5>
<% end %>
<h5>
<i class="icon-record"></i> <%= pluralize(@user.points, 'point') %>
</h5>
<% if @user.badges %>
<h5>
<% @user.badges.each do |badge| %>
<i class="<%= badge.custom_fields[:icon] %>" style="color: <%= badge.custom_fields[:color] %>">
</i>
<%= badge.name %>
<% end %>
</h5>
<% end %>
<br>
<div class="text-center">
<% unless is_current_user?(@user) %>
<%= render 'follows/form', user: @user %>
<h6><%= 'Follows you' if current_user.followed_by?(@user) %></h6>
<% end %>
</div>
</div>
</div>
7 changes: 0 additions & 7 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
<div id="user-<%= @user.id %>" class="row">
<div class="col-lg-3">
<%= render 'shared/user_info' %>

<p><%=@user.points%></p>
<% @user.badges.each do |badge| %>
<p class="activity"><%= badge.name %></p>
<p class="activity"><%= badge.custom_fields[:difficulty] %></p>
<p class="activity"><%=image_tag (badge.custom_fields[:img])%></p>
<% end %>
</div>
<div class="col-lg-6">
<div id="activities">
Expand Down
82 changes: 37 additions & 45 deletions config/initializers/merit.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
# Use this hook to configure merit parameters
Merit.setup do |config|


Merit::Badge.create!(
id: 1,
name: "Jr.Critics",
description: "Over 5 comments",
custom_fields: { difficulty: :bronze },
custom_fields: { img: 'bronze.png' }
)
Merit::Badge.create!(
id: 2,
name: "Sr.Critic",
description: "Over 50 comments",
custom_fields: { difficulty: :gold },
custom_fields: { img: 'badge.png' }
)

Merit::Badge.create!(
id: 3,
name: "Story Teller",
description: "Over 5 notes!",
custom_fields: { difficulty: :silver },
custom_fields: { img: 'badge.png' }
)
Merit::Badge.create!(
id: 4,
name: "First story ",
description: "created first story",
custom_fields: { difficulty: :bronze },
custom_fields: { img: 'grey.png' }
)
id: 1,
name: "Jr.Critics",
description: "Over 5 comments",
custom_fields: { color: '#C9AE5D', icon: 'icon-star-circled' }
)
Merit::Badge.create!(
id: 2,
name: "Sr.Critic",
description: "Over 50 comments",
custom_fields: { color: '#FFD700', icon: 'icon-crown' }
)

Merit::Badge.create!(
id: 5,
name: "Scholar",
description: "recieve over 2 likes on your post!",
custom_fields: { difficulty: :gold },
custom_fields: { img: 'badge.png' }
)
Merit::Badge.create!(
id: 6,
name: "Necromancer",
description: "followed 7 people",
custom_fields: { difficulty: :gold },
custom_fields: { img: 'badge.png' }
)
Merit::Badge.create!(
id: 3,
name: "Story Teller",
description: "Over 5 posts!",
custom_fields: { color: '#C0C0C0', icon: 'icon-certificate' }
)
Merit::Badge.create!(
id: 4,
name: "First story ",
description: "created first story",
custom_fields: { color: '#C9AE5D', icon: 'icon-star-1' }
)

Merit::Badge.create!(
id: 5,
name: "Scholar",
description: "Recieved over 2 likes on your post!",
custom_fields: { color: '#FFD700', icon: 'icon-certificate' }
)
Merit::Badge.create!(
id: 6,
name: "Necromancer",
description: "followed 7 people",
custom_fields: { color: '#FFD700', icon: 'icon-minefield' }
)
end
# Check rules on each request or in background
# config.checks_on_each_request = true

Expand All @@ -64,7 +56,7 @@
# to retrieve :user_model_name object if no `:to` option is given. Default
# is "current_#{user_model_name.downcase}".
# config.current_user_method = 'current_user'
end


# Create application badges (uses https://github.com/norman/ambry)
# badge_id = 0
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20170613183107_add_merit_fields_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddMeritFieldsToUsers < ActiveRecord::Migration
def change
add_column :users, :sash_id, :integer
add_column :users, :level, :integer, :default => 0
end
end
15 changes: 15 additions & 0 deletions db/migrate/20170613183243_create_merit_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateMeritActions < ActiveRecord::Migration
def change
create_table :merit_actions do |t|
t.integer :user_id
t.string :action_method
t.integer :action_value
t.boolean :had_errors, default: false
t.string :target_model
t.integer :target_id
t.text :target_data
t.boolean :processed, default: false
t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20170613183244_create_merit_activity_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateMeritActivityLogs < ActiveRecord::Migration
def change
create_table :merit_activity_logs do |t|
t.integer :action_id
t.string :related_change_type
t.integer :related_change_id
t.string :description
t.datetime :created_at
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20170613183245_create_sashes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateSashes < ActiveRecord::Migration
def change
create_table :sashes do |t|
t.timestamps
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/20170613183246_create_badges_sashes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateBadgesSashes < ActiveRecord::Migration
def self.up
create_table :badges_sashes do |t|
t.integer :badge_id, :sash_id
t.boolean :notified_user, default: false
t.datetime :created_at
end
add_index :badges_sashes, [:badge_id, :sash_id]
add_index :badges_sashes, :badge_id
add_index :badges_sashes, :sash_id
end

def self.down
drop_table :badges_sashes
end
end
15 changes: 15 additions & 0 deletions db/migrate/20170613183247_create_scores_and_points.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateScoresAndPoints < ActiveRecord::Migration
def change
create_table :merit_scores do |t|
t.references :sash
t.string :category, default: 'default'
end

create_table :merit_score_points do |t|
t.references :score
t.integer :num_points, default: 0
t.string :log
t.datetime :created_at
end
end
end
Loading

0 comments on commit 000d5fb

Please sign in to comment.