diff options
Diffstat (limited to 'app/assets/javascripts')
4 files changed, 69 insertions, 4 deletions
diff --git a/app/assets/javascripts/line_comments/application.js.coffee b/app/assets/javascripts/line_comments/application.js.coffee index ae65502800e..cf42dd67002 100644 --- a/app/assets/javascripts/line_comments/application.js.coffee +++ b/app/assets/javascripts/line_comments/application.js.coffee @@ -1,15 +1,27 @@ #= require mithril +#= require_directory ./observers #= require_directory ./components #= require_directory . $ -> + allNoteIds = [] + resolvedNoteIds = [] # Render all the buttons $('.discussion').each -> $this = $(this) $('.js-line-comment', $(this)).each -> + resolved = !!$(this).data('resolved') + allNoteIds.push $(this).data('id') + resolvedNoteIds.push $(this).data('id') if resolved + m.mount $(this).get(0), m(CommentButton, - discussion_id: $this.data('discussion-id') - note_id: $(this).data('id') + discussionId: $this.data('discussion-id') + noteId: $(this).data('id') resolved: !!$(this).data('resolved') ) + + m.mount $('.js-line-comments-all').get(0), m(AllLines, + noteIds: allNoteIds + resolvedNoteIds: resolvedNoteIds + ) diff --git a/app/assets/javascripts/line_comments/components/all_lines.js.coffee b/app/assets/javascripts/line_comments/components/all_lines.js.coffee new file mode 100644 index 00000000000..bcdbae8e02e --- /dev/null +++ b/app/assets/javascripts/line_comments/components/all_lines.js.coffee @@ -0,0 +1,28 @@ +@AllLines = + controller: (args) -> + @noteIds = m.prop(args.noteIds || []) + @resolvedCount = m.prop(args.resolvedNoteIds || []) + @resolvedtext = m.prop => + "#{@resolvedCount().length}/#{@noteIds().length} comments resolved" + @resolveButtontext = m.prop => + 'Resolve all line comments' + + LinesObserver.register (resolved, noteId) => + if resolved + @resolvedCount().push noteId + else + @resolvedCount().splice @resolvedCount().indexOf(noteId), 1 + return + view: (ctrl) -> + m('div', + class: 'line-resolve-all' + ,[ + m('button', + 'aria-label': ctrl.resolveButtontext()() + class: 'btn btn-gray' + type: 'button' + , ctrl.resolveButtontext()()) + m('span', + class: 'line-resolve-text' + , ctrl.resolvedtext()()) + ]) diff --git a/app/assets/javascripts/line_comments/components/comment_button.js.coffee b/app/assets/javascripts/line_comments/components/comment_button.js.coffee index 2f022d062d7..13ef6afef09 100644 --- a/app/assets/javascripts/line_comments/components/comment_button.js.coffee +++ b/app/assets/javascripts/line_comments/components/comment_button.js.coffee @@ -1,6 +1,6 @@ @CommentButton = model: (args) -> - @note = m.prop(args.note_id or false) + @note = m.prop(args.noteId or undefined) @resolved = m.prop(args.resolved or false) return controller: (args) -> @@ -11,16 +11,25 @@ @resolveLine = => @model.resolved(!@model.resolved()) + LinesObserver.trigger(@model.resolved(), @model.note()) return view: (ctrl) -> buttonText = ctrl.resolvedText()() + isActive = if ctrl.model.resolved() then 'is-active' else '' # Return the view elements m('button', 'aria-label': buttonText - class: 'line-resolve-btn' + title: buttonText + type: 'button' + class: "line-resolve-btn #{isActive}" onclick: ctrl.resolveLine + config: (el) -> + $(el) + .tooltip('hide') + .tooltip() + .tooltip('fixTitle') , [ m('i', class: 'fa fa-check' diff --git a/app/assets/javascripts/line_comments/observers/lines.js.coffee b/app/assets/javascripts/line_comments/observers/lines.js.coffee new file mode 100644 index 00000000000..b6556cc6cbb --- /dev/null +++ b/app/assets/javascripts/line_comments/observers/lines.js.coffee @@ -0,0 +1,16 @@ +@LinesObserver = do -> + ctrls = [] + return { + register: (controller) -> + ctrl = new controller + ctrl.onunload = -> + ctrls.splice ctrls.indexOf(ctrl), 1 + ctrls.push + insrance: ctrl + controller: controller + trigger: (resolved, noteId) -> + ctrls.map (c) -> + ctrl = new c.controller(resolved, noteId) + for i in ctrl + c.instance[i] = ctrl[i] + } |