1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Move all notifications to NotificationFactory

This commit is contained in:
Sonja Happ 2021-01-07 14:59:40 +01:00
parent 40f5b2286c
commit e49456490c
11 changed files with 150 additions and 127 deletions

View file

@ -18,19 +18,8 @@
import request from 'superagent/lib/client';
import Promise from 'es6-promise';
import NotificationsDataManager from '../data-managers/notifications-data-manager';
import NotificationsFactory from "../data-managers/notifications-factory";
// TODO: Add this to a central pool of notifications
const SERVER_NOT_REACHABLE_NOTIFICATION = {
title: 'Server not reachable',
message: 'The server could not be reached. Please try again later.',
level: 'error'
};
const REQUEST_TIMEOUT_NOTIFICATION = {
title: 'Request timeout',
message: 'Request timed out. Please try again later.',
level: 'error'
};
// Check if the error was due to network failure, timeouts, etc.
// Can be used for the rest of requests
@ -41,7 +30,7 @@ function isNetworkError(err) {
if (err.status == null || err.status === 500 || err.response == null) {
result = true;
let notification = err.timeout? REQUEST_TIMEOUT_NOTIFICATION : SERVER_NOT_REACHABLE_NOTIFICATION;
let notification = err.timeout? NotificationsFactory.REQUEST_TIMEOUT : NotificationsFactory.SERVER_NOT_REACHABLE;
NotificationsDataManager.addNotification(notification);
}
return result;

View file

@ -15,6 +15,7 @@
* along with VILLASweb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import NotificationsDataManager from "../data-managers/notifications-data-manager";
import NotificationsFactory from "../data-managers/notifications-factory";
import AppDispatcher from '../app-dispatcher';
class WebsocketAPI {
@ -70,7 +71,7 @@ class WebsocketAPI {
AppDispatcher.dispatch({
type: 'websocket/connected',
data: this.websocketurl,
});
});
this.wasConnected = true;
if ('onOpen' in this.callbacks)
@ -88,12 +89,8 @@ class WebsocketAPI {
type: 'websocket/connection-error',
data: this.websocketurl,
});
const IC_WEBSOCKET_CONNECTION_ERROR = {
title: 'Websocket connection warning',
message: "Connection to " + this.websocketurl + " dropped. Attempt reconnect in 1 sec",
level: 'warning'
};
NotificationsDataManager.addNotification(IC_WEBSOCKET_CONNECTION_ERROR);
NotificationsDataManager.addNotification(NotificationsFactory.WEBSOCKET_CONNECTION_WARN(this.websocketurl));
console.log("Connection to " + this.websocketurl + " dropped. Attempt reconnect in 1 sec");
window.setTimeout(() => { this.reconnect(); }, 1000);
}

View file

@ -19,6 +19,7 @@ import { ReduceStore } from 'flux/utils';
import AppDispatcher from './app-dispatcher';
import NotificationsDataManager from '../common/data-managers/notifications-data-manager';
import NotificationsFactory from "./data-managers/notifications-factory";
class ArrayStore extends ReduceStore {
constructor(type, dataManager) {
@ -83,13 +84,7 @@ class ArrayStore extends ReduceStore {
case this.type + '/load-error':
if (action.error && !action.error.handled && action.error.response) {
const USER_LOAD_ERROR_NOTIFICATION = {
title: 'Failed to load',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(USER_LOAD_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.LOAD_ERROR(action.error.response.body.message));
}
return super.reduce(state, action);
@ -120,17 +115,10 @@ class ArrayStore extends ReduceStore {
return (item.id !== action.data);
});
}
case this.type + '/remove-error':
if (action.error && !action.error.handled && action.error.response) {
const USER_REMOVE_ERROR_NOTIFICATION = {
title: 'Failed to add remove ',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(USER_REMOVE_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.DELETE_ERROR(action.error.response.body.message));
}
return super.reduce(state, action);

View file

@ -18,13 +18,117 @@
class NotificationsFactory {
// This is an example
static get EXAMPLE_NOTIFICATION() {
return {
title: 'Example notification',
message: 'Write something here that describes what happend.',
level: 'warning'
};
}
static get EXAMPLE_NOTIFICATION() {
return {
title: 'Example notification',
message: 'Write something here that describes what happend.',
level: 'warning'
};
}
static get SERVER_NOT_REACHABLE() {
return {
title: 'Server not reachable',
message: 'The server could not be reached. Please try again later.',
level: 'error'
};
}
static get REQUEST_TIMEOUT() {
return {
title: 'Request timeout',
message: 'Request timed out. Please try again later.',
level: 'error'
};
}
static ADD_ERROR(message) {
return {
title: "Add Error",
message: message,
level: 'error'
};
}
static UPDATE_ERROR(message) {
return {
title: 'Update Error ',
message: message,
level: 'error'
};
}
static UPDATE_WARNING(message) {
return {
title: 'Update Warning ',
message: message,
level: 'warning'
};
}
static LOAD_ERROR(message) {
return {
title: 'Failed to load',
message: message,
level: 'error'
};
}
static DELETE_ERROR(message) {
return {
title: 'Failed to delete ',
message: message,
level: 'error'
};
}
static WEBSOCKET_CONNECTION_WARN(websocket_url) {
return {
title: 'Websocket connection warning',
message: "Connection to " + websocket_url + " dropped. Attempt reconnect in 1 sec",
level: 'warning'
};
}
static WEBSOCKET_URL_WARN(ic_name, ic_uuid) {
return {
title: 'Websocket connection warning',
message: "Websocket URL parameter not available for IC " + ic_name + "(" + ic_uuid + "), connection not possible",
level: 'warning'
};
}
static SCENARIO_USERS_ERROR(message) {
return {
title: 'Failed to modify scenario users ',
message: message,
level: 'error'
};
}
static AUTOCONF_INFO() {
return {
title: 'Auto-configuration info',
message: 'Signal configuration loaded successfully.',
level: 'info'
};
}
static AUTOCONF_WARN(message) {
return {
title: 'Auto-configuration warning',
message: message,
level: 'warning'
};
}
static AUTOCONF_ERROR(message) {
return {
title: 'Auto-configuration error',
message: message,
level: 'error'
};
}
}

View file

@ -19,6 +19,7 @@ import ArrayStore from '../common/array-store';
import ICsDataManager from './ics-data-manager';
import ICDataDataManager from './ic-data-data-manager';
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
class InfrastructureComponentStore extends ArrayStore {
constructor() {
@ -47,14 +48,7 @@ class InfrastructureComponentStore extends ArrayStore {
if (ic.websocketurl != null && ic.websocketurl !== '') {
ICDataDataManager.open(ic.websocketurl, ic.id);
} else {
// TODO add to pool of notifications
const IC_WEBSOCKET_URL_ERROR = {
title: 'Websocket connection warning',
message: "Websocket URL parameter not available for IC " + ic.name + "(" + ic.uuid + "), connection not possible",
level: 'warning'
};
NotificationsDataManager.addNotification(IC_WEBSOCKET_URL_ERROR);
NotificationsDataManager.addNotification(NotificationsFactory.WEBSOCKET_URL_WARN(ic.name, ic.uuid));
}
}
return super.reduce(state, action);

View file

@ -19,6 +19,7 @@
import ScenariosDataManager from './scenarios-data-manager';
import ArrayStore from '../common/array-store';
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
class ScenarioStore extends ArrayStore{
@ -89,14 +90,7 @@ class ScenarioStore extends ArrayStore{
case 'scenarios/users-error':
if (action.error && !action.error.handled && action.error.response) {
const SCENARIO_USERS_ERROR_NOTIFICATION = {
title: 'Failed to modify scenario users ',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(SCENARIO_USERS_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.SCENARIO_USERS_ERROR(action.error.response.body.message));
}
return super.reduce(state, action);

View file

@ -18,6 +18,7 @@
import ArrayStore from '../common/array-store';
import SignalsDataManager from './signals-data-manager'
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
class SignalStore extends ArrayStore{
constructor() {
@ -45,14 +46,8 @@ class SignalStore extends ArrayStore{
case 'signals/autoconfig-error':
if (action.error && !action.error.handled && action.error.response) {
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
title: 'Failed to load signal config ',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.AUTOCONF_ERROR(action.error.response.body.message));
}
return super.reduce(state, action);

View file

@ -19,6 +19,7 @@ import RestDataManager from '../common/data-managers/rest-data-manager';
import RestAPI from "../common/api/rest-api";
import AppDispatcher from "../common/app-dispatcher";
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
class SignalsDataManager extends RestDataManager{
@ -62,12 +63,8 @@ class SignalsDataManager extends RestDataManager{
saveSignals(nodes, token, configID, socketname){
if(nodes.length === 0){
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
title: 'Failed to load nodes ',
message: 'VILLASnode returned empty response',
level: 'error'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.AUTOCONF_ERROR('Failed to load nodes, VILLASnode returned empty response'));
return;
}
@ -79,12 +76,9 @@ class SignalsDataManager extends RestDataManager{
console.warn("Could not parse the following node config because it lacks a name parameter:", nodeConfig);
} else if(nodeConfig.name === socketname){
if(configured){
const SIGNAL_AUTOCONF_WARNING_NOTIFICATION = {
title: 'There might be a problem with the signal auto-config',
message: 'VILLASnode returned multiple node configurations for the websocket ' + socketname + '. This is a problem of the VILLASnode.',
level: 'warning'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_WARNING_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.AUTOCONF_WARN('VILLASnode returned multiple node configurations for the websocket ' +
socketname + '. This is a problem of the VILLASnode.'));
continue;
}
// signals are not yet configured:
@ -92,12 +86,8 @@ class SignalsDataManager extends RestDataManager{
let index_out = 1
if(!nodeConfig.in.hasOwnProperty("signals")){
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
title: 'Failed to load in signal config ',
message: 'No field for in signals contained in response.',
level: 'error'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.AUTOCONF_ERROR('Failed to load in signal config, no field for in signals contained in response.'));
error = true;
} else{
@ -128,12 +118,8 @@ class SignalsDataManager extends RestDataManager{
}
if(!nodeConfig.out.hasOwnProperty("signals")){
const SIGNAL_AUTOCONF_ERROR_NOTIFICATION = {
title: 'Failed to load out signal config ',
message: 'No field for out signals contained in response.',
level: 'error'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.AUTOCONF_ERROR('Failed to load out signal config, no field for out signals contained in response.'));
error=true;
}else {
@ -173,12 +159,7 @@ class SignalsDataManager extends RestDataManager{
}
if(!error) {
const SIGNAL_AUTOCONF_INFO_NOTIFICATION = {
title: 'Signal configuration loaded successfully.',
message: '',
level: 'info'
};
NotificationsDataManager.addNotification(SIGNAL_AUTOCONF_INFO_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.AUTOCONF_INFO());
}
}

View file

@ -25,6 +25,7 @@ import UsersStore from './users-store';
import Icon from '../common/icon';
import EditOwnUserDialog from './edit-own-user'
import NotificationsDataManager from "../common/data-managers/notifications-data-manager"
import NotificationsFactory from "../common/data-managers/notifications-factory";
class User extends Component {
static getStores() {
@ -81,12 +82,7 @@ class User extends Component {
updatedData.password = data.password;
updatedData.oldPassword = data.oldPassword;
} else if (data.password !== '' && data.password !== data.confirmpassword) {
const USER_UPDATE_ERROR_NOTIFICATION = {
title: 'Update Error ',
message: 'New password not correctly confirmed',
level: 'error'
};
NotificationsDataManager.addNotification(USER_UPDATE_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_ERROR('New password not correctly confirmed'));
return
}
@ -102,12 +98,7 @@ class User extends Component {
token: this.state.token
});
} else {
const USER_UPDATE_WARNING_NOTIFICATION = {
title: 'Update Warning ',
message: 'No update requested, no input data',
level: 'warning'
};
NotificationsDataManager.addNotification(USER_UPDATE_WARNING_NOTIFICATION);
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_WARNING('No update requested, no input data'));
}
}
}

View file

@ -18,6 +18,7 @@
import ArrayStore from '../common/array-store';
import UsersDataManager from './users-data-manager';
import NotificationsDataManager from '../common/data-managers/notifications-data-manager';
import NotificationsFactory from "../common/data-managers/notifications-factory";
class UsersStore extends ArrayStore {
constructor() {
@ -30,12 +31,8 @@ class UsersStore extends ArrayStore {
case this.type + '/add-error':
if (action.error && !action.error.handled && action.error.response) {
// If it was an error and hasn't been handled, user could not be added
const USER_ADD_ERROR_NOTIFICATION = {
title: 'Failed to add new user',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(USER_ADD_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.ADD_ERROR('Failed to add new user: ' + action.error.response.body.message));
}
return super.reduce(state, action);
@ -43,12 +40,8 @@ class UsersStore extends ArrayStore {
case this.type + '/edit-error':
if (action.error && !action.error.handled && action.error.response) {
// If it was an error and hasn't been handled, user couldn't not be updated
const USER_EDIT_ERROR_NOTIFICATION = {
title: 'Failed to edit user',
message: action.error.response.body.message,
level: 'error'
};
NotificationsDataManager.addNotification(USER_EDIT_ERROR_NOTIFICATION);
NotificationsDataManager.addNotification(
NotificationsFactory.UPDATE_ERROR('Failed to edit user: ' + action.error.response.body.message));
}
return super.reduce(state, action);

View file

@ -30,6 +30,7 @@ import EditUserDialog from './edit-user';
import DeleteDialog from '../common/dialogs/delete-dialog';
import NotificationsDataManager from "../common/data-managers/notifications-data-manager";
import NotificationsFactory from "../common/data-managers/notifications-factory";
class Users extends Component {
static getStores() {
@ -97,12 +98,8 @@ class Users extends Component {
token: this.state.token
});
} else{
const USER_UPDATE_ERROR_NOTIFICATION = {
title: 'Update Error ',
message: 'New password not correctly confirmed',
level: 'error'
};
NotificationsDataManager.addNotification(USER_UPDATE_ERROR_NOTIFICATION)
NotificationsDataManager.addNotification(NotificationsFactory.UPDATE_ERROR("New password not correctly confirmed"))
}
}
}