Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uservoice plugin #333

Merged
merged 1 commit into from
Jan 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ gem 'acts_as_versioned', github: 'technoweenie/acts_as_versioned'
gem 'foodsoft_wiki', path: 'plugins/wiki'
gem 'foodsoft_messages', path: 'plugins/messages'

# plugins not enabled by default
#gem 'foodsoft_uservoice', path: 'plugins/uservoice'


group :production do
gem 'exception_notification'
end
Expand Down
45 changes: 45 additions & 0 deletions plugins/uservoice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FoodsoftUservoice
=================

Adds [uservoice](https://uservoice.com/) feedback form to foodsoft.


Configuration
-------------

This plugin is configured in the foodcoop configuration in foodsoft's
"config/app\_config.yml":

```yaml
uservoice:

# find the api key in your uservoice admin settings
api_key: Abc1234DefGhIjkl567MnoPQr

# https://developer.uservoice.com/docs/widgets/options/
set:
accent_color: '#448dd6'
trigger_color: white
trigger_background_color: rgba(46, 49, 51, 0.6)
addTrigger:
mode: contact
trigger_position: bottom-left

# Tell uservoice about the current user; only keys listed will be sent,
# when id, email, name or created_at has an empty value, get them from
# the current user.
identify:
id:
#email:
#name:
created_at:
#type: ExampleFoodcoopType
```

This plugin also introduces the foodcoop config option `use_uservoice`, which
can be set to `false` to disable uservoice integration. May be useful in
multicoop deployments.

This plugin is currently missing a configuration screen.

See also the [uservoice-widget documentation](http://rubydoc.info/gems/uservoice-widget).
20 changes: 20 additions & 0 deletions plugins/uservoice/foodsoft_uservoice.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "foodsoft_uservoice/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "foodsoft_uservoice"
s.version = FoodsoftUservoice::VERSION
s.authors = ["wvengen"]
s.email = ["dev-foodsoft@willem.engen.nl"]
s.homepage = "https://github.com/foodcoops/foodsoft"
s.summary = "Uservoice plugin for foodsoft."
s.description = "Adds a uservoice feedback button to foodsoft."

s.files = Dir["{app,config,db,lib}/**/*"] + ["README.md"]

s.add_dependency "rails"
s.add_dependency "content_for_in_controllers"
end
52 changes: 52 additions & 0 deletions plugins/uservoice/lib/foodsoft_uservoice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "content_for_in_controllers"
require "foodsoft_uservoice/engine"

module FoodsoftUservoice
# enabled when configured, but can still be disabled by use_uservoice option
def self.enabled?
FoodsoftConfig[:use_uservoice] != false and FoodsoftConfig[:uservoice]
end

module LoadUservoice
def self.included(base) # :nodoc:
base.class_eval do
before_filter :add_uservoice_script

protected

def add_uservoice_script
return unless FoodsoftUservoice.enabled?

# include uservoice javascript
api_key = FoodsoftConfig[:uservoice]['api_key']
js_pre = "UserVoice=window.UserVoice||[];"
js_load = "var uv=document.createElement('script');uv.type='text/javascript';uv.async=true;uv.src='//widget.uservoice.com/#{view_context.j api_key}.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(uv,s);"

# configuration
sections = FoodsoftConfig[:uservoice].reject {|k,v| k=='api_key'}
sections.each_pair do |k,v|
if k == 'identify'
v['id'] = current_user.try(:id) if v.include?('id')
v['name'] = current_user.try(:display) if v.include?('name')
v['email'] = current_user.try(:email) if v.include?('email')
v['created_at'] = current_user.try {|u| u.created_on.to_i} if v.include?('created_at')
elsif k == 'set'
v['locale'] = I18n.locale
end
js_load += "UserVoice.push(#{[k, v].to_json});"
end

# skip uservoice when serving mobile pages (using jquery mobile, a bit of a hack)
js_load = "$(function() { if(!$('[data-role=page]')[0]){#{js_load}} });"

# include in layout
content_for :javascript, view_context.javascript_tag(js_pre+js_load)
end
end
end
end
end

ActiveSupport.on_load(:after_initialize) do
ApplicationController.send :include, FoodsoftUservoice::LoadUservoice
end
4 changes: 4 additions & 0 deletions plugins/uservoice/lib/foodsoft_uservoice/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module FoodsoftUservoice
class Engine < ::Rails::Engine
end
end
3 changes: 3 additions & 0 deletions plugins/uservoice/lib/foodsoft_uservoice/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module FoodsoftUservoice
VERSION = "0.0.1"
end