2014-11-06 14:46:59 +01:00
|
|
|
module ApplicationHelper
|
2015-11-30 18:20:54 +01:00
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
|
2015-10-27 22:54:06 +01:00
|
|
|
def bootstrap_class_for flash_type
|
|
|
|
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def flash_messages(opts = {})
|
|
|
|
flash.map do |msg_type, message|
|
|
|
|
content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type.to_sym)}") do
|
|
|
|
content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) +
|
|
|
|
content_tag(:strong, [msg_type.capitalize, "! "].join("")) +
|
|
|
|
message
|
|
|
|
end
|
|
|
|
end.join().html_safe
|
|
|
|
end
|
2014-12-09 13:10:36 +01:00
|
|
|
|
|
|
|
def get_color(user)
|
2015-10-27 22:54:06 +01:00
|
|
|
require 'digest/md5'
|
2015-09-14 17:52:25 +02:00
|
|
|
Digest::MD5.hexdigest(user.name)[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)
|
2015-10-26 18:57:59 +01:00
|
|
|
if f
|
|
|
|
euro(f / 100.0)
|
|
|
|
else
|
|
|
|
"undefined"
|
|
|
|
end
|
2015-09-14 17:29:00 +02:00
|
|
|
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"]
|
2015-09-14 17:52:25 +02:00
|
|
|
slackmember = data["members"].select{ |m| m["profile"]["email"] == user.name + "@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
|