Temp. solution for movies

This commit is contained in:
Ari Timonen 2020-03-16 03:08:21 +02:00
parent 661eb61717
commit 0e64bb9333
13 changed files with 50 additions and 33 deletions

View file

@ -21,6 +21,7 @@ gem 'faraday', '~> 0.9.0'
# Model plugins
# FIXME: using this b/c ruby 2.4 not supported
gem 'unread', '0.10.1'
# gem "acts_as_rateable", :git => "git://github.com/anton-zaytsev/acts_as_rateable.git"
# View helper gems
gem 'nokogiri', '~> 1.9.0'

View file

@ -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
remote: https://github.com/koraktor/steam-condenser-ruby.git
revision: 2cb441f0518a0b8d20a017dfcc42783ae878311a
@ -327,6 +333,7 @@ PLATFORMS
DEPENDENCIES
active_link_to (~> 1.0.2)
active_record_union
acts_as_rateable!
annotate
bbcoder (~> 1.0.1)
better_errors

View file

@ -21,7 +21,7 @@ class ArticlesController < ApplicationController
def show
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?)
end

View file

@ -12,7 +12,7 @@ class ForumsController < ApplicationController
@topics = Topic.where(forum_id: @forum.id)
.joins(posts: :user)
.includes(:lock, :readings)
.includes(:lock)
.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')
.paginate(page: params[:page], per_page: 30)

View file

@ -2,23 +2,7 @@ class MoviesController < ApplicationController
before_filter :get_movie, except: [:index, :new, :create]
def index
@movies = []
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
@movies = Movie.filter_or_all(params[:filter], params[:order])
end
def show

View file

@ -124,6 +124,7 @@ class Article < ActiveRecord::Base
end
end
# FIXME
def remove_readings
Reading.delete_all ["readable_type = 'Category' AND readable_id = ?", category_id]
end

View file

@ -33,7 +33,7 @@ class Forum < ActiveRecord::Base
belongs_to :category
after_create :update_position
acts_as_readable
def to_s

View file

@ -92,6 +92,7 @@ class Issue < ActiveRecord::Base
bbcode_to_html(solution)
end
# FIXME
def remove_readings
if status_changed? and status == STATUS_SOLVED
Reading.delete_all ["readable_type = 'Issue' AND readable_id = ?", self.id]

View file

@ -18,6 +18,8 @@
# category_id :integer
#
# Rails.root.join('lib/plugins/acts_as_rateable/init.rb')
class Movie < ActiveRecord::Base
include Extra
@ -34,15 +36,13 @@ class Movie < ActiveRecord::Base
scope :ordered,
:include => "file",
:order => "data_files.created_at DESC"
scope :index,
lambda { |order| {
:select => "movies.*, users.username, AVG(rates.score) as total_ratings",
:joins => "LEFT JOIN data_files ON movies.file_id = data_files.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 rates ON ratings.rate_id = rates.id",
:order => order,
:group => "movies.id"} }
scope :index, -> {
select("movies.*, users.username, AVG(rates.score) as total_ratings")
.joins("LEFT JOIN data_files ON movies.file_id = data_files.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 rates ON ratings.rate_id = rates.id")
.group("movies.id") }
scope :active_streams, :conditions => "status > 0"
belongs_to :user
@ -89,7 +89,7 @@ class Movie < ActiveRecord::Base
def before_validation
if user_name and !user_name.empty?
self.user = User.find_by_username(user_name)
else
else
self.user = nil
end
#if file.nil? and match and stream_ip and stream_port
@ -129,6 +129,28 @@ def make_stream
cmd
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
# if status and status > 0
# begin

View file

@ -36,6 +36,7 @@ class Post < ActiveRecord::Base
end
end
# FIXME
def remove_readings
Reading.delete_all ["readable_type = 'Topic' AND readable_id = ?", topic.id]
Reading.delete_all ["readable_type = 'Forum' AND readable_id = ?", topic.forum.id]

View file

@ -34,7 +34,7 @@
<% end %>
<%= 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" : "") %>
</h5>

View file

@ -6,7 +6,7 @@
</h3>
<ul>
<% 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 %>
</li>
<% end %>

View file

@ -3,7 +3,7 @@
</p>
<ul>
<% 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 %>
</li>
<% end %>