2014-12-09 13:10:36 +01:00
|
|
|
require 'digest/md5'
|
2014-11-06 14:46:59 +01:00
|
|
|
module ApplicationHelper
|
2014-12-09 13:10:36 +01:00
|
|
|
|
|
|
|
def get_color(user)
|
2014-12-10 05:13:17 +01:00
|
|
|
Digest::MD5.hexdigest(user.nickname)[0..5]
|
2014-12-09 13:10:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_color_style(user)
|
2014-12-10 05:13:17 +01:00
|
|
|
"background-color: \#"+ get_color(user) +";"
|
2014-12-09 13:10:36 +01:00
|
|
|
end
|
|
|
|
|
2015-09-14 17:29:00 +02:00
|
|
|
def euro_from_cents(f)
|
|
|
|
euro(f / 100.0)
|
|
|
|
end
|
|
|
|
|
2014-12-09 14:39:27 +01:00
|
|
|
def euro(f)
|
2015-02-12 15:31:32 +01:00
|
|
|
number_to_currency(f, unit: '€')
|
2014-12-09 14:39:27 +01:00
|
|
|
end
|
|
|
|
|
2015-02-09 11:58:43 +01:00
|
|
|
def f_form_for(record, options = {}, &block)
|
|
|
|
options[:builder] = FormattedFormBuilder
|
|
|
|
form_for(record, options, &block)
|
2014-12-09 14:39:27 +01:00
|
|
|
end
|
2015-04-04 01:44:28 +02:00
|
|
|
|
|
|
|
def slack_notification(user, message)
|
|
|
|
require 'net/http'
|
|
|
|
require 'json'
|
2015-04-04 02:50:26 +02:00
|
|
|
postData = Net::HTTP.post_form(URI.parse('https://slack.com/api/users.list'), {'token'=>Rails.application.secrets.access_token})
|
|
|
|
data = JSON.parse(postData.body)
|
|
|
|
if data["ok"]
|
|
|
|
slackmember = data["members"].select{ |m| m["profile"]["email"] == user.uid + "@zeus.ugent.be" }.first
|
2015-04-04 01:44:28 +02:00
|
|
|
|
2015-04-04 02:50:26 +02:00
|
|
|
if slackmember
|
|
|
|
Webhook.new(channel: "@" + slackmember["name"], username: "Tab").ping(message)
|
|
|
|
end
|
2015-04-04 01:44:28 +02:00
|
|
|
end
|
|
|
|
end
|
2014-11-06 14:46:59 +01:00
|
|
|
end
|