mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-14 05:41:00 +00:00
Temp. solution for movies
This commit is contained in:
parent
661eb61717
commit
0e64bb9333
13 changed files with 50 additions and 33 deletions
1
Gemfile
1
Gemfile
|
@ -21,6 +21,7 @@ gem 'faraday', '~> 0.9.0'
|
||||||
# Model plugins
|
# Model plugins
|
||||||
# FIXME: using this b/c ruby 2.4 not supported
|
# FIXME: using this b/c ruby 2.4 not supported
|
||||||
gem 'unread', '0.10.1'
|
gem 'unread', '0.10.1'
|
||||||
|
# gem "acts_as_rateable", :git => "git://github.com/anton-zaytsev/acts_as_rateable.git"
|
||||||
|
|
||||||
# View helper gems
|
# View helper gems
|
||||||
gem 'nokogiri', '~> 1.9.0'
|
gem 'nokogiri', '~> 1.9.0'
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
GIT
|
||||||
|
remote: git://github.com/anton-zaytsev/acts_as_rateable.git
|
||||||
|
revision: 01066eceb2d16e35be437b7392cc3375f1f377f7
|
||||||
|
specs:
|
||||||
|
acts_as_rateable (3.0.0)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/koraktor/steam-condenser-ruby.git
|
remote: https://github.com/koraktor/steam-condenser-ruby.git
|
||||||
revision: 2cb441f0518a0b8d20a017dfcc42783ae878311a
|
revision: 2cb441f0518a0b8d20a017dfcc42783ae878311a
|
||||||
|
@ -327,6 +333,7 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
active_link_to (~> 1.0.2)
|
active_link_to (~> 1.0.2)
|
||||||
active_record_union
|
active_record_union
|
||||||
|
acts_as_rateable!
|
||||||
annotate
|
annotate
|
||||||
bbcoder (~> 1.0.1)
|
bbcoder (~> 1.0.1)
|
||||||
better_errors
|
better_errors
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ArticlesController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
raise AccessError unless @article.can_show? cuser
|
raise AccessError unless @article.can_show? cuser
|
||||||
cuser.mark_as_read(@article) if cuser
|
@article.mark_as_read! for: cuser if cuser
|
||||||
# @article.record_view_count(request.remote_ip, cuser.nil?)
|
# @article.record_view_count(request.remote_ip, cuser.nil?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class ForumsController < ApplicationController
|
||||||
|
|
||||||
@topics = Topic.where(forum_id: @forum.id)
|
@topics = Topic.where(forum_id: @forum.id)
|
||||||
.joins(posts: :user)
|
.joins(posts: :user)
|
||||||
.includes(:lock, :readings)
|
.includes(:lock)
|
||||||
.group('topics.id')
|
.group('topics.id')
|
||||||
.order('state DESC, (SELECT created_at FROM posts p2 WHERE p2.topic_id = topics.id ORDER BY created_at DESC LIMIT 1) DESC')
|
.order('state DESC, (SELECT created_at FROM posts p2 WHERE p2.topic_id = topics.id ORDER BY created_at DESC LIMIT 1) DESC')
|
||||||
.paginate(page: params[:page], per_page: 30)
|
.paginate(page: params[:page], per_page: 30)
|
||||||
|
|
|
@ -2,23 +2,7 @@ class MoviesController < ApplicationController
|
||||||
before_filter :get_movie, except: [:index, :new, :create]
|
before_filter :get_movie, except: [:index, :new, :create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@movies = []
|
@movies = Movie.filter_or_all(params[:filter], params[:order])
|
||||||
order = case params[:order]
|
|
||||||
when "date" then "data_files.created_at DESC"
|
|
||||||
when "author" then "users.username ASC"
|
|
||||||
when "ratings" then "total_ratings DESC"
|
|
||||||
else "total_ratings DESC"
|
|
||||||
end
|
|
||||||
|
|
||||||
if params[:filter]
|
|
||||||
Movie.index(order).each do |movie|
|
|
||||||
if movie.file and movie.file.average_rating_round >= params[:filter].to_i
|
|
||||||
@movies << movie
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
@movies = Movie.index(order)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -124,6 +124,7 @@ class Article < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME
|
||||||
def remove_readings
|
def remove_readings
|
||||||
Reading.delete_all ["readable_type = 'Category' AND readable_id = ?", category_id]
|
Reading.delete_all ["readable_type = 'Category' AND readable_id = ?", category_id]
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Forum < ActiveRecord::Base
|
||||||
belongs_to :category
|
belongs_to :category
|
||||||
|
|
||||||
after_create :update_position
|
after_create :update_position
|
||||||
|
|
||||||
acts_as_readable
|
acts_as_readable
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -92,6 +92,7 @@ class Issue < ActiveRecord::Base
|
||||||
bbcode_to_html(solution)
|
bbcode_to_html(solution)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME
|
||||||
def remove_readings
|
def remove_readings
|
||||||
if status_changed? and status == STATUS_SOLVED
|
if status_changed? and status == STATUS_SOLVED
|
||||||
Reading.delete_all ["readable_type = 'Issue' AND readable_id = ?", self.id]
|
Reading.delete_all ["readable_type = 'Issue' AND readable_id = ?", self.id]
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
# category_id :integer
|
# category_id :integer
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Rails.root.join('lib/plugins/acts_as_rateable/init.rb')
|
||||||
|
|
||||||
class Movie < ActiveRecord::Base
|
class Movie < ActiveRecord::Base
|
||||||
include Extra
|
include Extra
|
||||||
|
|
||||||
|
@ -34,15 +36,13 @@ class Movie < ActiveRecord::Base
|
||||||
scope :ordered,
|
scope :ordered,
|
||||||
:include => "file",
|
:include => "file",
|
||||||
:order => "data_files.created_at DESC"
|
:order => "data_files.created_at DESC"
|
||||||
scope :index,
|
scope :index, -> {
|
||||||
lambda { |order| {
|
select("movies.*, users.username, AVG(rates.score) as total_ratings")
|
||||||
:select => "movies.*, users.username, AVG(rates.score) as total_ratings",
|
.joins("LEFT JOIN data_files ON movies.file_id = data_files.id
|
||||||
:joins => "LEFT JOIN data_files ON movies.file_id = data_files.id
|
LEFT JOIN users ON movies.user_id = users.id
|
||||||
LEFT JOIN users ON movies.user_id = users.id
|
LEFT JOIN ratings ON rateable_id = data_files.id AND rateable_type = 'DataFile'
|
||||||
LEFT JOIN ratings ON rateable_id = data_files.id AND rateable_type = 'DataFile'
|
LEFT JOIN rates ON ratings.rate_id = rates.id")
|
||||||
LEFT JOIN rates ON ratings.rate_id = rates.id",
|
.group("movies.id") }
|
||||||
:order => order,
|
|
||||||
:group => "movies.id"} }
|
|
||||||
scope :active_streams, :conditions => "status > 0"
|
scope :active_streams, :conditions => "status > 0"
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
@ -89,7 +89,7 @@ class Movie < ActiveRecord::Base
|
||||||
def before_validation
|
def before_validation
|
||||||
if user_name and !user_name.empty?
|
if user_name and !user_name.empty?
|
||||||
self.user = User.find_by_username(user_name)
|
self.user = User.find_by_username(user_name)
|
||||||
else
|
else
|
||||||
self.user = nil
|
self.user = nil
|
||||||
end
|
end
|
||||||
#if file.nil? and match and stream_ip and stream_port
|
#if file.nil? and match and stream_ip and stream_port
|
||||||
|
@ -129,6 +129,28 @@ def make_stream
|
||||||
cmd
|
cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.filter_or_all order, filter
|
||||||
|
order = case order
|
||||||
|
when "date" then "data_files.created_at DESC"
|
||||||
|
when "author" then "users.username ASC"
|
||||||
|
when "ratings" then "total_ratings DESC"
|
||||||
|
else "total_ratings DESC"
|
||||||
|
end
|
||||||
|
|
||||||
|
# FIXME: use new system
|
||||||
|
#movies = []
|
||||||
|
#if filter
|
||||||
|
# Movie.index.order(order).each do |movie|
|
||||||
|
# if movie.file and movie.file.average_rating_round >= filter.to_i
|
||||||
|
# movies << movie
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# return movies
|
||||||
|
#else
|
||||||
|
return index.order(order)
|
||||||
|
#end
|
||||||
|
end
|
||||||
|
|
||||||
#def update_status
|
#def update_status
|
||||||
# if status and status > 0
|
# if status and status > 0
|
||||||
# begin
|
# begin
|
||||||
|
|
|
@ -36,6 +36,7 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME
|
||||||
def remove_readings
|
def remove_readings
|
||||||
Reading.delete_all ["readable_type = 'Topic' AND readable_id = ?", topic.id]
|
Reading.delete_all ["readable_type = 'Topic' AND readable_id = ?", topic.id]
|
||||||
Reading.delete_all ["readable_type = 'Forum' AND readable_id = ?", topic.forum.id]
|
Reading.delete_all ["readable_type = 'Forum' AND readable_id = ?", topic.forum.id]
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= link_to (h topic), topic,
|
<%= link_to (h topic), topic,
|
||||||
class: ((cuser and !topic.read_by? cuser) ? "unread" : "read") +
|
class: ((cuser and !cuser.have_read? topic) ? "unread" : "read") +
|
||||||
((topic.state == Topic::STATE_STICKY) ? " sticky" : "") %>
|
((topic.state == Topic::STATE_STICKY) ? " sticky" : "") %>
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<% Article.articles.nodrafts.nospecial.recent.each do |article| %>
|
<% Article.articles.nodrafts.nospecial.recent.each do |article| %>
|
||||||
<li class="<%= 'bold' if cuser and !article.read_by? cuser %>">
|
<li class="<%= 'bold' if cuser and !cuser.have_read? article %>">
|
||||||
<%= namelink article %>
|
<%= namelink article %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<% Article.nodrafts.interviews.recent.each do |article| %>
|
<% Article.nodrafts.interviews.recent.each do |article| %>
|
||||||
<li class="<%= 'bold' if cuser and !article.read_by? cuser %>">
|
<li class="<%= 'bold' if cuser and !cuser.have_read? article %>">
|
||||||
<%= namelink article %>
|
<%= namelink article %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue