1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
class SessionsController < ApplicationController |
3
|
|
|
|
4
|
|
|
load_resource only: [:new, :show, :edit, :create, :update] |
5
|
|
|
before_filter :verify_session, only: [:new, :create, :update, :edit] |
6
|
|
|
before_filter :verify_owner, only: [:update, :edit] |
7
|
|
|
|
8
|
|
|
respond_to :html |
9
|
|
|
respond_to :json, only: :index |
10
|
|
|
|
11
|
|
|
def show |
12
|
|
|
@similar_sessions = [] |
13
|
|
|
@similar_sessions = @session.recommended_sessions |
14
|
|
|
respond_with(@session) |
15
|
|
|
end |
16
|
|
|
|
17
|
|
|
def new |
18
|
|
|
respond_with(@session) |
19
|
|
|
end |
20
|
|
|
|
21
|
|
|
def edit |
22
|
|
|
respond_with(@session) |
23
|
|
|
end |
24
|
|
|
|
25
|
|
|
def update |
26
|
|
|
@session.update(session_params) |
27
|
|
|
respond_with(@session) |
28
|
|
|
end |
29
|
|
|
|
30
|
|
|
def index |
31
|
|
|
if params[:event_id].present? |
32
|
|
|
@event = Event.find(params[:event_id]) |
33
|
|
|
else |
34
|
|
|
@event = Event.current_event |
35
|
|
|
end |
36
|
|
|
@sessions = @event.sessions.order('created_at desc') |
37
|
|
|
respond_with @sessions do |format| |
38
|
|
|
format.json { |
39
|
|
|
render json: SessionsJsonBuilder.new.to_json(@sessions.uniq.flatten) |
40
|
|
|
} |
41
|
|
|
format.html |
42
|
|
|
end |
43
|
|
|
end |
44
|
|
|
|
45
|
|
|
def create |
46
|
|
|
@session.attributes = session_params |
47
|
|
|
@session.participant = current_participant |
48
|
|
|
@session.event = Event.current_event |
49
|
|
|
|
50
|
|
|
if @session.save |
51
|
|
|
flash[:notice] = "Thanks for adding your session." |
52
|
|
|
redirect_to @session |
53
|
|
|
else |
54
|
|
|
render :action => 'new' |
55
|
|
|
end |
56
|
|
|
end |
57
|
|
|
|
58
|
|
|
STOP_WORDS = Set.new(['session', 'etc', 'just', 'presentation', 'get', 'discussion']) |
59
|
|
|
|
60
|
|
|
def words |
61
|
|
|
@sessions = Event.current_event.sessions |
62
|
|
|
@words = @sessions.map(&:description). |
63
|
|
|
map { |desc| view_context.markdown(desc) }. |
64
|
|
|
map { |md| view_context.strip_tags(md) }. |
65
|
|
|
map(&:downcase). |
66
|
|
|
join(" "). |
67
|
|
|
gsub(/[.*,-?()+!"•—%]/, ''). |
68
|
|
|
split(/\s+/). |
69
|
|
|
reject { |w| STOP_WORDS.include?(w) }. |
70
|
|
|
join(" ") |
71
|
|
|
end |
72
|
|
|
|
73
|
|
|
def export |
74
|
|
|
@sessions = Event.current_event.sessions.all.order('lower(title) asc') |
75
|
|
|
render :layout => 'export' |
76
|
|
|
end |
77
|
|
|
|
78
|
|
|
def popularity |
79
|
|
|
@sessions = Event.current_event.sessions.with_attendence_count.all.order("COALESCE(attendence_count, 0) desc") |
80
|
|
|
render :layout => 'export' |
81
|
|
|
end |
82
|
|
|
|
83
|
|
|
private |
84
|
|
View Code Duplication |
|
|
|
|
|
85
|
|
|
def session_params |
86
|
|
|
params.require(controller_name.singularize).permit(:title, :description, :level_id, :name, :email, :category_ids => []) |
87
|
|
|
end |
88
|
|
|
|
89
|
|
|
def verify_owner |
90
|
|
|
redirect_to @session if @session.participant != current_participant |
91
|
|
|
end |
92
|
|
|
end |
93
|
|
|
|