mirror of
https://github.com/nasa/openmct.git
synced 2024-12-29 17:38:53 +00:00
[Persistence] Errors in persistence (after creating/modifying objects) should be visible to user #58
This commit is contained in:
parent
3fd4304de1
commit
26cf9c14f4
@ -188,7 +188,8 @@
|
||||
{
|
||||
"key": "persistence",
|
||||
"implementation": "capabilities/PersistenceCapability.js",
|
||||
"depends": [ "persistenceService", "identifierService" ]
|
||||
"depends": [ "persistenceService", "identifierService",
|
||||
"notificationService", "$q" ]
|
||||
},
|
||||
{
|
||||
"key": "metadata",
|
||||
|
@ -47,6 +47,8 @@ define(
|
||||
function PersistenceCapability(
|
||||
persistenceService,
|
||||
identifierService,
|
||||
alertService,
|
||||
$q,
|
||||
domainObject
|
||||
) {
|
||||
// Cache modified timestamp
|
||||
@ -55,6 +57,8 @@ define(
|
||||
this.domainObject = domainObject;
|
||||
this.identifierService = identifierService;
|
||||
this.persistenceService = persistenceService;
|
||||
this.alertService = alertService;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
// Utility function for creating promise-like objects which
|
||||
@ -72,6 +76,34 @@ define(
|
||||
return parts.length > 1 ? parts.slice(1).join(":") : id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value returned is falsey, and if so returns a
|
||||
* rejected promise
|
||||
*/
|
||||
function rejectIfFalsey(value, $q){
|
||||
if (!value){
|
||||
return $q.reject("Error persisting object")
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notification message if an error has occurred during
|
||||
* persistence.
|
||||
*/
|
||||
function notifyOnError(error, domainObject, notificationService, $q){
|
||||
var errorMessage = "Unable to persist " + domainObject.model.name + ": ";
|
||||
errorMessage += typeof error === "string" ? error : error.message;
|
||||
|
||||
notificationService.error({
|
||||
title: "Error persisting " + domainObject.model.name,
|
||||
hint: errorMessage || "Unknown error"
|
||||
});
|
||||
|
||||
return $q.reject(error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist any changes which have been made to this
|
||||
* domain object's model.
|
||||
@ -80,7 +112,8 @@ define(
|
||||
* if not.
|
||||
*/
|
||||
PersistenceCapability.prototype.persist = function () {
|
||||
var domainObject = this.domainObject,
|
||||
var self = this,
|
||||
domainObject = this.domainObject,
|
||||
model = domainObject.getModel(),
|
||||
modified = model.modified,
|
||||
persistenceService = this.persistenceService,
|
||||
@ -98,7 +131,11 @@ define(
|
||||
this.getSpace(),
|
||||
getKey(domainObject.getId()),
|
||||
domainObject.getModel()
|
||||
]);
|
||||
]).then(function(result){
|
||||
return rejectIfFalsey(result, self.$q);
|
||||
}).catch(function(error){
|
||||
return notifyOnError(error, domainObject, self.alertService, self.$q);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user