ngx-emfular-integration 0.0.2 → 0.0.4
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable, Component, InjectionToken, Inject } from '@angular/core';
|
|
3
|
+
import { Deserializer } from 'emfular';
|
|
3
4
|
import * as i1 from 'ngx-emfular-helper';
|
|
4
5
|
import { HistoryService } from 'ngx-emfular-helper';
|
|
5
6
|
|
|
@@ -42,47 +43,64 @@ function provideHistoryForModel(prefix = 'history_', bufferSize = 50) {
|
|
|
42
43
|
class ModelService {
|
|
43
44
|
historyService;
|
|
44
45
|
ioService;
|
|
46
|
+
modelClass;
|
|
45
47
|
_model;
|
|
46
48
|
get model() {
|
|
47
49
|
return this._model;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
set model(model) {
|
|
52
|
+
this._model = this.adjustModel(model);
|
|
53
|
+
this.adaptToModel();
|
|
54
|
+
}
|
|
55
|
+
constructor(historyService, ioService, modelClass) {
|
|
50
56
|
this.historyService = historyService;
|
|
51
57
|
this.ioService = ioService;
|
|
58
|
+
this.modelClass = modelClass;
|
|
52
59
|
//should actually initialize a model:this._model = new M;
|
|
60
|
+
this._model = new modelClass();
|
|
53
61
|
this.historyService.state$.subscribe(state => {
|
|
54
62
|
if (state) {
|
|
55
|
-
this.
|
|
63
|
+
this.applyJson(state);
|
|
56
64
|
}
|
|
57
65
|
});
|
|
58
66
|
}
|
|
67
|
+
//default implementation to override if you need any normalization on a model before setting it
|
|
68
|
+
adjustModel(model) {
|
|
69
|
+
return model;
|
|
70
|
+
}
|
|
71
|
+
//default implementation to override if you need adaptation of surroundings,
|
|
72
|
+
// e.g. other attributes, notifications, signals etc
|
|
73
|
+
adaptToModel() { }
|
|
74
|
+
// override by either a fixed string or sth from the current model itself
|
|
75
|
+
fileTitle() {
|
|
76
|
+
return "model";
|
|
77
|
+
}
|
|
59
78
|
serialize() {
|
|
60
79
|
return this.model.toJson();
|
|
61
80
|
}
|
|
81
|
+
deserialize(modelJson) {
|
|
82
|
+
let modelEClass = new this.modelClass().getEClass();
|
|
83
|
+
return Deserializer.fromJSON(modelJson, modelEClass);
|
|
84
|
+
}
|
|
62
85
|
saveCurrentState() {
|
|
63
86
|
this.historyService.save(this.serialize());
|
|
64
87
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
return m;
|
|
69
|
-
}
|
|
70
|
-
load(modelJson) {
|
|
71
|
-
const model = this.applyModel(modelJson);
|
|
72
|
-
this.saveCurrentState();
|
|
73
|
-
return model;
|
|
88
|
+
applyJson(modelJson) {
|
|
89
|
+
this._model = this.deserialize(modelJson);
|
|
90
|
+
return this.model;
|
|
74
91
|
}
|
|
75
92
|
loadFromFile(event) {
|
|
76
93
|
this.ioService.loadStringFromFile(event).then(txt => {
|
|
77
94
|
//todo insert detection code for wrong files (no json, not appropriately structured
|
|
78
|
-
this.
|
|
95
|
+
this.applyJson(JSON.parse(txt));
|
|
96
|
+
this.saveCurrentState();
|
|
79
97
|
});
|
|
80
98
|
}
|
|
81
99
|
save() {
|
|
82
100
|
const jsonString = JSON.stringify(this.serialize());
|
|
83
101
|
this.ioService.saveJson(jsonString, this.fileTitle());
|
|
84
102
|
}
|
|
85
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, deps:
|
|
103
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, deps: "invalid", target: i0.ɵɵFactoryTarget.Injectable });
|
|
86
104
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, providedIn: 'root' });
|
|
87
105
|
}
|
|
88
106
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, decorators: [{
|
|
@@ -93,7 +111,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
|
|
|
93
111
|
}], ctorParameters: () => [{ type: i1.HistoryService, decorators: [{
|
|
94
112
|
type: Inject,
|
|
95
113
|
args: [HISTORY_SERVICE]
|
|
96
|
-
}] }, { type: i1.IoService }] });
|
|
114
|
+
}] }, { type: i1.IoService }, { type: undefined }] });
|
|
97
115
|
|
|
98
116
|
/*
|
|
99
117
|
* Public API Surface of ngx-emfular-integration
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-emfular-integration.mjs","sources":["../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.service.ts","../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.component.ts","../../../projects/ngx-emfular-integration/src/lib/model.service.ts","../../../projects/ngx-emfular-integration/src/public-api.ts","../../../projects/ngx-emfular-integration/src/ngx-emfular-integration.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxEmfularIntegrationService {\n\n constructor() { }\n}\n","import { Component } from '@angular/core';\n\n@Component({\n selector: 'lib-ngx-emfular-integration',\n imports: [],\n template: `\n <p>\n ngx-emfular-integration works!\n </p>\n `,\n styles: ``\n})\nexport class NgxEmfularIntegrationComponent {\n\n}\n","import {Inject, Injectable, InjectionToken} from '@angular/core';\nimport {JsonOf, Referencable} from \"emfular\";\nimport {HistoryService, IoService} from \"ngx-emfular-helper\";\n\nexport const HISTORY_SERVICE = new InjectionToken<HistoryService<any>>(\n 'HistoryService'\n);\nexport function provideHistoryForModel<M>(\n prefix: string = 'history_',\n bufferSize: number = 50\n) {\n return {\n provide: HISTORY_SERVICE,\n useFactory: () => new HistoryService<JsonOf<M>>(prefix, bufferSize)\n };\n}\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport abstract class ModelService<M extends Referencable<any>> {\n\n
|
|
1
|
+
{"version":3,"file":"ngx-emfular-integration.mjs","sources":["../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.service.ts","../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.component.ts","../../../projects/ngx-emfular-integration/src/lib/model.service.ts","../../../projects/ngx-emfular-integration/src/public-api.ts","../../../projects/ngx-emfular-integration/src/ngx-emfular-integration.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxEmfularIntegrationService {\n\n constructor() { }\n}\n","import { Component } from '@angular/core';\n\n@Component({\n selector: 'lib-ngx-emfular-integration',\n imports: [],\n template: `\n <p>\n ngx-emfular-integration works!\n </p>\n `,\n styles: ``\n})\nexport class NgxEmfularIntegrationComponent {\n\n}\n","import {Inject, Injectable, InjectionToken} from '@angular/core';\nimport {Deserializer, JsonDeserializable, JsonOf, Referencable} from \"emfular\";\nimport {HistoryService, IoService} from \"ngx-emfular-helper\";\n\nexport const HISTORY_SERVICE = new InjectionToken<HistoryService<any>>(\n 'HistoryService'\n);\nexport function provideHistoryForModel<M>(\n prefix: string = 'history_',\n bufferSize: number = 50\n) {\n return {\n provide: HISTORY_SERVICE,\n useFactory: () => new HistoryService<JsonOf<M>>(prefix, bufferSize)\n };\n}\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport abstract class ModelService<M extends Referencable<any>> {\n\n private _model!: M\n get model(): M {\n return this._model;\n }\n protected set model(model: M) {\n this._model = this.adjustModel(model);\n this.adaptToModel()\n }\n\n protected constructor(\n @Inject(HISTORY_SERVICE) readonly historyService: HistoryService<JsonOf<M>>,\n readonly ioService: IoService,\n protected readonly modelClass: JsonDeserializable<M>,\n ) {\n //should actually initialize a model:this._model = new M;\n this._model = new modelClass()\n this.historyService.state$.subscribe(state => {\n if (state) {\n this.applyJson(state);\n }\n });\n }\n\n //default implementation to override if you need any normalization on a model before setting it\n adjustModel(model: M): M {\n return model;\n }\n\n //default implementation to override if you need adaptation of surroundings,\n // e.g. other attributes, notifications, signals etc\n adaptToModel() {}\n\n // override by either a fixed string or sth from the current model itself\n public fileTitle(): string {\n return \"model\"\n }\n\n serialize(): JsonOf<M> {\n return this.model.toJson()\n }\n\n deserialize(modelJson: JsonOf<M>): M {\n let modelEClass = new this.modelClass().getEClass();\n return Deserializer.fromJSON<M>(modelJson, modelEClass);\n }\n\n saveCurrentState() {\n this.historyService.save(this.serialize())\n }\n\n protected applyJson(modelJson: JsonOf<M>): M {\n this._model = this.deserialize(modelJson);\n return this.model;\n }\n\n loadFromFile(event: Event) {\n this.ioService.loadStringFromFile(event).then(txt => {\n //todo insert detection code for wrong files (no json, not appropriately structured\n this.applyJson(JSON.parse(txt));\n this.saveCurrentState()\n });\n }\n\n save() {\n const jsonString = JSON.stringify(this.serialize());\n this.ioService.saveJson(jsonString, this.fileTitle())\n }\n\n}\n","/*\n * Public API Surface of ngx-emfular-integration\n */\n\nexport * from './lib/ngx-emfular-integration.service';\nexport * from './lib/ngx-emfular-integration.component';\nexport * from './lib/model.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAKa,4BAA4B,CAAA;AAEvC,IAAA,WAAA,GAAA;uGAFW,4BAA4B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAA5B,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,4BAA4B,cAF3B,MAAM,EAAA,CAAA;;2FAEP,4BAA4B,EAAA,UAAA,EAAA,CAAA;kBAHxC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;MCQY,8BAA8B,CAAA;uGAA9B,8BAA8B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAA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AAA,SAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAZ,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,YAAY,cAFpB,MAAM,EAAA,CAAA;;2FAEE,YAAY,EAAA,UAAA,EAAA,CAAA;kBAHjC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;0BAaM,MAAM;2BAAC,eAAe;;;ACjC7B;;AAEG;;ACFH;;AAEG;;;;"}
|
package/lib/model.service.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import { JsonOf, Referencable } from "emfular";
|
|
2
|
+
import { JsonDeserializable, JsonOf, Referencable } from "emfular";
|
|
3
3
|
import { HistoryService, IoService } from "ngx-emfular-helper";
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
export declare const HISTORY_SERVICE: InjectionToken<HistoryService<any>>;
|
|
@@ -8,17 +8,20 @@ export declare function provideHistoryForModel<M>(prefix?: string, bufferSize?:
|
|
|
8
8
|
useFactory: () => HistoryService<JsonOf<M>>;
|
|
9
9
|
};
|
|
10
10
|
export declare abstract class ModelService<M extends Referencable<any>> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
protected
|
|
11
|
+
readonly historyService: HistoryService<JsonOf<M>>;
|
|
12
|
+
readonly ioService: IoService;
|
|
13
|
+
protected readonly modelClass: JsonDeserializable<M>;
|
|
14
|
+
private _model;
|
|
14
15
|
get model(): M;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
protected set model(model: M);
|
|
17
|
+
protected constructor(historyService: HistoryService<JsonOf<M>>, ioService: IoService, modelClass: JsonDeserializable<M>);
|
|
18
|
+
adjustModel(model: M): M;
|
|
19
|
+
adaptToModel(): void;
|
|
20
|
+
fileTitle(): string;
|
|
18
21
|
serialize(): JsonOf<M>;
|
|
22
|
+
deserialize(modelJson: JsonOf<M>): M;
|
|
19
23
|
saveCurrentState(): void;
|
|
20
|
-
protected
|
|
21
|
-
load(modelJson: JsonOf<M>): M;
|
|
24
|
+
protected applyJson(modelJson: JsonOf<M>): M;
|
|
22
25
|
loadFromFile(event: Event): void;
|
|
23
26
|
save(): void;
|
|
24
27
|
static ɵfac: i0.ɵɵFactoryDeclaration<ModelService<any>, never>;
|