big refactor of windows models
This commit is contained in:
@ -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>"
|
||||
|
@ -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
|
@ -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
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user