big refactor of windows models

This commit is contained in:
Lee Lawlor 2014-07-22 19:13:11 -04:00
parent 0739b17989
commit 0c5097803b
43 changed files with 211 additions and 411 deletions

View File

@ -230,7 +230,7 @@ GEM
activesupport (= 4.0.5) activesupport (= 4.0.5)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (10.3.1) rake (10.3.2)
ransack (1.2.3) ransack (1.2.3)
actionpack (>= 3.0) actionpack (>= 3.0)
activerecord (>= 3.0) activerecord (>= 3.0)

View File

@ -123,26 +123,18 @@ function setupColumns(current_user, channel_id) {
function createWindowsWithData (data, current_user, channel_id, colName) { function createWindowsWithData (data, current_user, channel_id, colName) {
for (var i in data) { for (var i in data) {
//each array element has a single chart object as an associative array with the type as the key
// so I need to iterate over a array with size=1 to get a string with the window type
for (var type in data[i]) {
var wtype = type;
}
if (data[i].chart_window) window = data[i].chart_window;
if (data[i].plugin_window) window = data[i].plugin_window;
if (data[i].portlet_window) window = data[i].portlet_window;
if (window == "undefined") // set the window and window_type
var window = (data[i].portlet_window) ? data[i].portlet_window : data[i].chart_window; var window = data[i].window;
var window_type = window.window_type;
colId = window.col; colId = window.col;
title = window.title; title = window.title;
var content = window.html; var content = window.html;
if (data[i].chart_window) { if (window.window_type === 'chart') {
var windowId = window.id; $("body").append("<div id='chartConfig" + window.id + "'></div>");
$("body").append("<div id='chartConfig"+windowId+"'></div>");
} }
var portlet = addWindow(colName, colId, window.id, wtype, title, content); var portlet = addWindow(colName, colId, window.id, window_type, title, content);
portlet.each ( decoratePortlet(current_user) ) ; portlet.each ( decoratePortlet(current_user) ) ;
portlet.find( ".ui-toggle" ).click( uiToggleClick ); portlet.find( ".ui-toggle" ).click( uiToggleClick );
@ -157,10 +149,10 @@ var createWindows = function (current_user, channel_id, colName) {
}; };
} }
function addWindow(colName, colId, windowId, wtype, title, content) { function addWindow(colName, colId, windowId, window_type, title, content) {
$("#"+colName+"_dialog"+colId).append('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ' + $("#"+colName+"_dialog"+colId).append('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ' +
'id="portlet_' + windowId + 'id="portlet_' + windowId +
'"><div class="portlet-header wtype wtype-'+ wtype '"><div class="portlet-header window_type window_type-'+ window_type
+ ' ui-widget-header ui-corner-all">' + title + + ' ui-widget-header ui-corner-all">' + title +
'</div><div class="portlet-content">'+content+'</div>') ; '</div><div class="portlet-content">'+content+'</div>') ;
@ -215,9 +207,9 @@ var decoratePortlet = function (current_user) {
thisObject = $(this); thisObject = $(this);
if (current_user == "true") { if (current_user == "true") {
// Use feature Rollout here - needs to be implemented for this user, and this channel needs to belong to this user. // Use feature Rollout here - needs to be implemented for this user, and this channel needs to belong to this user.
thisObject.find('.wtype').prepend( "<span id='minusBtn' class='ui-toggle ui-icon ui-icon-minusthick'></span>"); thisObject.find('.window_type').prepend( "<span id='minusBtn' class='ui-toggle ui-icon ui-icon-minusthick'></span>");
thisObject.find(".wtype-chart_window").append("<span id='pencilBtn' class='ui-edit ui-icon ui-icon-pencil'></span>"); thisObject.find(".window_type-chart").append("<span id='pencilBtn' class='ui-edit ui-icon ui-icon-pencil'></span>");
thisObject.find(".wtype").append("<span id='closeBtn' class='ui-close ui-icon ui-icon-close'></span>"); thisObject.find(".window_type").append("<span id='closeBtn' class='ui-close ui-icon ui-icon-close'></span>");
thisObject.find(".portlet-header").css("cursor","move"); thisObject.find(".portlet-header").css("cursor","move");
} }
else { else {

View File

@ -6,8 +6,8 @@ class ChartsController < ApplicationController
window_id = params[:id] window_id = params[:id]
logger.debug "Windows ID is #{window_id}" logger.debug "Windows ID is #{window_id}"
window_detail = @channel.windows.find(window_id).becomes(ChartWindow).window_detail window = @channel.windows.find(window_id)
options = window_detail.options unless window_detail.nil? options = window.options unless window.nil?
logger.debug "Options for window #{window_id} are " + options.inspect logger.debug "Options for window #{window_id} are " + options.inspect
render :partial => "charts/config", :locals => { render :partial => "charts/config", :locals => {
@ -78,9 +78,9 @@ class ChartsController < ApplicationController
# save data # save data
if params[:newOptions] if params[:newOptions]
logger.debug "Updating new style options on window id #{params[:id]} with #{params[:newOptions][:options]}" logger.debug "Updating new style options on window id #{params[:id]} with #{params[:newOptions][:options]}"
chart_window = @channel.windows.find(params[:id]).becomes(ChartWindow) window = @channel.windows.find(params[:id])
chart_window.window_detail.options = params[:newOptions][:options] window.options = params[:newOptions][:options]
if !chart_window.save if !window.save
raise "Couldn't save the Chart Window" raise "Couldn't save the Chart Window"
end end
end end

View File

@ -37,21 +37,22 @@ class WindowsController < ApplicationController
end end
def config_window(window) def config_window(window)
if window.type == "PluginWindow" if window.window_type == "plugin"
pluginName = Plugin.find(window.window_detail.plugin_id).name pluginName = Plugin.find(window.content_id).name
window.title = t(window.title, {:name => pluginName}) window.title = t(window.title, {:name => pluginName})
elsif window.type == "ChartWindow" elsif window.window_type == "chart"
window.title = t(window.title, {:field_number => window.window_detail.field_number}) window.title = t(window.title, {:field_number => window.content_id})
options = window.becomes(ChartWindow).window_detail.options if !window.becomes(ChartWindow).window_detail.nil? options = window.options if !window.nil?
options ||= "" options ||= ""
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
else else
window.title = t(window.title) window.title = t(window.title)
end end
end end
def html def html
window = Window.find(params[:id]) window = Window.find(params[:id])
options = window.window_detail.options unless window.window_detail.nil? || window.type!="ChartWindow" options = window.options unless window.nil? || window.window_type != "chart"
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
html = window.html html = window.html
@ -60,7 +61,7 @@ class WindowsController < ApplicationController
def iframe def iframe
window = Window.find(params[:id]) window = Window.find(params[:id])
options = window.window_detail.options unless window.window_detail.nil? || window.type!="ChartWindow" options = window.options unless window.nil? || window.window_type != "chart"
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
iframe_html = window.html iframe_html = window.html
@ -71,29 +72,29 @@ class WindowsController < ApplicationController
def index def index
channel = Channel.find(params[:channel_id]) channel = Channel.find(params[:channel_id])
channel.update_status_portlet false if (channel.windows.select { |w| w.wtype == :status && w.private_flag == false } ) #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.wtype == :status && w.private_flag == true } ) #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.wtype == :video && w.private_flag == false } ) #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.wtype == :video && w.private_flag == true } ) #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.wtype == :location && w.private_flag == false } ) #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.wtype == :location && w.private_flag == true } ) #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.wtype == :chart } ) #channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
windows = channel.public_windows(true).order(:position) unless params[:channel_id].nil? windows = channel.public_windows(true).order(:position) unless params[:channel_id].nil?
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0 if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
@windows = windows.delete_if { |w| w.wtype == "status" } @windows = windows.delete_if { |w| w.window_type == "status" }
else else
@windows = windows @windows = windows
end end
@windows.each do |window| @windows.each do |window|
if window.type == "PluginWindow" if window.window_type == "plugin"
pluginName = Plugin.find(window.window_detail.plugin_id).name pluginName = Plugin.find(window.content_id).name
window.title = t(window.title, {:name => pluginName}) window.title = t(window.title, {:name => pluginName})
elsif window.type == "ChartWindow" elsif window.window_type == "chart"
window.title = t(window.title, {:field_number => window.window_detail.field_number}) window.title = t(window.title, {:field_number => window.content_id})
options = window.becomes(ChartWindow).window_detail.options if !window.becomes(ChartWindow).window_detail.nil? options = window.options if !window.nil?
options ||= "" options ||= ""
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
else else
@ -104,7 +105,7 @@ class WindowsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render :json => @windows.as_json( :include => [:window_detail] ) } format.json { render :json => @windows.as_json }
end end
end end
@ -119,12 +120,12 @@ class WindowsController < ApplicationController
else else
@windows = channel.public_windows(false) unless channel.nil? @windows = channel.public_windows(false) unless channel.nil?
end end
@windows.reject! { |window| window.type == "PluginWindow" } @windows.reject! { |window| window.window_type == "plugin" }
@windows.each do |window| @windows.each do |window|
if window.type == "PluginWindow" if window.window_type == "plugin"
elsif window.type == "ChartWindow" elsif window.window_type == "chart"
window.title = t(window.title, {:field_number => window.window_detail.field_number}) window.title = t(window.title, {:field_number => window.content_id})
options = window.becomes(ChartWindow).window_detail.options unless window.becomes(ChartWindow).window_detail.nil? options = window.options unless window.nil?
options ||= "" options ||= ""
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
else else
@ -134,37 +135,36 @@ class WindowsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { render :partial => "hidden_windows" } format.html { render :partial => "hidden_windows" }
# format.json { render :json => @windows.as_json( :include => [:window_detail] ) } format.json { render :json => @windows.as_json }
end end
end end
def private_windows def private_windows
channel = Channel.find(params[:channel_id]) channel = Channel.find(params[:channel_id])
channel.update_status_portlet false if (channel.windows.select { |w| w.wtype == :status && w.private_flag == false } ) #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.wtype == :status && w.private_flag == true } ) #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.wtype == :video && w.private_flag == false } ) #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.wtype == :video && w.private_flag == true } ) #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.wtype == :location && w.private_flag == false } ) #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.wtype == :location && w.private_flag == true } ) #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.wtype == :chart } ) #channel.update_chart_portlets if (channel.windows.select { |w| w.window_type == 'chart' } )
windows = channel.private_windows(true).order(:position) unless params[:channel_id].nil? windows = channel.private_windows(true).order(:position) unless params[:channel_id].nil?
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0 if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
@windows = windows.delete_if { |w| w.wtype == "status" } @windows = windows.delete_if { |w| w.window_type == "status" }
else else
@windows = windows @windows = windows
end end
@windows.each do |window| @windows.each do |window|
if window.type == "PluginWindow" if window.window_type == "plugin"
windowDetail = window.window_detail pluginName = Plugin.find(window.content_id).name
pluginName = Plugin.find(windowDetail.plugin_id).name
window.title = t(window.title, {:name => pluginName}) window.title = t(window.title, {:name => pluginName})
elsif window.type == "ChartWindow" elsif window.window_type == "chart"
window.title = t(window.title, {:field_number => window.window_detail.field_number}) window.title = t(window.title, {:field_number => window.content_id})
options = window.becomes(ChartWindow).window_detail.options unless window.becomes(ChartWindow).window_detail.nil? options = window.options unless window.nil?
options ||= "" options ||= ""
window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil? window.html["::OPTIONS::"] = options unless window.html.nil? || window.html.index("::OPTIONS::").nil?
else else
@ -174,7 +174,7 @@ class WindowsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render :json => @windows.as_json( :include => [:window_detail] ) } format.json { render :json => @windows.as_json }
end end
end end

View File

@ -249,26 +249,24 @@ class Channel < ActiveRecord::Base
end end
#remove portlets for fields that don't exist #remove portlets for fields that don't exist
#iterate all chart windows... and look for a matching field #iterate all chart windows... and look for a matching field
chartWindows = windows.where(:wtype => :chart ) chart_windows = windows.where(:window_type => 'chart' )
chartWindows.each do |window| chart_windows.each do |window|
if self.send(window.name).blank? if self.send("field#{window.content_id}").blank?
window.destroy window.destroy
end end
end end
end end
def update_status_portlet isPrivate def update_status_portlet isPrivate
window = windows.where(:wtype => :status, :private_flag => isPrivate ) window = windows.where(:window_type => 'status', :private_flag => isPrivate )
status_html = "<iframe class=\"statusIFrame\" width=\"450\" height=\"260\" frameborder=\"0\" src=\"/channels/#{id}/status/recent\"></iframe>" status_html = "<iframe class=\"statusIFrame\" width=\"450\" height=\"260\" frameborder=\"0\" src=\"/channels/#{id}/status/recent\"></iframe>"
if window.nil? || window[0].nil? if window.nil? || window[0].nil?
window = PortletWindow.new window = Window.new
window.wtype = :status window.window_type = 'status'
window.position = 1 window.position = 1
window.col = 1 window.col = 1
window.title = "window_status" window.title = "window_status"
@ -279,7 +277,6 @@ class Channel < ActiveRecord::Base
window.private_flag = isPrivate window.private_flag = isPrivate
window.html = status_html window.html = status_html
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window self.windows.push window
end end
@ -289,13 +286,13 @@ class Channel < ActiveRecord::Base
end end
def update_video_portlet isPrivate def update_video_portlet isPrivate
window = windows.where(:wtype => :video, :private_flag => isPrivate ) window = windows.where(:window_type => 'video', :private_flag => isPrivate )
if video_fields_valid? if video_fields_valid?
youtube_html = "<iframe class=\"youtube-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"https://www.youtube.com/embed/#{video_id}?wmode=transparent\" frameborder=\"0\" wmode=\"Opaque\" ></iframe>" youtube_html = "<iframe class=\"youtube-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"https://www.youtube.com/embed/#{video_id}?wmode=transparent\" frameborder=\"0\" wmode=\"Opaque\" ></iframe>"
vimeo_html = "<iframe class=\"vimeo-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"http://player.vimeo.com/video/#{video_id}\" frameborder=\"0\"></iframe>" vimeo_html = "<iframe class=\"vimeo-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"http://player.vimeo.com/video/#{video_id}\" frameborder=\"0\"></iframe>"
if window.nil? || window[0].nil? if window.nil? || window[0].nil?
window = PortletWindow.new window = Window.new
window.wtype = :video window.window_type = 'video'
window.position = 1 window.position = 1
window.col = 1 window.col = 1
window.title = "window_channel_video" window.title = "window_channel_video"
@ -305,7 +302,6 @@ class Channel < ActiveRecord::Base
window.private_flag = isPrivate window.private_flag = isPrivate
window.html = youtube_html if video_type == 'youtube' window.html = youtube_html if video_type == 'youtube'
window.html = vimeo_html if video_type == 'vimeo' window.html = vimeo_html if video_type == 'vimeo'
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window self.windows.push window
else else
unless window[0].nil? unless window[0].nil?
@ -315,13 +311,13 @@ class Channel < ActiveRecord::Base
end end
def update_location_portlet isPrivate def update_location_portlet isPrivate
window = windows.where(:wtype => :location, :private_flag => isPrivate ) window = windows.where(:window_type => 'location', :private_flag => isPrivate )
if !latitude.nil? && !longitude.nil? if !latitude.nil? && !longitude.nil?
maps_html = "<iframe width=\"450\" height=\"260\" frameborder=\"0\" scrolling=\"no\" " + maps_html = "<iframe width=\"450\" height=\"260\" frameborder=\"0\" scrolling=\"no\" " +
"src=\"/channels/#{id}/maps/channel_show?width=450&height=260\"></iframe>" "src=\"/channels/#{id}/maps/channel_show?width=450&height=260\"></iframe>"
if window.nil? || window[0].nil? if window.nil? || window[0].nil?
window = PortletWindow.new window = Window.new
window.wtype = :location window.window_type = 'location'
window.position = 0 window.position = 0
window.col = 1 window.col = 1
window.title = "window_map" window.title = "window_map"
@ -330,7 +326,6 @@ class Channel < ActiveRecord::Base
end end
window.private_flag = isPrivate window.private_flag = isPrivate
window.html = maps_html window.html = maps_html
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window self.windows.push window
@ -487,27 +482,26 @@ class Channel < ActiveRecord::Base
def set_ranking def set_ranking
update_attribute(:ranking, calc_ranking) unless ranking == calc_ranking update_attribute(:ranking, calc_ranking) unless ranking == calc_ranking
end end
def update_chart_portlet (field, isPrivate) def update_chart_portlet (field, isPrivate)
chartWindows = windows.where(:type => "ChartWindow", :name => "field#{field.last.to_s}", :private_flag => isPrivate ) chartWindows = windows.where(:window_type => "chart", :name => "field#{field.last.to_s}", :private_flag => isPrivate )
if chartWindows.nil? || chartWindows[0].nil? if chartWindows.nil? || chartWindows[0].nil?
window = ChartWindow.new window = Window.new
window.wtype = :chart window.window_type = 'chart'
window.position = 0 window.position = 0
window.col = 0 window.col = 0
window.title = "window_field_chart" window.title = "window_field_chart"
window.name = field.to_s window.name = field.to_s
window.window_detail = ChartWindowDetail.new window.options = "&results=60&dynamic=true"
window.window_detail.options = "&results=60&dynamic=true"
else else
window = chartWindows[0] window = chartWindows[0]
# If there are options, use them.. if options are not available, then assign defaults # If there are options, use them.. if options are not available, then assign defaults
window.window_detail.options ||= "&results=60&dynamic=true" window.options ||= "&results=60&dynamic=true"
end end
window.window_detail.field_number = field.last window.content_id = field.last
window.private_flag = isPrivate window.private_flag = isPrivate
windows.push window windows.push window
window.html ="<iframe id=\"iframe#{window.id}\" width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\"/channels/#{id}/charts/#{field.last.to_s}?width=450&height=260::OPTIONS::\" ></iframe>" window.html ="<iframe id=\"iframe#{window.id}\" width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\"/channels/#{id}/charts/#{field.last.to_s}?width=450&height=260::OPTIONS::\" ></iframe>"

View File

@ -1,22 +0,0 @@
# == Schema Information
#
# Table name: windows
#
# id :integer not null, primary key
# channel_id :integer
# position :integer
# created_at :datetime
# updated_at :datetime
# html :text
# col :integer
# title :string(255)
# wtype :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
#
class ChartWindow < Window
relate_to_details
end

View File

@ -1,14 +0,0 @@
# == Schema Information
#
# Table name: chart_window_details
#
# id :integer not null, primary key
# chart_window_id :integer
# field_number :integer
# created_at :datetime
# updated_at :datetime
# options :string(255)
#
class ChartWindowDetail < ActiveRecord::Base
end

View File

@ -15,12 +15,11 @@
class Plugin < ActiveRecord::Base class Plugin < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :plugin_window_details has_many :windows, -> { where window_type: 'plugin' }, :foreign_key => :content_id, :source => :window
has_many :windows, :through => :plugin_window_details, :source => :plugin_window
before_destroy { |record| record.windows.each { |window| window.delete } } before_destroy { |record| record.windows.each { |window| window.delete } }
def destroy_window def destroy_window
window_id = PluginWindowDetail.find_by_plugin_id(self.id).plugin_window_id window_id = Window.where(content_id: self.id, window_type: 'plugin').first.id
Window.delete(window_id) Window.delete(window_id)
end end
@ -88,12 +87,11 @@ class Plugin < ActiveRecord::Base
end end
def make_windows(channel_id, api_domain) def make_windows(channel_id, api_domain)
pluginWindows = []
#create all the windows as appropriate #create all the windows as appropriate
#Private plugins have one window.. #Private plugins have one window..
#Public plugins have a private/private windows, private/public window and a public window #Public plugins have a private/private windows, private/public window and a public window
if !has_public_windows(channel_id) && self.public? if !has_public_windows(channel_id) && self.public?
windows << PluginWindow.new_from(self, channel_id, :public, api_domain) windows << Window.new_from(self, channel_id, :public, api_domain)
else else
update_windows(channel_id) update_windows(channel_id)
end end
@ -132,3 +130,4 @@ class Plugin < ActiveRecord::Base
end end
end end

View File

@ -1,23 +0,0 @@
# == Schema Information
#
# Table name: windows
#
# id :integer not null, primary key
# channel_id :integer
# position :integer
# created_at :datetime
# updated_at :datetime
# html :text
# col :integer
# title :string(255)
# wtype :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
#
class PluginWindow < Window
relate_to_details
end

View File

@ -1,16 +0,0 @@
# == Schema Information
#
# Table name: plugin_window_details
#
# id :integer not null, primary key
# plugin_id :integer
# plugin_window_id :integer
# created_at :datetime
# updated_at :datetime
#
class PluginWindowDetail < ActiveRecord::Base
belongs_to :plugin_window
belongs_to :plugin
end

View File

@ -1,22 +0,0 @@
# == Schema Information
#
# Table name: windows
#
# id :integer not null, primary key
# channel_id :integer
# position :integer
# created_at :datetime
# updated_at :datetime
# html :text
# col :integer
# title :string(255)
# wtype :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
#
class PortletWindow < Window
relate_to_details
end

View File

@ -1,12 +0,0 @@
# == Schema Information
#
# Table name: portlet_window_details
#
# id :integer not null, primary key
# portlet_window_id :integer
# created_at :datetime
# updated_at :datetime
#
class PortletWindowDetail < ActiveRecord::Base
end

View File

@ -10,32 +10,28 @@
# html :text # html :text
# col :integer # col :integer
# title :string(255) # title :string(255)
# wtype :string(255) # window_type :string(255)
# name :string(255) # name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE) # private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE) # show_flag :boolean default(TRUE)
# content_id :integer
# options :text
# #
# content_id refers to plugin_id, field_number, etc depending on the window type
# valid values for window_type: status, location, chart, plugin, video
class Window < ActiveRecord::Base class Window < ActiveRecord::Base
belongs_to :channel belongs_to :channel
self.include_root_in_json = true self.include_root_in_json = true
def self.relate_to_details
class_eval <<-EOF
has_one :window_detail, :class_name => "#{self.name}Detail"
accepts_nested_attributes_for :window_detail
default_scope { includes(:window_detail) }
EOF
end
def private? def private?
return private_flag return private_flag
end end
def self.new_from( plugin, channel_id, privacy_flag, api_domain ) def self.new_from( plugin, channel_id, privacy_flag, api_domain )
window = PluginWindow.new window = Window.new
window.wtype = :plugin window.window_type = 'plugin'
window.position = 0 window.position = 0
window.col = 0 window.col = 0
window.title = "window_plugin" window.title = "window_plugin"
@ -45,6 +41,7 @@ class Window < ActiveRecord::Base
window.html ="<iframe width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\"/plugins/#{plugin.id}\" ></iframe>" window.html ="<iframe width=\"450\" height=\"260\" style=\"border: 1px solid #cccccc;\" src=\"/plugins/#{plugin.id}\" ></iframe>"
window.show_flag = false window.show_flag = false
window if window.save window if window.save
end end
end end

View File

@ -26,16 +26,15 @@
$.update("/channels/" + channelId + "/windows/"+ windowId + "/display" , data, $.update("/channels/" + channelId + "/windows/"+ windowId + "/display" , data,
function(response) { function(response) {
var window = response.plugin_window; var window = response.window;
var window_type = window.window_type;
var colId = window.col; var colId = window.col;
var colName = (window.private_flag == true) ? "private" : "public"; var colName = (window.private_flag == true) ? "private" : "public";
addPlugin.hide(); addPlugin.hide();
for (var type in response) {
var wtype = type; var portlet = addWindow(colName,colId, window.id, window_type, window.title, window.html );
}
var portlet = addWindow(colName,colId, window.id, wtype, window.title, window.html );
//for each portlet //for each portlet
portlet.each ( decoratePortlet("true") ); portlet.each ( decoratePortlet("true") );
@ -56,14 +55,12 @@
var windowId =ids[2]; var windowId =ids[2];
$.update("/channels/" + channelId +"/windows/"+ windowId + "/display" , $.update("/channels/" + channelId +"/windows/"+ windowId + "/display" ,
function(response) { function(response) {
var window = (response.portlet_window) ? response.portlet_window : response.chart_window; var window = response.window;
var window_type = window.window_type;
var colId = window.col; var colId = window.col;
var colName = (window.private_flag == true) ? "private" : "public"; var colName = (window.private_flag == true) ? "private" : "public";
addPortlet.hide(); addPortlet.hide();
for (var type in response) { var portlet = addWindow(colName,colId, window.id, window_type, window.title, window.html );
var wtype = type;
}
var portlet = addWindow(colName,colId, window.id, wtype, window.title, window.html );
//for each portlet //for each portlet
portlet.each ( decoratePortlet("true") ); portlet.each ( decoratePortlet("true") );

View File

@ -447,7 +447,7 @@ en:
help_thinghttp_show: "You can now send your ThingHTTP request and view the response using the following URL:" help_thinghttp_show: "You can now send your ThingHTTP request and view the response using the following URL:"
help_thingtweet: "ThingTweet acts as a proxy to Twitter so that your devices can update Twitter statuses without having to implement Open Authentication (OAuth)." help_thingtweet: "ThingTweet acts as a proxy to Twitter so that your devices can update Twitter statuses without having to implement Open Authentication (OAuth)."
help_tweetcontrol: "Use TweetControl to listen to specific trigger words from Twitter, and then process a ThingHTTP request." help_tweetcontrol: "Use TweetControl to listen to specific trigger words from Twitter, and then process a ThingHTTP request."
help_tweetcontrol_edit: "Select Anonymous TweetControl to allow anyone to trigger your TweetControl or fill in a specfic Twitter Account." help_tweetcontrol_edit: "Select Anonymous TweetControl to allow anyone to trigger your TweetControl or fill in a specfic Twitter Account (don't include the '@' sign)."
help_tweetcontrol_hashtag: "To trigger a TweetControl, you need to send a Twitter Status Update with at least the hashtag #thingspeak and the trigger word, for example:" help_tweetcontrol_hashtag: "To trigger a TweetControl, you need to send a Twitter Status Update with at least the hashtag #thingspeak and the trigger word, for example:"
help_tweetcontrol_thinghttp: "Select a ThingHTTP request to use with this TweetControl. The ThingHTTP request will be executed when the TweetControl is triggered." help_tweetcontrol_thinghttp: "Select a ThingHTTP request to use with this TweetControl. The ThingHTTP request will be executed when the TweetControl is triggered."
help_tweetcontrol_trigger: "Fill in a trigger to listen for." help_tweetcontrol_trigger: "Fill in a trigger to listen for."

View File

@ -0,0 +1,7 @@
class AddFieldsToWindows < ActiveRecord::Migration
def change
add_column :windows, :content_id, :integer
add_column :windows, :options, :text
end
end

View File

@ -0,0 +1,7 @@
class MoveDataFromWindowDetailsToWindows < ActiveRecord::Migration
def change
execute "UPDATE windows w, plugin_window_details p SET w.content_id = p.plugin_id WHERE w.id = p.plugin_window_id;"
execute "UPDATE windows w, chart_window_details c SET w.content_id = c.field_number, w.options = c.options WHERE w.id = c.chart_window_id;"
end
end

View File

@ -0,0 +1,6 @@
class RemoveWindowType < ActiveRecord::Migration
def change
remove_column :windows, :type
end
end

View File

@ -0,0 +1,6 @@
class RenameWindowsWtypeToWindowsWindowType < ActiveRecord::Migration
def change
rename_column :windows, :wtype, :window_type
end
end

View File

@ -0,0 +1,6 @@
class AddIndexesToWindows < ActiveRecord::Migration
def change
add_index :windows, [:window_type, :content_id]
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140630153108) do ActiveRecord::Schema.define(version: 20140722162824) do
create_table "active_admin_comments", force: true do |t| create_table "active_admin_comments", force: true do |t|
t.string "namespace" t.string "namespace"
@ -405,7 +405,6 @@ ActiveRecord::Schema.define(version: 20140630153108) do
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.string "authentication_token" t.string "authentication_token"
t.datetime "terms_agreed_at"
end end
add_index "users", ["api_key"], name: "index_users_on_api_key", using: :btree add_index "users", ["api_key"], name: "index_users_on_api_key", using: :btree
@ -431,13 +430,15 @@ ActiveRecord::Schema.define(version: 20140630153108) do
t.text "html" t.text "html"
t.integer "col" t.integer "col"
t.string "title" t.string "title"
t.string "wtype" t.string "window_type"
t.string "name" t.string "name"
t.string "type"
t.boolean "private_flag", default: false t.boolean "private_flag", default: false
t.boolean "show_flag", default: true t.boolean "show_flag", default: true
t.integer "content_id"
t.text "options"
end end
add_index "windows", ["channel_id"], name: "index_windows_on_channel_id", using: :btree add_index "windows", ["channel_id"], name: "index_windows_on_channel_id", using: :btree
add_index "windows", ["window_type", "content_id"], name: "index_windows_on_window_type_and_content_id", using: :btree
end end

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -56,9 +56,7 @@ describe WindowsController do
render_views render_views
before :each do before :each do
@channel = FactoryGirl.create(:channel) @channel = FactoryGirl.create(:channel)
@window = FactoryGirl.create(:chart_window) @window = FactoryGirl.create(:window, html: "<iframe src=\"/\"/>")
@window_detail = FactoryGirl.create(:chart_window_detail)
@window.window_detail = @window_detail
@channel.windows << @window @channel.windows << @window
end end
@ -130,7 +128,3 @@ describe WindowsController do
end end

View File

@ -1,10 +0,0 @@
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :chart_window do
channel_id 1
position 1
html "<iframe src=\"/\"/>"
col 0
end
end

View File

@ -1,20 +0,0 @@
# == Schema Information
#
# Table name: chart_window_details
#
# id :integer not null, primary key
# chart_window_id :integer
# field_number :integer
# created_at :datetime
# updated_at :datetime
# options :string(255)
#
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :chart_window_detail do
chart_window_id 1
field_number 1
end
end

View File

@ -1,11 +0,0 @@
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :plugin_window do
channel_id 1
position 1
html "<iframe ::OPTIONS::></iframe>"
col 0
end
end

View File

@ -1,19 +0,0 @@
# == Schema Information
#
# Table name: plugin_window_details
#
# id :integer not null, primary key
# plugin_id :integer
# plugin_window_id :integer
# created_at :datetime
# updated_at :datetime
#
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :plugin_window_detail do
plugin_id 1
plugin_window_id 1
end
end

View File

@ -1,17 +0,0 @@
# == Schema Information
#
# Table name: portlet_window_details
#
# id :integer not null, primary key
# portlet_window_id :integer
# created_at :datetime
# updated_at :datetime
#
# Read about factories at http://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :portlet_window_detail do
portlet_window_id 1
end
end

View File

@ -10,11 +10,12 @@
# html :text # html :text
# col :integer # col :integer
# title :string(255) # title :string(255)
# wtype :string(255) # window_type :string(255)
# name :string(255) # name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE) # private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE) # show_flag :boolean default(TRUE)
# content_id :integer
# options :text
# #
# Read about factories at http://github.com/thoughtbot/factory_girl # Read about factories at http://github.com/thoughtbot/factory_girl
@ -25,5 +26,7 @@ FactoryGirl.define do
position 1 position 1
html "<iframe ::OPTIONS::></iframe>" html "<iframe ::OPTIONS::></iframe>"
col 0 col 0
content_id 1
end end
end end

View File

@ -79,7 +79,7 @@ describe Channel do
channel.assign_attributes({:video_id => video_id, :video_type => "youtube"}) channel.assign_attributes({:video_id => video_id, :video_type => "youtube"})
channel.set_windows channel.set_windows
channel.save channel.save
window = channel.windows.where({:wtype => :video }) window = channel.windows.where({:window_type => :video })
window[0].html.should == "<iframe class=\"youtube-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"https://www.youtube.com/embed/xxxxxx?wmode=transparent\" frameborder=\"0\" wmode=\"Opaque\" ></iframe>" window[0].html.should == "<iframe class=\"youtube-player\" type=\"text/html\" width=\"452\" height=\"260\" src=\"https://www.youtube.com/embed/xxxxxx?wmode=transparent\" frameborder=\"0\" wmode=\"Opaque\" ></iframe>"
end end

View File

@ -20,7 +20,7 @@ describe Plugin do
before :each do before :each do
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel, :user => @user) @channel = FactoryGirl.create(:channel, :user => @user)
@window = FactoryGirl.create(:plugin_window, :channel => @channel) @window = FactoryGirl.create(:window, :channel => @channel, :html => "<iframe ::OPTIONS::></iframe>")
end end
it "should be valid" do it "should be valid" do
@ -31,7 +31,7 @@ describe Plugin do
it "should confirm has_[public\private]_windows" do it "should confirm has_[public\private]_windows" do
plugin = Plugin.new plugin = Plugin.new
window = PluginWindow.new window = Window.new
window.private_flag = true window.private_flag = true
window.channel_id = 1 window.channel_id = 1
plugin.windows << window plugin.windows << window
@ -83,8 +83,6 @@ describe Plugin do
plugin.save plugin.save
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(1) plugin.windows.size.should eq(1)
end end
it "should allow only private_windows to be retrieved" do it "should allow only private_windows to be retrieved" do
@ -96,6 +94,7 @@ describe Plugin do
plugin.windows.size.should eq(2) plugin.windows.size.should eq(2)
plugin.private_dashboard_windows(@channel.id).size.should eq(1) plugin.private_dashboard_windows(@channel.id).size.should eq(1)
end end
it "should allow only public_windows to be retrieved" do it "should allow only public_windows to be retrieved" do
plugin = Plugin.new plugin = Plugin.new
plugin.private_flag = false plugin.private_flag = false
@ -108,17 +107,10 @@ describe Plugin do
it "should cascade delete to Window" do it "should cascade delete to Window" do
plugin = Plugin.new plugin = Plugin.new
plugin.make_windows @channel.id, "localhost" plugin.make_windows @channel.id, "localhost"
plugin_id = plugin.id
window_id = plugin.windows[0].id
plugin.destroy plugin.destroy
Window.where(window_type: 'plugin', content_id: plugin_id).count.should eq(0)
windows = Window.find_all_by_id(window_id)
windows.size.should eq(0)
end end
it "should have windows associated with separate channels" do it "should have windows associated with separate channels" do
@ -132,3 +124,4 @@ describe Plugin do
end end
end end

View File

@ -1,54 +0,0 @@
# == Schema Information
#
# Table name: plugin_window_details
#
# id :integer not null, primary key
# plugin_id :integer
# plugin_window_id :integer
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
describe PluginWindowDetail do
before :each do
@channel = FactoryGirl.create(:channel)
@plugin = FactoryGirl.create(:plugin)
end
it "should be valid" do
winDetail = PluginWindowDetail.new
winDetail.should be_valid
end
it "should allow windows plugin association" do
window = Window.new_from @plugin, @channel.id, :private, "localhost"
@plugin.windows << window
@plugin.save
window.should be_valid
window.window_detail.should_not be_nil
end
end
describe PluginWindowDetail do
before :each do
@user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel, :user => @user)
@plugin = FactoryGirl.create(:plugin, :user => @user)
end
it "should differentiate between public plugin_window and private plugin_window" do
window = Window.new_from @plugin, @channel.id, true, "localhost"
@plugin.windows << window
@plugin.save
plugin = PluginWindowDetail.find_all_by_plugin_id(@plugin.id)
plugin.length.should == 1
window = Window.new_from @plugin, @channel.id, false, "localhost"
@plugin.windows << window
@plugin.save
plugin = PluginWindowDetail.find_all_by_plugin_id(@plugin.id)
plugin.length.should == 2
end
end

View File

@ -10,11 +10,12 @@
# html :text # html :text
# col :integer # col :integer
# title :string(255) # title :string(255)
# wtype :string(255) # window_type :string(255)
# name :string(255) # name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE) # private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE) # show_flag :boolean default(TRUE)
# content_id :integer
# options :text
# #
require 'spec_helper' require 'spec_helper'
@ -24,6 +25,46 @@ describe Window do
window = Window.new window = Window.new
window.should be_valid window.should be_valid
end end
describe "plugin window" do
before :each do
@channel = FactoryGirl.create(:channel)
@plugin = FactoryGirl.create(:plugin)
end
it "should be valid" do
window = Window.new
window.should be_valid
end
it "should allow windows plugin association" do
window = Window.new_from @plugin, @channel.id, :private, "localhost"
@plugin.windows << window
@plugin.save
window.should be_valid
window.should_not be_nil
end
end
describe "plugin window with user" do
before :each do
@user = FactoryGirl.create(:user)
@channel = FactoryGirl.create(:channel, :user => @user)
@plugin = FactoryGirl.create(:plugin, :user => @user)
end
it "should differentiate between public plugin_window and private plugin_window" do
window = Window.new_from @plugin, @channel.id, true, "localhost"
@plugin.windows << window
@plugin.save
@plugin.windows.length.should == 1
window = Window.new_from @plugin, @channel.id, false, "localhost"
@plugin.windows << window
@plugin.save
@plugin.windows.length.should == 2
end
end
end end