From 0e64bb9333744e7d4ddc66ae5a8acd288d3832be Mon Sep 17 00:00:00 2001
From: Ari Timonen
Date: Mon, 16 Mar 2020 03:08:21 +0200
Subject: [PATCH] Temp. solution for movies
---
Gemfile | 1 +
Gemfile.lock | 7 +++++
app/controllers/articles_controller.rb | 2 +-
app/controllers/forums_controller.rb | 2 +-
app/controllers/movies_controller.rb | 18 +----------
app/models/article.rb | 1 +
app/models/forum.rb | 2 +-
app/models/issue.rb | 1 +
app/models/movie.rb | 42 ++++++++++++++++++++------
app/models/post.rb | 1 +
app/views/forums/show.html.erb | 2 +-
app/views/widgets/_articles.html.erb | 2 +-
app/views/widgets/_interviews.html.erb | 2 +-
13 files changed, 50 insertions(+), 33 deletions(-)
diff --git a/Gemfile b/Gemfile
index 0c65d24..28bf85b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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'
diff --git a/Gemfile.lock b/Gemfile.lock
index ad1189c..bc69dd5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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
diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb
index 477c07f..283e019 100644
--- a/app/controllers/articles_controller.rb
+++ b/app/controllers/articles_controller.rb
@@ -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
diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb
index 6b232fe..1380237 100644
--- a/app/controllers/forums_controller.rb
+++ b/app/controllers/forums_controller.rb
@@ -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)
diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb
index f154243..b3ae772 100644
--- a/app/controllers/movies_controller.rb
+++ b/app/controllers/movies_controller.rb
@@ -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
diff --git a/app/models/article.rb b/app/models/article.rb
index 52ab126..60791f7 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -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
diff --git a/app/models/forum.rb b/app/models/forum.rb
index dc34308..df1dd95 100644
--- a/app/models/forum.rb
+++ b/app/models/forum.rb
@@ -33,7 +33,7 @@ class Forum < ActiveRecord::Base
belongs_to :category
after_create :update_position
-
+
acts_as_readable
def to_s
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 887e3d7..a3ab281 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -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]
diff --git a/app/models/movie.rb b/app/models/movie.rb
index d834d0e..28e70ae 100644
--- a/app/models/movie.rb
+++ b/app/models/movie.rb
@@ -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
diff --git a/app/models/post.rb b/app/models/post.rb
index c526131..701f8c3 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -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]
diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb
index 6b70944..f8faea7 100644
--- a/app/views/forums/show.html.erb
+++ b/app/views/forums/show.html.erb
@@ -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" : "") %>
diff --git a/app/views/widgets/_articles.html.erb b/app/views/widgets/_articles.html.erb
index 1feb2e8..15d2bd2 100644
--- a/app/views/widgets/_articles.html.erb
+++ b/app/views/widgets/_articles.html.erb
@@ -6,7 +6,7 @@
<% Article.articles.nodrafts.nospecial.recent.each do |article| %>
- -
+
-
<%= namelink article %>
<% end %>
diff --git a/app/views/widgets/_interviews.html.erb b/app/views/widgets/_interviews.html.erb
index ec9249f..bdeada7 100644
--- a/app/views/widgets/_interviews.html.erb
+++ b/app/views/widgets/_interviews.html.erb
@@ -3,7 +3,7 @@
<% Article.nodrafts.interviews.recent.each do |article| %>
- -
+
-
<%= namelink article %>
<% end %>