From d8e7c2700a110bde087ae5bee817fe6fc997acfb Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 29 May 2023 12:42:27 +0200 Subject: [PATCH] refs #5066 fix autocomplete --- e2e/paths/08-route/02_basic_data.spec.js | 2 +- front/core/components/autocomplete/index.js | 14 +++++++++++++- .../back/methods/vehicle/getVehiclesSorted.js | 10 ++++++---- modules/route/front/basic-data/index.html | 8 +++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/e2e/paths/08-route/02_basic_data.spec.js b/e2e/paths/08-route/02_basic_data.spec.js index 6008b0482..7ab7dda42 100644 --- a/e2e/paths/08-route/02_basic_data.spec.js +++ b/e2e/paths/08-route/02_basic_data.spec.js @@ -24,7 +24,7 @@ describe('Route basic Data path', () => { const form = 'vn-route-basic-data form'; const values = { worker: 'adminBossNick', - vehicle: '1111-IMK - Warehouse One', + vehicle: '1111-IMK', created: nextMonth, kmStart: 1, kmEnd: 2, diff --git a/front/core/components/autocomplete/index.js b/front/core/components/autocomplete/index.js index 2539c4ef4..52491f7e0 100755 --- a/front/core/components/autocomplete/index.js +++ b/front/core/components/autocomplete/index.js @@ -174,6 +174,7 @@ export default class Autocomplete extends Field { refreshDisplayed() { let display = ''; + let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem'); if (this._selection && this.showField) { if (this.multiple && Array.isArray(this._selection)) { @@ -181,8 +182,19 @@ export default class Autocomplete extends Field { if (display.length > 0) display += ', '; display += item[this.showField]; } - } else + } else { display = this._selection[this.showField]; + if (hasTemplate) { + let template = this.$transclude(() => {}, null, 'tplItem'); + const element = template[0]; + const description = element.querySelector('.text-secondary'); + if (description) description.remove(); + + const displayElement = angular.element(element); + const displayText = displayElement.text(); + display = this.$interpolate(displayText)(this._selection); + } + } } this.input.value = display; diff --git a/modules/route/back/methods/vehicle/getVehiclesSorted.js b/modules/route/back/methods/vehicle/getVehiclesSorted.js index 9dad8b80a..384d89391 100644 --- a/modules/route/back/methods/vehicle/getVehiclesSorted.js +++ b/modules/route/back/methods/vehicle/getVehiclesSorted.js @@ -18,11 +18,13 @@ module.exports = Self => { Self.getVehiclesSorted = async warehouseFk => { const vehicles = await Self.rawSql(` - SELECT v.id, v.numberPlate, w.name + SELECT ROW_NUMBER() OVER (ORDER BY v.warehouseFk = ? DESC, w.id, v.numberPlate) AS 'order', + v.id, + v.warehouseFk, + CONCAT(v.numberPlate, ' - ', w.name) as description FROM vehicle v - JOIN warehouse w ON w.id = v.warehouseFk - ORDER BY v.warehouseFk = ? DESC, v.numberPlate ASC`, [warehouseFk]); - + JOIN warehouse w ON w.id = v.warehouseFk + ORDER BY v.warehouseFk = ? DESC, w.id, v.numberPlate ASC`, [warehouseFk, warehouseFk]); return vehicles; }; }; diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index 0f62dc107..1ba84583f 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -25,19 +25,17 @@ - - {{numberPlate}} - {{name}} - + vn-name="created">