2014-02-17 18:05:39 +01:00
|
|
|
class WindowsController < ApplicationController
|
|
|
|
before_filter :require_user, :except => [:index, :html, :iframe]
|
|
|
|
|
|
|
|
def hide
|
|
|
|
window = Window.find(params[:id])
|
|
|
|
window.show_flag = false
|
2014-04-16 04:02:13 +02:00
|
|
|
if window.save
|
2014-02-17 18:05:39 +01:00
|
|
|
render :text => window.id.to_s
|
|
|
|
else
|
|
|
|
render :text => '-1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Call WindowsController.display when we want to display a window on the dashboard
|
|
|
|
# params[:visibility_flag] is whether it is the private or public dashboard
|
|
|
|
# params[:plugin] is for displaying a plugin, instead of a window
|
|
|
|
# params[:id] is the window ID for conventional windows, but the plugin_id for plugins
|
|
|
|
# params[:channel_id] is the channel_id
|
|
|
|
def display
|
|
|
|
@visibility = params[:visibility_flag]
|
|
|
|
|
2014-04-16 04:02:13 +02:00
|
|
|
window = Window.find(params[:id])
|
2014-02-17 18:05:39 +01:00
|
|
|
window = Window.new if window.nil?
|
|
|
|
window.show_flag = true
|
|
|
|
#Just save this change, then modify the object before rendering the JSON
|
|
|
|
savedWindow = window.save
|
|
|
|
|
|
|
|
config_window window
|
|
|
|
|
|
|
|
@mychannel = current_user && current_user.id == window.channel.user_id
|
|
|
|
|
|
|
|
if savedWindow
|
|
|
|
render :json => window.to_json
|
|
|
|
else
|
|
|
|
render :json => 'An error occurred'.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_window(window)
|
2014-07-23 01:13:11 +02:00
|
|
|
if window.window_type == "plugin"
|
|
|
|
pluginName = Plugin.find(window.content_id).name
|
2014-02-17 18:05:39 +01:00
|
|
|
window.title = t(window.title, {:name => pluginName})
|
2014-07-23 01:13:11 +02:00
|
|
|
elsif window.window_type == "chart"
|
|
|
|
window.title = t(window.title, {:field_number => window.content_id})
|
|
|
|
options = window.options if !window.nil?
|
2014-02-17 18:05:39 +01:00
|
|
|
options ||= ""
|
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
else
|
|
|
|
window.title = t(window.title)
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 01:13:11 +02:00
|
|
|
|
2014-02-17 18:05:39 +01:00
|
|
|
def html
|
|
|
|
window = Window.find(params[:id])
|
2014-07-23 01:13:11 +02:00
|
|
|
options = window.options unless window.nil? || window.window_type != "chart"
|
2014-02-17 18:05:39 +01:00
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
html = window.html
|
|
|
|
|
|
|
|
render :text => html
|
|
|
|
end
|
|
|
|
|
|
|
|
def iframe
|
|
|
|
window = Window.find(params[:id])
|
2014-07-23 01:13:11 +02:00
|
|
|
options = window.options unless window.nil? || window.window_type != "chart"
|
2014-02-17 18:05:39 +01:00
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
iframe_html = window.html
|
|
|
|
|
|
|
|
iframe_html = iframe_html.gsub(/src=\"[\/.]/, 'src="' + api_domain);
|
|
|
|
render :text => iframe_html
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
channel = Channel.find(params[:channel_id])
|
|
|
|
|
2014-07-23 01:13:11 +02:00
|
|
|
#channel.update_status_portlet false if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == false } )
|
|
|
|
#channel.update_status_portlet true if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == true } )
|
|
|
|
#channel.update_video_portlet false if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == false } )
|
|
|
|
#channel.update_video_portlet true if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == true } )
|
|
|
|
#channel.update_location_portlet false if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == false } )
|
|
|
|
#channel.update_location_portlet true if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == true } )
|
|
|
|
#channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
|
2014-02-17 18:05:39 +01:00
|
|
|
windows = channel.public_windows(true).order(:position) unless params[:channel_id].nil?
|
|
|
|
|
|
|
|
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
|
2014-07-23 01:13:11 +02:00
|
|
|
@windows = windows.delete_if { |w| w.window_type == "status" }
|
2014-02-17 18:05:39 +01:00
|
|
|
else
|
|
|
|
@windows = windows
|
|
|
|
end
|
|
|
|
|
|
|
|
@windows.each do |window|
|
|
|
|
|
2014-07-23 01:13:11 +02:00
|
|
|
if window.window_type == "plugin"
|
|
|
|
pluginName = Plugin.find(window.content_id).name
|
2014-02-17 18:05:39 +01:00
|
|
|
window.title = t(window.title, {:name => pluginName})
|
2014-07-23 01:13:11 +02:00
|
|
|
elsif window.window_type == "chart"
|
|
|
|
window.title = t(window.title, {:field_number => window.content_id})
|
|
|
|
options = window.options if !window.nil?
|
2014-02-17 18:05:39 +01:00
|
|
|
options ||= ""
|
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
else
|
|
|
|
window.title = t(window.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
2014-04-16 04:02:13 +02:00
|
|
|
format.html
|
2014-07-23 01:13:11 +02:00
|
|
|
format.json { render :json => @windows.as_json }
|
2014-02-17 18:05:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is going to display windows that are hidden (show_flag = false)
|
|
|
|
# The "visibility_flag" param indicates whether it's public or private visibility
|
|
|
|
def hidden_windows
|
|
|
|
@visibility = params[:visibility_flag]
|
|
|
|
channel = Channel.find(params[:channel_id])
|
|
|
|
|
|
|
|
if @visibility == "private"
|
|
|
|
@windows = channel.private_windows(false) unless channel.nil?
|
|
|
|
else
|
|
|
|
@windows = channel.public_windows(false) unless channel.nil?
|
|
|
|
end
|
2014-07-23 01:13:11 +02:00
|
|
|
@windows.reject! { |window| window.window_type == "plugin" }
|
2014-02-17 18:05:39 +01:00
|
|
|
@windows.each do |window|
|
2014-07-23 01:13:11 +02:00
|
|
|
if window.window_type == "plugin"
|
|
|
|
elsif window.window_type == "chart"
|
|
|
|
window.title = t(window.title, {:field_number => window.content_id})
|
|
|
|
options = window.options unless window.nil?
|
2014-02-17 18:05:39 +01:00
|
|
|
options ||= ""
|
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
else
|
|
|
|
window.title = t(window.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :partial => "hidden_windows" }
|
2014-07-23 01:13:11 +02:00
|
|
|
format.json { render :json => @windows.as_json }
|
2014-02-17 18:05:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def private_windows
|
|
|
|
channel = Channel.find(params[:channel_id])
|
|
|
|
|
2014-07-23 01:13:11 +02:00
|
|
|
#channel.update_status_portlet false if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == false } )
|
|
|
|
#channel.update_status_portlet true if (channel.windows.select { |w| w.window_type == 'status' && w.private_flag == true } )
|
|
|
|
#channel.update_video_portlet false if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == false } )
|
|
|
|
#channel.update_video_portlet true if (channel.windows.select { |w| w.window_type == 'video' && w.private_flag == true } )
|
|
|
|
#channel.update_location_portlet false if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == false } )
|
|
|
|
#channel.update_location_portlet true if (channel.windows.select { |w| w.window_type == 'location' && w.private_flag == true } )
|
|
|
|
#channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
|
2014-02-17 18:05:39 +01:00
|
|
|
|
|
|
|
windows = channel.private_windows(true).order(:position) unless params[:channel_id].nil?
|
2014-04-16 04:02:13 +02:00
|
|
|
|
2014-02-17 18:05:39 +01:00
|
|
|
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
|
2014-07-23 01:13:11 +02:00
|
|
|
@windows = windows.delete_if { |w| w.window_type == "status" }
|
2014-02-17 18:05:39 +01:00
|
|
|
else
|
|
|
|
@windows = windows
|
|
|
|
end
|
|
|
|
|
|
|
|
@windows.each do |window|
|
2014-07-23 01:13:11 +02:00
|
|
|
if window.window_type == "plugin"
|
|
|
|
pluginName = Plugin.find(window.content_id).name
|
2014-02-17 18:05:39 +01:00
|
|
|
window.title = t(window.title, {:name => pluginName})
|
2014-07-23 01:13:11 +02:00
|
|
|
elsif window.window_type == "chart"
|
|
|
|
window.title = t(window.title, {:field_number => window.content_id})
|
|
|
|
options = window.options unless window.nil?
|
2014-02-17 18:05:39 +01:00
|
|
|
options ||= ""
|
|
|
|
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
|
|
|
|
else
|
|
|
|
window.title = t(window.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
2014-04-16 04:02:13 +02:00
|
|
|
format.html
|
2014-07-23 01:13:11 +02:00
|
|
|
format.json { render :json => @windows.as_json }
|
2014-02-17 18:05:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
logger.info "We're trying to update the windows with " + params.to_s
|
|
|
|
#params for this put are going to look like
|
|
|
|
# page"=>"{\"col\":0,\"positions\":[1,2,3]}"
|
|
|
|
#So.. the position values are Windows.id They should get updated with the ordinal value based
|
|
|
|
# on their array position and the column should get updated according to col value.
|
2014-04-16 04:02:13 +02:00
|
|
|
# Since the windows are order by position, when a window record changes from
|
|
|
|
# col1,position0 -> col0,position0 the entire new column is reordered.
|
|
|
|
# The old column is missing a position, but the remaining are just left to their order
|
2014-02-17 18:05:39 +01:00
|
|
|
# (ie., 0,1,2 become 1,2) Unless they are also changed
|
|
|
|
|
|
|
|
# First parse the JSON in params["page"] ...
|
|
|
|
values = JSON(params[:page])
|
2014-04-16 04:02:13 +02:00
|
|
|
|
2014-02-17 18:05:39 +01:00
|
|
|
# .. then find each window and update with new ordinal position and col.
|
|
|
|
logger.info "Channel id = " + params[:channel_id].to_s
|
|
|
|
@channel = current_user.channels.find(params[:channel_id])
|
|
|
|
col = values["col"]
|
|
|
|
saved = true
|
|
|
|
values["positions"].each_with_index do |p,i|
|
|
|
|
windows = @channel.windows.where({:id => p}) unless p.nil?
|
|
|
|
unless windows.nil? || windows.empty?
|
|
|
|
w = windows[0]
|
|
|
|
w.position = i
|
|
|
|
w.col = col
|
|
|
|
if !w.save
|
|
|
|
saved = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if saved
|
|
|
|
render :text => '0'
|
|
|
|
else
|
|
|
|
render :text => '-1'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2014-04-16 04:02:13 +02:00
|
|
|
|