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

View File

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

View File

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