Made online notifications "removable" by user (x).

This commit is contained in:
Martin Edenhofer 2015-10-19 08:55:21 +02:00
parent d88ac684b1
commit 043dd6c11e
5 changed files with 64 additions and 25 deletions

View file

@ -88,27 +88,11 @@ class App.OnlineNotificationWidget extends App.Controller
notificationsContainer.find('.popover-content').css('height', "#{heightPopoverContentNew}px") notificationsContainer.find('.popover-content').css('height', "#{heightPopoverContentNew}px")
# close notification list on click
$('.js-notificationsContainer').on('click', (e) =>
@hidePopover()
)
# execute controller again of already open (because hash hasn't changed, we need to do it manually)
$('.js-locationVerify').on('click', (e) =>
newLocation = $(e.target).attr 'href'
if !newLocation
newLocation = $(e.target).closest('.js-locationVerify').attr 'href'
return if !newLocation
currentLocation = Spine.Route.getPath()
return if newLocation.replace(/#/, '') isnt currentLocation
@log 'debug', "execute controller again for '#{currentLocation}' because of same hash"
Spine.Route.matchRoutes(currentLocation)
)
# mark all notifications as read # mark all notifications as read
$('.js-markAllAsRead').on('click', (e) => notificationsContainer.find('.js-markAllAsRead').on('click', (e) =>
e.preventDefault() e.preventDefault()
@markAllAsRead() @markAllAsRead()
@hidePopover()
) )
# add clickCatcher # add clickCatcher
@ -154,6 +138,35 @@ class App.OnlineNotificationWidget extends App.Controller
$( App.view('widget/online_notification_content')(items: items) ) $( App.view('widget/online_notification_content')(items: items) )
) )
notificationsContainer = $('.js-notificationsContainer .popover-content')
# execute controller again of already open (because hash hasn't changed, we need to do it manually)
notificationsContainer.find('.js-locationVerify').on('click', (e) =>
newLocation = $(e.target).attr 'href'
if !newLocation
newLocation = $(e.target).closest('.js-locationVerify').attr 'href'
return if !newLocation
currentLocation = Spine.Route.getPath()
return if newLocation.replace(/#/, '') isnt currentLocation
@hidePopover()
@log 'debug', "execute controller again for '#{currentLocation}' because of same hash"
Spine.Route.matchRoutes(currentLocation)
)
# close notification list on click
notificationsContainer.find('.activity-entry').on('click', (e) =>
@hidePopover()
)
# remove
notificationsContainer.find('.js-remove').on('click', (e) =>
e.preventDefault()
e.stopPropagation()
row = $(e.target).closest('.activity-entry')
id = row.data('id')
App.OnlineNotification.destroy(id)
)
createContainer: => createContainer: =>
@removeContainer() @removeContainer()

View file

@ -1,6 +1,6 @@
<% if @items.length: %> <% if @items.length: %>
<% for item in @items: %> <% for item in @items: %>
<div class="activity-entry activity-entry--removeable<% if item.seen: %> is-inactive<% end %>"> <div class="activity-entry activity-entry--removeable<% if item.seen: %> is-inactive<% end %>" data-id="<%- item.id %>">
<a class="activity-avatar user-popover" data-id="<%= item.created_by_id %>" href="<%- item.created_by.uiUrl() %>"> <a class="activity-avatar user-popover" data-id="<%= item.created_by_id %>" href="<%- item.created_by.uiUrl() %>">
<%- item.created_by.avatar() %> <%- item.created_by.avatar() %>
</a> </a>

View file

@ -80,16 +80,30 @@ curl http://localhost/api/v1/online_notifications -v -u #{login}:#{password} -H
=end =end
def update def update
notification = OnlineNotification.find(params[:id]) return if !access?
if notification.user_id != current_user.id
response_access_deny
return
end
model_update_render(OnlineNotification, params) model_update_render(OnlineNotification, params)
end end
=begin =begin
Resource:
DELETE /api/v1/online_notifications/{id}.json
Response:
{}
Test:
curl http://localhost/api/v1/online_notifications/{id}.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
=end
def destroy
return if !access?
model_destory_render(OnlineNotification, params)
end
=begin
Resource: Resource:
PUT /api/v1/online_notifications/mark_all_as_read PUT /api/v1/online_notifications/mark_all_as_read
@ -114,4 +128,15 @@ curl http://localhost/api/v1/online_notifications/mark_all_as_read -v -u #{login
render json: {}, status: :ok render json: {}, status: :ok
end end
private
def access?
notification = OnlineNotification.find(params[:id])
if notification.user_id != current_user.id
response_access_deny
return false
end
true
end
end end

View file

@ -155,7 +155,7 @@ Response:
{} {}
Test: Test:
curl http://localhost/api/v1/overviews.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE curl http://localhost/api/v1/overviews/#{id}.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
=end =end

View file

@ -4,6 +4,7 @@ Zammad::Application.routes.draw do
# groups # groups
match api_path + '/online_notifications', to: 'online_notifications#index', via: :get match api_path + '/online_notifications', to: 'online_notifications#index', via: :get
match api_path + '/online_notifications/:id', to: 'online_notifications#update', via: :put match api_path + '/online_notifications/:id', to: 'online_notifications#update', via: :put
match api_path + '/online_notifications/:id', to: 'online_notifications#destroy', via: :delete
match api_path + '/online_notifications/mark_all_as_read', to: 'online_notifications#mark_all_as_read', via: :post match api_path + '/online_notifications/mark_all_as_read', to: 'online_notifications#mark_all_as_read', via: :post
end end