@entropic-bond/crud-panel 1.1.0 → 2.2.0
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 +1 -1
- package/lib/crud-controller.d.ts +18 -22
- package/lib/crud-controller.js +93 -68
- package/lib/crud-controller.js.map +1 -1
- package/lib/crud-controller.spec.d.ts +12 -0
- package/lib/crud-controller.spec.js +176 -0
- package/lib/crud-controller.spec.js.map +1 -0
- package/lib/crud-panel.d.ts +7 -4
- package/lib/crud-panel.js +40 -31
- package/lib/crud-panel.js.map +1 -1
- package/lib/crud-panel.spec.js +66 -80
- package/lib/crud-panel.spec.js.map +1 -1
- package/lib/progress-controller.d.ts +22 -0
- package/lib/progress-controller.js +35 -0
- package/lib/progress-controller.js.map +1 -0
- package/lib/progress-controller.spec.d.ts +1 -0
- package/lib/progress-controller.spec.js +139 -0
- package/lib/progress-controller.spec.js.map +1 -0
- package/package.json +15 -15
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js +0 -9
- package/lib/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# Crud Panel
|
|
1
|
+
# Crud Panel 2.0
|
package/lib/crud-controller.d.ts
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import { Callback, Persistent, Model } from 'entropic-bond';
|
|
1
|
+
import { Callback, Persistent, Model, Observable } from 'entropic-bond';
|
|
2
|
+
import { ProgressController, ProgressEvent } from './progress-controller';
|
|
2
3
|
export interface CrudControllerEvent<T extends Persistent> {
|
|
3
4
|
documentChanged?: T;
|
|
4
5
|
documentCollection?: T[];
|
|
5
6
|
}
|
|
6
7
|
export declare abstract class CrudController<T extends Persistent> {
|
|
7
|
-
constructor(document
|
|
8
|
+
constructor(document?: T);
|
|
9
|
+
abstract allRequiredPropertiesFilled(): boolean;
|
|
10
|
+
protected abstract createDocument(): T;
|
|
8
11
|
protected abstract getModel(): Model<T>;
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
protected storeDoc(): Promise<void>;
|
|
13
|
+
protected deleteDoc(): Promise<void>;
|
|
14
|
+
protected findDocs(limit: number): Promise<T[]>;
|
|
11
15
|
onChange(observer: Callback<CrudControllerEvent<T>>): import("entropic-bond").Unsubscriber;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
getDocumentCollection(): Promise<T[]>;
|
|
16
|
+
newDocument(): CrudController<T>;
|
|
17
|
+
storeDocument(): Promise<void>;
|
|
18
|
+
deleteDocument(): Promise<void>;
|
|
19
|
+
documentCollection(limit?: number): Promise<T[]>;
|
|
20
|
+
onProgress(observer: Callback<ProgressEvent>): import("entropic-bond").Unsubscriber;
|
|
18
21
|
protected get model(): Model<T>;
|
|
19
|
-
|
|
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>>;
|
|
20
27
|
private _model;
|
|
21
28
|
private _document;
|
|
22
|
-
private static _factories;
|
|
23
29
|
}
|
|
24
|
-
declare type ControllerConstructor = new (document: Persistent) => CrudController<Persistent>;
|
|
25
|
-
/**
|
|
26
|
-
* Decorator to associate this controller with the document type that it manages.
|
|
27
|
-
* This will allow to create a controller from a given document automatically.
|
|
28
|
-
*
|
|
29
|
-
* @param documentTypeName the document type name that this controller is
|
|
30
|
-
* dessigned for.
|
|
31
|
-
*/
|
|
32
|
-
export declare function controllerFor(documentTypeName: string): (constructor: ControllerConstructor) => void;
|
|
33
|
-
export {};
|
package/lib/crud-controller.js
CHANGED
|
@@ -36,93 +36,115 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.CrudController = void 0;
|
|
40
40
|
var entropic_bond_1 = require("entropic-bond");
|
|
41
|
+
var progress_controller_1 = require("./progress-controller");
|
|
41
42
|
var CrudController = /** @class */ (function () {
|
|
42
43
|
function CrudController(document) {
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
44
|
+
this.progressController = new progress_controller_1.ProgressController();
|
|
45
|
+
this.onChangeHdl = new entropic_bond_1.Observable();
|
|
46
|
+
this._document = document || this.createDocument();
|
|
45
47
|
}
|
|
46
|
-
CrudController.
|
|
47
|
-
this.
|
|
48
|
-
return new construct(document);
|
|
49
|
-
};
|
|
48
|
+
CrudController.prototype.storeDoc = function () {
|
|
49
|
+
return this.model.save(this.document);
|
|
50
50
|
};
|
|
51
|
-
CrudController.
|
|
52
|
-
|
|
53
|
-
throw new Error("You should register " + document.className + " controller prior to use in the CRUD system");
|
|
54
|
-
var factory = this._factories[document.className];
|
|
55
|
-
return factory(document);
|
|
51
|
+
CrudController.prototype.deleteDoc = function () {
|
|
52
|
+
return this.model.delete(this.document.id);
|
|
56
53
|
};
|
|
57
|
-
CrudController.prototype.
|
|
58
|
-
return this.
|
|
54
|
+
CrudController.prototype.findDocs = function (limit) {
|
|
55
|
+
return this.model.find().limit(limit).get();
|
|
59
56
|
};
|
|
60
|
-
CrudController.prototype.
|
|
61
|
-
this.
|
|
62
|
-
this._onChange.notify({ documentChanged: this._document });
|
|
63
|
-
return this._document;
|
|
57
|
+
CrudController.prototype.onChange = function (observer) {
|
|
58
|
+
return this.onChangeHdl.subscribe(observer);
|
|
64
59
|
};
|
|
65
|
-
CrudController.prototype.
|
|
66
|
-
|
|
67
|
-
this._document = value;
|
|
68
|
-
this._onChange.notify({ documentChanged: value });
|
|
69
|
-
}
|
|
70
|
-
return this;
|
|
60
|
+
CrudController.prototype.newDocument = function () {
|
|
61
|
+
return this.setDocument(this.createDocument());
|
|
71
62
|
};
|
|
72
|
-
|
|
73
|
-
get: function () {
|
|
74
|
-
return this._document;
|
|
75
|
-
},
|
|
76
|
-
enumerable: false,
|
|
77
|
-
configurable: true
|
|
78
|
-
});
|
|
79
|
-
CrudController.prototype.storeDocument = function (document) {
|
|
63
|
+
CrudController.prototype.storeDocument = function () {
|
|
80
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var _a, _b;
|
|
65
|
+
var progressStage, _a, _b;
|
|
82
66
|
var _c;
|
|
83
67
|
return __generator(this, function (_d) {
|
|
84
68
|
switch (_d.label) {
|
|
85
|
-
case 0:
|
|
69
|
+
case 0:
|
|
70
|
+
progressStage = 'Saving main document';
|
|
71
|
+
_d.label = 1;
|
|
86
72
|
case 1:
|
|
87
|
-
_d.
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
_c = {
|
|
91
|
-
documentChanged: this._document !== document ? document : undefined
|
|
92
|
-
};
|
|
93
|
-
return [4 /*yield*/, this.getDocumentCollection()];
|
|
73
|
+
_d.trys.push([1, , 4, 5]);
|
|
74
|
+
this.progressController.notifyBusy(true, progressStage);
|
|
75
|
+
return [4 /*yield*/, this.storeDoc()];
|
|
94
76
|
case 2:
|
|
77
|
+
_d.sent();
|
|
78
|
+
_b = (_a = this.onChangeHdl).notify;
|
|
79
|
+
_c = {};
|
|
80
|
+
return [4 /*yield*/, this.documentCollection()];
|
|
81
|
+
case 3:
|
|
95
82
|
_b.apply(_a, [(_c.documentCollection = _d.sent(),
|
|
96
83
|
_c)]);
|
|
97
|
-
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*/];
|
|
98
89
|
}
|
|
99
90
|
});
|
|
100
91
|
});
|
|
101
92
|
};
|
|
102
|
-
CrudController.prototype.deleteDocument = function (
|
|
93
|
+
CrudController.prototype.deleteDocument = function () {
|
|
103
94
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var _a, _b;
|
|
95
|
+
var progressStage, _a, _b;
|
|
105
96
|
var _c;
|
|
106
97
|
return __generator(this, function (_d) {
|
|
107
98
|
switch (_d.label) {
|
|
108
|
-
case 0:
|
|
99
|
+
case 0:
|
|
100
|
+
progressStage = 'Delete main document';
|
|
101
|
+
_d.label = 1;
|
|
109
102
|
case 1:
|
|
110
|
-
_d.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
documentChanged: document
|
|
114
|
-
};
|
|
115
|
-
return [4 /*yield*/, this.getDocumentCollection()];
|
|
103
|
+
_d.trys.push([1, , 4, 5]);
|
|
104
|
+
this.progressController.notifyBusy(true, progressStage);
|
|
105
|
+
return [4 /*yield*/, this.deleteDoc()];
|
|
116
106
|
case 2:
|
|
107
|
+
_d.sent();
|
|
108
|
+
_b = (_a = this.onChangeHdl).notify;
|
|
109
|
+
_c = {};
|
|
110
|
+
return [4 /*yield*/, this.documentCollection()];
|
|
111
|
+
case 3:
|
|
117
112
|
_b.apply(_a, [(_c.documentCollection = _d.sent(),
|
|
118
113
|
_c)]);
|
|
119
|
-
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*/];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
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];
|
|
120
142
|
}
|
|
121
143
|
});
|
|
122
144
|
});
|
|
123
145
|
};
|
|
124
|
-
CrudController.prototype.
|
|
125
|
-
return this.
|
|
146
|
+
CrudController.prototype.onProgress = function (observer) {
|
|
147
|
+
return this.progressController.onProgress(observer);
|
|
126
148
|
};
|
|
127
149
|
Object.defineProperty(CrudController.prototype, "model", {
|
|
128
150
|
get: function () {
|
|
@@ -131,21 +153,24 @@ var CrudController = /** @class */ (function () {
|
|
|
131
153
|
enumerable: false,
|
|
132
154
|
configurable: true
|
|
133
155
|
});
|
|
134
|
-
CrudController.
|
|
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
|
+
});
|
|
135
173
|
return CrudController;
|
|
136
174
|
}());
|
|
137
175
|
exports.CrudController = CrudController;
|
|
138
|
-
/**
|
|
139
|
-
* Decorator to associate this controller with the document type that it manages.
|
|
140
|
-
* This will allow to create a controller from a given document automatically.
|
|
141
|
-
*
|
|
142
|
-
* @param documentTypeName the document type name that this controller is
|
|
143
|
-
* dessigned for.
|
|
144
|
-
*/
|
|
145
|
-
function controllerFor(documentTypeName) {
|
|
146
|
-
return function (constructor) {
|
|
147
|
-
CrudController.registerController(documentTypeName, constructor);
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
exports.controllerFor = controllerFor;
|
|
151
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;
|
|
1
|
+
{"version":3,"file":"crud-controller.js","sourceRoot":"","sources":["../src/crud-controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuE;AACvE,6DAAyE;AAOzE;IACC,wBAAa,QAAY;QAkGf,uBAAkB,GAAuB,IAAI,wCAAkB,EAAE,CAAA;QACjE,gBAAW,GAAuC,IAAI,0BAAU,EAA0B,CAAA;QAlGnG,IAAI,CAAC,SAAS,GAAG,QAAQ,IAAI,IAAI,CAAC,cAAc,EAAE,CAAA;IACnD,CAAC;IAMS,iCAAQ,GAAlB;QACC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAE,IAAI,CAAC,QAAQ,CAAE,CAAA;IACxC,CAAC;IAES,kCAAS,GAAnB;QACC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAE,CAAA;IAC7C,CAAC;IAES,iCAAQ,GAAlB,UAAoB,KAAa;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAE,KAAK,CAAE,CAAC,GAAG,EAAE,CAAA;IAC9C,CAAC;IAED,iCAAQ,GAAR,UAAU,QAA0C;QACnD,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAE,QAAQ,CAAE,CAAA;IAC9C,CAAC;IAED,oCAAW,GAAX;QACC,OAAO,IAAI,CAAC,WAAW,CAAE,IAAI,CAAC,cAAc,EAAE,CAAE,CAAA;IACjD,CAAC;IAEK,sCAAa,GAAnB;;;;;;;wBACO,aAAa,GAAG,sBA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;IAED,mCAAU,GAAV,UAAY,QAAiC;QAC5C,OAAO,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAE,QAAQ,CAAE,CAAA;IACtD,CAAC;IAED,sBAAc,iCAAK;aAAnB;YACC,OAAO,IAAI,CAAC,MAAM,IAAI,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,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AC,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;QAEF,EAAE,CAAE,6BAA6B,EAAE;;;;;wBAC5B,OAAO,GAAG,UAAU,CAAC,aAAa,EAAE,CAAA;wBAC1C,MAAM,CAAE,UAAU,CAAE,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"}
|
package/lib/crud-panel.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ declare enum Mode {
|
|
|
8
8
|
}
|
|
9
9
|
export interface CrudCardProps<T extends Persistent> {
|
|
10
10
|
document: T;
|
|
11
|
-
onSelect
|
|
12
|
-
onDelete
|
|
11
|
+
onSelect?: (document: T) => void;
|
|
12
|
+
onDelete?: (document: T) => void;
|
|
13
13
|
}
|
|
14
14
|
export interface CrudContentViewProps<T extends Persistent> {
|
|
15
|
-
|
|
15
|
+
document: T;
|
|
16
16
|
submitButtonCaption: string;
|
|
17
17
|
onSubmit: (document: T) => void;
|
|
18
18
|
onCancel: () => void;
|
|
@@ -24,7 +24,7 @@ export interface CrudPanelLabels {
|
|
|
24
24
|
documentsInCollectionCaption: string;
|
|
25
25
|
noDocumentsFoundLabel: string;
|
|
26
26
|
}
|
|
27
|
-
export declare type Layout = 'formOrItems' | '
|
|
27
|
+
export declare type Layout = 'formOrItems' | 'itemsAlways' | 'formAndItems';
|
|
28
28
|
interface CrudPanelState<T extends Persistent> {
|
|
29
29
|
documents: T[];
|
|
30
30
|
mode: Mode;
|
|
@@ -38,6 +38,9 @@ interface CrudPanelProps<T extends Persistent> {
|
|
|
38
38
|
((props: CrudCardProps<T>) => ReactElement) | ReactElement<CrudCardProps<T>>
|
|
39
39
|
];
|
|
40
40
|
className?: string;
|
|
41
|
+
cardAddButton?: boolean | JSX.Element;
|
|
42
|
+
header?: string | JSX.Element;
|
|
43
|
+
footer?: string | JSX.Element;
|
|
41
44
|
}
|
|
42
45
|
export declare class CrudPanel<T extends Persistent> extends Component<CrudPanelProps<T>, CrudPanelState<T>> {
|
|
43
46
|
constructor(props: CrudPanelProps<T>);
|