Module: Sinatra::NotificationHandler
- Extended by:
- Hexacta
- Defined in:
- lib/sinatra/handlers/notifications.rb
Constant Summary
Constants included
from Hexacta
Hexacta::GEM_FILE_DIR
Instance Method Summary
collapse
Methods included from Hexacta
copy_dir_structure, setup_dir, symlink, symlink_all
Instance Method Details
#delete_notification ⇒ Object
41
42
43
44
45
|
# File 'lib/sinatra/handlers/notifications.rb', line 41
def delete_notification
delete '/notifications/:id' do |id|
Notification.find(:user_id => authenticated(User).id, :id => id).destroy.to_hash.to_json.to_s
end
end
|
#delete_notifications ⇒ Object
47
48
49
50
51
|
# File 'lib/sinatra/handlers/notifications.rb', line 47
def delete_notifications
delete '/notifications' do
Notification.where(:user_id => authenticated(User).id, :id => params["ids"]).destroy.to_s
end
end
|
#edit_notification ⇒ Object
19
20
21
22
23
24
|
# File 'lib/sinatra/handlers/notifications.rb', line 19
def edit_notification
post '/notifications/:id' do |id|
Notification.where(:user_id => authenticated(User).id, :id => id).update(:read_date => Date.today)
200
end
end
|
#get_notification ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/sinatra/handlers/notifications.rb', line 33
def get_notification
get '/notifications/:id' do |id|
notification = Notification.find(:id => id)
redirect "/notifications" if notification.nil?
slim "#{Hexacta::GEM_FILE_DIR}/notifications/view".to_sym, locals: { :notification => notification }
end
end
|
#get_notifications ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/sinatra/handlers/notifications.rb', line 53
def get_notifications
get '/notifications' do
filters = params.select { |attribute| Notification.columns.include?(attribute.to_sym) }
params["limit"] = "20" if params["limit"].to_i < 20
params["limit"] = "100" if params["limit"].to_i > 100
limit = params["limit"].to_i
offset = params["offset"].to_i
query = Notification.where(:user_id => authenticated(User).id).where(filters.to_filter).order(:read_date,Sequel.desc(:id))
slim "#{Hexacta::GEM_FILE_DIR}/notifications".to_sym, locals: { :notifications => query.limit(limit).offset(offset*limit).all, :total => query.count, :filters => params, :query => query }
end
end
|
#new_notification ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sinatra/handlers/notifications.rb', line 6
def new_notification
post '/notification' do
if params["user_ids"].blank?
notify(authenticated(User),params["title"],params["message"],params["label"])
else
for id in params["user_ids"]
notify_to(User.find(:id => id),authenticated(User),params["title"],params["message"],params["label"])
end
end
redirect back
end
end
|
#read_notifications ⇒ Object
26
27
28
29
30
31
|
# File 'lib/sinatra/handlers/notifications.rb', line 26
def read_notifications
post '/notifications' do
Notification.where(:user_id => authenticated(User).id, :id => params["ids"]).update(:read_date => Date.today)
redirect back
end
end
|