Changed to single scope for all inputs
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-11-12 14:15:35 +01:00
parent f28401303e
commit 3e35e7e0b8
3 changed files with 42 additions and 34 deletions

View File

@ -12,7 +12,7 @@ export default class SmartTable extends Component {
this.currentUserId = window.localStorage.currentUserWorkerId; this.currentUserId = window.localStorage.currentUserWorkerId;
this.$transclude = $transclude; this.$transclude = $transclude;
this.sortCriteria = []; this.sortCriteria = [];
this.$inputScopes = []; this.$inputsScope;
this.columns = []; this.columns = [];
this.autoSave = false; this.autoSave = false;
this.transclude(); this.transclude();
@ -118,29 +118,11 @@ export default class SmartTable extends Component {
transclude() { transclude() {
const slotTable = this.element.querySelector('#table'); const slotTable = this.element.querySelector('#table');
this.$transclude(($clone, $scope) => { this.$transclude($clone => {
const table = $clone[0]; const table = $clone[0];
slotTable.appendChild(table); slotTable.appendChild(table);
this.registerColumns(); this.registerColumns();
this.emptyDataRows();
const header = this.element.querySelector('thead > tr');
const columns = header.querySelectorAll('th');
const tbody = this.element.querySelector('tbody');
if (tbody) {
const noSearch = this.$compile(`
<tr class="empty-rows" ng-if="!model.data">
<td colspan="${columns.length}" translate>Enter a new search</td>
</tr>
`)($scope);
tbody.appendChild(noSearch[0]);
const noRows = this.$compile(`
<tr class="empty-rows" ng-if="model.data.length == 0">
<td colspan="${columns.length}" translate>No data</td>
</tr>
`)($scope);
tbody.appendChild(noRows[0]);
}
}, null, 'table'); }, null, 'table');
} }
@ -150,7 +132,8 @@ export default class SmartTable extends Component {
viewConfig.configuration = Object.assign({}, viewConfig.configuration); viewConfig.configuration = Object.assign({}, viewConfig.configuration);
userViewModel.save() userViewModel.save()
.then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) .then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.applyViewConfig()); .then(() => this.applyViewConfig())
.then(() => this.$.smartTableColumns.hide());
} }
applyViewConfig() { applyViewConfig() {
@ -199,6 +182,27 @@ export default class SmartTable extends Component {
} }
} }
emptyDataRows() {
const header = this.element.querySelector('thead > tr');
const columns = header.querySelectorAll('th');
const tbody = this.element.querySelector('tbody');
if (tbody) {
const noSearch = this.$compile(`
<tr class="empty-rows" ng-if="!model.data">
<td colspan="${columns.length}" translate>Enter a new search</td>
</tr>
`)(this.$);
tbody.appendChild(noSearch[0]);
const noRows = this.$compile(`
<tr class="empty-rows" ng-if="model.data.length == 0">
<td colspan="${columns.length}" translate>No data</td>
</tr>
`)(this.$);
tbody.appendChild(noRows[0]);
}
}
orderHandler(element) { orderHandler(element) {
const field = element.getAttribute('field'); const field = element.getAttribute('field');
const existingCriteria = this.sortCriteria.find(criteria => { const existingCriteria = this.sortCriteria.find(criteria => {
@ -240,15 +244,17 @@ export default class SmartTable extends Component {
const hasSearchRow = tbody.querySelector('tr#searchRow'); const hasSearchRow = tbody.querySelector('tr#searchRow');
if (hasSearchRow) { if (hasSearchRow) {
if (this.$inputScopes) { if (this.$inputsScope)
for (let $inputScope of this.$inputScopes) this.$inputsScope.$destroy();
$inputScope.$destroy();
}
return hasSearchRow.remove(); return hasSearchRow.remove();
} }
const searchRow = document.createElement('tr'); const searchRow = document.createElement('tr');
searchRow.setAttribute('id', 'searchRow'); searchRow.setAttribute('id', 'searchRow');
this.$inputsScope = this.$.$new();
for (let column of columns) { for (let column of columns) {
const field = column.getAttribute('field'); const field = column.getAttribute('field');
const cell = document.createElement('td'); const cell = document.createElement('td');
@ -265,7 +271,6 @@ export default class SmartTable extends Component {
continue; continue;
} }
const $inputScope = this.$.$new();
if (options && options.autocomplete) { if (options && options.autocomplete) {
let props = ``; let props = ``;
@ -280,7 +285,7 @@ export default class SmartTable extends Component {
${props} ${props}
on-change="$ctrl.searchByColumn('${field}')" on-change="$ctrl.searchByColumn('${field}')"
clear-disabled="true" clear-disabled="true"
/>`)($inputScope); />`)(this.$inputsScope);
} else { } else {
input = this.$compile(` input = this.$compile(`
<vn-textfield <vn-textfield
@ -289,9 +294,8 @@ export default class SmartTable extends Component {
ng-model="searchProps['${field}']" ng-model="searchProps['${field}']"
ng-keydown="$ctrl.searchWithEvent($event, '${field}')" ng-keydown="$ctrl.searchWithEvent($event, '${field}')"
clear-disabled="true" clear-disabled="true"
/>`)($inputScope); />`)(this.$inputsScope);
} }
this.$inputScopes.push($inputScope);
cell.appendChild(input[0]); cell.appendChild(input[0]);
} }
searchRow.appendChild(cell); searchRow.appendChild(cell);
@ -307,7 +311,7 @@ export default class SmartTable extends Component {
} }
searchByColumn(field) { searchByColumn(field) {
const searchCriteria = this.$.searchProps[field]; const searchCriteria = this.$inputsScope.searchProps[field];
const emptySearch = searchCriteria == '' || null; const emptySearch = searchCriteria == '' || null;
const filters = this.filterSanitizer(field); const filters = this.filterSanitizer(field);
@ -316,7 +320,7 @@ export default class SmartTable extends Component {
this.model.userFilter = filters.userFilter; this.model.userFilter = filters.userFilter;
if (!emptySearch) if (!emptySearch)
this.addFilter(field, this.$.searchProps[field]); this.addFilter(field, this.$inputsScope.searchProps[field]);
else this.model.refresh(); else this.model.refresh();
} }

View File

@ -32,8 +32,12 @@ smart-table table {
text-overflow: ellipsis; text-overflow: ellipsis;
&[number] { &[number] {
flex-direction: column;
text-align: right; text-align: right;
width: 96px; align-items:flex-end;
align-content: flex-end;
justify-content: right;
} }
&[centered] { &[centered] {
text-align: center; text-align: center;

View File

@ -137,7 +137,7 @@
<span <span
vn-click-stop="itemDescriptor.show($event, buy.itemFk)" vn-click-stop="itemDescriptor.show($event, buy.itemFk)"
class="link"> class="link">
{{::buy.itemFk | zeroFill:6}} {{::buy.itemFk}}
</span> </span>
</td> </td>
<td number> <td number>