@sumaris-net/ngx-components 1.21.0-beta18 → 1.21.0-beta20
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 +231 -83
- 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 +9 -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 +10 -8
- package/esm2015/src/app/social/user-event/user-event.service.js +93 -31
- package/fesm2015/sumaris-net.ngx-components.js +116 -39
- 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/testing/user-event.testing.service.d.ts +0 -2
- 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
|
@@ -26176,9 +26176,15 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26176
26176
|
}
|
|
26177
26177
|
save(entity, options) {
|
|
26178
26178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26179
|
+
if (!this.mutations.save) {
|
|
26180
|
+
if (!this.mutations.saveAll)
|
|
26181
|
+
throw new Error('Not implemented');
|
|
26182
|
+
const allData = yield this.saveAll([entity], options);
|
|
26183
|
+
return allData === null || allData === void 0 ? void 0 : allData[0];
|
|
26184
|
+
}
|
|
26179
26185
|
this.fillDefaultProperties(entity);
|
|
26180
26186
|
// Transform into json
|
|
26181
|
-
const
|
|
26187
|
+
const withContent = !!entity.content;
|
|
26182
26188
|
const json = entity.asObject();
|
|
26183
26189
|
const now = Date.now();
|
|
26184
26190
|
if (this._debug)
|
|
@@ -26197,39 +26203,87 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26197
26203
|
console.debug(`${this._logPrefix}User event saved in ${Date.now() - now}ms`, entity);
|
|
26198
26204
|
this.copyIdAndUpdateDate(savedEntity, entity);
|
|
26199
26205
|
// Add to cache
|
|
26200
|
-
if (
|
|
26201
|
-
this.insertIntoMutableCachedQueries(proxy, {
|
|
26202
|
-
query: this.queries.loadAll,
|
|
26203
|
-
data: Object.assign(Object.assign({}, savedEntity), { content: null })
|
|
26204
|
-
});
|
|
26206
|
+
if (withContent) {
|
|
26205
26207
|
this.insertIntoMutableCachedQueries(proxy, {
|
|
26206
26208
|
query: this.queries.loadAllWithContent,
|
|
26207
26209
|
data: savedEntity
|
|
26208
26210
|
});
|
|
26209
26211
|
}
|
|
26212
|
+
else {
|
|
26213
|
+
this.insertIntoMutableCachedQueries(proxy, {
|
|
26214
|
+
query: this.queries.loadAll,
|
|
26215
|
+
data: Object.assign(Object.assign({}, savedEntity), { content: null })
|
|
26216
|
+
});
|
|
26217
|
+
}
|
|
26210
26218
|
}
|
|
26211
26219
|
}
|
|
26212
26220
|
});
|
|
26213
26221
|
return entity;
|
|
26214
26222
|
});
|
|
26215
26223
|
}
|
|
26216
|
-
saveAll(
|
|
26217
|
-
return
|
|
26218
|
-
|
|
26224
|
+
saveAll(entities, opts) {
|
|
26225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26226
|
+
if (isEmptyArray(entities))
|
|
26227
|
+
return entities;
|
|
26228
|
+
if (!this.mutations.saveAll) {
|
|
26229
|
+
if (!this.mutations.save)
|
|
26230
|
+
throw new Error('Not implemented');
|
|
26231
|
+
// Save one by one
|
|
26232
|
+
return chainPromises(entities.map((entity) => () => this.save(entity, opts)));
|
|
26233
|
+
}
|
|
26234
|
+
// Transform into json
|
|
26235
|
+
const json = entities.map(entity => {
|
|
26236
|
+
this.fillDefaultProperties(entity);
|
|
26237
|
+
return entity.asObject();
|
|
26238
|
+
});
|
|
26239
|
+
const now = Date.now();
|
|
26240
|
+
if (this._debug)
|
|
26241
|
+
console.debug(`${this._logPrefix}Saving user events...`, json);
|
|
26242
|
+
yield this.graphql.mutate({
|
|
26243
|
+
mutation: this.mutations.saveAll,
|
|
26244
|
+
variables: {
|
|
26245
|
+
data: json
|
|
26246
|
+
},
|
|
26247
|
+
error: { code: SocialErrorCodes.SAVE_USER_EVENT_ERROR, message: 'SOCIAL.ERROR.SAVE_USER_EVENT_ERROR' },
|
|
26248
|
+
update: (proxy, { data }) => {
|
|
26249
|
+
// Update entity
|
|
26250
|
+
const savedEntities = (data === null || data === void 0 ? void 0 : data.data) || [];
|
|
26251
|
+
if (savedEntities.length) {
|
|
26252
|
+
if (this._debug)
|
|
26253
|
+
console.debug(`${this._logPrefix}User events saved in ${Date.now() - now}ms`, savedEntities);
|
|
26254
|
+
entities.forEach(entity => {
|
|
26255
|
+
const savedEntity = savedEntities.find((e) => EntityUtils.equals(e, entity, 'id'));
|
|
26256
|
+
this.copyIdAndUpdateDate(savedEntity, entity);
|
|
26257
|
+
});
|
|
26258
|
+
// Add to cache (assuming all with content)
|
|
26259
|
+
this.insertIntoMutableCachedQueries(proxy, {
|
|
26260
|
+
query: this.queries.loadAllWithContent,
|
|
26261
|
+
data: savedEntities
|
|
26262
|
+
});
|
|
26263
|
+
}
|
|
26264
|
+
}
|
|
26265
|
+
});
|
|
26266
|
+
return entities;
|
|
26267
|
+
});
|
|
26219
26268
|
}
|
|
26220
|
-
markAsRead(
|
|
26269
|
+
markAsRead(entities) {
|
|
26221
26270
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26222
|
-
|
|
26223
|
-
const
|
|
26224
|
-
|
|
26225
|
-
|
|
26226
|
-
|
|
26271
|
+
const userEventWithoutReadListeners = [];
|
|
26272
|
+
for (const entity of (entities || [])) {
|
|
26273
|
+
// Get onRead listeners
|
|
26274
|
+
const onReadListeners = (this.listeners || []).filter(listener => !!listener.onRead).filter(listener => listener.accept(entity));
|
|
26275
|
+
if (onReadListeners.length) {
|
|
26276
|
+
for (const listener of onReadListeners) {
|
|
26277
|
+
yield listener.onRead(entity);
|
|
26278
|
+
}
|
|
26279
|
+
}
|
|
26280
|
+
else {
|
|
26281
|
+
// Add to this list for default operation
|
|
26282
|
+
userEventWithoutReadListeners.push(entity);
|
|
26227
26283
|
}
|
|
26228
26284
|
}
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
yield this.defaultMarkAsRead(entity);
|
|
26232
|
-
}
|
|
26285
|
+
// Use default
|
|
26286
|
+
yield this.defaultMarkAsRead(userEventWithoutReadListeners);
|
|
26233
26287
|
});
|
|
26234
26288
|
}
|
|
26235
26289
|
registerListener(listener) {
|
|
@@ -26237,6 +26291,9 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26237
26291
|
this.listeners = [];
|
|
26238
26292
|
this.listeners.push(listener);
|
|
26239
26293
|
}
|
|
26294
|
+
resetCount() {
|
|
26295
|
+
this._count$.next(undefined);
|
|
26296
|
+
}
|
|
26240
26297
|
/* -- protected methods -- */
|
|
26241
26298
|
onLogin() {
|
|
26242
26299
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -26247,10 +26304,7 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26247
26304
|
// Update count
|
|
26248
26305
|
this._count$.next(count);
|
|
26249
26306
|
// Then listen changes
|
|
26250
|
-
this._listenSubscription = this.listenCountChanges(undefined).subscribe(
|
|
26251
|
-
if (this._debug)
|
|
26252
|
-
console.debug(`${this._logPrefix}Receiving new user events count`, count);
|
|
26253
|
-
});
|
|
26307
|
+
this._listenSubscription = this.listenCountChanges(undefined).subscribe();
|
|
26254
26308
|
});
|
|
26255
26309
|
}
|
|
26256
26310
|
onLogout() {
|
|
@@ -26275,19 +26329,26 @@ class AbstractUserEventService extends BaseGraphqlService {
|
|
|
26275
26329
|
}
|
|
26276
26330
|
return target;
|
|
26277
26331
|
}
|
|
26278
|
-
defaultMarkAsRead(
|
|
26332
|
+
defaultMarkAsRead(userEvents) {
|
|
26279
26333
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26280
|
-
if (!
|
|
26334
|
+
if (!userEvents)
|
|
26281
26335
|
throw new Error(`${this._logPrefix}Invalid event to save`);
|
|
26336
|
+
if (!userEvents.length)
|
|
26337
|
+
return;
|
|
26282
26338
|
// set read date
|
|
26283
|
-
userEvent.readDate = moment$6();
|
|
26284
|
-
|
|
26339
|
+
userEvents.forEach(userEvent => userEvent.readDate = moment$6());
|
|
26340
|
+
// split local/remote entities
|
|
26341
|
+
const localEntities = userEvents.filter(userEvent => !userEvent.id || userEvent.id < 0);
|
|
26342
|
+
const remoteEntities = userEvents.filter(userEvent => userEvent.id > 0);
|
|
26343
|
+
// save local entities
|
|
26344
|
+
if (localEntities.length) {
|
|
26285
26345
|
if (this._debug)
|
|
26286
26346
|
console.debug(`${this._logPrefix}Save local user event`);
|
|
26287
26347
|
// TODO !!!!!!!!!!!!!
|
|
26288
26348
|
}
|
|
26289
|
-
|
|
26290
|
-
|
|
26349
|
+
// save remote entities
|
|
26350
|
+
if (remoteEntities.length) {
|
|
26351
|
+
yield this.saveAll(remoteEntities);
|
|
26291
26352
|
}
|
|
26292
26353
|
});
|
|
26293
26354
|
}
|
|
@@ -26663,12 +26724,19 @@ class UserEventNotificationList {
|
|
|
26663
26724
|
ngOnDestroy() {
|
|
26664
26725
|
this.subscriptions.unsubscribe();
|
|
26665
26726
|
}
|
|
26666
|
-
read(
|
|
26727
|
+
read(event, userEvent) {
|
|
26667
26728
|
var _a;
|
|
26668
26729
|
if (userEvent === null || userEvent === void 0 ? void 0 : userEvent.readDate)
|
|
26669
26730
|
return;
|
|
26670
26731
|
(_a = this.readEvent) === null || _a === void 0 ? void 0 : _a.emit(userEvent);
|
|
26671
26732
|
}
|
|
26733
|
+
readAll(event) {
|
|
26734
|
+
var _a;
|
|
26735
|
+
const unreadUserEvents = (this.userEvents.value || []).filter(value => !value.readDate);
|
|
26736
|
+
if (!unreadUserEvents.length)
|
|
26737
|
+
return;
|
|
26738
|
+
(_a = this.readEvents) === null || _a === void 0 ? void 0 : _a.emit(unreadUserEvents);
|
|
26739
|
+
}
|
|
26672
26740
|
executeAction(action, userEvent) {
|
|
26673
26741
|
// Execute then close popover
|
|
26674
26742
|
action.executeAction(userEvent);
|
|
@@ -26684,7 +26752,7 @@ class UserEventNotificationList {
|
|
|
26684
26752
|
UserEventNotificationList.decorators = [
|
|
26685
26753
|
{ type: Component, args: [{
|
|
26686
26754
|
selector: 'app-user-event-notification-list',
|
|
26687
|
-
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",
|
|
26755
|
+
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",
|
|
26688
26756
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
26689
26757
|
styles: [":host(.popover-viewport){overflow-y:auto;-webkit-user-select:none;-moz-user-select:none;user-select:none}.unread{font-weight:700}"]
|
|
26690
26758
|
},] }
|
|
@@ -26697,7 +26765,8 @@ UserEventNotificationList.ctorParameters = () => [
|
|
|
26697
26765
|
UserEventNotificationList.propDecorators = {
|
|
26698
26766
|
debug: [{ type: Input }],
|
|
26699
26767
|
titleI18n: [{ type: Input }],
|
|
26700
|
-
readEvent: [{ type: Output }]
|
|
26768
|
+
readEvent: [{ type: Output }],
|
|
26769
|
+
readEvents: [{ type: Output }]
|
|
26701
26770
|
};
|
|
26702
26771
|
|
|
26703
26772
|
class UserEventNotificationComponent {
|
|
@@ -26710,6 +26779,7 @@ class UserEventNotificationComponent {
|
|
|
26710
26779
|
this.disabled = false;
|
|
26711
26780
|
this._logPrefix = '[user-event-notification] ';
|
|
26712
26781
|
this._readEvent = new EventEmitter();
|
|
26782
|
+
this._readEvents = new EventEmitter();
|
|
26713
26783
|
}
|
|
26714
26784
|
get count() {
|
|
26715
26785
|
var _a;
|
|
@@ -26725,18 +26795,24 @@ class UserEventNotificationComponent {
|
|
|
26725
26795
|
// Subscribe to read event
|
|
26726
26796
|
this._readEvent.subscribe(value => {
|
|
26727
26797
|
// default: mark event as read
|
|
26798
|
+
this.userEventService.markAsRead([value]);
|
|
26799
|
+
});
|
|
26800
|
+
this._readEvents.subscribe(value => {
|
|
26728
26801
|
this.userEventService.markAsRead(value);
|
|
26729
26802
|
});
|
|
26730
26803
|
});
|
|
26731
26804
|
}
|
|
26732
26805
|
showList(event) {
|
|
26733
26806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26807
|
+
// Reset count
|
|
26808
|
+
this.userEventService.resetCount();
|
|
26734
26809
|
const popover = yield this.popoverController.create({
|
|
26735
26810
|
component: UserEventNotificationList,
|
|
26736
26811
|
componentProps: {
|
|
26737
26812
|
debug: this.debug,
|
|
26738
26813
|
titleI18n: this.titleI18n,
|
|
26739
|
-
readEvent: this._readEvent
|
|
26814
|
+
readEvent: this._readEvent,
|
|
26815
|
+
readEvents: this._readEvents
|
|
26740
26816
|
},
|
|
26741
26817
|
backdropDismiss: true,
|
|
26742
26818
|
keyboardClose: true,
|
|
@@ -26781,7 +26857,6 @@ class UserEventTestService extends AbstractUserEventService {
|
|
|
26781
26857
|
this.translate = translate;
|
|
26782
26858
|
this.environment = environment;
|
|
26783
26859
|
this.userEvents = [];
|
|
26784
|
-
this.count$ = new BehaviorSubject(0);
|
|
26785
26860
|
}
|
|
26786
26861
|
fromObject(source) {
|
|
26787
26862
|
return UserEvent.fromObject(source);
|
|
@@ -26790,10 +26865,7 @@ class UserEventTestService extends AbstractUserEventService {
|
|
|
26790
26865
|
entity = this.processUserEvent(entity);
|
|
26791
26866
|
entity.id = this.userEvents.length + 1;
|
|
26792
26867
|
this.userEvents.push(entity);
|
|
26793
|
-
this.
|
|
26794
|
-
}
|
|
26795
|
-
get userEventCount() {
|
|
26796
|
-
return this.count$.asObservable();
|
|
26868
|
+
this._count$.next(this.userEvents.length);
|
|
26797
26869
|
}
|
|
26798
26870
|
asFilter(filter) {
|
|
26799
26871
|
return filter;
|
|
@@ -26817,7 +26889,12 @@ class UserEventTestService extends AbstractUserEventService {
|
|
|
26817
26889
|
return entity;
|
|
26818
26890
|
}
|
|
26819
26891
|
saveAll(data, opts) {
|
|
26820
|
-
return
|
|
26892
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26893
|
+
for (const entity of (data || [])) {
|
|
26894
|
+
yield this.save(entity);
|
|
26895
|
+
}
|
|
26896
|
+
return Promise.resolve(this.userEvents);
|
|
26897
|
+
});
|
|
26821
26898
|
}
|
|
26822
26899
|
watchAll(offset, size, sortBy, sortDirection, filter, options) {
|
|
26823
26900
|
return of({ data: this.userEvents });
|