Skip to content

Commit

Permalink
Maintenance: Improve Checklist handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas committed Oct 3, 2024
1 parent 29b5f45 commit 12e7524
Show file tree
Hide file tree
Showing 89 changed files with 823 additions and 792 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class ChecklistTemplate extends App.ControllerSubContent

@html elLocal

value = @checklistSetting.prop('checked')
checklistTemplatesTable = elLocal.find('.js-checklistTemplatesTable')
if value is true
checklistTemplatesTable.show()
else
checklistTemplatesTable.hide()

validateOnSubmit: (params) ->
errors = {}
if !params.items || params.items.length is 0
Expand Down
19 changes: 9 additions & 10 deletions app/assets/javascripts/app/controllers/ticket_zoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -974,17 +974,16 @@ class App.TicketZoom extends App.Controller
isPendingClose = ticketState.state_type.name is 'pending action' && App.TicketState.find(ticketState.next_state_id).state_type.name is 'closed'
return @submitTimeAccounting(e, ticket, macro, editContollerForm) if !isClosed && !isPendingClose

App.Checklist.completedForTicketId(ticket.id, (data) =>
return @submitTimeAccounting(e, ticket, macro, editContollerForm) if !data || data.completed is null || data.completed
if !ticket.checklist_incomplete
return @submitTimeAccounting(e, ticket, macro, editContollerForm)

new App.TicketZoomChecklistModal(
container: @el.closest('.content')
ticket: ticket
cancelCallback: =>
@submitEnable(e)
submitCallback: =>
@submitTimeAccounting(e, ticket, macro, editContollerForm)
)
new App.TicketZoomChecklistModal(
container: @el.closest('.content')
ticket: ticket
cancelCallback: =>
@submitEnable(e)
submitCallback: =>
@submitTimeAccounting(e, ticket, macro, editContollerForm)
)

submitTimeAccounting: (e, ticket, macro, editContollerForm) =>
Expand Down
40 changes: 7 additions & 33 deletions app/assets/javascripts/app/controllers/ticket_zoom/meta.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,16 @@ class App.TicketZoomMeta extends App.ControllerObserver
observe:
number: true
created_at: true
updated_at: true
escalation_at: true

constructor: ->
super
App.ChecklistItem.subscribe(@checklistItemsChanged)
@subscribeToChecklistTickets()

checklistItemsChanged: =>
@subscribeToChecklistTickets()
@forceRerender()

checklistTicketChanged: =>
@forceRerender()

forceRerender: =>
@render(App[@model].fullLocal(@object_id))

subscribeToChecklistTickets: =>
if @checklistTicketsSubscriptions
for id, key in @checklistTicketsSubscriptions
App.Ticket.unsubscribeItem(id, key)

@checklistTicketsSubscriptions = undefined

checklist = App.Checklist.findByAttribute('ticket_id', @object_id)

return if !checklist

@checklistTicketsSubscriptions = checklist
.sorted_items()
.filter (elem) -> elem.ticket_id
.map (elem) => [elem.ticket_id, App.Ticket.subscribeItem(elem.ticket_id, @checklistTicketChanged)]
checklist_total: true
checklist_incomplete: true

render: (ticket) =>
checklistState = App.Checklist.calculateState(ticket)
checklistReferences = App.Checklist.calculateReferences(ticket)
if App.Config.get('checklist')
checklistState = App.Checklist.calculateState(ticket)
checklistReferences = App.Checklist.calculateReferences(ticket)


@html App.view('ticket_zoom/meta')(
ticket: ticket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ class SidebarChecklist extends App.Controller
# ticket subscriptions
sid = App.Ticket.subscribeItem(
@ticket.id,
=>
(ticket) =>
@delay =>
@badgeRenderLocal()
return if ticket.updated_by_id is App.Session.get().id

@shown() if !@widget?.actionController
)
Expand All @@ -76,6 +77,10 @@ class SidebarChecklist extends App.Controller
sid: sid,
)

# Exit early and subscribe only to the ticket when sidebar is not opened
return if !(@widget instanceof App.SidebarChecklistShow)
# Keep going and subscribe to checklist items and tickets in there when sidebar is opened

# checklist subscriptions
checklist = App.Checklist.findByAttribute('ticket_id', @ticket.id)
return if !checklist
Expand Down Expand Up @@ -126,9 +131,9 @@ class SidebarChecklist extends App.Controller
@startLoading()

@ajax(
id: 'checklist_ticket'
id: "checklist_ticket#{@ticket.id}"
type: 'GET'
url: "#{@apiPath}/tickets/#{@ticket.id}/checklist"
url: "#{@apiPath}/checklists/by_ticket/#{@ticket.id}"
processData: true
success: (data, status, xhr) =>
@clearWidget()
Expand All @@ -140,11 +145,11 @@ class SidebarChecklist extends App.Controller
@checklist = App.Checklist.find(data.id)

@widget = new App.SidebarChecklistShow(el: @elSidebar, parentVC: @, checklist: @checklist, readOnly: !@changeable, enterEditMode: enterEditMode)

@subscribe()
else
@widget = new App.SidebarChecklistStart(el: @elSidebar, parentVC: @, readOnly: !@changeable)

@subscribe()

@renderActions()
@badgeRenderLocal()
)
Expand All @@ -161,7 +166,7 @@ class SidebarChecklist extends App.Controller
name: 'checklist'
icon: 'checklist'
counterPossible: true
counter: App.Checklist.findByAttribute('ticket_id', @ticket.id)?.open_items().length
counter: @ticket.checklist_incomplete
}

badgeRender: (el) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class App.SidebarChecklistShow extends App.Controller
item.checklist_id = @checklist.id
item.text = ''


item.save(
done: ->
App.ChecklistItem.full(@id, callbackDone, force: true)
Expand Down Expand Up @@ -235,8 +236,6 @@ class App.SidebarChecklistShow extends App.Controller
sorted_items = @checklist.sorted_items()

for object in sorted_items
ticket = undefined
ticketAccess = undefined
if object.ticket_id
ticket = App.Ticket.find(object.ticket_id)
ticketAccess = if ticket then ticket.userGroupAccess('read') else false
Expand Down Expand Up @@ -272,6 +271,7 @@ class App.SidebarChecklistShow extends App.Controller
if @enterEditModeId
cell = @table.find("tbody tr[data-id='" + @enterEditModeId + "']").find('.checklistItemValue')[0]
row = $(cell).closest('tr')
return if !row.length
@enterEditModeId = undefined
@activateItemEditMode(cell, row, row.data('id'))

Expand All @@ -283,6 +283,7 @@ class ChecklistItemEdit extends App.Controller
events:
'click .js-cancel': 'onCancel'
'click .js-confirm': 'onConfirm'
'blur .js-input': 'onConfirm'
'keyup #checklistItemEditText': 'onKeyUp'

constructor: ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class App.SidebarChecklistStart extends App.Controller
@ajax(
id: 'checklist_ticket_add_empty'
type: 'POST'
url: "#{@apiPath}/tickets/#{@parentVC.ticket.id}/checklist"
url: "#{@apiPath}/checklists"
data: JSON.stringify({ ticket_id: @parentVC.ticket.id })
processData: true
success: (data, status, xhr) =>
@parentVC.shown(true)
Expand All @@ -52,7 +53,7 @@ class App.SidebarChecklistStart extends App.Controller
@ajax(
id: 'checklist_ticket_add_from_template'
type: 'POST'
url: "#{@apiPath}/tickets/#{@parentVC.ticket.id}/checklist"
url: "#{@apiPath}/checklists"
data: JSON.stringify({ ticket_id: @parentVC.ticket.id, template_id: params.checklist_template_id })
success: (data, status, xhr) =>
@parentVC.shown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class TicketReferences extends App.PopoverProvider
@includeData = false

buildTitleFor: (elem) ->
App.i18n.translateInline('Tracked by checklist item by')
App.i18n.translateInline('Tracked as checklist item in')

buildContentFor: (elem) ->
@buildHtmlContent(
Expand Down
21 changes: 6 additions & 15 deletions app/assets/javascripts/app/models/checklist.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,17 @@ class App.Checklist extends App.Model
)

@calculateState: (ticket) ->
checklist = App.Checklist.findByAttribute('ticket_id', ticket.id)

return if !checklist

all = checklist.sorted_items().length
open = checklist.open_items().length

return undefined if !open
return if !ticket.checklist_incomplete

{
all: all,
open: open
all: ticket.checklist_total
open: ticket.checklist_incomplete

}

@calculateReferences: (ticket) ->
items = App.ChecklistItem
.findAllByAttribute('ticket_id', ticket.id)
checklists = App.Checklist
.findAll(ticket.referencing_checklist_ids)
.filter (elem) -> !elem.ticket_inaccessible

checklist_ids = _.unique items.map (elem) -> elem.checklist_id
checklists = App.Checklist.findAll checklist_ids

App.Ticket.findAll checklists.map (elem) -> elem.ticket_id
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class App.ChecklistTemplateItem extends App.Model
@configure 'ChecklistTemplateItem', 'text', 'checklist_template_id', 'updated_at'
@extend Spine.Model.Ajax
@url: @apiPath + '/checklist_template_items'

@configure_attributes = [
{ name: 'text', display: __('Name'), tag: 'input', type: 'text', limit: 100, null: false, parentClass: 'checklistItemNameCell' },
Expand Down
15 changes: 4 additions & 11 deletions app/assets/javascripts/app/views/checklist_template/index.jst.eco
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<div class="page-header">
<div class="page-header-title">
<div class="zammad-switch zammad-switch--small js-checklistSetting">
<input name="enableChecklists" type="checkbox" id="enableChecklists" <% if @C('checklist'): %>checked<% end %>>
<label for="enableChecklists"></label>
</div>
<h1><%- @T('Checklists') %><small></small></h1>
</div>
</div>

<div class="page-content">
<p><%- @T('With checklists you can keep track of the progress of your ticket related tasks.') %></p>

<div class="settings-entry">
<div class="page-header-title">
<div class="zammad-switch zammad-switch--small js-checklistSetting">
<input name="enableChecklists" type="checkbox" id="enableChecklists" <% if @C('checklist'): %>checked<% end %>>
<label for="enableChecklists"></label>
</div>
<h2><%- @T('Enable Checklists') %></h2>
</div>
<p><%- @T('Allow users to add new checklists.') %></p>
</div>

<div class="settings-entry settings-entry--stretched vertical js-checklistTemplatesTable">
</div>
</div>
22 changes: 14 additions & 8 deletions app/controllers/checklist_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
class ChecklistItemsController < ApplicationController
prepend_before_action :authenticate_and_authorize!

def index
model_index_render(Checklist::Item.for_user(current_user), params)
end

def show
model_show_render(Checklist::Item.for_user(current_user), params)
model_show_render(Checklist::Item, existing_item_params)
end

def create
model_create_render(Checklist::Item.for_user(current_user), params)
model_create_render(Checklist::Item, new_item_params)
end

def update
model_update_render(Checklist::Item.for_user(current_user), params)
model_update_render(Checklist::Item, existing_item_params)
end

def destroy
model_destroy_render(Checklist::Item.for_user(current_user), params)
model_destroy_render(Checklist::Item, existing_item_params)
end

private

def new_item_params
params.permit(:text, :checklist_id)
end

def existing_item_params
params.permit(:text, :id, :checked)
end
end
25 changes: 0 additions & 25 deletions app/controllers/checklist_template_items_controller.rb

This file was deleted.

Loading

0 comments on commit 12e7524

Please sign in to comment.