diff --git a/Gemfile b/Gemfile index a364c6a..973c847 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '4.0.2' +gem 'rails', '4.0.3' gem 'jquery-rails', '3.0.4' gem 'rails_autolink' gem 'mysql2' @@ -30,7 +30,7 @@ gem 'rack-utf8_sanitizer' gem 'newrelic_rpm' gem 'actionpack-xml_parser' -# To use debugger +# to use debugger # gem 'ruby-debug' # assets diff --git a/Gemfile.lock b/Gemfile.lock index 9902680..dd16c75 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,27 +17,27 @@ GEM remote: http://rubygems.org/ specs: ZenTest (4.9.5) - actionmailer (4.0.2) - actionpack (= 4.0.2) + actionmailer (4.0.3) + actionpack (= 4.0.3) mail (~> 2.5.4) - actionpack (4.0.2) - activesupport (= 4.0.2) + actionpack (4.0.3) + activesupport (= 4.0.3) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) actionpack-xml_parser (1.0.1) actionpack (>= 4.0.0.rc1) - activemodel (4.0.2) - activesupport (= 4.0.2) + activemodel (4.0.3) + activesupport (= 4.0.3) builder (~> 3.1.0) - activerecord (4.0.2) - activemodel (= 4.0.2) + activerecord (4.0.3) + activemodel (= 4.0.3) activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.2) + activesupport (= 4.0.3) arel (~> 4.0.0) activerecord-deprecated_finders (1.0.3) - activesupport (4.0.2) + activesupport (4.0.3) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) @@ -51,7 +51,7 @@ GEM annotate (2.6.1) activerecord (>= 2.3.0) rake (>= 0.8.7) - arel (4.0.1) + arel (4.0.2) atomic (1.1.14) authlogic (3.3.0) activerecord (>= 3.2) @@ -157,7 +157,7 @@ GEM nokogiri (1.6.1) mini_portile (~> 0.5.0) oauth (0.4.7) - polyglot (0.3.3) + polyglot (0.3.4) quiet_assets (1.0.2) railties (>= 3.1, < 5.0) rack (1.5.2) @@ -167,19 +167,19 @@ GEM rack (>= 1.0) rack-utf8_sanitizer (1.1.0) rack (~> 1.0) - rails (4.0.2) - actionmailer (= 4.0.2) - actionpack (= 4.0.2) - activerecord (= 4.0.2) - activesupport (= 4.0.2) + rails (4.0.3) + actionmailer (= 4.0.3) + actionpack (= 4.0.3) + activerecord (= 4.0.3) + activesupport (= 4.0.3) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.2) + railties (= 4.0.3) sprockets-rails (~> 2.0.0) rails_autolink (1.1.5) rails (> 3.1) - railties (4.0.2) - actionpack (= 4.0.2) - activesupport (= 4.0.2) + railties (4.0.3) + actionpack (= 4.0.3) + activesupport (= 4.0.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.1.1) @@ -228,7 +228,7 @@ GEM rack-protection (~> 1.4) tilt (~> 1.3, >= 1.3.4) spork (0.9.2) - sprockets (2.10.1) + sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -314,7 +314,7 @@ DEPENDENCIES nokogiri quiet_assets rack-utf8_sanitizer - rails (= 4.0.2) + rails (= 4.0.3) rails_autolink redis resque-scheduler (= 2.3.1) diff --git a/app/assets/images/channel_public_view.png b/app/assets/images/channel_public_view.png new file mode 100644 index 0000000..fa760f5 Binary files /dev/null and b/app/assets/images/channel_public_view.png differ diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js index 80306ab..bb204a5 100644 --- a/app/assets/javascripts/sidebar.js +++ b/app/assets/javascripts/sidebar.js @@ -1,9 +1,12 @@ -$(document).ready(function() { +// execute on window load (and not document.ready), so that the sidebar is positioned correctly +$(window).load(function() { // if affix function exists if ($.fn.affix) { - // add sidebar affix - $('#bootstrap-sidebar').affix(); + // add sidebar affix, wrapped in a timeout so that it displays correctly + setTimeout(function() { + $('#bootstrap-sidebar').affix(); + }, 100); // add sidebar scrollspy $(document.body).scrollspy({ target: '#leftcol', offset: 300 }); diff --git a/app/assets/stylesheets/custom.css b/app/assets/stylesheets/custom.css index 1bce4c3..9d078bb 100644 --- a/app/assets/stylesheets/custom.css +++ b/app/assets/stylesheets/custom.css @@ -29,6 +29,8 @@ body { padding-top: 70px; } .format-xml { display: none; } .format-block { min-height: 200px; } .format-block-lg { min-height: 350px; } +.format-block-xl { min-height: 400px; } +.format-block-xxl { min-height: 600px; } /* Sticky footer styles @@ -70,7 +72,6 @@ body { .apps a:hover, .apps:hover div { text-decoration: none; } .commentarea { width: 300px; height: 80px; } -#options { float: right; text-align: right; } #login { padding: 6px; border: 1px solid #bbbbbb; diff --git a/app/assets/stylesheets/sidebar.css b/app/assets/stylesheets/sidebar.css index a5acce1..dd24323 100644 --- a/app/assets/stylesheets/sidebar.css +++ b/app/assets/stylesheets/sidebar.css @@ -7,6 +7,13 @@ border: 1px solid #bbb; border-radius: 5px; padding: 2px 0; + margin-top: 20px; + width: 228px; +} + +#bootstrap-sidebar li a { + padding: 2px 8px; + font-size: 16px; } #bootstrap-sidebar li a:hover { @@ -18,11 +25,23 @@ border-right-width:4px; } +#bootstrap-sidebar li.subitem a { + padding-left: 30px; + font-size: 12px; +} + @media (min-width: 979px) { #bootstrap-sidebar.affix-top, #bootstrap-sidebar.affix { position: fixed; top:90px; - width:228px; + width: 228px; + margin-top: 0; + } +} + +@media (max-width: 978px) { + #bootstrap-sidebar.affix-top, #bootstrap-sidebar.affix { + width: 100%; } } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 85990c6..c1e8276 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -33,8 +33,15 @@ class ApplicationController < ActionController::Base @ssl_api_domain ||= ssl_api_domain @locale ||= get_locale I18n.locale = @locale + # sets timezone for current user, all DateTime outputs will be automatically formatted Time.zone = current_user.time_zone if current_user + + # allows use of daily params + params[:timescale] = '1440' if params[:timescale] == 'daily' + params[:average] = '1440' if params[:average] == 'daily' + params[:median] = '1440' if params[:median] == 'daily' + params[:sum] = '1440' if params[:sum] == 'daily' end # get the locale, but don't fail if header value doesn't exist @@ -90,21 +97,12 @@ class ApplicationController < ActionController::Base return output.join(', ') end - def set_channels_menu - @menu = 'channels' - end - - def set_apps_menu - @menu = 'apps' - end - - def set_plugins_menu - @menu = 'plugins' - end - - def set_devices_menu - @menu = 'devices' - end + # set menus + def set_support_menu; @menu = 'support'; end + def set_channels_menu; @menu = 'channels'; end + def set_apps_menu; @menu = 'apps'; end + def set_plugins_menu; @menu = 'plugins'; end + def set_devices_menu; @menu = 'devices'; end def current_user_session return @current_user_session if defined?(@current_user_session) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index f8e69e9..d8a6217 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -29,10 +29,19 @@ class ChannelsController < ApplicationController # list public channels def public + @domain = domain + # default blank response + @channels = Channel.where(:id => 0).paginate :page => params[:page] + # get channels by ids if params[:channel_ids].present? flash[:notice] = t(:selected_channels) @channels = Channel.public_viewable.by_array(params[:channel_ids]).order('ranking desc, updated_at DESC').paginate :page => params[:page] + # get channels that match a user + elsif params[:username].present? + flash[:notice] = "#{t(:user).capitalize}: #{params[:username]}" + searched_user = User.find_by_login(params[:username]) + @channels = searched_user.channels.public_viewable.active.order('ranking desc, updated_at DESC').paginate :page => params[:page] if searched_user.present? # get channels that match a tag elsif params[:tag].present? flash[:notice] = "#{t(:tag).capitalize}: #{params[:tag]}" @@ -40,6 +49,7 @@ class ChannelsController < ApplicationController # normal channel list else flash[:notice] = t(:featured_channels) + respond_with_error(:error_resource_not_found) and return if params[:page] == '0' @channels = Channel.public_viewable.active.order('ranking desc, updated_at DESC').paginate :page => params[:page] end @@ -311,8 +321,12 @@ class ChannelsController < ApplicationController # if there is a talkback_key but no command respond_with_blank and return if params[:talkback_key].present? && command.blank? - # normal route, respond with the entry id of the feed - render :text => status + # normal route, respond with the feed + respond_to do |format| + format.html { render :text => status } + format.json { render :json => feed.to_json } + format.xml { render :xml => feed.to_xml(Feed.public_options) } + end and return end # import view diff --git a/app/controllers/docs_controller.rb b/app/controllers/docs_controller.rb index 3a4b123..c3afcb3 100644 --- a/app/controllers/docs_controller.rb +++ b/app/controllers/docs_controller.rb @@ -1,6 +1,43 @@ class DocsController < ApplicationController + before_filter :set_support_menu - def index; ;end + def index; ; end + def errors; ; end + def tweetcontrol; ; end + def plugins; ; end + def importer; ; end + def charts; ; end + def users; ; end + + def channels + # default values + @channel_api_key = 'XXXXXXXXXXXXXXXX' + + # if user is signed in + if current_user && current_user.channels.any? + @channel_api_key = current_user.channels.order('updated_at desc').first.write_api_key + end + end + + def thinghttp + # default values + @thinghttp_api_key = 'XXXXXXXXXXXXXXXX' + + # if user is signed in + if current_user && current_user.thinghttps.any? + @thinghttp_api_key = current_user.thinghttps.order('updated_at desc').first.api_key + end + end + + def thingtweet + # default values + @thingtweet_api_key = 'XXXXXXXXXXXXXXXX' + + # if user is signed in + if current_user && current_user.twitter_accounts.any? + @thingtweet_api_key = current_user.twitter_accounts.order('updated_at desc').first.api_key + end + end def talkback # default values diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb index 8bbf376..669e01d 100644 --- a/app/controllers/feed_controller.rb +++ b/app/controllers/feed_controller.rb @@ -194,13 +194,13 @@ class FeedController < ApplicationController output = @feed.to_xml elsif params[:format] == 'csv' @csv_headers = Feed.select_options(@channel, params) - elsif (params[:format] == 'txt' or params[:format] == 'text') + elsif (params[:format] == 'txt' || params[:format] == 'text' || params[:format] == 'html') output = add_prepend_append(@feed["field#{params[:field_id]}"]) else output = @feed.to_json - end - # else set error code + + # else set error code else if params[:format] == 'xml' output = bad_feed_xml @@ -211,7 +211,7 @@ class FeedController < ApplicationController # output data in proper format respond_to do |format| - format.html { render :json => output } + format.html { render :text => output } format.json { render :json => output, :callback => params[:callback] } format.xml { render :xml => output } format.csv diff --git a/app/models/channel.rb b/app/models/channel.rb index f1597e6..d6bba02 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -81,6 +81,11 @@ class Channel < ActiveRecord::Base cattr_reader :per_page @@per_page = 15 + # write key for a channel + def write_api_key + self.api_keys.where(:write_flag => true).first.api_key + end + # select options def select_options only = [:name, :created_at, :updated_at, :id, :last_entry_id] diff --git a/app/models/feed.rb b/app/models/feed.rb index f7a4563..c9f12a4 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -33,6 +33,13 @@ class Feed < ActiveRecord::Base attr_readonly :created_at + # for to_xml, return only the public attributes + def self.public_options + { + :except => [:id, :updated_at] + } + end + # only output these fields for feed def self.select_options(channel, params) only = [:created_at] @@ -96,7 +103,7 @@ class Feed < ActiveRecord::Base # custom json output def as_json(options = {}) - super(options.merge(:except => [:updated_at, :id])) + super(Feed.public_options) end # check if a field value is a number diff --git a/app/views/api_keys/_index.html.erb b/app/views/api_keys/_index.html.erb index 9240fa9..1e1675e 100644 --- a/app/views/api_keys/_index.html.erb +++ b/app/views/api_keys/_index.html.erb @@ -39,7 +39,7 @@