refactor channel rankings
This commit is contained in:
@ -260,11 +260,7 @@ class ApplicationController < ActionController::Base
|
||||
def get_channel_data
|
||||
@channel = current_user.channels.find(params[:channel_id]) if params[:channel_id]
|
||||
@channel = current_user.channels.find(params[:id]) if @channel.nil? and params[:id]
|
||||
|
||||
if @channel.ranking.blank?
|
||||
@channel.ranking = @channel.calc_ranking
|
||||
end
|
||||
|
||||
@channel.ranking = @channel.set_ranking if @channel.ranking.blank?
|
||||
@key = @channel.api_keys.write_keys.first.try(:api_key) || ""
|
||||
end
|
||||
|
||||
|
@ -177,7 +177,6 @@ class ChannelsController < ApplicationController
|
||||
get_channel_data
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
# get the current user or find the user via their api key
|
||||
@user = current_user || User.find_by_api_key(get_apikey)
|
||||
@ -195,6 +194,7 @@ class ChannelsController < ApplicationController
|
||||
@channel.assign_attributes(channel_params)
|
||||
@channel.set_windows
|
||||
@channel.save
|
||||
@channel.set_ranking
|
||||
else
|
||||
session[:errors] = @channel.errors
|
||||
redirect_to channel_path(@channel.id, :anchor => "channelsettings") and return
|
||||
@ -221,6 +221,7 @@ class ChannelsController < ApplicationController
|
||||
channel.save
|
||||
channel.save_tags(params[:channel][:tags]) if params[:channel][:tags].present?
|
||||
channel.add_write_api_key
|
||||
channel.set_ranking
|
||||
@channel_id = channel.id
|
||||
respond_to do |format|
|
||||
format.json { render :json => channel.to_json(Channel.private_options) }
|
||||
|
@ -68,7 +68,6 @@ class Channel < ActiveRecord::Base
|
||||
attr_readonly :created_at
|
||||
|
||||
after_commit :set_default_name
|
||||
after_commit :set_ranking, :unless => "ranking == calc_ranking"
|
||||
|
||||
before_destroy :delete_feeds
|
||||
|
||||
@ -221,14 +220,10 @@ class Channel < ActiveRecord::Base
|
||||
def public?; self.public_flag; end
|
||||
|
||||
# check if the video has changed
|
||||
def video_changed?
|
||||
video_id_changed? || video_type_changed?
|
||||
end
|
||||
def video_changed?; video_id_changed? || video_type_changed?; end
|
||||
|
||||
# check if the location has changed
|
||||
def location_changed?
|
||||
latitude_changed? || longitude_changed?
|
||||
end
|
||||
def location_changed?; latitude_changed? || longitude_changed?; end
|
||||
|
||||
# check if the any of the fields have changed
|
||||
def fields_changed?
|
||||
@ -437,16 +432,19 @@ class Channel < ActiveRecord::Base
|
||||
}
|
||||
end
|
||||
|
||||
def calc_ranking
|
||||
result = 0
|
||||
result = result + 15 unless name.blank?
|
||||
result = result + 20 unless description.blank?
|
||||
result = result + 15 unless latitude.blank? || longitude.blank?
|
||||
result = result + 15 unless url.blank?
|
||||
result = result + 15 unless video_id.blank? || video_type.blank?
|
||||
# set the ranking correctly for the channel
|
||||
def set_ranking
|
||||
new_ranking = 0
|
||||
new_ranking += 15 if name.present?
|
||||
new_ranking += 20 if description.present?
|
||||
new_ranking += 15 if latitude.present? && longitude.present?
|
||||
new_ranking += 15 if url.present?
|
||||
new_ranking += 15 if video_id.present? && video_type.present?
|
||||
new_ranking += 20 if tags.present?
|
||||
|
||||
result = result + 20 unless tags.empty?
|
||||
result
|
||||
# update the ranking if it has changed
|
||||
update_attribute(:ranking, new_ranking) if self.ranking != new_ranking
|
||||
return new_ranking
|
||||
end
|
||||
|
||||
def set_windows
|
||||
@ -472,10 +470,6 @@ class Channel < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def set_ranking
|
||||
update_attribute(:ranking, calc_ranking) unless ranking == calc_ranking
|
||||
end
|
||||
|
||||
def update_chart_portlet (field, isPrivate)
|
||||
|
||||
chartWindows = windows.where(:window_type => "chart", :name => "field#{field.last.to_s}", :private_flag => isPrivate )
|
||||
@ -503,13 +497,10 @@ class Channel < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# set the default channel name
|
||||
def set_default_name
|
||||
update_attribute(:name, "#{I18n.t(:channel_default_name)} #{self.id}") if self.name.blank?
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
<div>
|
||||
<% @channels.each do |channel| %>
|
||||
|
||||
<% channel.ranking = channel.calc_ranking if channel.ranking.blank? %>
|
||||
<div class="public_channel_box">
|
||||
<div class="public_channel_inner">
|
||||
<p class="public_channel_name">
|
||||
|
Reference in New Issue
Block a user