@easydata/crud 1.4.0 → 1.4.1-rc01

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;
@@ -7778,7 +7779,7 @@ var data_context_DataContext = /** @class */ (function () {
7778
7779
  DataContext.prototype.getActiveEntity = function () {
7779
7780
  return this.activeEntity;
7780
7781
  };
7781
- DataContext.prototype.setActiveEntity = function (entityId) {
7782
+ DataContext.prototype.setActiveSource = function (entityId) {
7782
7783
  this.activeEntity = this.model.getRootEntity().subEntities
7783
7784
  .filter(function (e) { return e.id == entityId; })[0];
7784
7785
  };
@@ -8016,10 +8017,12 @@ var entity_data_view_EntityDataView = /** @class */ (function () {
8016
8017
  showBackToEntities: true
8017
8018
  };
8018
8019
  this.defaultValidators = [new required_validator_RequiredValidator(), new type_validator_TypeValidator()];
8019
- options = options || {};
8020
8020
  this.options = utils_utils.assignDeep(this.options, options || {});
8021
8021
  this.dlg = new DefaultDialogService();
8022
8022
  var ent = this.context.getActiveEntity();
8023
+ if (!ent) {
8024
+ throw "Can't find active entity for " + window.location.pathname;
8025
+ }
8023
8026
  this.slot.innerHTML += "<h1>" + (ent.captionPlural || ent.caption) + "</h1>";
8024
8027
  if (this.options.showBackToEntities) {
8025
8028
  domel(this.slot)
@@ -8272,51 +8275,62 @@ var root_data_view_RootDataView = /** @class */ (function () {
8272
8275
  var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function () {
8273
8276
  function EasyDataViewDispatcher(options) {
8274
8277
  var _this = this;
8275
- this.options = { basePath: 'easydata' };
8278
+ this.options = {
8279
+ container: '#EasyDataContainer',
8280
+ basePath: 'easydata'
8281
+ };
8276
8282
  this.onSetLocation = function () {
8277
8283
  _this.setActiveView();
8278
8284
  };
8279
- options = options || {};
8280
- this.options = utils_utils.assign(this.options, options);
8281
- this.options.basePath = (!this.options.rootEntity)
8282
- ? this.pretiffyPath(this.options.basePath)
8283
- : this.pretiffyPath(window.location.pathname);
8284
- if (this.options.rootEntity)
8285
+ this.options = utils_utils.assign(this.options, options || {});
8286
+ if (this.options.rootEntity) {
8285
8287
  this.options.showBackToEntities = false;
8286
- this.setContainer(options.container);
8288
+ this.basePath = '/';
8289
+ }
8290
+ else {
8291
+ this.basePath = this.normalizeBasePath(this.options.basePath);
8292
+ }
8293
+ this.setContainer(this.options.container);
8287
8294
  var progressBarSlot = document.createElement('div');
8288
8295
  var bar = new ProgressBar(progressBarSlot);
8289
8296
  var parent = this.container.parentElement;
8290
8297
  parent.insertBefore(progressBarSlot, parent.firstElementChild);
8291
8298
  this.context = new data_context_DataContext({
8292
- endpoint: options.endpoint,
8293
- dataTable: options.dataTable,
8299
+ endpoint: this.options.endpoint,
8300
+ dataTable: this.options.dataTable,
8294
8301
  onProcessStart: function () { return bar.show(); },
8295
8302
  onProcessEnd: function () { return bar.hide(); }
8296
8303
  });
8297
- this.basePath = this.getBasePath();
8298
8304
  }
8299
- EasyDataViewDispatcher.prototype.pretiffyPath = function (path) {
8305
+ EasyDataViewDispatcher.prototype.normalizeBasePath = function (basePath) {
8306
+ basePath = this.trimSlashes(basePath);
8307
+ var fullPath = decodeURIComponent(window.location.pathname);
8308
+ var idx = fullPath.toLocaleLowerCase().indexOf(basePath);
8309
+ return idx >= 0 ? fullPath.substring(0, idx + basePath.length) : '/';
8310
+ };
8311
+ EasyDataViewDispatcher.prototype.trimSlashes = function (path) {
8300
8312
  return path.replace(/^\/|\/$/g, '');
8301
8313
  };
8302
8314
  EasyDataViewDispatcher.prototype.setContainer = function (container) {
8303
8315
  if (!container) {
8304
- this.container = document.getElementById('EasyDataContainer');
8305
- return;
8316
+ throw 'Container is undefined';
8306
8317
  }
8307
8318
  if (typeof container === 'string') {
8308
8319
  if (container.length) {
8309
- if (container[0] === '#') {
8310
- this.container = document.getElementById(container.substring(1));
8311
- }
8312
- else if (container[0] === '.') {
8320
+ if (container[0] === '.') {
8313
8321
  var result = document.getElementsByClassName(container.substring(1));
8314
8322
  if (result.length)
8315
8323
  this.container = result[0];
8316
8324
  }
8317
8325
  else {
8318
- throw Error('Unrecognized container parameter ' +
8319
- '(Must be an element ID, a class name or HTMLElement object itself): ' + container);
8326
+ if (container[0] === '#') {
8327
+ container = container.substring(1);
8328
+ }
8329
+ this.container = document.getElementById(container);
8330
+ }
8331
+ if (!this.container) {
8332
+ throw Error('Unrecognized `container` parameter: ' + container + '\n'
8333
+ + 'It must be an element ID, a class name (starting with .) or an HTMLElement object itself.');
8320
8334
  }
8321
8335
  }
8322
8336
  }
@@ -8324,20 +8338,12 @@ var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function (
8324
8338
  this.container = container;
8325
8339
  }
8326
8340
  };
8327
- EasyDataViewDispatcher.prototype.getActiveEntityId = function () {
8341
+ EasyDataViewDispatcher.prototype.getActiveSourceId = function () {
8328
8342
  if (this.options.rootEntity)
8329
8343
  return this.options.rootEntity;
8330
- var decodedUrl = decodeURIComponent(window.location.href);
8331
- var splitIndex = decodedUrl.lastIndexOf('/');
8332
- var typeName = decodedUrl.substring(splitIndex + 1);
8333
- return typeName && typeName.toLocaleLowerCase() !== this.options.basePath
8334
- ? typeName
8335
- : null;
8336
- };
8337
- EasyDataViewDispatcher.prototype.getBasePath = function () {
8338
- var decodedUrl = decodeURIComponent(window.location.href);
8339
- var optBasePathIndex = decodedUrl.toLocaleLowerCase().indexOf(this.options.basePath);
8340
- return decodedUrl.substring(0, optBasePathIndex + this.options.basePath.length);
8344
+ var path = decodeURIComponent(window.location.pathname);
8345
+ var idIndex = this.basePath.length + 1;
8346
+ return idIndex < path.length ? path.substring(idIndex) : null;
8341
8347
  };
8342
8348
  EasyDataViewDispatcher.prototype.run = function () {
8343
8349
  var _this = this;
@@ -8350,9 +8356,9 @@ var easy_data_view_dispatcher_EasyDataViewDispatcher = /** @class */ (function (
8350
8356
  };
8351
8357
  EasyDataViewDispatcher.prototype.setActiveView = function () {
8352
8358
  this.clear();
8353
- var activeEntityId = this.getActiveEntityId();
8354
- if (activeEntityId) {
8355
- this.context.setActiveEntity(activeEntityId);
8359
+ var sourceId = this.getActiveSourceId();
8360
+ if (sourceId) {
8361
+ this.context.setActiveSource(sourceId);
8356
8362
  window['EDView'] = new entity_data_view_EntityDataView(this.container, this.context, this.basePath, this.options);
8357
8363
  }
8358
8364
  else {