diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 93d5f93947..cb0304b344 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -44,16 +44,10 @@ export default class SmartTable extends Component { set model(value) { this._model = value; - if (value) + if (value) { this.$.model = value; - } - - get viewConfigId() { - return this._viewConfigId; - } - - set viewConfigId(value) { - this._viewConfigId = value; + this.defaultOrder(); + } } getDefaultViewConfig() { @@ -163,6 +157,40 @@ export default class SmartTable extends Component { } } + defaultOrder() { + const order = this.model.order; + if (!order) return; + + const orderFields = order.split(', '); + + for (const fieldString of orderFields) { + const field = fieldString.split(' '); + const fieldName = field[0]; + + let sortType = 'ASC'; + if (field.length === 2) + sortType = field[1]; + + const column = this.columns.find(column => column.field == fieldName); + if (column) { + this.sortCriteria.push({field: fieldName, sortType: sortType}); + + const isASC = sortType == 'ASC'; + const isDESC = sortType == 'DESC'; + + if (isDESC) { + column.element.classList.remove('asc'); + column.element.classList.add('desc'); + } + + if (isASC) { + column.element.classList.remove('desc'); + column.element.classList.add('asc'); + } + } + } + } + registerColumns() { const header = this.element.querySelector('thead > tr'); if (!header) return; @@ -175,7 +203,7 @@ export default class SmartTable extends Component { const columnElement = angular.element(column); const caption = columnElement.text().trim(); - this.columns.push({field, caption, index}); + this.columns.push({field, caption, index, element: column}); column.addEventListener('click', () => this.orderHandler(column)); } diff --git a/front/core/components/smart-table/index.spec.js b/front/core/components/smart-table/index.spec.js index 9b8cc1d09e..94edd45bba 100644 --- a/front/core/components/smart-table/index.spec.js +++ b/front/core/components/smart-table/index.spec.js @@ -80,6 +80,45 @@ describe('Component smartTable', () => { }); }); + describe('defaultOrder', () => { + it('should insert a new object to the controller sortCriteria with a sortType value of "ASC"', () => { + const element = document.createElement('div'); + controller.model = {order: 'id'}; + controller.columns = [ + {field: 'id', element: element}, + {field: 'test1', element: element}, + {field: 'test2', element: element} + ]; + + controller.defaultOrder(); + + const firstSortCriteria = controller.sortCriteria[0]; + + expect(firstSortCriteria.field).toEqual('id'); + expect(firstSortCriteria.sortType).toEqual('ASC'); + }); + + it('should insert two new objects to the controller sortCriteria with a sortType values of "ASC" and "DESC"', () => { + const element = document.createElement('div'); + controller.model = {order: 'test1, id DESC'}; + controller.columns = [ + {field: 'id', element: element}, + {field: 'test1', element: element}, + {field: 'test2', element: element} + ]; + + controller.defaultOrder(); + + const firstSortCriteria = controller.sortCriteria[0]; + const secondSortCriteria = controller.sortCriteria[1]; + + expect(firstSortCriteria.field).toEqual('test1'); + expect(firstSortCriteria.sortType).toEqual('ASC'); + expect(secondSortCriteria.field).toEqual('id'); + expect(secondSortCriteria.sortType).toEqual('DESC'); + }); + }); + describe('addFilter()', () => { it('should call the model addFilter() with a basic where filter if exprBuilder() was not received', () => { controller.model = {addFilter: jest.fn()}; diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index 32d26c3a4e..4eeeeedce7 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -1,6 +1,7 @@ @@ -34,8 +35,8 @@ Picture - - Identifier + + Item ID Packing diff --git a/modules/monitor/front/index/tickets/index.html b/modules/monitor/front/index/tickets/index.html index 0d7f265f81..2653af1956 100644 --- a/modules/monitor/front/index/tickets/index.html +++ b/modules/monitor/front/index/tickets/index.html @@ -2,7 +2,7 @@ vn-id="model" url="SalesMonitors/salesFilter" limit="20" - order="shippedDate DESC, theoreticalhour, id"> + order="shipped DESC, theoreticalHour, id"> - - + + + + diff --git a/modules/monitor/front/index/tickets/style.scss b/modules/monitor/front/index/tickets/style.scss index ef7b80da8d..102c92a8a8 100644 --- a/modules/monitor/front/index/tickets/style.scss +++ b/modules/monitor/front/index/tickets/style.scss @@ -29,7 +29,7 @@ vn-monitor-sales-tickets { height: 736px } - vn-tbody a[ng-repeat].vn-tr:focus { + tbody tr[ng-repeat]:focus { background-color: $color-primary-light }