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

Routes' refactoring.

parent a4245363
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -3,9 +3,9 @@ class ApplicationController < ActionController::Base ...@@ -3,9 +3,9 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_filter :get_tags, :get_users, :get_channel before_filter :get_tags, :get_users, :get_channels
def get_channel def get_channels
channels = Channel.all channels = Channel.all
@channels = Array.new @channels = Array.new
channels.each do |channel| channels.each do |channel|
......
class ChannelsController < ApplicationController class ChannelsController < ApplicationController
def index_users def index_users
users = Channel.all get_users()
list_users = Array.new
users.each do |user|
list_users.push(user.sender_irc)
end
@usercloud = Hash.new
list_users.each do |user|
if @usercloud.key?(user)
@usercloud[user] += 1.0
else
@usercloud[user] = 1.0
end
end
max_weight = @usercloud.values.max
@usercloud.each do |user, occ|
@usercloud[user] = occ / max_weight
end
respond_to do |format| respond_to do |format|
format.html format.html
...@@ -27,18 +8,7 @@ class ChannelsController < ApplicationController ...@@ -27,18 +8,7 @@ class ChannelsController < ApplicationController
end end
def index def index
channels = Channel.all get_channels()
#list_channels = Array.new
#channels.each do |channel|
# list_channels.push(channel.chan)
#end
@channels = Array.new
channels.each do |channel|
if @channels.include?(channel.chan) == false
@channels.push(channel.chan)
end
end
respond_to do |format| respond_to do |format|
format.html format.html
......
class MusicsController < ApplicationController class MusicsController < ApplicationController
def add_filters(filters)
@musics = @musics.with_tag(filters[:tag_id]) if filters.has_key?(:tag_id)
@musics = @musics.with_channel('#'+filters[:channel_id]) if filters.has_key?(:channel_id)
@musics = @musics.with_user(filters[:user_id]) if filters.has_key?(:user_id)
end
def index def index
@musics = Music.page params[:page] @musics = Music.page params[:page]
add_filters(params)
respond_to do |format| respond_to do |format|
format.html format.html
...@@ -14,13 +22,4 @@ class MusicsController < ApplicationController ...@@ -14,13 +22,4 @@ class MusicsController < ApplicationController
end end
end end
def filters
@musics = Music.joins(:tags).where(playbot_tags: {tag: params[:tag]}).joins(:channel).where(playbot_chan: {chan: params[:channel]}).where(playbot_chan: {sender_irc: params[:user]}).page params[:page]
respond_to do |format|
format.html
end
end
# where(playbot_tags: {tag: params[:tag]})
end end
...@@ -4,4 +4,17 @@ class Music < ActiveRecord::Base ...@@ -4,4 +4,17 @@ class Music < ActiveRecord::Base
has_many :tags, foreign_key: "id" has_many :tags, foreign_key: "id"
has_one :channel, primary_key: "id", foreign_key: "content" has_one :channel, primary_key: "id", foreign_key: "content"
def self.with_tag(tag)
self.joins(:tags).where("tag = ?", tag )
end
def self.with_channel(channel)
self.joins(:channel).where("channel = ?", channel)
end
def self.with_user(user)
self.joins(:channel).where("playbot_chan.sender_irc = ?", user)
end
end end
...@@ -2,8 +2,4 @@ class Tag < ActiveRecord::Base ...@@ -2,8 +2,4 @@ class Tag < ActiveRecord::Base
self.table_name = "playbot_tags" self.table_name = "playbot_tags"
belongs_to :music belongs_to :music
def self.with_tag(tag)
where("tag = ?", tag)
end
end end
<ul> <ul>
<% @channels.each do |channel| %> <% @channels.each do |channel| %>
<li><%= link_to channel, '/musics/channels/'+channel.sub('#',''), class: "cloud" %></li> <li><%= link_to channel, '/channels/'+channel.sub('#','')+'/musics', class: "cloud" %></li>
<% end %> <% end %>
</ul> </ul>
<% @usercloud.each do |user,weight| %> <% @users.each do |user,weight| %>
<%= link_to user, '/musics/users/'+user, style: "font-size:"+(15+weight*100).to_s+"px", class: "cloud" %> <%= link_to user, '/users/'+user+'/musics', style: "font-size:"+(15+weight*100).to_s+"px", class: "cloud" %>
<% end %> <% end %>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<ul> <ul>
<li id="menu"> <li id="menu">
<span><a id="menu_button">Menu</a></span> <span><a id="menu_button">Menu</a></span>
<span class="menu_toggleable"><a href="/musics">Home</a></span> <span class="menu_toggleable"><a href="/">Home</a></span>
<span class="menu_toggleable"><a href="/channels">Channels</a></span> <span class="menu_toggleable"><a href="/channels">Channels</a></span>
<span class="menu_toggleable"><a href="/users">Users</a></span> <span class="menu_toggleable"><a href="/users">Users</a></span>
<span class="menu_toggleable"><a href="/tags">Tags</a></span> <span class="menu_toggleable"><a href="/tags">Tags</a></span>
......
<% @tags.each do |tag,weight| %> <% @tags.each do |tag,weight| %>
<%= link_to tag, '/musics/tags/'+tag, style: "font-size:"+(15+weight*100).to_s+"px", class: "cloud" %> <%= link_to tag, '/tags/'+tag+'/musics', style: "font-size:"+(15+weight*100).to_s+"px", class: "cloud" %>
<% end %> <% end %>
<% @usercloud.each do |user,weight| %>
<%= link_to user, '/musics/users/'+user, style: "font-size:"+(15+weight*100).to_s+"px", class: "cloud" %>
<% end %>
...@@ -53,17 +53,22 @@ Rails.application.routes.draw do ...@@ -53,17 +53,22 @@ Rails.application.routes.draw do
# # (app/controllers/admin/products_controller.rb) # # (app/controllers/admin/products_controller.rb)
# resources :products # resources :products
# end # end
resources :musics #
resources :tags get '/users', to: "channels#index_users"
resources :channels
concern :tracks do
resources :musics, only: [:index]
end
resources :tags, concerns: :tracks, only: [:index, :show]
resources :channels, concerns: :tracks, only: [:index, :show]
resources :users, concerns: :tracks, only: [:index, :show]
root to: 'musics#index' root to: 'musics#index'
get '/musics/tags/:tag', to: "tags#show" #get '/musics/tags/:tag', to: "tags#show"
get '/musics/users/:user', to: "channels#show_user" #get '/users/:user_id/musics', to: "musics#index"
get '/musics/channels/:channel', to: "channels#show_channel" #get '/musics/channels/:channel', to: "channels#show_channel"
get '/users', to: "channels#index_users"
#Experiment #Experiment
get '/filters/:channel/:user/:tag', to: "musics#filters" #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