From d43ed42e6cc311e92c8d041625714b83ab0f0771 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Mon, 30 May 2022 16:24:25 +0300 Subject: [PATCH] [SSE] Make resize of results table --- apps/common/main/lib/view/SearchPanel.js | 142 +++++++++++++++++- .../main/app/controller/Search.js | 14 +- .../main/resources/less/leftmenu.less | 88 +++++++++-- 3 files changed, 217 insertions(+), 27 deletions(-) diff --git a/apps/common/main/lib/view/SearchPanel.js b/apps/common/main/lib/view/SearchPanel.js index 1f1d52163..7051e5e8f 100644 --- a/apps/common/main/lib/view/SearchPanel.js +++ b/apps/common/main/lib/view/SearchPanel.js @@ -52,6 +52,12 @@ define([ Common.UI.BaseView.prototype.initialize.call(this, arguments); this.mode = false; + this.resizeResults = { + events: { + mousemove: _.bind(this.resultsResizeMove, this), + mouseup: _.bind(this.resultsResizeStop, this) + } + }; window.SSE && (this.extendedOptions = Common.localStorage.getBool('sse-search-options-extended', true)); }, @@ -252,13 +258,19 @@ define([ this.cmbSearch.setValue(0); this.cmbLookIn.setValue(0); - var tableTemplate = '
' + - '
' + this.textSheet + '
' + - '
' + this.textName + '
' + - '
' + this.textCell + '
' + - '
' + this.textValue + '
' + - '
' + this.textFormula + '
' + - '
' + + var tableTemplate = '
' + + '
' + this.textSheet + '
' + + '
' + + '
' + this.textName + '
' + + '
' + + '
' + this.textCell + '
' + + '
' + + '
' + this.textValue + '
' + + '
' + + '
' + this.textFormula + '
' + + '
' + + '
' + + '
' + '
', $resultTable = $(tableTemplate).appendTo(this.$resultsContainer); this.$resultsContainer.scroller = new Common.UI.Scroller({ @@ -268,6 +280,21 @@ define([ minScrollbarLength: 40, alwaysVisibleY: true }); + this.$resultsContainer.scrollerX = new Common.UI.Scroller({ + el: this.$resultsContainer, + includePadding: true, + useKeyboard: true, + minScrollbarLength: 40, + alwaysVisibleX: true + }); + var resizers = $resultTable.find('.header-resizer'); + _.each(resizers, _.bind(function (item) { + var $el = $(item), + data = $el.data('resizer'), + $col = $resultTable.find('[data-col=' + data + ']'); + $el.on('mousedown', {col: $col, resizer: $el, data: data}, _.bind(this.resultsResizeStart, this)); + }, this)); + Common.NotificationCenter.on('layout:resizestop', _.bind(this.onLayoutResize, this)); } else { this.$resultsContainer.scroller = new Common.UI.Scroller({ el: this.$resultsContainer, @@ -279,7 +306,9 @@ define([ } Common.NotificationCenter.on('window:resize', function() { me.$resultsContainer.outerHeight($('#search-box').outerHeight() - $('#search-header').outerHeight() - $('#search-adv-settings').outerHeight()); + me.$resultsContainer.scroller.update({alwaysVisibleY: true}); + window.SSE && me.$resultsContainer.scrollerX.update({alwaysVisibleX: true}); }); } @@ -381,6 +410,105 @@ define([ this.btnReplaceAll.setDisabled(disable); }, + resultsResizeStart: function (e) { + $(document).on('mousemove', this.resizeResults.events.mousemove) + .on('mouseup', this.resizeResults.events.mouseup); + + e.data.resizer.addClass('move'); + + this.resizeResults.$resizer = e.data.resizer; + this.resizeResults.$col = e.data.col; + this.resizeResults.data = e.data.data; + + this.resizeResults.currentIndex = parseInt(this.resizeResults.$resizer.data('index')); + this.resizeResults.containerLeft = $('#search-results').offset().left; + this.resizeResults.min = this.resizeResults.currentIndex === 0 ? 0 : + this.$resultsContainer.find('.header-resizer[data-index=' + (this.resizeResults.currentIndex - 1) + ']').offset().left - this.resizeResults.containerLeft; // left border + this.resizeResults.max = Common.Utils.innerWidth(); // document width + this.resizeResults.initX = e.pageX*Common.Utils.zoom() - this.resizeResults.containerLeft; // start position + + console.log('current index ', this.resizeResults.currentIndex); + console.log('initX ', this.resizeResults.initX); + console.log('max/doc width ', this.resizeResults.max); + console.log('min 0/header resizer left - container left border ', this.resizeResults.min); + }, + + resultsResizeMove: function (e) { + var zoom = (e instanceof jQuery.Event) ? Common.Utils.zoom() : 1, + value = e.pageX*zoom - this.resizeResults.containerLeft; + this.resizeResults.currentX = Math.min(Math.max(this.resizeResults.min, value), this.resizeResults.max); + this.resizeResults.$resizer.css('left', this.resizeResults.currentX + this.$resultsContainer.scrollLeft() + 'px'); + + console.log('current x ', this.resizeResults.currentX); + console.log('resizer position (+scroll) ', this.resizeResults.currentX + this.$resultsContainer.scrollLeft()); + }, + + resultsResizeStop: function (e) { + this.resizeResults.$resizer.removeClass('move'); + $(document).off('mousemove', this.resizeResults.events.mousemove) + .off('mouseup', this.resizeResults.events.mouseup); + + var delta = this.resizeResults.currentX - this.resizeResults.initX, + cols = this.$resultsContainer.find('.header-item'), + col = $(cols[this.resizeResults.currentIndex]), + newWidth = (col.hasClass('zero-width') ? 0 : col.outerWidth()) + delta, + resizers = this.$resultsContainer.find('.header-resizer'); + col.width(newWidth < 0.1 ? 0 : newWidth - 4 - 1 + 2); // change width in header, 4 - padding, 1 - border, 2 - half of width of resizer + col[newWidth < 0.1 ? 'addClass' : 'removeClass']('zero-width'); + console.log('cols ', cols); + console.log('new col width', newWidth); + console.log('new col width without padding', newWidth - 4 - 1 + 2); + + var resTable = this.$resultsContainer.find('.search-table'); + resTable.css('min-width', (resTable.outerWidth() + delta) + 'px'); + console.log('new table width ', resTable.outerWidth() + delta); + //resTable.css('min-width', '100%'); + + var resCols = resTable.find('.item [data-index=' + this.resizeResults.currentIndex + ']'), // change col width in table + resColWidth = newWidth < 0.1 ? 0 : newWidth - 4 + 2; // 4 - padding, 2 - half of width of resizer + _.each(resCols, function (item) { + $(item).width(resColWidth); + $(item)[resColWidth < 0.1 ? 'addClass' : 'removeClass']('zero-width'); + }); + console.log('current resCols', resCols); + console.log('new width current resCols', resColWidth); + + // change left positions of resizers on right side + for(var i = this.resizeResults.currentIndex + 1; i < 5; i++) { + var el = $(cols[i]), + elLeft = el.offset().left - this.resizeResults.containerLeft + this.$resultsContainer.scrollLeft() + delta + 2; + el.css('left', elLeft + 'px'); + console.log('el ', el); + console.log('el left ', elLeft); + var resizer = resizers[i]; + console.log(resizer); + if (resizer) { + var resizerLeft = $(resizer).offset().left - this.resizeResults.containerLeft + this.$resultsContainer.scrollLeft() + delta + 2; + $(resizer).css('left', resizerLeft + 'px'); + console.log('resizer left ', resizerLeft); + } + } + + this.updateFormulaColWidth(); + this.$resultsContainer.scrollerX.update({alwaysVisibleX: true}); + }, + + onLayoutResize: function () { + this.$resultsContainer.find('.search-table').width(this.$resultsContainer.outerWidth() + this.$resultsContainer.scrollLeft() + 'px'); + + this.updateFormulaColWidth(); + this.$resultsContainer.scrollerX.update({alwaysVisibleX: true}); + }, + + updateFormulaColWidth: function () { + var formulaCol = this.$resultsContainer.find('[data-col="formula"]'), + formulaLeftBorder = window.getComputedStyle(formulaCol[0],null).getPropertyValue("left"), + newWidth = this.$resultsContainer.find('.search-table').outerWidth() - parseInt(formulaLeftBorder) - 4; + formulaCol.width(newWidth + 'px'); + + console.log('update formula width ', newWidth); + }, + textFind: 'Find', textFindAndReplace: 'Find and replace', textCloseSearch: 'Close search', diff --git a/apps/spreadsheeteditor/main/app/controller/Search.js b/apps/spreadsheeteditor/main/app/controller/Search.js index 09f2fbac8..d94158c2c 100644 --- a/apps/spreadsheeteditor/main/app/controller/Search.js +++ b/apps/spreadsheeteditor/main/app/controller/Search.js @@ -425,12 +425,12 @@ define([ me.resultItems = []; data.forEach(function (item, ind) { var isSelected = ind === me._state.currentResult; - var tr = '
' + - '
' + (item[1] ? item[1] : '') + '
' + - '
' + (item[2] ? item[2] : '') + '
' + - '
' + (item[3] ? item[3] : '') + '
' + - '
' + (item[4] ? item[4] : '') + '
' + - '
' + (item[5] ? item[5] : '') + '
' + + var tr = '
' + + '
' + (item[1] ? item[1] : '') + '
' + + '
' + (item[2] ? item[2] : '') + '
' + + '
' + (item[3] ? item[3] : '') + '
' + + '
' + (item[4] ? item[4] : '') + '
' + + '
' + (item[5] ? item[5] : '') + '
' + '
'; var $item = $(tr).appendTo($innerResults); if (isSelected) { @@ -449,7 +449,7 @@ define([ }, addTooltips: function (item, data) { - var cells = [item.find('.sheet'), item.find('.name'), item.find('.cell'), item.find('.value'), item.find('.formula')], + var cells = [item.find('[data-col="sheet"]'), item.find('[data-col="name"]'), item.find('[data-col="cell"]'), item.find('[data-col="value"]'), item.find('[data-col="formula"]')], tips = [data[1], data[2], data[3], data[4], data[5]]; cells.forEach(function (el, ind) { var tip = tips[ind]; diff --git a/apps/spreadsheeteditor/main/resources/less/leftmenu.less b/apps/spreadsheeteditor/main/resources/less/leftmenu.less index fc7d33bf1..43ca82513 100644 --- a/apps/spreadsheeteditor/main/resources/less/leftmenu.less +++ b/apps/spreadsheeteditor/main/resources/less/leftmenu.less @@ -754,39 +754,98 @@ } #search-results { padding: 0; - .search-table { - padding-top: 5px; - width:100%; + width: 100%; + .search-header { + position: absolute; + top: 0; + left: 0; height: 100%; - position: relative; + min-width: 100%; + } + .search-table { + height: calc(100% - 28px); + min-width: 100%; + position: absolute; + top: 28px; } .header-item { - width:16%; - display: inline-block; + position: absolute; + top: 4px; + width: 42px; height: 18px; + display: inline-block; + line-height: 18px; text-align: start; font-weight: normal; padding-left: 4px; - padding-top: 2px; + overflow: hidden; + text-overflow: ellipsis; + &[data-col="sheet"] { + left: 0; + } + &[data-col="name"] { + left: 42px; + } + &[data-col="cell"] { + left: 84px; + } + &[data-col="value"] { + left: 126px; + } + &[data-col="formula"] { + left: 168px; + } &:not(:first-child) { border-left: @scaled-one-px-value-ie solid @border-divider-ie; border-left: @scaled-one-px-value solid @border-divider; } &:last-child { - width:36%; + width: calc(100% - 168px); + } + &.zero-width { + display: none; + } + } + .header-resizer { + position: absolute; + height: 100%; + width: 4px; + cursor: col-resize; + z-index: @zindex-dropdown - 10; + background: transparent; + border: 0 none; + opacity: 0; + &[data-resizer="name"] { + left: calc(42px - 2px); + } + &[data-resizer="cell"] { + left: calc(84px - 2px); + } + &[data-resizer="value"] { + left: calc(126px - 2px); + } + &[data-resizer="formula"] { + left: calc(168px - 2px); + } + &.move { + opacity: 0.4; + border-left: solid @scaled-one-px-value-ie @border-toolbar-ie; + border-left: solid @scaled-one-px-value @border-toolbar; + border-right: solid @scaled-one-px-value-ie @border-toolbar-ie; + border-right: solid @scaled-one-px-value @border-toolbar; } } .search-items { - height: calc(100% - 24px); - position: absolute; - top: 28px; + height: 100%; + position: relative; width: 100%; overflow: hidden; .item { padding: 0; display: flex; div { - width: 16%; + flex-shrink: 0; + width: 42px; padding-left: 4px; height: 28px; line-height: 28px; @@ -794,7 +853,10 @@ overflow: hidden; text-overflow: ellipsis; &:last-child { - width: 36%; + width: calc(100% - 168px); + } + &.zero-width { + display: none; } } }