@smartbit4all/ng-client 1.1.19 → 1.1.21
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/esm2020/lib/session/smart-session.service.mjs +29 -23
- package/esm2020/lib/view-context/smart-view-context.service.mjs +21 -14
- package/fesm2015/smartbit4all-ng-client.mjs +132 -125
- package/fesm2015/smartbit4all-ng-client.mjs.map +1 -1
- package/fesm2020/smartbit4all-ng-client.mjs +46 -33
- package/fesm2020/smartbit4all-ng-client.mjs.map +1 -1
- package/lib/session/smart-session.service.d.ts +4 -4
- package/lib/view-context/smart-view-context.service.d.ts +3 -3
- package/package.json +1 -1
- package/smartbit4all-ng-client-1.1.21.tgz +0 -0
- package/smartbit4all-ng-client-1.1.19.tgz +0 -0
|
@@ -679,7 +679,7 @@ class SmartSessionService {
|
|
|
679
679
|
this.headerParams = new Array();
|
|
680
680
|
this.headersUpdated = new Subject();
|
|
681
681
|
// Locale
|
|
682
|
-
this.localStorageLocaleName =
|
|
682
|
+
this.localStorageLocaleName = 'locale';
|
|
683
683
|
this.localeChanged = new Subject();
|
|
684
684
|
this.sessionExpiracyChanged = new Subject();
|
|
685
685
|
}
|
|
@@ -706,16 +706,24 @@ class SmartSessionService {
|
|
|
706
706
|
});
|
|
707
707
|
}
|
|
708
708
|
addHeaderParam(headerParam) {
|
|
709
|
-
|
|
709
|
+
console.log('addHeaderParam called ');
|
|
710
|
+
console.log(headerParam);
|
|
711
|
+
if (this.headerParams.find((h) => h.headerName === headerParam.headerName)) {
|
|
712
|
+
let index = this.headerParams.findIndex((h) => h.headerName === headerParam.headerName);
|
|
713
|
+
this.headerParams[index].value = headerParam.value;
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
716
|
+
this.headerParams.push(headerParam);
|
|
717
|
+
}
|
|
710
718
|
this.headersUpdated.next();
|
|
711
719
|
}
|
|
712
720
|
setUpTokenForSessionService() {
|
|
713
|
-
if (this.headerParams.find((header) => header.headerName ===
|
|
714
|
-
let index = this.headerParams.findIndex((header) => header.headerName ===
|
|
721
|
+
if (this.headerParams.find((header) => header.headerName === 'Authorization')) {
|
|
722
|
+
let index = this.headerParams.findIndex((header) => header.headerName === 'Authorization');
|
|
715
723
|
this.headerParams[index].value = `Bearer ${this.token}`;
|
|
716
724
|
}
|
|
717
725
|
else {
|
|
718
|
-
this.addHeaderParam({ headerName:
|
|
726
|
+
this.addHeaderParam({ headerName: 'Authorization', value: `Bearer ${this.token}` });
|
|
719
727
|
}
|
|
720
728
|
}
|
|
721
729
|
setUrl(url) {
|
|
@@ -723,7 +731,7 @@ class SmartSessionService {
|
|
|
723
731
|
}
|
|
724
732
|
getBasePath() {
|
|
725
733
|
if (!this.basePath) {
|
|
726
|
-
throw new Error(
|
|
734
|
+
throw new Error('BasePath has not been set in SmartSessionService!');
|
|
727
735
|
}
|
|
728
736
|
return this.basePath;
|
|
729
737
|
}
|
|
@@ -732,10 +740,10 @@ class SmartSessionService {
|
|
|
732
740
|
}
|
|
733
741
|
saveTokenToLocalStorage() {
|
|
734
742
|
if (this.sessionInfoData && this.cookieName) {
|
|
735
|
-
localStorage.setItem(
|
|
743
|
+
localStorage.setItem('token', this.sessionInfoData.sid);
|
|
736
744
|
if (this.sessionInfoData.refreshToken &&
|
|
737
|
-
this.sessionInfoData.refreshToken !== localStorage.getItem(
|
|
738
|
-
localStorage.setItem(
|
|
745
|
+
this.sessionInfoData.refreshToken !== localStorage.getItem('refreshToken')) {
|
|
746
|
+
localStorage.setItem('refreshToken', this.sessionInfoData.refreshToken);
|
|
739
747
|
}
|
|
740
748
|
this.cookieService.set(this.cookieName, this.token);
|
|
741
749
|
}
|
|
@@ -748,20 +756,18 @@ class SmartSessionService {
|
|
|
748
756
|
}
|
|
749
757
|
checkStatements() {
|
|
750
758
|
if (!this.basePath) {
|
|
751
|
-
throw new Error(
|
|
759
|
+
throw new Error('The url of the backend api has not been set!');
|
|
752
760
|
}
|
|
753
761
|
else if (!this.cookieName) {
|
|
754
|
-
throw new Error(
|
|
762
|
+
throw new Error('The name of the cookie required by the backend has not been set!');
|
|
755
763
|
}
|
|
756
764
|
}
|
|
757
765
|
initialize() {
|
|
758
766
|
return __awaiter(this, void 0, void 0, function* () {
|
|
759
767
|
this.checkStatements();
|
|
760
|
-
let tokenFromLocalStorage = localStorage.getItem(
|
|
768
|
+
let tokenFromLocalStorage = localStorage.getItem('token');
|
|
761
769
|
let tokenFromCookies = this.cookieService.get(this.cookieName);
|
|
762
|
-
if (tokenFromLocalStorage &&
|
|
763
|
-
tokenFromCookies &&
|
|
764
|
-
tokenFromLocalStorage === tokenFromCookies) {
|
|
770
|
+
if (tokenFromLocalStorage && tokenFromCookies && tokenFromLocalStorage === tokenFromCookies) {
|
|
765
771
|
this.token = tokenFromLocalStorage;
|
|
766
772
|
this.setUpTokenForSessionService();
|
|
767
773
|
try {
|
|
@@ -807,7 +813,7 @@ class SmartSessionService {
|
|
|
807
813
|
}
|
|
808
814
|
refreshSession() {
|
|
809
815
|
return __awaiter(this, void 0, void 0, function* () {
|
|
810
|
-
let refreshToken = localStorage.getItem(
|
|
816
|
+
let refreshToken = localStorage.getItem('refreshToken');
|
|
811
817
|
if (!refreshToken) {
|
|
812
818
|
return yield this.startSession();
|
|
813
819
|
}
|
|
@@ -819,7 +825,7 @@ class SmartSessionService {
|
|
|
819
825
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
820
826
|
if (error.error &&
|
|
821
827
|
error.error.code &&
|
|
822
|
-
error.error.code ===
|
|
828
|
+
error.error.code === 'session.refreshtoken.invalid') {
|
|
823
829
|
yield this.startSession();
|
|
824
830
|
}
|
|
825
831
|
}));
|
|
@@ -867,7 +873,7 @@ class SmartSessionService {
|
|
|
867
873
|
}
|
|
868
874
|
return this.sessionInfoData.locale;
|
|
869
875
|
}
|
|
870
|
-
throw new Error(
|
|
876
|
+
throw new Error('There is no SessionInfoData or locale is undefined.');
|
|
871
877
|
}
|
|
872
878
|
changeLocale(locale) {
|
|
873
879
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -880,11 +886,11 @@ class SmartSessionService {
|
|
|
880
886
|
}
|
|
881
887
|
}
|
|
882
888
|
SmartSessionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: SmartSessionService, deps: [{ token: SessionService }, { token: SmartCookieService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
883
|
-
SmartSessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: SmartSessionService, providedIn:
|
|
889
|
+
SmartSessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: SmartSessionService, providedIn: 'root' });
|
|
884
890
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: SmartSessionService, decorators: [{
|
|
885
891
|
type: Injectable,
|
|
886
892
|
args: [{
|
|
887
|
-
providedIn:
|
|
893
|
+
providedIn: 'root',
|
|
888
894
|
}]
|
|
889
895
|
}], ctorParameters: function () { return [{ type: SessionService }, { type: SmartCookieService }]; } });
|
|
890
896
|
|
|
@@ -2066,9 +2072,9 @@ class SmartViewContextService {
|
|
|
2066
2072
|
if (!uuid) {
|
|
2067
2073
|
uuid = this.getUuidOfPage(this.tabIdName);
|
|
2068
2074
|
}
|
|
2069
|
-
yield this.getViewContext(uuid).then(() =>
|
|
2070
|
-
|
|
2071
|
-
})
|
|
2075
|
+
yield this.getViewContext(uuid).then(() => {
|
|
2076
|
+
this.syncView();
|
|
2077
|
+
});
|
|
2072
2078
|
});
|
|
2073
2079
|
}
|
|
2074
2080
|
getViewContext(uuid) {
|
|
@@ -2108,6 +2114,7 @@ class SmartViewContextService {
|
|
|
2108
2114
|
sessionStorage.clear();
|
|
2109
2115
|
}
|
|
2110
2116
|
setTabId(tabId) {
|
|
2117
|
+
console.log('setTabId ' + tabId);
|
|
2111
2118
|
sessionStorage.setItem(this.tabIdName, tabId);
|
|
2112
2119
|
this.session.addHeaderParam({
|
|
2113
2120
|
headerName: this.tabIdhttpHeaderName,
|
|
@@ -2116,6 +2123,7 @@ class SmartViewContextService {
|
|
|
2116
2123
|
}
|
|
2117
2124
|
startViewContext() {
|
|
2118
2125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2126
|
+
console.log('startViewContext');
|
|
2119
2127
|
this.clearSessionStorage();
|
|
2120
2128
|
let newViewContext = yield this.view
|
|
2121
2129
|
.createViewContext()
|
|
@@ -2124,6 +2132,7 @@ class SmartViewContextService {
|
|
|
2124
2132
|
throw new Error('No ViewContext was created');
|
|
2125
2133
|
}
|
|
2126
2134
|
this.viewContext = newViewContext;
|
|
2135
|
+
console.log(this.viewContext);
|
|
2127
2136
|
this.setTabId(newViewContext.uuid);
|
|
2128
2137
|
return this.viewContext;
|
|
2129
2138
|
});
|
|
@@ -2136,6 +2145,8 @@ class SmartViewContextService {
|
|
|
2136
2145
|
if (!this.messageDialogname) {
|
|
2137
2146
|
throw new Error('The messageDialogName provided by the backend has not been set.');
|
|
2138
2147
|
}
|
|
2148
|
+
console.log('init viewContext');
|
|
2149
|
+
console.log(uuid);
|
|
2139
2150
|
if (uuid) {
|
|
2140
2151
|
let subscription = this.session.headersUpdated.subscribe(() => __awaiter(this, void 0, void 0, function* () {
|
|
2141
2152
|
subscription.unsubscribe();
|
|
@@ -2157,128 +2168,124 @@ class SmartViewContextService {
|
|
|
2157
2168
|
}
|
|
2158
2169
|
openView(view) {
|
|
2159
2170
|
var _a;
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
});
|
|
2180
|
-
}
|
|
2181
|
-
else if (view.type === ViewType.Normal) {
|
|
2182
|
-
if (viewHandler.route === undefined) {
|
|
2183
|
-
throw new Error(`Route is undefined in SmartViewHandlerModel with name: ${view.viewName}`);
|
|
2184
|
-
}
|
|
2185
|
-
this.navigation.navigateTo(viewHandler.route.split('/'));
|
|
2186
|
-
}
|
|
2187
|
-
else {
|
|
2188
|
-
throw new Error('The type of the view and its viewHandler is not the same!');
|
|
2189
|
-
}
|
|
2190
|
-
view.state = ViewState.Opened;
|
|
2191
|
-
this.openedViewUuids.push(view.uuid);
|
|
2192
|
-
this.openedViewData.push(view);
|
|
2193
|
-
this.uuidOfPageHasBeenChanged.next(view.viewName);
|
|
2194
|
-
yield this.updateViewContext({
|
|
2195
|
-
updates: [
|
|
2196
|
-
{
|
|
2197
|
-
state: ViewState.Opened,
|
|
2198
|
-
uuid: view.uuid,
|
|
2199
|
-
},
|
|
2200
|
-
],
|
|
2201
|
-
uuid: (_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.uuid,
|
|
2171
|
+
let viewHandler = this.viewHandlers.find((handler) => handler.name === view.viewName);
|
|
2172
|
+
if (!viewHandler) {
|
|
2173
|
+
throw new Error(`SmartViewHandlerModel was not found by view name: ${view.viewName}`);
|
|
2174
|
+
}
|
|
2175
|
+
console.log(view);
|
|
2176
|
+
sessionStorage.setItem(view.viewName, view.uuid);
|
|
2177
|
+
if (view.type === ViewType.Dialog) {
|
|
2178
|
+
if (!viewHandler.component) {
|
|
2179
|
+
throw new Error(`Component is undefined in SmartViewHandlerModel with name: ${view.viewName}`);
|
|
2180
|
+
}
|
|
2181
|
+
let dialogRef = this.dialog.openComponentAsDialog(viewHandler.component, viewHandler.name);
|
|
2182
|
+
dialogRef.disableClose = true;
|
|
2183
|
+
// if (view.viewName === this.messageDialogname) {
|
|
2184
|
+
// if (view.message?.options && view.message.options.length) {
|
|
2185
|
+
// }
|
|
2186
|
+
// }
|
|
2187
|
+
this.dialogRefs.push({
|
|
2188
|
+
uuid: view.uuid,
|
|
2189
|
+
dialogRef,
|
|
2202
2190
|
});
|
|
2191
|
+
}
|
|
2192
|
+
else if (view.type === ViewType.Normal) {
|
|
2193
|
+
if (viewHandler.route === undefined) {
|
|
2194
|
+
throw new Error(`Route is undefined in SmartViewHandlerModel with name: ${view.viewName}`);
|
|
2195
|
+
}
|
|
2196
|
+
this.navigation.navigateTo(viewHandler.route.split('/'));
|
|
2197
|
+
}
|
|
2198
|
+
else {
|
|
2199
|
+
throw new Error('The type of the view and its viewHandler is not the same!');
|
|
2200
|
+
}
|
|
2201
|
+
view.state = ViewState.Opened;
|
|
2202
|
+
this.openedViewUuids.push(view.uuid);
|
|
2203
|
+
this.openedViewData.push(view);
|
|
2204
|
+
this.uuidOfPageHasBeenChanged.next(view.viewName);
|
|
2205
|
+
this.updateViewContext({
|
|
2206
|
+
updates: [
|
|
2207
|
+
{
|
|
2208
|
+
state: ViewState.Opened,
|
|
2209
|
+
uuid: view.uuid,
|
|
2210
|
+
},
|
|
2211
|
+
],
|
|
2212
|
+
uuid: (_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.uuid,
|
|
2203
2213
|
});
|
|
2204
2214
|
}
|
|
2205
2215
|
closeView(view) {
|
|
2206
2216
|
var _a;
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
this.dialogRefs.splice(index, 1);
|
|
2218
|
-
}
|
|
2219
|
-
else {
|
|
2220
|
-
throw new Error('DialogRef is not found by uuid.');
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
else if (view.type === ViewType.Normal) {
|
|
2224
|
-
// TODO: close normal page???
|
|
2225
|
-
// this.navigation.navigateTo(viewHandler.route.split("/"));
|
|
2217
|
+
let viewHandler = this.viewHandlers.find((handler) => handler.name === view.viewName);
|
|
2218
|
+
if (!viewHandler) {
|
|
2219
|
+
throw new Error(`SmartViewHandlerModel was not found by view name: ${view.viewName}`);
|
|
2220
|
+
}
|
|
2221
|
+
if (view.type === ViewType.Dialog) {
|
|
2222
|
+
let dialogRef = this.dialogRefs.find((dialogRef) => dialogRef.uuid === view.uuid);
|
|
2223
|
+
if (dialogRef) {
|
|
2224
|
+
dialogRef.dialogRef.close();
|
|
2225
|
+
let index = this.dialogRefs.indexOf(dialogRef);
|
|
2226
|
+
this.dialogRefs.splice(index, 1);
|
|
2226
2227
|
}
|
|
2227
2228
|
else {
|
|
2228
|
-
throw new Error('
|
|
2229
|
-
}
|
|
2230
|
-
view.state = ViewState.Closed;
|
|
2231
|
-
const index = this.openedViewUuids.indexOf(view.uuid);
|
|
2232
|
-
if (index >= 0) {
|
|
2233
|
-
this.openedViewUuids.splice(index, 1);
|
|
2234
|
-
this.openedViewData.splice(index, 1);
|
|
2229
|
+
throw new Error('DialogRef is not found by uuid.');
|
|
2235
2230
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2231
|
+
}
|
|
2232
|
+
else if (view.type === ViewType.Normal) {
|
|
2233
|
+
// TODO: close normal page???
|
|
2234
|
+
// this.navigation.navigateTo(viewHandler.route.split("/"));
|
|
2235
|
+
}
|
|
2236
|
+
else {
|
|
2237
|
+
throw new Error('The type of the view and its viewHandler is not the same!');
|
|
2238
|
+
}
|
|
2239
|
+
view.state = ViewState.Closed;
|
|
2240
|
+
const index = this.openedViewUuids.indexOf(view.uuid);
|
|
2241
|
+
if (index >= 0) {
|
|
2242
|
+
this.openedViewUuids.splice(index, 1);
|
|
2243
|
+
this.openedViewData.splice(index, 1);
|
|
2244
|
+
}
|
|
2245
|
+
sessionStorage.removeItem(view.viewName);
|
|
2246
|
+
this.updateViewContext({
|
|
2247
|
+
updates: [
|
|
2248
|
+
{
|
|
2249
|
+
state: ViewState.Closed,
|
|
2250
|
+
uuid: view.uuid,
|
|
2251
|
+
},
|
|
2252
|
+
],
|
|
2253
|
+
uuid: (_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.uuid,
|
|
2246
2254
|
});
|
|
2247
2255
|
}
|
|
2248
2256
|
restoreViews(uuid) {
|
|
2249
2257
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2258
|
+
console.log('restoreViews');
|
|
2250
2259
|
if (!this.viewContext) {
|
|
2251
2260
|
yield this.getViewContext(uuid);
|
|
2252
2261
|
}
|
|
2253
|
-
this.viewContext.views.map((view) =>
|
|
2254
|
-
|
|
2255
|
-
})
|
|
2262
|
+
this.viewContext.views.map((view) => {
|
|
2263
|
+
this.openView(view);
|
|
2264
|
+
});
|
|
2256
2265
|
});
|
|
2257
2266
|
}
|
|
2258
2267
|
syncView() {
|
|
2259
2268
|
var _a;
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
break;
|
|
2269
|
-
}
|
|
2270
|
-
}));
|
|
2271
|
-
const viewDataToClose = this.openedViewData.filter((viewData) => {
|
|
2272
|
-
var _a;
|
|
2273
|
-
return !((_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.views.flatMap((viewData) => viewData.uuid).includes(viewData.uuid));
|
|
2274
|
-
});
|
|
2275
|
-
if (viewDataToClose === null || viewDataToClose === void 0 ? void 0 : viewDataToClose.length) {
|
|
2276
|
-
viewDataToClose.map((viewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2277
|
-
yield this.closeView(viewData);
|
|
2278
|
-
}));
|
|
2269
|
+
(_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.views.map((view) => {
|
|
2270
|
+
switch (view.state) {
|
|
2271
|
+
case ViewState.ToOpen:
|
|
2272
|
+
this.openView(view);
|
|
2273
|
+
break;
|
|
2274
|
+
case ViewState.ToClose:
|
|
2275
|
+
this.closeView(view);
|
|
2276
|
+
break;
|
|
2279
2277
|
}
|
|
2280
|
-
this.viewContextHasBeenSynced.next();
|
|
2281
2278
|
});
|
|
2279
|
+
const viewDataToClose = this.openedViewData.filter((viewData) => {
|
|
2280
|
+
var _a;
|
|
2281
|
+
return !((_a = this.viewContext) === null || _a === void 0 ? void 0 : _a.views.flatMap((viewData) => viewData.uuid).includes(viewData.uuid));
|
|
2282
|
+
});
|
|
2283
|
+
if (viewDataToClose === null || viewDataToClose === void 0 ? void 0 : viewDataToClose.length) {
|
|
2284
|
+
viewDataToClose.map((viewData) => __awaiter(this, void 0, void 0, function* () {
|
|
2285
|
+
yield this.closeView(viewData);
|
|
2286
|
+
}));
|
|
2287
|
+
}
|
|
2288
|
+
this.viewContextHasBeenSynced.next();
|
|
2282
2289
|
}
|
|
2283
2290
|
getUuidOfPage(pageName) {
|
|
2284
2291
|
let uuid = sessionStorage.getItem(pageName);
|
|
@@ -2441,7 +2448,7 @@ class SmartViewContextService {
|
|
|
2441
2448
|
handlePerformActionResponse(viewContextChange) {
|
|
2442
2449
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2443
2450
|
this.viewContext = viewContextChange === null || viewContextChange === void 0 ? void 0 : viewContextChange.viewContext;
|
|
2444
|
-
|
|
2451
|
+
this.syncView();
|
|
2445
2452
|
if (viewContextChange === null || viewContextChange === void 0 ? void 0 : viewContextChange.changes) {
|
|
2446
2453
|
this.handleChanges(viewContextChange.changes);
|
|
2447
2454
|
}
|