fix(smart-table): load default viewConfig
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-11-12 17:51:27 +01:00
parent 2e359fd8b7
commit b83f0fb52f
3 changed files with 33 additions and 17 deletions

View File

@ -7,7 +7,8 @@ comment 'The default configuration of columns for views';
INSERT INTO `salix`.`defaultViewConfig` (tableCode, columns) INSERT INTO `salix`.`defaultViewConfig` (tableCode, columns)
VALUES VALUES
('itemsIndex', '{"intrastat":false,"stemMultiplier":false}'), ('itemsIndex', '{"intrastat":false,"stemMultiplier":false,"landed":false}'),
('latestBuys', '{"intrastat":false,"description":false,"density":false,"isActive":false,"freightValue":false,"packageValue":false,"isIgnored":false,"price2":false,"minPrice":true,"ektFk":false,"weight":false,"id":true,"packing":true,"grouping":true,"quantity":true,"size":false,"name":true,"code":true,"origin":true,"family":true,"entryFk":true,"buyingValue":true,"comissionValue":false,"price3":true,"packageFk":true,"packingOut":true}'); ('latestBuys', '{"intrastat":false,"description":false,"density":false,"isActive":false,"freightValue":false,"packageValue":false,"isIgnored":false,"price2":false,"minPrice":true,"ektFk":false,"weight":false,"id":true,"packing":true,"grouping":true,"quantity":true,"size":false,"name":true,"code":true,"origin":true,"family":true,"entryFk":true,"buyingValue":true,"comissionValue":false,"price3":true,"packageFk":true,"packingOut":true}'),
('ticketsMonitor', '{"id":false}');

View File

@ -55,7 +55,7 @@ export default class SmartTable extends Component {
set viewConfigId(value) { set viewConfigId(value) {
this._viewConfigId = value; this._viewConfigId = value;
if (value) { /* if (value) {
this.defaultViewConfig = {}; this.defaultViewConfig = {};
const url = 'DefaultViewConfigs'; const url = 'DefaultViewConfigs';
@ -67,7 +67,18 @@ export default class SmartTable extends Component {
this.defaultViewConfig = columns; this.defaultViewConfig = columns;
} }
}); });
} } */
}
getDefaultViewConfig() {
// this.defaultViewConfig = {};
const url = 'DefaultViewConfigs';
const filter = {where: {tableCode: this.viewConfigId}};
return this.$http.get(url, {filter})
.then(res => {
if (res && res.data.length)
return res.data[0].columns;
});
} }
get viewConfig() { get viewConfig() {
@ -80,19 +91,23 @@ export default class SmartTable extends Component {
if (!value) return; if (!value) return;
if (!value.length) { if (!value.length) {
const userViewModel = this.$.userViewModel; this.getDefaultViewConfig().then(columns => {
const defaultViewConfig = columns ? columns : {};
for (const column of this.columns) { const userViewModel = this.$.userViewModel;
if (this.defaultViewConfig[column.field] == undefined) for (const column of this.columns) {
this.defaultViewConfig[column.field] = true; if (defaultViewConfig[column.field] == undefined)
} defaultViewConfig[column.field] = true;
userViewModel.insert({ }
userFk: this.currentUserId,
tableConfig: this.viewConfigId, userViewModel.insert({
configuration: this.defaultViewConfig ? this.defaultViewConfig : {} userFk: this.currentUserId,
}); tableConfig: this.viewConfigId,
} configuration: defaultViewConfig
this.applyViewConfig(); });
}).finally(() => this.applyViewConfig());
} else
this.applyViewConfig();
} }
get checkedRows() { get checkedRows() {

View File

@ -27,7 +27,7 @@ smart-table table {
& > th, & > th,
& > td { & > td {
text-align: left; text-align: left;
padding: 9px 8px; padding: 9px 5px;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;