Merge pull request #333 from foodcoops/feature/plugin-uservoice

Add uservoice plugin
This commit is contained in:
wvengen 2015-01-02 23:22:12 +01:00
commit 68f56a55e5
6 changed files with 128 additions and 0 deletions

View file

@ -47,6 +47,10 @@ gem 'acts_as_versioned', github: 'technoweenie/acts_as_versioned'
gem 'foodsoft_wiki', path: 'plugins/wiki' gem 'foodsoft_wiki', path: 'plugins/wiki'
gem 'foodsoft_messages', path: 'plugins/messages' gem 'foodsoft_messages', path: 'plugins/messages'
# plugins not enabled by default
#gem 'foodsoft_uservoice', path: 'plugins/uservoice'
group :production do group :production do
gem 'exception_notification' gem 'exception_notification'
end end

View file

@ -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).

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,4 @@
module FoodsoftUservoice
class Engine < ::Rails::Engine
end
end

View file

@ -0,0 +1,3 @@
module FoodsoftUservoice
VERSION = "0.0.1"
end