@sumaris-net/ngx-components 1.21.0-beta19 → 1.21.0-beta21
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/bundles/sumaris-net.ngx-components.umd.js +223 -70
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/src/app/social/user-event/notification/user-event-notification.component.js +7 -2
- package/esm2015/src/app/social/user-event/notification/user-event-notification.list.js +12 -4
- package/esm2015/src/app/social/user-event/testing/user-event.testing.service.js +9 -3
- package/esm2015/src/app/social/user-event/user-event.service.js +100 -38
- package/fesm2015/sumaris-net.ngx-components.js +121 -42
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/social/user-event/notification/user-event-notification.component.d.ts +1 -0
- package/src/app/social/user-event/notification/user-event-notification.list.d.ts +4 -1
- package/src/app/social/user-event/user-event.service.d.ts +10 -7
- package/src/assets/i18n/en.json +2 -1
- package/src/assets/i18n/fr.json +2 -1
- package/src/theme/_ngx-components.scss +1 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -25962,15 +25962,15 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
25962
25962
|
this.mutations = mutations;
|
|
25963
25963
|
this.subscriptions = subscriptions;
|
|
25964
25964
|
this.environment = environment;
|
|
25965
|
-
this.
|
|
25966
|
-
this._subscriptions = new Subscription();
|
|
25965
|
+
this.count$ = new BehaviorSubject(0);
|
|
25967
25966
|
this.listeners = [];
|
|
25967
|
+
this._subscriptions = new Subscription();
|
|
25968
25968
|
this._logPrefix = '[user-event-service] ';
|
|
25969
25969
|
// For DEV only
|
|
25970
25970
|
this._debug = !(environment === null || environment === void 0 ? void 0 : environment.production);
|
|
25971
25971
|
}
|
|
25972
25972
|
get userEventCount() {
|
|
25973
|
-
return this.
|
|
25973
|
+
return this.count$.asObservable();
|
|
25974
25974
|
}
|
|
25975
25975
|
ngOnStart() {
|
|
25976
25976
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -26054,7 +26054,7 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26054
26054
|
data: entity
|
|
26055
26055
|
});
|
|
26056
26056
|
// Update count
|
|
26057
|
-
this.
|
|
26057
|
+
this.count$.next(this.count$.value + 1);
|
|
26058
26058
|
}
|
|
26059
26059
|
count(filter, options) {
|
|
26060
26060
|
var _a;
|
|
@@ -26086,6 +26086,8 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26086
26086
|
}
|
|
26087
26087
|
if (!filter)
|
|
26088
26088
|
filter = this.defaultFilter();
|
|
26089
|
+
// Apply last reset date as start date
|
|
26090
|
+
filter.startDate = this.resetCountDate;
|
|
26089
26091
|
filter = this.asFilter(filter);
|
|
26090
26092
|
if (this._debug)
|
|
26091
26093
|
console.debug(`${this._logPrefix}[WS] Listening count changes for user events with filter:`, filter);
|
|
@@ -26101,7 +26103,7 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26101
26103
|
if (total && this._debug)
|
|
26102
26104
|
console.debug(`${this._logPrefix}Received new user events count:`, total);
|
|
26103
26105
|
// update count
|
|
26104
|
-
this.
|
|
26106
|
+
this.count$.next(total);
|
|
26105
26107
|
return total;
|
|
26106
26108
|
}));
|
|
26107
26109
|
}
|
|
@@ -26176,9 +26178,15 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26176
26178
|
}
|
|
26177
26179
|
save(entity, options) {
|
|
26178
26180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26181
|
+
if (!this.mutations.save) {
|
|
26182
|
+
if (!this.mutations.saveAll)
|
|
26183
|
+
throw new Error('Not implemented');
|
|
26184
|
+
const allData = yield this.saveAll([entity], options);
|
|
26185
|
+
return allData === null || allData === void 0 ? void 0 : allData[0];
|
|
26186
|
+
}
|
|
26179
26187
|
this.fillDefaultProperties(entity);
|
|
26180
26188
|
// Transform into json
|
|
26181
|
-
const
|
|
26189
|
+
const withContent = !!entity.content;
|
|
26182
26190
|
const json = entity.asObject();
|
|
26183
26191
|
const now = Date.now();
|
|
26184
26192
|
if (this._debug)
|
|
@@ -26197,39 +26205,87 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26197
26205
|
console.debug(`${this._logPrefix}User event saved in ${Date.now() - now}ms`, entity);
|
|
26198
26206
|
this.copyIdAndUpdateDate(savedEntity, entity);
|
|
26199
26207
|
// Add to cache
|
|
26200
|
-
if (
|
|
26201
|
-
this.insertIntoMutableCachedQueries(proxy, {
|
|
26202
|
-
query: this.queries.loadAll,
|
|
26203
|
-
data: Object.assign(Object.assign({}, savedEntity), { content: null })
|
|
26204
|
-
});
|
|
26208
|
+
if (withContent) {
|
|
26205
26209
|
this.insertIntoMutableCachedQueries(proxy, {
|
|
26206
26210
|
query: this.queries.loadAllWithContent,
|
|
26207
26211
|
data: savedEntity
|
|
26208
26212
|
});
|
|
26209
26213
|
}
|
|
26214
|
+
else {
|
|
26215
|
+
this.insertIntoMutableCachedQueries(proxy, {
|
|
26216
|
+
query: this.queries.loadAll,
|
|
26217
|
+
data: Object.assign(Object.assign({}, savedEntity), { content: null })
|
|
26218
|
+
});
|
|
26219
|
+
}
|
|
26210
26220
|
}
|
|
26211
26221
|
}
|
|
26212
26222
|
});
|
|
26213
26223
|
return entity;
|
|
26214
26224
|
});
|
|
26215
26225
|
}
|
|
26216
|
-
saveAll(
|
|
26217
|
-
return
|
|
26218
|
-
|
|
26226
|
+
saveAll(entities, opts) {
|
|
26227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26228
|
+
if (isEmptyArray(entities))
|
|
26229
|
+
return entities;
|
|
26230
|
+
if (!this.mutations.saveAll) {
|
|
26231
|
+
if (!this.mutations.save)
|
|
26232
|
+
throw new Error('Not implemented');
|
|
26233
|
+
// Save one by one
|
|
26234
|
+
return chainPromises(entities.map((entity) => () => this.save(entity, opts)));
|
|
26235
|
+
}
|
|
26236
|
+
// Transform into json
|
|
26237
|
+
const json = entities.map(entity => {
|
|
26238
|
+
this.fillDefaultProperties(entity);
|
|
26239
|
+
return entity.asObject();
|
|
26240
|
+
});
|
|
26241
|
+
const now = Date.now();
|
|
26242
|
+
if (this._debug)
|
|
26243
|
+
console.debug(`${this._logPrefix}Saving user events...`, json);
|
|
26244
|
+
yield this.graphql.mutate({
|
|
26245
|
+
mutation: this.mutations.saveAll,
|
|
26246
|
+
variables: {
|
|
26247
|
+
data: json
|
|
26248
|
+
},
|
|
26249
|
+
error: { code: SocialErrorCodes.SAVE_USER_EVENT_ERROR, message: 'SOCIAL.ERROR.SAVE_USER_EVENT_ERROR' },
|
|
26250
|
+
update: (proxy, { data }) => {
|
|
26251
|
+
// Update entity
|
|
26252
|
+
const savedEntities = (data === null || data === void 0 ? void 0 : data.data) || [];
|
|
26253
|
+
if (savedEntities.length) {
|
|
26254
|
+
if (this._debug)
|
|
26255
|
+
console.debug(`${this._logPrefix}User events saved in ${Date.now() - now}ms`, savedEntities);
|
|
26256
|
+
entities.forEach(entity => {
|
|
26257
|
+
const savedEntity = savedEntities.find((e) => EntityUtils.equals(e, entity, 'id'));
|
|
26258
|
+
this.copyIdAndUpdateDate(savedEntity, entity);
|
|
26259
|
+
});
|
|
26260
|
+
// Add to cache (assuming all with content)
|
|
26261
|
+
this.insertIntoMutableCachedQueries(proxy, {
|
|
26262
|
+
query: this.queries.loadAllWithContent,
|
|
26263
|
+
data: savedEntities
|
|
26264
|
+
});
|
|
26265
|
+
}
|
|
26266
|
+
}
|
|
26267
|
+
});
|
|
26268
|
+
return entities;
|
|
26269
|
+
});
|
|
26219
26270
|
}
|
|
26220
|
-
markAsRead(
|
|
26271
|
+
markAsRead(entities) {
|
|
26221
26272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26222
|
-
|
|
26223
|
-
const
|
|
26224
|
-
|
|
26225
|
-
|
|
26226
|
-
|
|
26273
|
+
const userEventWithoutReadListeners = [];
|
|
26274
|
+
for (const entity of (entities || [])) {
|
|
26275
|
+
// Get onRead listeners
|
|
26276
|
+
const onReadListeners = (this.listeners || []).filter(listener => !!listener.onRead).filter(listener => listener.accept(entity));
|
|
26277
|
+
if (onReadListeners.length) {
|
|
26278
|
+
for (const listener of onReadListeners) {
|
|
26279
|
+
yield listener.onRead(entity);
|
|
26280
|
+
}
|
|
26281
|
+
}
|
|
26282
|
+
else {
|
|
26283
|
+
// Add to this list for default operation
|
|
26284
|
+
userEventWithoutReadListeners.push(entity);
|
|
26227
26285
|
}
|
|
26228
26286
|
}
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
yield this.defaultMarkAsRead(entity);
|
|
26232
|
-
}
|
|
26287
|
+
// Use default
|
|
26288
|
+
yield this.defaultMarkAsRead(userEventWithoutReadListeners);
|
|
26233
26289
|
});
|
|
26234
26290
|
}
|
|
26235
26291
|
registerListener(listener) {
|
|
@@ -26238,7 +26294,8 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26238
26294
|
this.listeners.push(listener);
|
|
26239
26295
|
}
|
|
26240
26296
|
resetCount() {
|
|
26241
|
-
this.
|
|
26297
|
+
this.count$.next(undefined);
|
|
26298
|
+
this.resetCountDate = moment$6();
|
|
26242
26299
|
}
|
|
26243
26300
|
/* -- protected methods -- */
|
|
26244
26301
|
onLogin() {
|
|
@@ -26248,12 +26305,9 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26248
26305
|
if (this._debug)
|
|
26249
26306
|
console.debug(`${this._logPrefix}Receiving user events count`, count);
|
|
26250
26307
|
// Update count
|
|
26251
|
-
this.
|
|
26308
|
+
this.count$.next(count);
|
|
26252
26309
|
// Then listen changes
|
|
26253
|
-
this._listenSubscription = this.listenCountChanges(undefined).subscribe(
|
|
26254
|
-
if (this._debug)
|
|
26255
|
-
console.debug(`${this._logPrefix}Receiving new user events count`, count);
|
|
26256
|
-
});
|
|
26310
|
+
this._listenSubscription = this.listenCountChanges(undefined).subscribe();
|
|
26257
26311
|
});
|
|
26258
26312
|
}
|
|
26259
26313
|
onLogout() {
|
|
@@ -26278,19 +26332,26 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26278
26332
|
}
|
|
26279
26333
|
return target;
|
|
26280
26334
|
}
|
|
26281
|
-
defaultMarkAsRead(
|
|
26335
|
+
defaultMarkAsRead(userEvents) {
|
|
26282
26336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26283
|
-
if (!
|
|
26337
|
+
if (!userEvents)
|
|
26284
26338
|
throw new Error(`${this._logPrefix}Invalid event to save`);
|
|
26339
|
+
if (!userEvents.length)
|
|
26340
|
+
return;
|
|
26285
26341
|
// set read date
|
|
26286
|
-
userEvent.readDate = moment$6();
|
|
26287
|
-
|
|
26342
|
+
userEvents.forEach(userEvent => userEvent.readDate = moment$6());
|
|
26343
|
+
// split local/remote entities
|
|
26344
|
+
const localEntities = userEvents.filter(userEvent => !userEvent.id || userEvent.id < 0);
|
|
26345
|
+
const remoteEntities = userEvents.filter(userEvent => userEvent.id > 0);
|
|
26346
|
+
// save local entities
|
|
26347
|
+
if (localEntities.length) {
|
|
26288
26348
|
if (this._debug)
|
|
26289
26349
|
console.debug(`${this._logPrefix}Save local user event`);
|
|
26290
26350
|
// TODO !!!!!!!!!!!!!
|
|
26291
26351
|
}
|
|
26292
|
-
|
|
26293
|
-
|
|
26352
|
+
// save remote entities
|
|
26353
|
+
if (remoteEntities.length) {
|
|
26354
|
+
yield this.saveAll(remoteEntities);
|
|
26294
26355
|
}
|
|
26295
26356
|
});
|
|
26296
26357
|
}
|
|
@@ -26666,12 +26727,19 @@ class UserEventNotificationList {
|
|
|
26666
26727
|
ngOnDestroy() {
|
|
26667
26728
|
this.subscriptions.unsubscribe();
|
|
26668
26729
|
}
|
|
26669
|
-
read(
|
|
26730
|
+
read(event, userEvent) {
|
|
26670
26731
|
var _a;
|
|
26671
26732
|
if (userEvent === null || userEvent === void 0 ? void 0 : userEvent.readDate)
|
|
26672
26733
|
return;
|
|
26673
26734
|
(_a = this.readEvent) === null || _a === void 0 ? void 0 : _a.emit(userEvent);
|
|
26674
26735
|
}
|
|
26736
|
+
readAll(event) {
|
|
26737
|
+
var _a;
|
|
26738
|
+
const unreadUserEvents = (this.userEvents.value || []).filter(value => !value.readDate);
|
|
26739
|
+
if (!unreadUserEvents.length)
|
|
26740
|
+
return;
|
|
26741
|
+
(_a = this.readEvents) === null || _a === void 0 ? void 0 : _a.emit(unreadUserEvents);
|
|
26742
|
+
}
|
|
26675
26743
|
executeAction(action, userEvent) {
|
|
26676
26744
|
// Execute then close popover
|
|
26677
26745
|
action.executeAction(userEvent);
|
|
@@ -26687,7 +26755,7 @@ class UserEventNotificationList {
|
|
|
26687
26755
|
UserEventNotificationList.decorators = [
|
|
26688
26756
|
{ type: Component, args: [{
|
|
26689
26757
|
selector: 'app-user-event-notification-list',
|
|
26690
|
-
template: "\n<ion-list class=\"ion-list-popover\">\n\n <ion-row class=\"ion-list-header column\">\n <ion-col>\n <ion-label>{{titleI18n | translate}}</ion-label>\n </ion-col>\n </ion-row>\n\n <ion-item *ngIf=\"!(userEvents | async)?.length\">\n {{'SOCIAL.USER_EVENT.NOTIFICATION.EMPTY' | translate}}\n </ion-item>\n <ion-item\n *ngFor=\"let userEvent of userEvents | async\"\n (click)=\"read($event, userEvent)\"\n >\n\n <ion-avatar slot=\"start\">\n\n <img *ngIf=\"userEvent.avatar; else avatarIcon\" src=\"{{ userEvent.avatar }}\">\n\n <ng-template #avatarIcon>\n <app-icon\n *ngIf=\"userEvent.avatarIcon\"\n [ref]=\"userEvent.avatarIcon\"\n height=\"40\"\n width=\"40\"\n ></app-icon>\n </ng-template>\n\n </ion-avatar>\n\n <ion-grid class=\"ion-no-margin ion-no-padding\">\n <ion-row>\n <ion-col>\n <p [class.unread]=\"!userEvent.readDate\">\n {{userEvent.message}}\n </p>\n </ion-col>\n </ion-row>\n <ion-row *ngIf=\"userEvent.actions?.length\">\n <ion-col>\n <p>\n <span *ngFor=\"let action of userEvent.actions\">\n <a\n [style.margin-right.px]=\"8\"\n [style.cursor]=\"'pointer'\"\n (click)=\"executeAction(action, userEvent)\"\n >\n {{ '➞ ' + action.name}}\n </a>\n </span>\n </p>\n </ion-col>\n </ion-row>\n <ion-row>\n <ion-col>\n <app-icon\n *ngIf=\"userEvent.icon\"\n [ref]=\"userEvent.icon\"\n height=\"16\"\n width=\"16\"\n [style.vertical-align]=\"'sub'\"\n ></app-icon>\n <small>\n <span>{{userEvent.creationDate|dateFromNow}}</span>\n <span [style.color]=\"'gray'\">{{ ' | ' + (userEvent.creationDate|dateFormat:{time:true}) }}</span>\n </small>\n </ion-col>\n </ion-row>\n </ion-grid>\n </ion-item>\n\n</ion-list>\n",
|
|
26758
|
+
template: "\n<ion-list class=\"ion-list-popover\">\n\n <ion-row class=\"ion-list-header column\">\n <ion-col>\n <ion-label>{{titleI18n | translate}}</ion-label>\n </ion-col>\n </ion-row>\n\n <ion-item *ngIf=\"!(userEvents | async)?.length\">\n {{'SOCIAL.USER_EVENT.NOTIFICATION.EMPTY' | translate}}\n </ion-item>\n <ion-item\n *ngFor=\"let userEvent of userEvents | async\"\n (click)=\"read($event, userEvent)\"\n >\n\n <ion-avatar slot=\"start\">\n\n <img *ngIf=\"userEvent.avatar; else avatarIcon\" src=\"{{ userEvent.avatar }}\">\n\n <ng-template #avatarIcon>\n <app-icon\n *ngIf=\"userEvent.avatarIcon\"\n [ref]=\"userEvent.avatarIcon\"\n height=\"40\"\n width=\"40\"\n ></app-icon>\n </ng-template>\n\n </ion-avatar>\n\n <ion-grid class=\"ion-no-margin ion-no-padding\">\n <ion-row>\n <ion-col>\n <p [class.unread]=\"!userEvent.readDate\">\n {{userEvent.message}}\n </p>\n </ion-col>\n </ion-row>\n <ion-row *ngIf=\"userEvent.actions?.length\">\n <ion-col>\n <p>\n <span *ngFor=\"let action of userEvent.actions\">\n <a\n [style.margin-right.px]=\"8\"\n [style.cursor]=\"'pointer'\"\n (click)=\"executeAction(action, userEvent)\"\n >\n {{ '➞ ' + action.name}}\n </a>\n </span>\n </p>\n </ion-col>\n </ion-row>\n <ion-row>\n <ion-col>\n <app-icon\n *ngIf=\"userEvent.icon\"\n [ref]=\"userEvent.icon\"\n height=\"16\"\n width=\"16\"\n [style.vertical-align]=\"'sub'\"\n ></app-icon>\n <small>\n <span>{{userEvent.creationDate|dateFromNow}}</span>\n <span [style.color]=\"'gray'\">{{ ' | ' + (userEvent.creationDate|dateFormat:{time:true}) }}</span>\n </small>\n </ion-col>\n </ion-row>\n </ion-grid>\n </ion-item>\n\n <ion-row class=\"ion-list-footer column\">\n <ion-col>\n <a style=\"cursor: pointer\" (click)=\"readAll($event)\">{{'SOCIAL.USER_EVENT.NOTIFICATION.READ_ALL' | translate}}</a>\n </ion-col>\n </ion-row>\n\n</ion-list>\n",
|
|
26691
26759
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
26692
26760
|
styles: [":host(.popover-viewport){overflow-y:auto;-webkit-user-select:none;-moz-user-select:none;user-select:none}.unread{font-weight:700}"]
|
|
26693
26761
|
},] }
|
|
@@ -26700,7 +26768,8 @@ UserEventNotificationList.ctorParameters = () => [
|
|
|
26700
26768
|
UserEventNotificationList.propDecorators = {
|
|
26701
26769
|
debug: [{ type: Input }],
|
|
26702
26770
|
titleI18n: [{ type: Input }],
|
|
26703
|
-
readEvent: [{ type: Output }]
|
|
26771
|
+
readEvent: [{ type: Output }],
|
|
26772
|
+
readEvents: [{ type: Output }]
|
|
26704
26773
|
};
|
|
26705
26774
|
|
|
26706
26775
|
class UserEventNotificationComponent {
|
|
@@ -26713,6 +26782,7 @@ class UserEventNotificationComponent {
|
|
|
26713
26782
|
this.disabled = false;
|
|
26714
26783
|
this._logPrefix = '[user-event-notification] ';
|
|
26715
26784
|
this._readEvent = new EventEmitter();
|
|
26785
|
+
this._readEvents = new EventEmitter();
|
|
26716
26786
|
}
|
|
26717
26787
|
get count() {
|
|
26718
26788
|
var _a;
|
|
@@ -26728,6 +26798,9 @@ class UserEventNotificationComponent {
|
|
|
26728
26798
|
// Subscribe to read event
|
|
26729
26799
|
this._readEvent.subscribe(value => {
|
|
26730
26800
|
// default: mark event as read
|
|
26801
|
+
this.userEventService.markAsRead([value]);
|
|
26802
|
+
});
|
|
26803
|
+
this._readEvents.subscribe(value => {
|
|
26731
26804
|
this.userEventService.markAsRead(value);
|
|
26732
26805
|
});
|
|
26733
26806
|
});
|
|
@@ -26741,7 +26814,8 @@ class UserEventNotificationComponent {
|
|
|
26741
26814
|
componentProps: {
|
|
26742
26815
|
debug: this.debug,
|
|
26743
26816
|
titleI18n: this.titleI18n,
|
|
26744
|
-
readEvent: this._readEvent
|
|
26817
|
+
readEvent: this._readEvent,
|
|
26818
|
+
readEvents: this._readEvents
|
|
26745
26819
|
},
|
|
26746
26820
|
backdropDismiss: true,
|
|
26747
26821
|
keyboardClose: true,
|
|
@@ -26794,7 +26868,7 @@ class UserEventTestService extends AbstractUserEventService {
|
|
|
26794
26868
|
entity = this.processUserEvent(entity);
|
|
26795
26869
|
entity.id = this.userEvents.length + 1;
|
|
26796
26870
|
this.userEvents.push(entity);
|
|
26797
|
-
this.
|
|
26871
|
+
this.count$.next(this.userEvents.length);
|
|
26798
26872
|
}
|
|
26799
26873
|
asFilter(filter) {
|
|
26800
26874
|
return filter;
|
|
@@ -26818,7 +26892,12 @@ class UserEventTestService extends AbstractUserEventService {
|
|
|
26818
26892
|
return entity;
|
|
26819
26893
|
}
|
|
26820
26894
|
saveAll(data, opts) {
|
|
26821
|
-
return
|
|
26895
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26896
|
+
for (const entity of (data || [])) {
|
|
26897
|
+
yield this.save(entity);
|
|
26898
|
+
}
|
|
26899
|
+
return Promise.resolve(this.userEvents);
|
|
26900
|
+
});
|
|
26822
26901
|
}
|
|
26823
26902
|
watchAll(offset, size, sortBy, sortDirection, filter, options) {
|
|
26824
26903
|
return of({ data: this.userEvents });
|