Add notification reload module actions

- Reload notifications upon some module actions on the front end. Like save or create.
This commit is contained in:
Clemente Raposo 2023-03-14 11:16:17 +00:00
parent e65d9956d5
commit d580c04694
7 changed files with 57 additions and 7 deletions

View file

@ -50,6 +50,7 @@ services:
$massupdate: '%massupdate%'
$uiConfigs: '%ui%'
$notificationsConfigs: '%notifications%'
$notificationsReloadActions: '%notifications_reload_actions%'
$systemSettings: '%system.settings%'
$extensions: '%extensions%'
$upgradeConfig: '%upgrades%'

View file

@ -0,0 +1,8 @@
parameters:
notifications_reload_actions:
meetings:
- create
- edit
calls:
- create
- edit

View file

@ -35,6 +35,7 @@ import {MessageService} from "../../services/message/message.service";
import {RecordThreadStore} from '../../containers/record-thread/store/record-thread/record-thread.store';
import {NotificationsService} from '../../containers/notifications/services/notifications.service';
import {Process} from '../../services/process/process.service';
import {SystemConfigStore} from '../system-config/system-config.store';
export interface AppState {
loading?: boolean;
@ -97,7 +98,8 @@ export class AppStateStore implements StateStore {
constructor(
protected loadingBufferFactory: LoadingBufferFactory,
protected messageService: MessageService,
protected notificationService: NotificationsService
protected notificationService: NotificationsService,
protected configs: SystemConfigStore
) {
this.loading$ = this.state$.pipe(map(state => state.loading), distinctUntilChanged());
@ -178,6 +180,37 @@ export class AppStateStore implements StateStore {
});
}
public conditionalNotificationRefresh(view: string = ''): void {
const reloadActions = this.configs.getConfigValue('ui')['notifications_reload_actions'] ?? null;
const previousModule = this.getModule();
if (!view) {
view = this.getView();
}
if (!reloadActions || !previousModule) {
return;
}
const actions: string[] = reloadActions[previousModule];
if (!actions || !actions.length) {
return;
}
const reload = actions.some(action => {
return action === 'any' || action === view;
});
if (reload) {
this.refreshNotifications();
setTimeout(() => {
this.refreshNotifications();
}, 500)
}
}
public setRecordAsReadTrue(): void {
this.notificationStore.getRecordList().records.forEach(record => {
if (!record.attributes.is_read) {

View file

@ -25,11 +25,12 @@
*/
import {Injectable} from '@angular/core';
import {Record, ViewMode} from 'common';
import {ViewMode} from 'common';
import {take} from 'rxjs/operators';
import {RecordActionData, RecordActionHandler} from '../record.action';
import {MessageService} from '../../../../services/message/message.service';
import {ModuleNavigation} from '../../../../services/navigation/module-navigation/module-navigation.service';
import {AppStateStore} from '../../../../store/app-state/app-state.store';
@Injectable({
providedIn: 'root'
@ -39,7 +40,11 @@ export class RecordSaveAction extends RecordActionHandler {
key = 'save';
modes = ['edit' as ViewMode];
constructor(protected message: MessageService, protected navigation: ModuleNavigation) {
constructor(
protected message: MessageService,
protected navigation: ModuleNavigation,
protected appState: AppStateStore
) {
super();
}
@ -50,6 +55,7 @@ export class RecordSaveAction extends RecordActionHandler {
const params = data.store.params;
const moduleName = data.store.getModuleName();
const id = record.id;
this.appState.conditionalNotificationRefresh('edit');
this.navigateBack(this.navigation, params, id, moduleName, record);
});
return;

View file

@ -52,7 +52,7 @@ export class AppComponent {
if (routerEvent instanceof NavigationStart) {
this.appStateStore.updateLoading('router-navigation', true);
this.conditionalCacheReset();
this.appStateStore.conditionalNotificationRefresh();
}
if (routerEvent instanceof NavigationEnd) {

View file

@ -28,8 +28,6 @@
namespace App\Data\LegacyHandler\PresetDataHandlers;
use App\Data\LegacyHandler\BaseListDataHandler;
use App\Data\LegacyHandler\FilterMapper\LegacyFilterMapper;
use App\Data\LegacyHandler\ListData;
use App\Data\LegacyHandler\ListDataHandler;
use App\Data\LegacyHandler\PresetListDataHandlerInterface;
@ -129,7 +127,7 @@ class AlertsDataHandler extends ListDataHandler implements PresetListDataHandler
$now = date('Y-m-d H:i:s');
$where .= " AND (alerts.snooze < '$now' OR alerts.snooze IS NULL )";
$where .= " AND (alerts.snooze <= '$now' OR alerts.snooze IS NULL )";
$queryParts = $this->getListDataPort()->getQueryParts($bean, $where, $filter_fields, $params);
$queryParts['select'] = 'SELECT count(*) as unread';

View file

@ -99,6 +99,8 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
* @param array $recordViewActionLimits
* @param array $listViewLineActionsLimits
* @param array $uiConfigs
* @param array $notificationsConfigs
* @param array $notificationsReloadActions
* @param array $extensions
* @param array $logoutConfig
* @param array $sessionExpiredConfig
@ -128,6 +130,7 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
array $listViewLineActionsLimits,
array $uiConfigs,
array $notificationsConfigs,
array $notificationsReloadActions,
array $extensions,
array $logoutConfig,
array $sessionExpiredConfig,
@ -157,6 +160,7 @@ class SystemConfigHandler extends LegacyHandler implements SystemConfigProviderI
$this->injectedSystemConfigs['listview_line_actions_limits'] = $listViewLineActionsLimits;
$this->injectedSystemConfigs['ui'] = $uiConfigs ?? [];
$this->injectedSystemConfigs['ui']['notifications'] = $notificationsConfigs ?? [];
$this->injectedSystemConfigs['ui']['notifications_reload_actions'] = $notificationsReloadActions ?? [];
$this->injectedSystemConfigs['list_max_entries_per_record_thread'] = $uiConfigs['list_max_entries_per_record_thread'] ?? null;
$this->injectedSystemConfigs['extensions'] = $extensions;