From ee05bbd10267661587ba28ca279a596e5ebaf52e Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Tue, 14 Oct 2014 19:47:57 -0400 Subject: [PATCH] add templates for plugins: Google gauge and multiline charts --- app/controllers/charts_controller.rb | 9 +- app/controllers/plugins_controller.rb | 30 ++-- app/views/charts/multiple_series.html.erb | 136 ++++++++++++++++++ app/views/plugins/edit.html.erb | 20 +-- app/views/plugins/index.html.erb | 7 +- app/views/plugins/new.html.erb | 61 ++++++++ app/views/plugins/templates/chart.css | 5 + app/views/plugins/templates/chart.html | 18 +++ app/views/plugins/templates/chart.js | 122 ++++++++++++++++ app/views/plugins/{ => templates}/default.css | 0 .../plugins/{ => templates}/default.html | 0 app/views/plugins/{ => templates}/default.js | 0 app/views/plugins/templates/gauge.css | 7 + app/views/plugins/templates/gauge.html | 19 +++ app/views/plugins/templates/gauge.js | 66 +++++++++ config/locales/en.yml | 7 +- config/routes.rb | 3 + 17 files changed, 479 insertions(+), 31 deletions(-) create mode 100644 app/views/charts/multiple_series.html.erb create mode 100644 app/views/plugins/new.html.erb create mode 100644 app/views/plugins/templates/chart.css create mode 100644 app/views/plugins/templates/chart.html create mode 100644 app/views/plugins/templates/chart.js rename app/views/plugins/{ => templates}/default.css (100%) rename app/views/plugins/{ => templates}/default.html (100%) rename app/views/plugins/{ => templates}/default.js (100%) create mode 100644 app/views/plugins/templates/gauge.css create mode 100644 app/views/plugins/templates/gauge.html create mode 100644 app/views/plugins/templates/gauge.js diff --git a/app/controllers/charts_controller.rb b/app/controllers/charts_controller.rb index b1253a7..19b6457 100644 --- a/app/controllers/charts_controller.rb +++ b/app/controllers/charts_controller.rb @@ -1,5 +1,6 @@ class ChartsController < ApplicationController before_filter :require_user, :only => [:edit] + def edit # params[:id] is the windows ID @channel = current_user.channels.find(params[:channel_id]) @@ -22,7 +23,6 @@ class ChartsController < ApplicationController end def index - set_channels_menu @channel = Channel.find(params[:channel_id]) @channel_id = params[:channel_id] @@ -35,8 +35,12 @@ class ChartsController < ApplicationController check_permissions(@channel) end - def show + # show a chart with multiple series + def multiple_series + render :layout => false + end + def show # allow these parameters when creating feed querystring feed_params = ['key', 'api_key', 'apikey', 'days','start','end','round','timescale','average','median','sum','results','location','status','timezone'] @@ -66,7 +70,6 @@ class ChartsController < ApplicationController render :layout => false end - # save chart options def update @channel = Channel.find(params[:channel_id]) diff --git a/app/controllers/plugins_controller.rb b/app/controllers/plugins_controller.rb index 3dde1df..2c64c7a 100644 --- a/app/controllers/plugins_controller.rb +++ b/app/controllers/plugins_controller.rb @@ -8,13 +8,14 @@ class PluginsController < ApplicationController respond_with_error(:error_auth_required) and return if current_user.blank? || (@plugin.user_id != current_user.id) end + def new; ; end + def edit; ; end + def index @plugins = current_user.plugins - end def public_plugins - channel_id = params[:channel_id].to_i return if channel_id.nil? #private page should display all plugins @@ -24,7 +25,6 @@ class PluginsController < ApplicationController plugins.each do |plugin| plugin.make_windows channel_id, api_domain #will only make the window the first time @plugin_windows = @plugin_windows + plugin.public_dashboard_windows(channel_id) - end respond_to do |format| @@ -53,9 +53,21 @@ class PluginsController < ApplicationController def create # add plugin with defaults @plugin = Plugin.new - @plugin.html = read_file('app/views/plugins/default.html') - @plugin.css = read_file('app/views/plugins/default.css') - @plugin.js = read_file('app/views/plugins/default.js') + + # set default template + template = 'default' + + # use case statement to set template, since user input is untrusted + case params[:template] + when 'gauge' then template = 'gauge' + when 'chart' then template = 'chart' + end + + # set template dynamically + @plugin.html = read_file("app/views/plugins/templates/#{template}.html") + @plugin.css = read_file("app/views/plugins/templates/#{template}.css") + @plugin.js = read_file("app/views/plugins/templates/#{template}.js") + @plugin.user_id = current_user.id @plugin.private_flag = true @plugin.save @@ -82,7 +94,6 @@ class PluginsController < ApplicationController end def show_public - @plugin = Plugin.find(params[:id]) @output = @plugin.html.sub('%%PLUGIN_CSS%%', @plugin.css).sub('%%PLUGIN_JAVASCRIPT%%', @plugin.js) if @plugin.private? @@ -100,9 +111,6 @@ class PluginsController < ApplicationController end end - def edit - end - def update @plugin.update_attribute(:name, params[:plugin][:name]) @plugin.update_attribute(:private_flag, params[:plugin][:private_flag]) @@ -111,11 +119,9 @@ class PluginsController < ApplicationController @plugin.update_attribute(:html,params[:plugin][:html]) if @plugin.save - @plugin.update_all_windows redirect_to plugins_path and return end - end def ajax_update diff --git a/app/views/charts/multiple_series.html.erb b/app/views/charts/multiple_series.html.erb new file mode 100644 index 0000000..a216b79 --- /dev/null +++ b/app/views/charts/multiple_series.html.erb @@ -0,0 +1,136 @@ + + + + + + + + + + +
+ <%= image_tag 'ajax-loader.gif', :style => "position: absolute; margin: auto; top: 0; left: 0; right: 0; bottom: 0;" %> +
+ + + diff --git a/app/views/plugins/edit.html.erb b/app/views/plugins/edit.html.erb index dea2bac..cf3234e 100644 --- a/app/views/plugins/edit.html.erb +++ b/app/views/plugins/edit.html.erb @@ -14,7 +14,7 @@ .CodeMirror-scroll { height: 300px; } -
+