From 043dd6c11e2a924f841eda0eccbd989af151762a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Oct 2015 08:55:21 +0200 Subject: [PATCH] Made online notifications "removable" by user (x). --- .../widget/online_notification.coffee | 49 ++++++++++++------- .../online_notification_content.jst.eco | 2 +- .../online_notifications_controller.rb | 35 +++++++++++-- app/controllers/overviews_controller.rb | 2 +- config/routes/online_notification.rb | 1 + 5 files changed, 64 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/app/controllers/widget/online_notification.coffee b/app/assets/javascripts/app/controllers/widget/online_notification.coffee index 2c4373aa8..ac9b00eb1 100644 --- a/app/assets/javascripts/app/controllers/widget/online_notification.coffee +++ b/app/assets/javascripts/app/controllers/widget/online_notification.coffee @@ -88,27 +88,11 @@ class App.OnlineNotificationWidget extends App.Controller 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 - $('.js-markAllAsRead').on('click', (e) => + notificationsContainer.find('.js-markAllAsRead').on('click', (e) => e.preventDefault() @markAllAsRead() + @hidePopover() ) # add clickCatcher @@ -154,6 +138,35 @@ class App.OnlineNotificationWidget extends App.Controller $( 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: => @removeContainer() diff --git a/app/assets/javascripts/app/views/widget/online_notification_content.jst.eco b/app/assets/javascripts/app/views/widget/online_notification_content.jst.eco index 92c046088..915b64f26 100644 --- a/app/assets/javascripts/app/views/widget/online_notification_content.jst.eco +++ b/app/assets/javascripts/app/views/widget/online_notification_content.jst.eco @@ -1,6 +1,6 @@ <% if @items.length: %> <% for item in @items: %> -
+
<%- item.created_by.avatar() %> diff --git a/app/controllers/online_notifications_controller.rb b/app/controllers/online_notifications_controller.rb index 95daa2d0b..ae20a6981 100644 --- a/app/controllers/online_notifications_controller.rb +++ b/app/controllers/online_notifications_controller.rb @@ -80,16 +80,30 @@ curl http://localhost/api/v1/online_notifications -v -u #{login}:#{password} -H =end def update - notification = OnlineNotification.find(params[:id]) - if notification.user_id != current_user.id - response_access_deny - return - end + return if !access? model_update_render(OnlineNotification, params) end =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: 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 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 diff --git a/app/controllers/overviews_controller.rb b/app/controllers/overviews_controller.rb index e430b3351..4ad74fce9 100644 --- a/app/controllers/overviews_controller.rb +++ b/app/controllers/overviews_controller.rb @@ -155,7 +155,7 @@ Response: {} 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 diff --git a/config/routes/online_notification.rb b/config/routes/online_notification.rb index b7606f39d..92e4e9932 100644 --- a/config/routes/online_notification.rb +++ b/config/routes/online_notification.rb @@ -4,6 +4,7 @@ Zammad::Application.routes.draw do # groups 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#destroy', via: :delete match api_path + '/online_notifications/mark_all_as_read', to: 'online_notifications#mark_all_as_read', via: :post end