Compare commits
1 Commits
fix-github
...
notebook-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68d4619b1a |
2
src/api/objects/ConflictError.js
Normal file
2
src/api/objects/ConflictError.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export default class ConflictError extends Error {
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ import RootRegistry from './RootRegistry';
|
|||||||
import RootObjectProvider from './RootObjectProvider';
|
import RootObjectProvider from './RootObjectProvider';
|
||||||
import EventEmitter from 'EventEmitter';
|
import EventEmitter from 'EventEmitter';
|
||||||
import InterceptorRegistry from './InterceptorRegistry';
|
import InterceptorRegistry from './InterceptorRegistry';
|
||||||
|
import ConflictError from './ConflictError';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for loading, saving, and manipulating domain objects.
|
* Utilities for loading, saving, and manipulating domain objects.
|
||||||
@@ -34,6 +35,7 @@ import InterceptorRegistry from './InterceptorRegistry';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function ObjectAPI(typeRegistry, openmct) {
|
function ObjectAPI(typeRegistry, openmct) {
|
||||||
|
this.openmct = openmct;
|
||||||
this.typeRegistry = typeRegistry;
|
this.typeRegistry = typeRegistry;
|
||||||
this.eventEmitter = new EventEmitter();
|
this.eventEmitter = new EventEmitter();
|
||||||
this.providers = {};
|
this.providers = {};
|
||||||
@@ -47,6 +49,10 @@ function ObjectAPI(typeRegistry, openmct) {
|
|||||||
this.interceptorRegistry = new InterceptorRegistry();
|
this.interceptorRegistry = new InterceptorRegistry();
|
||||||
|
|
||||||
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'plan'];
|
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'plan'];
|
||||||
|
|
||||||
|
this.errors = {
|
||||||
|
Conflict: ConflictError
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,7 +304,8 @@ ObjectAPI.prototype.save = function (domainObject) {
|
|||||||
savedResolve = resolve;
|
savedResolve = resolve;
|
||||||
});
|
});
|
||||||
domainObject.persisted = persistedTime;
|
domainObject.persisted = persistedTime;
|
||||||
provider.create(domainObject).then((response) => {
|
provider.create(domainObject)
|
||||||
|
.then((response) => {
|
||||||
this.mutate(domainObject, 'persisted', persistedTime);
|
this.mutate(domainObject, 'persisted', persistedTime);
|
||||||
savedResolve(response);
|
savedResolve(response);
|
||||||
});
|
});
|
||||||
@@ -309,7 +316,23 @@ ObjectAPI.prototype.save = function (domainObject) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result.catch((error) => {
|
||||||
|
if (error instanceof this.errors.Conflict) {
|
||||||
|
if (this.supportsMutation(domainObject.identifier)) {
|
||||||
|
return this.getMutable(domainObject.identifier).then((mutable) => {
|
||||||
|
mutable.$refresh(mutable);
|
||||||
|
this.destroyMutable(mutable);
|
||||||
|
this.openmct.notifications.alert(`Conflict while saving ${domainObject.name}. Please try again.`, {
|
||||||
|
autoDismissTimeout: 5000
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ const DEFAULTS = [
|
|||||||
'platform/forms',
|
'platform/forms',
|
||||||
'platform/identity',
|
'platform/identity',
|
||||||
'platform/persistence/aggregator',
|
'platform/persistence/aggregator',
|
||||||
'platform/persistence/queue',
|
|
||||||
'platform/policy',
|
'platform/policy',
|
||||||
'platform/entanglement',
|
'platform/entanglement',
|
||||||
'platform/search',
|
'platform/search',
|
||||||
|
|||||||
@@ -15,12 +15,16 @@
|
|||||||
|
|
||||||
port.onmessage = async function (event) {
|
port.onmessage = async function (event) {
|
||||||
if (event.data.request === 'close') {
|
if (event.data.request === 'close') {
|
||||||
|
console.log('Closing connection');
|
||||||
connections.splice(event.data.connectionId - 1, 1);
|
connections.splice(event.data.connectionId - 1, 1);
|
||||||
if (connections.length <= 0) {
|
if (connections.length <= 0) {
|
||||||
// abort any outstanding requests if there's nobody listening to it.
|
// abort any outstanding requests if there's nobody listening to it.
|
||||||
controller.abort();
|
controller.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Closed.');
|
||||||
|
connected = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +33,28 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connected = true;
|
do {
|
||||||
|
await self.listenForChanges(event.data.url, event.data.body, port);
|
||||||
|
} while (connected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let url = event.data.url;
|
port.start();
|
||||||
let body = event.data.body;
|
|
||||||
|
};
|
||||||
|
|
||||||
|
self.onerror = function () {
|
||||||
|
//do nothing
|
||||||
|
console.log('Error on feed');
|
||||||
|
};
|
||||||
|
|
||||||
|
self.listenForChanges = async function (url, body, port) {
|
||||||
|
connected = true;
|
||||||
let error = false;
|
let error = false;
|
||||||
// feed=continuous maintains an indefinitely open connection with a keep-alive of HEARTBEAT milliseconds until this client closes the connection
|
// feed=continuous maintains an indefinitely open connection with a keep-alive of HEARTBEAT milliseconds until this client closes the connection
|
||||||
// style=main_only returns only the current winning revision of the document
|
// style=main_only returns only the current winning revision of the document
|
||||||
|
|
||||||
|
console.log('Opening changes feed connection.');
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -65,6 +83,7 @@
|
|||||||
let chunk = new Uint8Array(value.length);
|
let chunk = new Uint8Array(value.length);
|
||||||
chunk.set(value, 0);
|
chunk.set(value, 0);
|
||||||
const decodedChunk = new TextDecoder("utf-8").decode(chunk).split('\n');
|
const decodedChunk = new TextDecoder("utf-8").decode(chunk).split('\n');
|
||||||
|
console.log('Received chunk');
|
||||||
if (decodedChunk.length && decodedChunk[decodedChunk.length - 1] === '') {
|
if (decodedChunk.length && decodedChunk[decodedChunk.length - 1] === '') {
|
||||||
decodedChunk.forEach((doc, index) => {
|
decodedChunk.forEach((doc, index) => {
|
||||||
try {
|
try {
|
||||||
@@ -86,21 +105,14 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Done reading changes feed');
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
console.log(`Finished with error ${error.toString()}`);
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
error
|
error
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
port.start();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
self.onerror = function () {
|
|
||||||
//do nothing
|
|
||||||
console.log('Error on feed');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -126,11 +126,12 @@ export default class CouchObjectProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fetch(this.url + '/' + subPath, fetchOptions)
|
return fetch(this.url + '/' + subPath, fetchOptions)
|
||||||
.then(response => response.json())
|
.then((response) => {
|
||||||
.then(function (response) {
|
if (response.status === 409) {
|
||||||
return response;
|
throw new this.openmct.objects.errors.Conflict(`Conflict persisting ${fetchOptions.body.name}`);
|
||||||
}, function () {
|
}
|
||||||
return undefined;
|
|
||||||
|
return response.json();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,6 +582,9 @@ export default class CouchObjectProvider {
|
|||||||
let document = new CouchDocument(key, queued.model, this.objectQueue[key].rev);
|
let document = new CouchDocument(key, queued.model, this.objectQueue[key].rev);
|
||||||
this.request(key, "PUT", document).then((response) => {
|
this.request(key, "PUT", document).then((response) => {
|
||||||
this.checkResponse(response, queued.intermediateResponse, key);
|
this.checkResponse(response, queued.intermediateResponse, key);
|
||||||
|
}).catch((error) => {
|
||||||
|
queued.intermediateResponse.reject(error);
|
||||||
|
this.objectQueue[key].pending = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user