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)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.1)
rake (10.3.2)
ransack (1.2.3)
actionpack (>= 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) {
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")
var window = (data[i].portlet_window) ? data[i].portlet_window : data[i].chart_window;
// set the window and window_type
var window = data[i].window;
var window_type = window.window_type;
colId = window.col;
title = window.title;
var content = window.html;
if (data[i].chart_window) {
var windowId = window.id;
$("body").append("<div id='chartConfig"+windowId+"'></div>");
}
var portlet = addWindow(colName, colId, window.id, wtype, title, content);
if (window.window_type === 'chart') {
$("body").append("<div id='chartConfig" + window.id + "'></div>");
}
var portlet = addWindow(colName, colId, window.id, window_type, title, content);
portlet.each ( decoratePortlet(current_user) ) ;
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" ' +
'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 +
'</div><div class="portlet-content">'+content+'</div>') ;
@ -215,9 +207,9 @@ var decoratePortlet = function (current_user) {
thisObject = $(this);
if (current_user == "true") {
// 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(".wtype-chart_window").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').prepend( "<span id='minusBtn' class='ui-toggle ui-icon ui-icon-minusthick'></span>");
thisObject.find(".window_type-chart").append("<span id='pencilBtn' class='ui-edit ui-icon ui-icon-pencil'></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");
}
else {

View File

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

View File

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

View File

@ -249,26 +249,24 @@ class Channel < ActiveRecord::Base
end
#remove portlets for fields that don't exist
#iterate all chart windows... and look for a matching field
chartWindows = windows.where(:wtype => :chart )
chartWindows.each do |window|
if self.send(window.name).blank?
chart_windows = windows.where(:window_type => 'chart' )
chart_windows.each do |window|
if self.send("field#{window.content_id}").blank?
window.destroy
end
end
end
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>"
if window.nil? || window[0].nil?
window = PortletWindow.new
window.wtype = :status
window = Window.new
window.window_type = 'status'
window.position = 1
window.col = 1
window.title = "window_status"
@ -279,7 +277,6 @@ class Channel < ActiveRecord::Base
window.private_flag = isPrivate
window.html = status_html
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window
end
@ -289,13 +286,13 @@ class Channel < ActiveRecord::Base
end
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?
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>"
if window.nil? || window[0].nil?
window = PortletWindow.new
window.wtype = :video
window = Window.new
window.window_type = 'video'
window.position = 1
window.col = 1
window.title = "window_channel_video"
@ -305,7 +302,6 @@ class Channel < ActiveRecord::Base
window.private_flag = isPrivate
window.html = youtube_html if video_type == 'youtube'
window.html = vimeo_html if video_type == 'vimeo'
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window
else
unless window[0].nil?
@ -315,13 +311,13 @@ class Channel < ActiveRecord::Base
end
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?
maps_html = "<iframe width=\"450\" height=\"260\" frameborder=\"0\" scrolling=\"no\" " +
"src=\"/channels/#{id}/maps/channel_show?width=450&height=260\"></iframe>"
if window.nil? || window[0].nil?
window = PortletWindow.new
window.wtype = :location
window = Window.new
window.window_type = 'location'
window.position = 0
window.col = 1
window.title = "window_map"
@ -330,7 +326,6 @@ class Channel < ActiveRecord::Base
end
window.private_flag = isPrivate
window.html = maps_html
window.window_detail = PortletWindowDetail.new if window.window_detail.nil?
self.windows.push window
@ -487,27 +482,26 @@ class Channel < ActiveRecord::Base
def set_ranking
update_attribute(:ranking, calc_ranking) unless ranking == calc_ranking
end
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?
window = ChartWindow.new
window.wtype = :chart
window = Window.new
window.window_type = 'chart'
window.position = 0
window.col = 0
window.title = "window_field_chart"
window.name = field.to_s
window.window_detail = ChartWindowDetail.new
window.window_detail.options = "&results=60&dynamic=true"
window.options = "&results=60&dynamic=true"
else
window = chartWindows[0]
# 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
window.window_detail.field_number = field.last
window.content_id = field.last
window.private_flag = isPrivate
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>"

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
belongs_to :user
has_many :plugin_window_details
has_many :windows, :through => :plugin_window_details, :source => :plugin_window
has_many :windows, -> { where window_type: 'plugin' }, :foreign_key => :content_id, :source => :window
before_destroy { |record| record.windows.each { |window| window.delete } }
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)
end
@ -88,12 +87,11 @@ class Plugin < ActiveRecord::Base
end
def make_windows(channel_id, api_domain)
pluginWindows = []
#create all the windows as appropriate
#Private plugins have one window..
#Public plugins have a private/private windows, private/public window and a public window
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
update_windows(channel_id)
end
@ -132,3 +130,4 @@ class Plugin < ActiveRecord::Base
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
# col :integer
# title :string(255)
# wtype :string(255)
# window_type :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# 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
belongs_to :channel
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?
return private_flag
end
def self.new_from( plugin, channel_id, privacy_flag, api_domain )
window = PluginWindow.new
window.wtype = :plugin
window = Window.new
window.window_type = 'plugin'
window.position = 0
window.col = 0
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.show_flag = false
window if window.save
end
end

View File

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

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.
ActiveRecord::Schema.define(version: 20140630153108) do
ActiveRecord::Schema.define(version: 20140722162824) do
create_table "active_admin_comments", force: true do |t|
t.string "namespace"
@ -405,7 +405,6 @@ ActiveRecord::Schema.define(version: 20140630153108) do
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.string "authentication_token"
t.datetime "terms_agreed_at"
end
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.integer "col"
t.string "title"
t.string "wtype"
t.string "window_type"
t.string "name"
t.string "type"
t.boolean "private_flag", default: false
t.boolean "show_flag", default: true
t.integer "content_id"
t.text "options"
end
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

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

@ -3,7 +3,7 @@ require 'spec_helper'
describe WindowsController do
before :each do
@user = FactoryGirl.create(:user)
controller.stub(:current_user).and_return(@user)
controller.stub(:current_user_session).and_return(true)
@ -20,7 +20,7 @@ describe WindowsController do
response.should be_successful
end
end
describe "POST 'update'" do
it "should allow an update" do
post 'update', :channel_id => @channel.id, :page => "{\"col\":0,\"positions\":[#{@window.id}]}"
@ -56,9 +56,7 @@ describe WindowsController do
render_views
before :each do
@channel = FactoryGirl.create(:channel)
@window = FactoryGirl.create(:chart_window)
@window_detail = FactoryGirl.create(:chart_window_detail)
@window.window_detail = @window_detail
@window = FactoryGirl.create(:window, html: "<iframe src=\"/\"/>")
@channel.windows << @window
end
@ -69,7 +67,7 @@ describe WindowsController do
end
end
describe "When getting " do
it "should render json" do
get 'index', :channel_id => @channel.id, :format => :json
@ -130,7 +128,3 @@ describe WindowsController do
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
# col :integer
# title :string(255)
# wtype :string(255)
# window_type :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
# content_id :integer
# options :text
#
# Read about factories at http://github.com/thoughtbot/factory_girl
@ -25,5 +26,7 @@ FactoryGirl.define do
position 1
html "<iframe ::OPTIONS::></iframe>"
col 0
content_id 1
end
end

View File

@ -79,7 +79,7 @@ describe Channel do
channel.assign_attributes({:video_id => video_id, :video_type => "youtube"})
channel.set_windows
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>"
end

View File

@ -20,8 +20,8 @@ describe Plugin do
before :each do
@user = FactoryGirl.create(: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
it "should be valid" do
plugin = Plugin.new
@ -31,7 +31,7 @@ describe Plugin do
it "should confirm has_[public\private]_windows" do
plugin = Plugin.new
window = PluginWindow.new
window = Window.new
window.private_flag = true
window.channel_id = 1
plugin.windows << window
@ -49,7 +49,7 @@ describe Plugin do
plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(2)
end
it "new, private window should not be showing" do
@ -62,7 +62,7 @@ describe Plugin do
plugin.windows.size.should eq(1)
window = plugin.windows[0]
window.show_flag.should be_false
end
it "should destroy public windows when changing plugin from public to private" do
@ -75,7 +75,7 @@ describe Plugin do
plugin.private_flag = false
plugin.save
plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(2)
@ -83,8 +83,6 @@ describe Plugin do
plugin.save
plugin.make_windows @channel.id, "localhost"
plugin.windows.size.should eq(1)
end
it "should allow only private_windows to be retrieved" do
@ -96,6 +94,7 @@ describe Plugin do
plugin.windows.size.should eq(2)
plugin.private_dashboard_windows(@channel.id).size.should eq(1)
end
it "should allow only public_windows to be retrieved" do
plugin = Plugin.new
plugin.private_flag = false
@ -108,19 +107,12 @@ describe Plugin do
it "should cascade delete to Window" do
plugin = Plugin.new
plugin.make_windows @channel.id, "localhost"
window_id = plugin.windows[0].id
plugin_id = plugin.id
plugin.destroy
windows = Window.find_all_by_id(window_id)
windows.size.should eq(0)
Window.where(window_type: 'plugin', content_id: plugin_id).count.should eq(0)
end
it "should have windows associated with separate channels" do
channel2 = FactoryGirl.create(:channel, :user => @user)
plugin = Plugin.new
@ -129,6 +121,7 @@ describe Plugin do
plugin.windows.size.should eq(2)
plugin.private_dashboard_windows(@channel.id).size.should eq(1)
plugin.private_dashboard_windows(channel2.id).size.should eq(1)
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
# col :integer
# title :string(255)
# wtype :string(255)
# window_type :string(255)
# name :string(255)
# type :string(255)
# private_flag :boolean default(FALSE)
# show_flag :boolean default(TRUE)
# content_id :integer
# options :text
#
require 'spec_helper'
@ -24,6 +25,46 @@ describe Window do
window = Window.new
window.should be_valid
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