@entropic-bond/crud-panel 1.1.1 → 2.2.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.
package/README.md CHANGED
@@ -1 +1 @@
1
- # Crud Panel
1
+ # Crud Panel 2.0
@@ -1,50 +1,29 @@
1
- import { Callback, Persistent, Model } from 'entropic-bond';
2
- interface ProgressStage {
3
- name: string;
4
- progress: number;
5
- total: number;
6
- }
7
- export interface ProgressEvent {
8
- stages: {
9
- [stageId: string]: ProgressStage;
10
- };
11
- overallProgress: number;
12
- }
1
+ import { Callback, Persistent, Model, Observable } from 'entropic-bond';
2
+ import { ProgressController, ProgressEvent } from './progress-controller';
13
3
  export interface CrudControllerEvent<T extends Persistent> {
14
4
  documentChanged?: T;
15
- documentCollection?: T[];
5
+ documentCollection?: T[] | readonly T[];
16
6
  }
17
7
  export declare abstract class CrudController<T extends Persistent> {
18
- constructor(document: T);
8
+ constructor(document?: T);
9
+ abstract allRequiredPropertiesFilled(): boolean;
10
+ protected abstract createDocument(): T;
19
11
  protected abstract getModel(): Model<T>;
20
- allRequiredPropertiesFilled(): boolean;
21
- static registerController(documentName: string, construct: ControllerConstructor): void;
22
- static createController(document: Persistent): CrudController<Persistent>;
12
+ protected storeDoc(): Promise<void>;
13
+ protected deleteDoc(): Promise<void>;
14
+ protected findDocs(limit: number): Promise<T[] | readonly T[]>;
23
15
  onChange(observer: Callback<CrudControllerEvent<T>>): import("entropic-bond").Unsubscriber;
24
- createDocument(): T;
25
- setDocument(value: T): this;
26
- get document(): T;
27
- storeDocument(document: T): Promise<void>;
28
- deleteDocument(document: T): Promise<void>;
29
- getDocumentCollection(): Promise<T[]>;
16
+ newDocument(): CrudController<T>;
17
+ storeDocument(): Promise<void>;
18
+ deleteDocument(): Promise<void>;
19
+ documentCollection(limit?: number): Promise<T[] | readonly T[]>;
30
20
  onProgress(observer: Callback<ProgressEvent>): import("entropic-bond").Unsubscriber;
31
- protected notifyProgress(stageId: string, progress: ProgressStage): void;
32
- protected resetProgress(): void;
33
21
  protected get model(): Model<T>;
34
- private _onChange;
22
+ setDocument(value: T): CrudController<T>;
23
+ set document(value: T);
24
+ get document(): T;
25
+ protected progressController: ProgressController;
26
+ protected onChangeHdl: Observable<CrudControllerEvent<T>>;
35
27
  private _model;
36
28
  private _document;
37
- private static _factories;
38
- private _progressStage;
39
- private _onProgress;
40
29
  }
41
- declare type ControllerConstructor = new (document: Persistent) => CrudController<Persistent>;
42
- /**
43
- * Decorator to associate this controller with the document type that it manages.
44
- * This will allow to create a controller from a given document automatically.
45
- *
46
- * @param documentTypeName the document type name that this controller is
47
- * dessigned for.
48
- */
49
- export declare function controllerFor(documentTypeName: string): (constructor: ControllerConstructor) => void;
50
- export {};
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -47,138 +36,115 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
36
  }
48
37
  };
49
38
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.controllerFor = exports.CrudController = void 0;
39
+ exports.CrudController = void 0;
51
40
  var entropic_bond_1 = require("entropic-bond");
41
+ var progress_controller_1 = require("./progress-controller");
52
42
  var CrudController = /** @class */ (function () {
53
43
  function CrudController(document) {
54
- this._progressStage = {};
55
- this._document = document;
56
- this._onChange = new entropic_bond_1.Observable();
57
- this._onProgress = new entropic_bond_1.Observable();
44
+ this.progressController = new progress_controller_1.ProgressController();
45
+ this.onChangeHdl = new entropic_bond_1.Observable();
46
+ this._document = document || this.createDocument();
58
47
  }
59
- CrudController.prototype.allRequiredPropertiesFilled = function () {
60
- return true;
48
+ CrudController.prototype.storeDoc = function () {
49
+ return this.model.save(this.document);
61
50
  };
62
- CrudController.registerController = function (documentName, construct) {
63
- this._factories[documentName] = function (document) {
64
- return new construct(document);
65
- };
51
+ CrudController.prototype.deleteDoc = function () {
52
+ return this.model.delete(this.document.id);
66
53
  };
67
- CrudController.createController = function (document) {
68
- if (!this._factories[document.className])
69
- throw new Error("You should register " + document.className + " controller prior to use in the CRUD system");
70
- var factory = this._factories[document.className];
71
- return factory(document);
54
+ CrudController.prototype.findDocs = function (limit) {
55
+ return this.model.find().limit(limit).get();
72
56
  };
73
57
  CrudController.prototype.onChange = function (observer) {
74
- return this._onChange.subscribe(observer);
58
+ return this.onChangeHdl.subscribe(observer);
75
59
  };
76
- CrudController.prototype.createDocument = function () {
77
- this._document = entropic_bond_1.Persistent.createInstance(this.document.className);
78
- this._onChange.notify({ documentChanged: this._document });
79
- return this._document;
60
+ CrudController.prototype.newDocument = function () {
61
+ return this.setDocument(this.createDocument());
80
62
  };
81
- CrudController.prototype.setDocument = function (value) {
82
- if (this._document != value) {
83
- this._document = value;
84
- this._onChange.notify({ documentChanged: value });
85
- }
86
- return this;
87
- };
88
- Object.defineProperty(CrudController.prototype, "document", {
89
- get: function () {
90
- return this._document;
91
- },
92
- enumerable: false,
93
- configurable: true
94
- });
95
- CrudController.prototype.storeDocument = function (document) {
63
+ CrudController.prototype.storeDocument = function () {
96
64
  return __awaiter(this, void 0, void 0, function () {
97
- var _a, _b;
65
+ var progressStage, _a, _b;
98
66
  var _c;
99
67
  return __generator(this, function (_d) {
100
68
  switch (_d.label) {
101
69
  case 0:
102
- this.notifyProgress('storeMainDocument', {
103
- name: 'Store main document',
104
- progress: 0.2,
105
- total: 1
106
- });
107
- return [4 /*yield*/, this.model.save(document)];
70
+ progressStage = 'Saving main document';
71
+ _d.label = 1;
108
72
  case 1:
109
- _d.sent();
110
- this._document = document;
111
- this.notifyProgress('storeMainDocument', {
112
- name: 'Store main document',
113
- progress: 1,
114
- total: 1
115
- });
116
- this.resetProgress();
117
- _b = (_a = this._onChange).notify;
118
- _c = {
119
- documentChanged: this._document !== document ? document : undefined
120
- };
121
- return [4 /*yield*/, this.getDocumentCollection()];
73
+ _d.trys.push([1, , 4, 5]);
74
+ this.progressController.notifyBusy(true, progressStage);
75
+ return [4 /*yield*/, this.storeDoc()];
122
76
  case 2:
77
+ _d.sent();
78
+ _b = (_a = this.onChangeHdl).notify;
79
+ _c = {};
80
+ return [4 /*yield*/, this.documentCollection()];
81
+ case 3:
123
82
  _b.apply(_a, [(_c.documentCollection = _d.sent(),
124
83
  _c)]);
125
- return [2 /*return*/];
84
+ return [3 /*break*/, 5];
85
+ case 4:
86
+ this.progressController.notifyBusy(false, progressStage);
87
+ return [7 /*endfinally*/];
88
+ case 5: return [2 /*return*/];
126
89
  }
127
90
  });
128
91
  });
129
92
  };
130
- CrudController.prototype.deleteDocument = function (document) {
93
+ CrudController.prototype.deleteDocument = function () {
131
94
  return __awaiter(this, void 0, void 0, function () {
132
- var _a, _b;
95
+ var progressStage, _a, _b;
133
96
  var _c;
134
97
  return __generator(this, function (_d) {
135
98
  switch (_d.label) {
136
99
  case 0:
137
- this.notifyProgress('deleteMainDocument', {
138
- name: 'Delete main document',
139
- progress: 0.2,
140
- total: 1
141
- });
142
- return [4 /*yield*/, this.model.delete(document.id)];
100
+ progressStage = 'Delete main document';
101
+ _d.label = 1;
143
102
  case 1:
144
- _d.sent();
145
- this.notifyProgress('deleteMainDocument', {
146
- name: 'Delete main document',
147
- progress: 1,
148
- total: 1
149
- });
150
- this.resetProgress();
151
- _b = (_a = this._onChange).notify;
152
- _c = {
153
- documentChanged: document
154
- };
155
- return [4 /*yield*/, this.getDocumentCollection()];
103
+ _d.trys.push([1, , 4, 5]);
104
+ this.progressController.notifyBusy(true, progressStage);
105
+ return [4 /*yield*/, this.deleteDoc()];
156
106
  case 2:
107
+ _d.sent();
108
+ _b = (_a = this.onChangeHdl).notify;
109
+ _c = {};
110
+ return [4 /*yield*/, this.documentCollection()];
111
+ case 3:
157
112
  _b.apply(_a, [(_c.documentCollection = _d.sent(),
158
113
  _c)]);
159
- return [2 /*return*/];
114
+ return [3 /*break*/, 5];
115
+ case 4:
116
+ this.progressController.notifyBusy(false, progressStage);
117
+ return [7 /*endfinally*/];
118
+ case 5: return [2 /*return*/];
160
119
  }
161
120
  });
162
121
  });
163
122
  };
164
- CrudController.prototype.getDocumentCollection = function () {
165
- return this.model.find().get();
166
- };
167
- CrudController.prototype.onProgress = function (observer) {
168
- return this._onProgress.subscribe(observer);
169
- };
170
- CrudController.prototype.notifyProgress = function (stageId, progress) {
171
- this._progressStage[stageId] = progress;
172
- var overallProgress = Object.values(this._progressStage).reduce(function (prev, stage, _i, arr) {
173
- return prev + stage.progress / stage.total / arr.length;
174
- }, 0);
175
- this._onProgress.notify({
176
- stages: __assign({}, this._progressStage),
177
- overallProgress: overallProgress
123
+ CrudController.prototype.documentCollection = function (limit) {
124
+ return __awaiter(this, void 0, void 0, function () {
125
+ var progressStage, found;
126
+ return __generator(this, function (_a) {
127
+ switch (_a.label) {
128
+ case 0:
129
+ progressStage = 'Retrieving document collection';
130
+ _a.label = 1;
131
+ case 1:
132
+ _a.trys.push([1, , 3, 4]);
133
+ this.progressController.notifyBusy(true, progressStage);
134
+ return [4 /*yield*/, this.findDocs(limit)];
135
+ case 2:
136
+ found = _a.sent();
137
+ return [3 /*break*/, 4];
138
+ case 3:
139
+ this.progressController.notifyBusy(false, progressStage);
140
+ return [7 /*endfinally*/];
141
+ case 4: return [2 /*return*/, found];
142
+ }
143
+ });
178
144
  });
179
145
  };
180
- CrudController.prototype.resetProgress = function () {
181
- this._progressStage = {};
146
+ CrudController.prototype.onProgress = function (observer) {
147
+ return this.progressController.onProgress(observer);
182
148
  };
183
149
  Object.defineProperty(CrudController.prototype, "model", {
184
150
  get: function () {
@@ -187,21 +153,24 @@ var CrudController = /** @class */ (function () {
187
153
  enumerable: false,
188
154
  configurable: true
189
155
  });
190
- CrudController._factories = {};
156
+ CrudController.prototype.setDocument = function (value) {
157
+ if (this._document !== value) {
158
+ this._document = value;
159
+ this.onChangeHdl.notify({ documentChanged: this._document });
160
+ }
161
+ return this;
162
+ };
163
+ Object.defineProperty(CrudController.prototype, "document", {
164
+ get: function () {
165
+ return this._document;
166
+ },
167
+ set: function (value) {
168
+ this.setDocument(value);
169
+ },
170
+ enumerable: false,
171
+ configurable: true
172
+ });
191
173
  return CrudController;
192
174
  }());
193
175
  exports.CrudController = CrudController;
194
- /**
195
- * Decorator to associate this controller with the document type that it manages.
196
- * This will allow to create a controller from a given document automatically.
197
- *
198
- * @param documentTypeName the document type name that this controller is
199
- * dessigned for.
200
- */
201
- function controllerFor(documentTypeName) {
202
- return function (constructor) {
203
- CrudController.registerController(documentTypeName, constructor);
204
- };
205
- }
206
- exports.controllerFor = controllerFor;
207
176
  //# sourceMappingURL=crud-controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"crud-controller.js","sourceRoot":"","sources":["../src/crud-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuE;AAqBvE;IACC,wBAAa,QAAW;QA6HhB,mBAAc,GAAyC,EAAE,CAAA;QA5HhE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAU,EAA0B,CAAA;QACzD,IAAI,CAAC,WAAW,GAAG,IAAI,0BAAU,EAAiB,CAAA;IACnD,CAAC;IAID,oDAA2B,GAA3B;QACC,OAAO,IAAI,CAAA;IACZ,CAAC;IAEM,iCAAkB,GAAzB,UAA2B,YAAoB,EAAE,SAAgC;QAChF,IAAI,CAAC,UAAU,CAAE,YAAY,CAAE,GAAG,UAAE,QAAoB;YACvD,OAAO,IAAI,SAAS,CAAE,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,CAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAE,CAAA;QACxD,CAAC;;;OAAA;IAED,oCAAW,GAAX,UAAa,KAAQ;QACpB,IAAK,IAAI,CAAC,SAAS,KAAK,KAAK,EAAG;YAC/B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;YACtB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;SAC5D;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,sBAAI,oCAAQ;aAIZ;YACC,OAAO,IAAI,CAAC,SAAS,CAAA;QACtB,CAAC;aAND,UAAc,KAAQ;YACrB,IAAI,CAAC,WAAW,CAAE,KAAK,CAAE,CAAA;QAC1B,CAAC;;;OAAA;IAUF,qBAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGqB,wCAAc"}
@@ -0,0 +1,12 @@
1
+ import { EntropicComponent, Model } from 'entropic-bond';
2
+ import { CrudController } from './crud-controller';
3
+ export declare class Test extends EntropicComponent {
4
+ set testProp(value: string);
5
+ get testProp(): string;
6
+ private _testProp;
7
+ }
8
+ export declare class TestController extends CrudController<Test> {
9
+ createDocument(): Test;
10
+ protected getModel(): Model<Test>;
11
+ allRequiredPropertiesFilled(): boolean;
12
+ }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
29
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
30
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
31
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
32
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
33
+ };
34
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ };
43
+ var __generator = (this && this.__generator) || function (thisArg, body) {
44
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
45
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
46
+ function verb(n) { return function (v) { return step([n, v]); }; }
47
+ function step(op) {
48
+ if (f) throw new TypeError("Generator is already executing.");
49
+ while (_) try {
50
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
51
+ if (y = 0, t) op = [op[0] & 2, t.value];
52
+ switch (op[0]) {
53
+ case 0: case 1: t = op; break;
54
+ case 4: _.label++; return { value: op[1], done: false };
55
+ case 5: _.label++; y = op[1]; op = [0]; continue;
56
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
57
+ default:
58
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
59
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
60
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
61
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
62
+ if (t[2]) _.ops.pop();
63
+ _.trys.pop(); continue;
64
+ }
65
+ op = body.call(thisArg, _);
66
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
67
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
68
+ }
69
+ };
70
+ Object.defineProperty(exports, "__esModule", { value: true });
71
+ exports.TestController = exports.Test = void 0;
72
+ var entropic_bond_1 = require("entropic-bond");
73
+ var crud_controller_1 = require("./crud-controller");
74
+ var mockData = {
75
+ Test: {
76
+ test1: {
77
+ __className: 'Test',
78
+ id: 'test1',
79
+ testProp: 'Test prop 1'
80
+ },
81
+ test2: {
82
+ __className: 'Test',
83
+ id: 'test2',
84
+ testProp: 'Test prop 2'
85
+ }
86
+ }
87
+ };
88
+ var Test = /** @class */ (function (_super) {
89
+ __extends(Test, _super);
90
+ function Test() {
91
+ return _super !== null && _super.apply(this, arguments) || this;
92
+ }
93
+ Object.defineProperty(Test.prototype, "testProp", {
94
+ get: function () {
95
+ return this._testProp;
96
+ },
97
+ set: function (value) {
98
+ this.changeProp('testProp', value);
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ __decorate([
104
+ entropic_bond_1.persistent
105
+ ], Test.prototype, "_testProp", void 0);
106
+ Test = __decorate([
107
+ (0, entropic_bond_1.registerPersistentClass)('Test')
108
+ ], Test);
109
+ return Test;
110
+ }(entropic_bond_1.EntropicComponent));
111
+ exports.Test = Test;
112
+ var TestController = /** @class */ (function (_super) {
113
+ __extends(TestController, _super);
114
+ function TestController() {
115
+ return _super !== null && _super.apply(this, arguments) || this;
116
+ }
117
+ TestController.prototype.createDocument = function () {
118
+ return new Test();
119
+ };
120
+ TestController.prototype.getModel = function () {
121
+ return entropic_bond_1.Store.getModel('Test');
122
+ };
123
+ TestController.prototype.allRequiredPropertiesFilled = function () {
124
+ return true;
125
+ };
126
+ return TestController;
127
+ }(crud_controller_1.CrudController));
128
+ exports.TestController = TestController;
129
+ describe('Crud Controller', function () {
130
+ var controller;
131
+ var datasource;
132
+ var onProgress;
133
+ beforeEach(function () {
134
+ datasource = new entropic_bond_1.JsonDataSource(__assign({}, mockData));
135
+ entropic_bond_1.Store.useDataSource(datasource);
136
+ controller = new TestController();
137
+ onProgress = jest.fn();
138
+ controller.onProgress(onProgress);
139
+ });
140
+ describe('Long operations', function () {
141
+ beforeEach(function () {
142
+ datasource.simulateDelay(50);
143
+ });
144
+ it('should notify busy on delete', function () { return __awaiter(void 0, void 0, void 0, function () {
145
+ var promise;
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ promise = controller.deleteDocument();
150
+ expect(onProgress).toHaveBeenLastCalledWith(expect.objectContaining({ busy: true }));
151
+ return [4 /*yield*/, promise];
152
+ case 1:
153
+ _a.sent();
154
+ expect(onProgress).toHaveBeenLastCalledWith(expect.objectContaining({ busy: false }));
155
+ return [2 /*return*/];
156
+ }
157
+ });
158
+ }); });
159
+ it('should notify busy on store', function () { return __awaiter(void 0, void 0, void 0, function () {
160
+ var promise;
161
+ return __generator(this, function (_a) {
162
+ switch (_a.label) {
163
+ case 0:
164
+ promise = controller.storeDocument();
165
+ expect(onProgress).toHaveBeenLastCalledWith(expect.objectContaining({ busy: true }));
166
+ return [4 /*yield*/, promise];
167
+ case 1:
168
+ _a.sent();
169
+ expect(onProgress).toHaveBeenLastCalledWith(expect.objectContaining({ busy: false }));
170
+ return [2 /*return*/];
171
+ }
172
+ });
173
+ }); });
174
+ });
175
+ });
176
+ //# sourceMappingURL=crud-controller.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crud-controller.spec.js","sourceRoot":"","sources":["../src/crud-controller.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAoH;AACpH,qDAAkD;AAElD,IAAM,QAAQ,GAAG;IAChB,IAAI,EAAE;QACL,KAAK,EAAC;YACL,WAAW,EAAE,MAAM;YACnB,EAAE,EAAE,OAAO;YACX,QAAQ,EAAE,aAAa;SACvB;QACD,KAAK,EAAC;YACL,WAAW,EAAE,MAAM;YACnB,EAAE,EAAE,OAAO;YACX,QAAQ,EAAE,aAAa;SACvB;KACD;CACD,CAAA;AAGD;IAA0B,wBAAiB;IAA3C;;IAUA,CAAC;IATA,sBAAI,0BAAQ;aAIZ;YACC,OAAO,IAAI,CAAC,SAAS,CAAA;QACtB,CAAC;aAND,UAAc,KAAa;YAC1B,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,CAAE,CAAA;QACpC,CAAC;;;OAAA;IAMW;QAAX,0BAAU;2CAA0B;IATzB,IAAI;QADhB,IAAA,uCAAuB,EAAE,MAAM,CAAE;OACrB,IAAI,CAUhB;IAAD,WAAC;CAAA,AAVD,CAA0B,iCAAiB,GAU1C;AAVY,oBAAI;AAYjB;IAAoC,kCAAoB;IAAxD;;IAaA,CAAC;IAXA,uCAAc,GAAd;QACC,OAAO,IAAI,IAAI,EAAE,CAAA;IAClB,CAAC;IAES,iCAAQ,GAAlB;QACC,OA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E,CAAC,wBAAwB,CAAE,MAAM,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAE,CAAA;wBACxF,qBAAM,OAAO,EAAA;;wBAAb,SAAa,CAAA;wBACb,MAAM,CAAE,UAAU,CAAE,CAAC,wBAAwB,CAAE,MAAM,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAE,CAAA;;;;aACzF,CAAC,CAAA;IAEH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -11,9 +11,8 @@ export interface CrudCardProps<T extends Persistent> {
11
11
  onSelect?: (document: T) => void;
12
12
  onDelete?: (document: T) => void;
13
13
  }
14
- declare type ProgressBarElement = (progress: number) => JSX.Element;
15
14
  export interface CrudContentViewProps<T extends Persistent> {
16
- controller: CrudController<T>;
15
+ document: T;
17
16
  submitButtonCaption: string;
18
17
  onSubmit: (document: T) => void;
19
18
  onCancel: () => void;
@@ -27,9 +26,8 @@ export interface CrudPanelLabels {
27
26
  }
28
27
  export declare type Layout = 'formOrItems' | 'itemsAlways' | 'formAndItems';
29
28
  interface CrudPanelState<T extends Persistent> {
30
- documents: T[];
29
+ documents: T[] | readonly T[];
31
30
  mode: Mode;
32
- progress: number;
33
31
  }
34
32
  interface CrudPanelProps<T extends Persistent> {
35
33
  controller: CrudController<T>;
@@ -41,7 +39,6 @@ interface CrudPanelProps<T extends Persistent> {
41
39
  ];
42
40
  className?: string;
43
41
  cardAddButton?: boolean | JSX.Element;
44
- progressBar?: ProgressBarElement;
45
42
  header?: string | JSX.Element;
46
43
  footer?: string | JSX.Element;
47
44
  }
@@ -56,6 +53,5 @@ export declare class CrudPanel<T extends Persistent> extends Component<CrudPanel
56
53
  private invokeDetailViewChild;
57
54
  render(): JSX.Element;
58
55
  private unsubscriber;
59
- private progressUnsubscriber;
60
56
  }
61
57
  export {};