Skip to content
Extraits de code Groupes Projets
Valider e29ff8c0 rédigé par Sybil's avatar Sybil
Parcourir les fichiers

The refactoring continues ! Filters upgraded, tagcloud upgraded.

parent 6055516e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -21,11 +21,8 @@ class ApplicationController < ActionController::Base ...@@ -21,11 +21,8 @@ class ApplicationController < ActionController::Base
@tags = Hash.new @tags = Hash.new
tags.each do |tag| tags.each do |tag|
if @tags.key?(tag.tag) @tags[tag.tag] ||= 0.0
@tags[tag.tag] += 1.0 @tags[tag.tag] += 1.0
else
@tags[tag.tag] = 1.0
end
end end
max_weight = @tags.values.max max_weight = @tags.values.max
@tags.each do |tag, occ| @tags.each do |tag, occ|
...@@ -42,11 +39,8 @@ class ApplicationController < ActionController::Base ...@@ -42,11 +39,8 @@ class ApplicationController < ActionController::Base
@users = Hash.new @users = Hash.new
users.each do |user| users.each do |user|
if @users.key?(user.sender_irc) @users[user.sender_irc] ||= 0.0
@users[user.sender_irc] += 1.0 @users[user.sender_irc] += 1.0
else
@users[user.sender_irc] = 1.0
end
end end
max_weight = @users.values.max max_weight = @users.values.max
......
class MusicsController < ApplicationController class MusicsController < ApplicationController
def add_filters(filters) def filters( *filters )
filters.each do | filter |
@musics = @musics.with_tag(filters[:tag_id]) if filters.has_key?(:tag_id) if param = params[filter] || params["#{filter}_id"]
@musics = @musics.with_channel('#'+filters[:channel_id]) if filters.has_key?(:channel_id) @musics = @musics.send( "with_#{filter}", param )
@musics = @musics.with_user(filters[:user_id]) if filters.has_key?(:user_id) end
end
end end
def index def index
@musics = Music.page params[:page] @musics = Music.page params[:page]
add_filters(params) filters :tag, :channel, :user
respond_to do |format| respond_to do |format|
format.html format.html
......
...@@ -10,7 +10,7 @@ class Music < ActiveRecord::Base ...@@ -10,7 +10,7 @@ class Music < ActiveRecord::Base
end end
def self.with_channel(channel) def self.with_channel(channel)
self.joins(:channel).where("channel = ?", channel) self.joins(:channel).where("channel = ?", "##{channel}")
end end
def self.with_user(user) def self.with_user(user)
......
...@@ -9,15 +9,15 @@ ...@@ -9,15 +9,15 @@
end %>"> end %>">
<span class="music_id"><%= music.id %></span> <span class="music_id"><%= music.id %></span>
<span class="music_chan"> <span class="music_chan">
<%= link_to music.channel.chan, '/musics/channels/'+music.channel.chan.sub('#','') %> <%= link_to music.channel.chan, "/channels/#{music.channel.chan.sub('#','')}/musics" %>
</span> </span>
<span class="music_title"> <span class="music_title">
<%= music.title %> <%= music.title %>
</span> </span>
<span class="music_tags"> <span class="music_tags">
<%= raw(music.tags.map{|t| link_to t.tag, '/musics/tags/'+t.tag}.join(" ")) %> <%= raw(music.tags.map{|t| link_to t.tag, "/tags/#{t.tag}/musics"}.join(" ")) %>
</span> </span>
<span class="music_sender"> <span class="music_sender">
<%= link_to music.channel.sender_irc, '/musics/users/'+music.channel.sender_irc %> <%= link_to music.channel.sender_irc, "/users/#{music.channel.sender_irc}/musics" %>
</span> </span>
</li> </li>
...@@ -65,10 +65,5 @@ Rails.application.routes.draw do ...@@ -65,10 +65,5 @@ Rails.application.routes.draw do
root to: 'musics#index' root to: 'musics#index'
#get '/musics/tags/:tag', to: "tags#show"
#get '/users/:user_id/musics', to: "musics#index" #get '/users/:user_id/musics', to: "musics#index"
#get '/musics/channels/:channel', to: "channels#show_channel"
#Experiment
#get '/filters/:channel/:user/:tag', to: "musics#filters"
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter