From 50c2a8540e5df4edf33a8521b373c55a98fab7d9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 26 Nov 2018 07:50:41 +0100 Subject: [PATCH] Only do resizing of columns if table is shown. Followup for issue #2031. --- .../_application_controller.coffee | 6 ++ .../_application_controller_generic.coffee | 34 +++++++++-- .../_application_controller_table.coffee | 58 ++++++++++++------- .../javascripts/app/controllers/groups.coffee | 2 +- .../javascripts/app/controllers/job.coffee | 2 +- .../javascripts/app/controllers/macro.coffee | 2 +- .../app/controllers/organizations.coffee | 2 +- .../app/controllers/overview.coffee | 2 +- .../javascripts/app/controllers/report.coffee | 12 ++-- .../app/controllers/report_profile.coffee | 2 +- .../javascripts/app/controllers/role.coffee | 2 +- .../javascripts/app/controllers/search.coffee | 8 ++- .../app/controllers/text_module.coffee | 2 +- .../app/controllers/ticket_overview.coffee | 33 ++++++++--- .../app/controllers/trigger.coffee | 2 +- .../javascripts/app/controllers/users.coffee | 24 ++++++-- .../app/controllers/widget/ticket_list.coffee | 23 +++++--- .../app/views/generic/table.jst.eco | 2 +- 18 files changed, 149 insertions(+), 69 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index f51d9094b..00bea44bd 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -425,9 +425,15 @@ class App.ControllerSubContent extends App.Controller super show: => + if @genericController && @genericController.show + @genericController.show() return if !@header @title @header, true + hide: => + if @genericController && @genericController.hide + @genericController.hide() + class App.ControllerContent extends App.Controller constructor: -> if @requiredPermission diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index 9ece5b90a..fbe1fff1f 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -132,6 +132,14 @@ class App.ControllerGenericIndex extends App.Controller clear: true ) + show: => + if @table + @table.show() + + hide: => + if @table + @table.hide() + release: => if @subscribeId App[ @genericObject ].unsubscribe(@subscribeId) @@ -371,6 +379,18 @@ class App.ControllerTabs extends App.Controller if !@permissionCheckRedirect(@requiredPermission) throw "No permission for #{@requiredPermission}" + show: => + return if !@controllerList + for localeController in @controllerList + if localeController && localeController.show + localeController.show() + + hide: => + return if !@controllerList + for localeController in @controllerList + if localeController && localeController.hide + localeController.hide() + render: -> @html App.view('generic/tabs')( header: @header @@ -386,8 +406,9 @@ class App.ControllerTabs extends App.Controller params = tab.params || {} params.name = tab.name params.target = tab.target - params.el = @$( "##{tab.target}" ) - new tab.controller( params ) + params.el = @$("##{tab.target}") + @controllerList ||= [] + @controllerList.push new tab.controller(params) # check if tabs need to be show / cant' use .tab(), because tabs are note shown (only one tab exists) if @tabs.length <= 1 @@ -422,12 +443,13 @@ class App.ControllerNavSidbar extends App.Controller @updateNavigation(true) ) - show: (params) => + show: (params = {}) => @navupdate '' @shown = true - for key, value of params - if key isnt 'el' && key isnt 'shown' && key isnt 'match' - @[key] = value + if params + for key, value of params + if key isnt 'el' && key isnt 'shown' && key isnt 'match' + @[key] = value @updateNavigation() if @activeController && _.isFunction(@activeController.show) @activeController.show(params) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index 76d1c6f7f..1d9e8a95e 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -171,8 +171,15 @@ class App.ControllerTable extends App.Controller @renderQueue() + show: => + return if @windowIsResized isnt true + @windowIsResized = false + @onResize() + + hide: -> + release: => - $(window).off 'resize.table', @onResize + $(window).off('resize.table', @onResize) update: (params) => if params.sync is true @@ -214,12 +221,12 @@ class App.ControllerTable extends App.Controller if _.isEmpty(@objects) @renderState = 'emptyList' @el.html(@renderEmptyList()) - $(window).on 'resize.table', @onResize + $(window).on('resize.table', @onResize) return ['emptyList.new'] else @renderState = 'List' @renderTableFull() - $(window).on 'resize.table', @onResize + $(window).on('resize.table', @onResize) return ['fullRender.new'] else if @renderState is 'emptyList' && !_.isEmpty(@objects) @renderState = 'List' @@ -342,7 +349,7 @@ class App.ControllerTable extends App.Controller do (container, event, callback) -> if cursorMap[event] container.find("tbody > tr > td:nth-child(#{position})").css('cursor', cursorMap[event]) - container.on( event, "tbody > tr > td:nth-child(#{position})", + container.on(event, "tbody > tr > td:nth-child(#{position})", (e) -> e.stopPropagation() id = $(e.target).parents('tr').data('id') @@ -356,7 +363,7 @@ class App.ControllerTable extends App.Controller do (container, event, callback) -> if cursorMap[event] container.find('tbody > tr').css( 'cursor', cursorMap[event] ) - container.on( event, 'tbody > tr', + container.on(event, 'tbody > tr', (e) -> id = $(e.target).parents('tr').data('id') callback(id, e) @@ -378,8 +385,8 @@ class App.ControllerTable extends App.Controller if @tableId # enable resize column - container.on 'mousedown', '.js-col-resize', @onColResizeMousedown - container.on 'click', '.js-col-resize', @stopPropagation + container.on('mousedown', '.js-col-resize', @onColResizeMousedown) + container.on('click', '.js-col-resize', @stopPropagation) # enable checkbox bulk selection if @checkbox @@ -626,20 +633,19 @@ class App.ControllerTable extends App.Controller if @actions.length @headers.push - name: 'action' - display: 'Action' - width: '38px' - displayWidth: 38 - unresizeable: true - align: 'right' - parentClass: 'noTruncate no-padding' + name: 'action' + display: 'Action' + width: '50px' + displayWidth: 50 + align: 'right' + parentClass: 'noTruncate no-padding' + unresizable: true @bindCol['action'] = events: click: @toggleActionDropdown - if @tableId - @calculateHeaderWidths() + @calculateHeaderWidths() @columnsLength = @headers.length if @checkbox || @radio @@ -818,6 +824,7 @@ class App.ControllerTable extends App.Controller @runAction(name, id) calculateHeaderWidths: -> + return if !@tableId return if !@headers availableWidth = @availableWidth @@ -838,7 +845,7 @@ class App.ControllerTable extends App.Controller if roundingLeftOver > 0 && roundingLeftOver < 10 @headers[@headers.length - 1].displayWidth = @headers[@headers.length - 1].displayWidth + roundingLeftOver - @storeHeaderWidths() + true getShrinkableHeadersCount: -> _.reduce @headers, (memo, col) -> @@ -868,11 +875,13 @@ class App.ControllerTable extends App.Controller widths setHeaderWidths: => - @calculateHeaderWidths() + return if !@calculateHeaderWidths() @$('.js-tableHead').each (i, el) => el.style.width = @headers[i].displayWidth + 'px' + @storeHeaderWidths() + storeHeaderWidths: -> widths = {} @@ -882,7 +891,12 @@ class App.ControllerTable extends App.Controller App.LocalStorage.set(@preferencesStoreKey(), { headerWidth: widths }, @Session.get('id')) onResize: => - @availableWidth = @el.width() + localWidth = @el.width() + if localWidth is 0 + @windowIsResized = true + return + + @availableWidth = localWidth localDelay = => localSetHeaderWidths = => @setHeaderWidths() @@ -901,8 +915,8 @@ class App.ControllerTable extends App.Controller @resizeLeftStartWidth = @resizeTargetLeft.width() @resizeRightStartWidth = @resizeTargetRight.width() - $(document).on 'mousemove.resizeCol', @onColResizeMousemove - $(document).one 'mouseup', @onColResizeMouseup + $(document).on('mousemove.resizeCol', @onColResizeMousemove) + $(document).one('mouseup', @onColResizeMouseup) @tableWidth = @el.width() @@ -920,7 +934,7 @@ class App.ControllerTable extends App.Controller @resizeTargetRight.width @resizeRightStartWidth - difference onColResizeMouseup: => - $(document).off 'mousemove.resizeCol' + $(document).off('mousemove.resizeCol') # switch to percentage resizeBaseWidth = @resizeTargetLeft.parents('table').width() diff --git a/app/assets/javascripts/app/controllers/groups.coffee b/app/assets/javascripts/app/controllers/groups.coffee index c84d07c21..2feff9b40 100644 --- a/app/assets/javascripts/app/controllers/groups.coffee +++ b/app/assets/javascripts/app/controllers/groups.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Group' diff --git a/app/assets/javascripts/app/controllers/job.coffee b/app/assets/javascripts/app/controllers/job.coffee index 22d3526e1..c4408600f 100644 --- a/app/assets/javascripts/app/controllers/job.coffee +++ b/app/assets/javascripts/app/controllers/job.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Job' diff --git a/app/assets/javascripts/app/controllers/macro.coffee b/app/assets/javascripts/app/controllers/macro.coffee index c64c99d04..8c326973a 100644 --- a/app/assets/javascripts/app/controllers/macro.coffee +++ b/app/assets/javascripts/app/controllers/macro.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Macro' diff --git a/app/assets/javascripts/app/controllers/organizations.coffee b/app/assets/javascripts/app/controllers/organizations.coffee index 3135c83fc..07efb1a1d 100644 --- a/app/assets/javascripts/app/controllers/organizations.coffee +++ b/app/assets/javascripts/app/controllers/organizations.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Organization' diff --git a/app/assets/javascripts/app/controllers/overview.coffee b/app/assets/javascripts/app/controllers/overview.coffee index 01cd6f043..b52a04455 100644 --- a/app/assets/javascripts/app/controllers/overview.coffee +++ b/app/assets/javascripts/app/controllers/overview.coffee @@ -9,7 +9,7 @@ class Index extends App.ControllerSubContent if attribute.name is 'group_by' attribute.options = App.Overview.groupByAttributes() - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Overview' diff --git a/app/assets/javascripts/app/controllers/report.coffee b/app/assets/javascripts/app/controllers/report.coffee index 6476e3828..129a513ce 100644 --- a/app/assets/javascripts/app/controllers/report.coffee +++ b/app/assets/javascripts/app/controllers/report.coffee @@ -307,12 +307,12 @@ class Download extends App.Controller value callbackIconHeader = (headers) -> attribute = - name: 'icon' - display: '' - translation: false - width: '28px' - displayWidth:28 - unresizable: true + name: 'icon' + display: '' + translation: false + width: '28px' + displayWidth: 28 + unresizable: true headers.unshift(0) headers[0] = attribute headers diff --git a/app/assets/javascripts/app/controllers/report_profile.coffee b/app/assets/javascripts/app/controllers/report_profile.coffee index 060e85806..71f1f6892 100644 --- a/app/assets/javascripts/app/controllers/report_profile.coffee +++ b/app/assets/javascripts/app/controllers/report_profile.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'ReportProfile' diff --git a/app/assets/javascripts/app/controllers/role.coffee b/app/assets/javascripts/app/controllers/role.coffee index b4b4d7034..a274843ce 100644 --- a/app/assets/javascripts/app/controllers/role.coffee +++ b/app/assets/javascripts/app/controllers/role.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Role' diff --git a/app/assets/javascripts/app/controllers/search.coffee b/app/assets/javascripts/app/controllers/search.coffee index acd4b492f..5f718dc19 100644 --- a/app/assets/javascripts/app/controllers/search.coffee +++ b/app/assets/javascripts/app/controllers/search.coffee @@ -55,6 +55,8 @@ class App.Search extends App.Controller '#search' show: (params) => + if @table + @table.show() @navupdate(url: '#search', type: 'menu') return if _.isEmpty(params.query) @$('.js-search').val(params.query).trigger('change') @@ -63,6 +65,8 @@ class App.Search extends App.Controller hide: -> @shown = false + if @table + @table.hide() changed: -> # nothing @@ -158,7 +162,7 @@ class App.Search extends App.Controller ticket_ids = [] for item in localList ticket_ids.push item.id - new App.TicketList( + @table = new App.TicketList( tableId: "find_#{model}" el: @$('.js-content') columns: [ 'number', 'title', 'customer', 'group', 'owner', 'created_at' ] @@ -169,7 +173,7 @@ class App.Search extends App.Controller openObject = (id,e) => object = App[@model].fullLocal(id) @navigate object.uiUrl() - new App.ControllerTable( + @table = new App.ControllerTable( tableId: "find_#{model}" el: @$('.js-content') model: App[model] diff --git a/app/assets/javascripts/app/controllers/text_module.coffee b/app/assets/javascripts/app/controllers/text_module.coffee index 4ff914eb6..f6c989134 100644 --- a/app/assets/javascripts/app/controllers/text_module.coffee +++ b/app/assets/javascripts/app/controllers/text_module.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'TextModule' diff --git a/app/assets/javascripts/app/controllers/ticket_overview.coffee b/app/assets/javascripts/app/controllers/ticket_overview.coffee index 8da834f17..aafffcd23 100644 --- a/app/assets/javascripts/app/controllers/ticket_overview.coffee +++ b/app/assets/javascripts/app/controllers/ticket_overview.coffee @@ -669,17 +669,22 @@ class App.TicketOverview extends App.Controller # build nav bar if @navBarController - @navBarController.update + @navBarController.update( view: @view activeState: true + ) if @navBarControllerVertical - @navBarControllerVertical.update + @navBarControllerVertical.update( view: @view activeState: true + ) # do not rerender overview if current overview is requested again - return if @viewLast is @view + if @viewLast is @view + if @contentController + @contentController.show() + return # remember last view @viewLast = @view @@ -699,6 +704,8 @@ class App.TicketOverview extends App.Controller @navBarController.active(false) if @navBarControllerVertical @navBarControllerVertical.active(false) + if @contentController + @contentController.hide() setPosition: (position) => @$('.main').scrollTop(position) @@ -945,6 +952,14 @@ class Table extends App.Controller return if !@view @render(App.OverviewListCollection.get(@view)) + show: => + if @table + @table.show() + + hide: => + if @table + @table.hide() + release: => if @bindId App.OverviewListCollection.unbind(@bindId) @@ -1123,12 +1138,12 @@ class Table extends App.Controller @lastChecked = e.currentTarget callbackIconHeader = (headers) -> attribute = - name: 'icon' - display: '' - translation: false - width: '28px' - displayWidth:28 - unresizable: true + name: 'icon' + display: '' + translation: false + width: '28px' + displayWidth: 28 + unresizable: true headers.unshift(0) headers[0] = attribute headers diff --git a/app/assets/javascripts/app/controllers/trigger.coffee b/app/assets/javascripts/app/controllers/trigger.coffee index c726aeced..77678a3e3 100644 --- a/app/assets/javascripts/app/controllers/trigger.coffee +++ b/app/assets/javascripts/app/controllers/trigger.coffee @@ -4,7 +4,7 @@ class Index extends App.ControllerSubContent constructor: -> super - new App.ControllerGenericIndex( + @genericController = new App.ControllerGenericIndex( el: @el id: @id genericObject: 'Trigger' diff --git a/app/assets/javascripts/app/controllers/users.coffee b/app/assets/javascripts/app/controllers/users.coffee index 2b78316fc..418732f7e 100644 --- a/app/assets/javascripts/app/controllers/users.coffee +++ b/app/assets/javascripts/app/controllers/users.coffee @@ -11,6 +11,16 @@ class Index extends App.ControllerSubContent super @render() + show: => + super + return if !@table + @table.show() + + hide: => + super + return if !@table + @table.hide() + render: -> @html App.view('user')( head: 'Users' @@ -47,11 +57,13 @@ class Index extends App.ControllerSubContent callbackHeader = (header) -> attribute = - name: 'switch_to' - display: 'Action' - className: 'actionCell' - translation: true - width: '200px' + name: 'switch_to' + display: 'Action' + className: 'actionCell' + translation: true + width: '200px' + displayWidth: 200 + unresizable: true header.push attribute header @@ -111,7 +123,7 @@ class Index extends App.ControllerSubContent users.push user @$('.table-overview').html('') - new App.ControllerTable( + @table = new App.ControllerTable( tableId: 'users_admin_overview' el: @$('.table-overview') model: App.User diff --git a/app/assets/javascripts/app/controllers/widget/ticket_list.coffee b/app/assets/javascripts/app/controllers/widget/ticket_list.coffee index d4a994059..738127ecf 100644 --- a/app/assets/javascripts/app/controllers/widget/ticket_list.coffee +++ b/app/assets/javascripts/app/controllers/widget/ticket_list.coffee @@ -4,9 +4,16 @@ class App.TicketList extends App.Controller constructor: -> super - @render() + show: => + if @table + @table.show() + + hide: => + if @table + @table.hide() + render: => openTicket = (id,e) => @@ -40,12 +47,12 @@ class App.TicketList extends App.Controller callbackIconHeader = (headers) -> attribute = - name: 'icon' - display: '' - translation: false - width: '28px' - displayWidth:28 - unresizable: true + name: 'icon' + display: '' + translation: false + width: '28px' + displayWidth: 28 + unresizable: true headers.unshift(0) headers[0] = attribute headers @@ -62,7 +69,7 @@ class App.TicketList extends App.Controller ticketItem = App.Ticket.fullLocal(ticket_id) list.push ticketItem @el.html('') - new App.ControllerTable( + @table = new App.ControllerTable( tableId: @tableId el: @el overview: @columns || [ 'number', 'title', 'customer', 'group', 'created_at' ] diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index ea1ce0b1b..58efea9f7 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -24,7 +24,7 @@
<%- @T(header.display) %>
<% if header.sortOrderIcon: %><%- @Icon(header.sortOrderIcon[0], header.sortOrderIcon[1]) %><% end %>
- <% if @tableId && !header.unresizable && i < @headers.length - 1: %> + <% if @tableId && !header.unresizable && i < @headers.length - 1 && (@headers.length - 1 != i && @headers[ i + 1 ] && !@headers[ i + 1 ].unresizable): %>
<% end %>