Skip to content
Snippets Groups Projects

Added custom notification setting to dropdown

Merged Phil Hughes requested to merge custom-notification-modal-window into issue_12758

What does this MR do?

Adds an option in the notification dropdown to allow users to customise their notification settings.

What are the relevant issue numbers?

Part of #12758 (closed)

Screenshots (if relevant)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Phil Hughes Added 1 commit:

    Added 1 commit:

    • 2889e29c - Removed method on model, instead get variable straight from model
  • Phil Hughes Unmarked this merge request as a Work In Progress

    Unmarked this merge request as a Work In Progress

  • Reassigned to @jschatz1

  • Reassigned to @fatihacet

  • @fatihacet can you do an initial review.

  • 1 class @NotificationsForm
    2 constructor: ->
    3 @form = $('.custom-notifications-form')
    4
    5 @removeEventListeners()
    6 @initEventListeners()
    7
    8 removeEventListeners: ->
    9 $(document).off 'change', '.js-custom-notification-event'
    10
    11 initEventListeners: ->
    12 $(document).on 'change', '.js-custom-notification-event', @toggleCheckbox
    • I think we shouldn't pass callback function in this way. It's because this will be the $document inside the method you passed. Usually you want this to point your class itself but with this usage it won't. To fix that in line 14, we are using => in method declaration which is also a bad thing because CoffeeScript compiler does some extra stuff to fix that in behind the scene. See the code below. This is what CS compiler adds to code.

      var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
      
      this.NotificationsForm = (function() {
        function NotificationsForm() {
          this.toggleCheckbox = bind(this.toggleCheckbox, this);
        }
      })();

      Instead of this we can use the code below. By doing that we will always be sure this will point the class and save us from some magic.

      initEventListeners: ->
        $(document).on 'change', '.js-custom-notification-event', (e) => @toggleCheckbox e
    • Author Developer

      I don't understand how this helps. Either way we are using a double arrow. Just the way I have done it, it calls the functions rather than calling a function to call another function.

      this could never be document because of the fat arrows.

      & the way I have done it has been done through different places in the code.

      Edited by Phil Hughes
    • Actually in the current version, CoffeeScript fixes it for us behind the scene. If you would write it in vanilla JS you wouldn't do that so basically we are abusing CoffeeScript here. When you put a fat arrow in the method declaration CoffeeScript creates another bound function for it. What if CoffeeScript compiler changes this behaviour in the next version? It would take hours to find what is wrong and fix it.

  • 1 class @NotificationsForm
    2 constructor: ->
    3 @form = $('.custom-notifications-form')
    4
    5 @removeEventListeners()
    6 @initEventListeners()
    7
    8 removeEventListeners: ->
    9 $(document).off 'change', '.js-custom-notification-event'
    10
    11 initEventListeners: ->
    12 $(document).on 'change', '.js-custom-notification-event', @toggleCheckbox
    13
    14 toggleCheckbox: (e) =>
    15 $checkbox = $(e.target)
    16 $parent = $checkbox.closest('.checkbox')
  • 12 $(document).on 'change', '.js-custom-notification-event', @toggleCheckbox
    13
    14 toggleCheckbox: (e) =>
    15 $checkbox = $(e.target)
    16 $parent = $checkbox.closest('.checkbox')
    17
    18 @saveEvent($checkbox, $parent)
    19
    20 saveEvent: ($checkbox, $parent) ->
    21 $.ajax(
    22 url: @form.attr('action')
    23 method: 'patch'
    24 dataType: 'json'
    25 data: @form.serialize()
    26 beforeSend: ->
    27 $parent
    • Can you move these lines to a method and call it in here? It will increase the readability and code will look better. Right now I have to read the lines below to understand what you are trying to do. Instead it would be easy to just read the method name and understand what it is doing. It's my 2 cents.

  • @jschatz1 I added a few comments. I will assign back to @iamphill @DouweM can you review the backend part in meanwhile?

  • Reassigned to @iamphill

  • Phil Hughes Added 1 commit:

    Added 1 commit:

    • 2c5f343f - Moved beforeSend into a method
  • Jacob Schatz Status changed to merged

    Status changed to merged

  • Please register or sign in to reply
    Loading