@easydata/crud 1.4.0-rc02 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2738,6 +2738,7 @@ var easy_data_table_EasyDataTable = /** @class */ (function () {
2738
2738
  this.cachedRows = [];
2739
2739
  this.total = 0;
2740
2740
  this.needTotal = !this._elasticChunks;
2741
+ this.fireUpdated();
2741
2742
  };
2742
2743
  EasyDataTable.prototype.createRow = function (dataOrRow) {
2743
2744
  var _this = this;
@@ -4511,7 +4512,7 @@ var easy_grid_EasyGrid = /** @class */ (function () {
4511
4512
  pageSizeItems: [20, 30, 50, 100, 200]
4512
4513
  },
4513
4514
  columnWidths: {
4514
- autoResize: AutoResizeColumns.Once,
4515
+ autoResize: AutoResizeColumns.Always,
4515
4516
  stringColumns: {
4516
4517
  min: 100,
4517
4518
  max: 500,
@@ -4749,9 +4750,6 @@ var easy_grid_EasyGrid = /** @class */ (function () {
4749
4750
  .then(function () {
4750
4751
  _this.firstRender = false;
4751
4752
  _this.rowsOnPagePromise = null;
4752
- if (needAutoResize) {
4753
- _this.resizeColumns();
4754
- }
4755
4753
  });
4756
4754
  }
4757
4755
  else {
@@ -4924,9 +4922,15 @@ var easy_grid_EasyGrid = /** @class */ (function () {
4924
4922
  _this.updateTotalsState(groups_1, row, true);
4925
4923
  }
4926
4924
  }
4927
- var containerWidth = _this.getContainerWidth();
4928
- domel(_this.bodyCellContainerDiv)
4929
- .setStyle('width', containerWidth + "px");
4925
+ var needAutoResize = _this.options.columnWidths.autoResize !== AutoResizeColumns.Never;
4926
+ if (needAutoResize) {
4927
+ _this.resizeColumns();
4928
+ }
4929
+ else {
4930
+ var containerWidth = _this.getContainerWidth();
4931
+ domel(_this.bodyCellContainerDiv)
4932
+ .setStyle('width', containerWidth + "px");
4933
+ }
4930
4934
  return rowsToRender;
4931
4935
  })
4932
4936
  .catch(function (error) { console.error(error); return 0; });
@@ -6841,7 +6845,7 @@ var getEditDateTimeFormat = function (dtype) {
6841
6845
  };
6842
6846
  var setLocation = function (path) {
6843
6847
  var state = window.history.state;
6844
- history.replaceState(state, document.title, path);
6848
+ history.pushState(state, document.title, path);
6845
6849
  window.dispatchEvent(new Event('ed_set_location'));
6846
6850
  };
6847
6851
 
@@ -7273,7 +7277,9 @@ var entity_form_builder_EntityEditFormBuilder = /** @class */ (function () {
7273
7277
  var lookupEntity = this.context.getMetaData().getRootEntity()
7274
7278
  .subEntities.filter(function (ent) { return ent.id == attr.lookupEntity; })[0];
7275
7279
  var dataAttr = this.context.getMetaData().getAttributeById(attr.dataAttr);
7276
- readOnly = readOnly && dataAttr.isEditable;
7280
+ if (!dataAttr)
7281
+ return;
7282
+ readOnly = readOnly || !dataAttr.isEditable;
7277
7283
  value = this.params.values
7278
7284
  ? this.params.values.getValue(dataAttr.id)
7279
7285
  : undefined;
@@ -7664,15 +7670,10 @@ var entity_form_builder_EntityEditFormBuilder = /** @class */ (function () {
7664
7670
  this.form['setHtmlInt'](formHtml);
7665
7671
  for (var _i = 0, _a = this.context.getActiveEntity().attributes; _i < _a.length; _i++) {
7666
7672
  var attr = _a[_i];
7667
- if (!attr.isPrimaryKey) {
7668
- if (this.params.isEditForm) {
7669
- if (!attr.showOnEdit)
7670
- continue;
7671
- }
7672
- else {
7673
- if (!attr.showOnCreate)
7674
- continue;
7675
- }
7673
+ if (!this.params.isEditForm && !attr.showOnCreate)
7674
+ continue;
7675
+ if (!attr.isPrimaryKey && this.params.isEditForm && !attr.showOnEdit) {
7676
+ continue;
7676
7677
  }
7677
7678
  this.addFormField(fb.toDOM(), attr);
7678
7679
  }
@@ -7775,7 +7776,7 @@ var data_context_DataContext = /** @class */ (function () {
7775
7776
  DataContext.prototype.getActiveEntity = function () {
7776
7777
  return this.activeEntity;
7777
7778
  };
7778
- DataContext.prototype.setActiveEntity = function (entityId) {
7779
+ DataContext.prototype.setActiveSource = function (entityId) {
7779
7780
  this.activeEntity = this.model.getRootEntity().subEntities
7780
7781
  .filter(function (e) { return e.id == entityId; })[0];
7781
7782
  };
@@ -8013,10 +8014,12 @@ var entity_data_view_EntityDataView = /** @class */ (function () {
8013
8014
  showBackToEntities: true
8014
8015
  };
8015
8016
  this.defaultValidators = [new required_validator_RequiredValidator(), new type_validator_TypeValidator()];
8016
- options = options || {};
8017
8017
  this.options = utils_utils.assignDeep(this.options, options || {});
8018
8018
  this.dlg = new DefaultDialogService();
8019
8019
  var ent = this.context.getActiveEntity();
8020
+ if (!ent) {
8021
+ throw "Can't find active entity for " + window.location.pathname;
8022
+ }
8020
8023
  this.slot.innerHTML += "<h1>" + (ent.captionPlural || ent.caption) + "</h1>";
8021
8024
  if (this.options.showBackToEntities) {
8022
8025
  domel(this.slot)
@@ -8269,51 +8272,66 @@ var root_data_view_RootDataView = /** @class */ (function () {
8269
8272
  var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function () {
8270
8273
  function EasyDataViewDispatcher(options) {
8271
8274
  var _this = this;
8272
- this.options = { basePath: 'easydata' };
8275
+ this.options = {
8276
+ container: '#EasyDataContainer',
8277
+ basePath: 'easydata'
8278
+ };
8273
8279
  this.onSetLocation = function () {
8274
8280
  _this.setActiveView();
8275
8281
  };
8276
- options = options || {};
8277
- this.options = utils_utils.assign(this.options, options);
8278
- this.options.basePath = (!this.options.rootEntity)
8279
- ? this.pretiffyPath(this.options.basePath)
8280
- : this.pretiffyPath(window.location.pathname);
8281
- if (this.options.rootEntity)
8282
+ this.attach = function () {
8283
+ window.addEventListener('ed_set_location', _this.onSetLocation);
8284
+ window.addEventListener('popstate', _this.onSetLocation);
8285
+ };
8286
+ this.options = utils_utils.assign(this.options, options || {});
8287
+ if (this.options.rootEntity) {
8282
8288
  this.options.showBackToEntities = false;
8283
- this.setContainer(options.container);
8289
+ this.basePath = '/';
8290
+ }
8291
+ else {
8292
+ this.basePath = this.normalizeBasePath(this.options.basePath);
8293
+ }
8294
+ this.setContainer(this.options.container);
8284
8295
  var progressBarSlot = document.createElement('div');
8285
8296
  var bar = new ProgressBar(progressBarSlot);
8286
8297
  var parent = this.container.parentElement;
8287
8298
  parent.insertBefore(progressBarSlot, parent.firstElementChild);
8288
8299
  this.context = new data_context_DataContext({
8289
- endpoint: options.endpoint,
8290
- dataTable: options.dataTable,
8300
+ endpoint: this.options.endpoint,
8301
+ dataTable: this.options.dataTable,
8291
8302
  onProcessStart: function () { return bar.show(); },
8292
8303
  onProcessEnd: function () { return bar.hide(); }
8293
8304
  });
8294
- this.basePath = this.getBasePath();
8295
8305
  }
8296
- EasyDataViewDispatcher.prototype.pretiffyPath = function (path) {
8306
+ EasyDataViewDispatcher.prototype.normalizeBasePath = function (basePath) {
8307
+ basePath = this.trimSlashes(basePath);
8308
+ var fullPath = decodeURIComponent(window.location.pathname);
8309
+ var idx = fullPath.toLocaleLowerCase().indexOf(basePath);
8310
+ return idx >= 0 ? fullPath.substring(0, idx + basePath.length) : '/';
8311
+ };
8312
+ EasyDataViewDispatcher.prototype.trimSlashes = function (path) {
8297
8313
  return path.replace(/^\/|\/$/g, '');
8298
8314
  };
8299
8315
  EasyDataViewDispatcher.prototype.setContainer = function (container) {
8300
8316
  if (!container) {
8301
- this.container = document.getElementById('EasyDataContainer');
8302
- return;
8317
+ throw 'Container is undefined';
8303
8318
  }
8304
8319
  if (typeof container === 'string') {
8305
8320
  if (container.length) {
8306
- if (container[0] === '#') {
8307
- this.container = document.getElementById(container.substring(1));
8308
- }
8309
- else if (container[0] === '.') {
8321
+ if (container[0] === '.') {
8310
8322
  var result = document.getElementsByClassName(container.substring(1));
8311
8323
  if (result.length)
8312
8324
  this.container = result[0];
8313
8325
  }
8314
8326
  else {
8315
- throw Error('Unrecognized container parameter ' +
8316
- '(Must be an element ID, a class name or HTMLElement object itself): ' + container);
8327
+ if (container[0] === '#') {
8328
+ container = container.substring(1);
8329
+ }
8330
+ this.container = document.getElementById(container);
8331
+ }
8332
+ if (!this.container) {
8333
+ throw Error('Unrecognized `container` parameter: ' + container + '\n'
8334
+ + 'It must be an element ID, a class name (starting with .) or an HTMLElement object itself.');
8317
8335
  }
8318
8336
  }
8319
8337
  }
@@ -8321,24 +8339,16 @@ var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function (
8321
8339
  this.container = container;
8322
8340
  }
8323
8341
  };
8324
- EasyDataViewDispatcher.prototype.getActiveEntityId = function () {
8342
+ EasyDataViewDispatcher.prototype.getActiveSourceId = function () {
8325
8343
  if (this.options.rootEntity)
8326
8344
  return this.options.rootEntity;
8327
- var decodedUrl = decodeURIComponent(window.location.href);
8328
- var splitIndex = decodedUrl.lastIndexOf('/');
8329
- var typeName = decodedUrl.substring(splitIndex + 1);
8330
- return typeName && typeName.toLocaleLowerCase() !== this.options.basePath
8331
- ? typeName
8332
- : null;
8333
- };
8334
- EasyDataViewDispatcher.prototype.getBasePath = function () {
8335
- var decodedUrl = decodeURIComponent(window.location.href);
8336
- var optBasePathIndex = decodedUrl.toLocaleLowerCase().indexOf(this.options.basePath);
8337
- return decodedUrl.substring(0, optBasePathIndex + this.options.basePath.length);
8345
+ var path = decodeURIComponent(window.location.pathname);
8346
+ var idIndex = this.basePath.length + 1;
8347
+ return idIndex < path.length ? path.substring(idIndex) : null;
8338
8348
  };
8339
8349
  EasyDataViewDispatcher.prototype.run = function () {
8340
8350
  var _this = this;
8341
- window.addEventListener('ed_set_location', this.onSetLocation);
8351
+ this.attach();
8342
8352
  return this.context.loadMetaData()
8343
8353
  .then(function () {
8344
8354
  _this.setActiveView();
@@ -8347,9 +8357,9 @@ var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function (
8347
8357
  };
8348
8358
  EasyDataViewDispatcher.prototype.setActiveView = function () {
8349
8359
  this.clear();
8350
- var activeEntityId = this.getActiveEntityId();
8351
- if (activeEntityId) {
8352
- this.context.setActiveEntity(activeEntityId);
8360
+ var sourceId = this.getActiveSourceId();
8361
+ if (sourceId) {
8362
+ this.context.setActiveSource(sourceId);
8353
8363
  window['EDView'] = new entity_data_view_EntityDataView(this.container, this.context, this.basePath, this.options);
8354
8364
  }
8355
8365
  else {
@@ -8362,6 +8372,7 @@ var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function (
8362
8372
  };
8363
8373
  EasyDataViewDispatcher.prototype.detach = function () {
8364
8374
  window.removeEventListener('ed_set_location', this.onSetLocation);
8375
+ window.removeEventListener('popstate', this.onSetLocation);
8365
8376
  };
8366
8377
  return EasyDataViewDispatcher;
8367
8378
  }());