mirror of
https://github.com/nasa/openmct.git
synced 2025-06-27 11:32:13 +00:00
Compare commits
6 Commits
notebook-d
...
introduce-
Author | SHA1 | Date | |
---|---|---|---|
4ff96ff091 | |||
ad87dd6fdc | |||
80c833db88 | |||
a756891ccd | |||
2e1b6c5190 | |||
b042d9098d |
@ -180,7 +180,7 @@ ObjectAPI.prototype.get = function (identifier, abortSignal) {
|
||||
this.cache[keystring] = objectPromise;
|
||||
|
||||
return objectPromise.then(result => {
|
||||
delete this.cache[keystring];
|
||||
//delete this.cache[keystring];
|
||||
result = this.applyGetInterceptors(identifier, result);
|
||||
|
||||
return result;
|
||||
|
@ -69,7 +69,7 @@ export default {
|
||||
methods: {
|
||||
deletePage(id) {
|
||||
const selectedSection = this.sections.find(s => s.isSelected);
|
||||
const page = this.pages.find(p => p.id !== id);
|
||||
const page = this.pages.find(p => p.id === id);
|
||||
deleteNotebookEntries(this.openmct, this.domainObject, selectedSection, page);
|
||||
|
||||
const selectedPage = this.pages.find(p => p.isSelected);
|
||||
|
@ -26,6 +26,7 @@ import CouchObjectQueue from "./CouchObjectQueue";
|
||||
const REV = "_rev";
|
||||
const ID = "_id";
|
||||
const HEARTBEAT = 50000;
|
||||
const ALL_DOCS = "_all_docs?include_docs=true";
|
||||
|
||||
export default class CouchObjectProvider {
|
||||
// options {
|
||||
@ -67,6 +68,9 @@ export default class CouchObjectProvider {
|
||||
// stringify body if needed
|
||||
if (fetchOptions.body) {
|
||||
fetchOptions.body = JSON.stringify(fetchOptions.body);
|
||||
fetchOptions.headers = {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
}
|
||||
|
||||
return fetch(this.url + '/' + subPath, fetchOptions)
|
||||
@ -131,10 +135,70 @@ export default class CouchObjectProvider {
|
||||
}
|
||||
|
||||
get(identifier, abortSignal) {
|
||||
return this.request(identifier.key, "GET", undefined, abortSignal).then(this.getModel.bind(this));
|
||||
return new Promise((resolve, reject) => {
|
||||
this.batchIds = this.batchIds || [];
|
||||
this.batchIds.push(identifier.key);
|
||||
|
||||
if (this.bulkPromise === undefined) {
|
||||
this.bulkPromise = new Promise((bulkResolve, bulkReject) => {
|
||||
setTimeout(() => {
|
||||
let batchIds = this.batchIds;
|
||||
delete this.batchIds;
|
||||
delete this.bulkPromise;
|
||||
if (batchIds.length === 1) {
|
||||
this.request(identifier.key, "GET", undefined, abortSignal)
|
||||
.then((result) => resolve(this.getModel(result)));
|
||||
} else {
|
||||
this.bulkGet(batchIds, abortSignal)
|
||||
.then(bulkResolve)
|
||||
.catch(bulkReject);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.bulkPromise
|
||||
.then((domainObjectMap) => {
|
||||
resolve(domainObjectMap[identifier.key]);
|
||||
})
|
||||
.catch(error => reject(error));
|
||||
});
|
||||
}
|
||||
|
||||
async getObjectsByFilter(filter) {
|
||||
bulkGet(ids, signal) {
|
||||
//Remove dupes
|
||||
ids = Array.from(new Set(ids));
|
||||
|
||||
const query = {
|
||||
'keys': ids
|
||||
};
|
||||
|
||||
return this.request(ALL_DOCS, 'POST', query, signal).then((response) => {
|
||||
return response.rows.reduce((map, row) => {
|
||||
if (row.doc !== undefined) {
|
||||
map[row.key] = this.getModel(row.doc);
|
||||
}
|
||||
|
||||
return map;
|
||||
}, {});
|
||||
});
|
||||
}
|
||||
|
||||
search(query, abortSignal) {
|
||||
const filter = {
|
||||
"selector": {
|
||||
"model": {
|
||||
"name": {
|
||||
"$regex": `(?i)${query}`
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return this.getObjectsByFilter(filter, abortSignal);
|
||||
}
|
||||
|
||||
async getObjectsByFilter(filter, abortSignal) {
|
||||
let objects = [];
|
||||
|
||||
let url = `${this.url}/_find`;
|
||||
@ -149,6 +213,7 @@ export default class CouchObjectProvider {
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
signal: abortSignal,
|
||||
body
|
||||
});
|
||||
|
||||
|
@ -143,5 +143,9 @@ describe('the plugin', () => {
|
||||
|
||||
expect(couchProvider.updateQueued).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
describe('batches object requests', () => {
|
||||
//NEED TO MAKE SURE THERE ARE NO RACE CONDITIONS WHERE REQUESTS FOR OBJECTS ARE DROPPED
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -710,25 +710,25 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
async aggregateSearchResults(results, abortSignal) {
|
||||
aggregateSearchResults(results, abortSignal) {
|
||||
for (const result of results) {
|
||||
if (!abortSignal.aborted) {
|
||||
const objectPath = await this.openmct.objects.getOriginalPath(result.identifier);
|
||||
this.openmct.objects.getOriginalPath(result.identifier).then((objectPath) => {
|
||||
// removing the item itself, as the path we pass to buildTreeItem is a parent path
|
||||
objectPath.shift();
|
||||
|
||||
// removing the item itself, as the path we pass to buildTreeItem is a parent path
|
||||
objectPath.shift();
|
||||
// if root, remove, we're not using in object path for tree
|
||||
let lastObject = objectPath.length ? objectPath[objectPath.length - 1] : false;
|
||||
if (lastObject && lastObject.type === 'root') {
|
||||
objectPath.pop();
|
||||
}
|
||||
|
||||
// if root, remove, we're not using in object path for tree
|
||||
let lastObject = objectPath.length ? objectPath[objectPath.length - 1] : false;
|
||||
if (lastObject && lastObject.type === 'root') {
|
||||
objectPath.pop();
|
||||
}
|
||||
// we reverse the objectPath in the tree, so have to do it here first,
|
||||
// since this one is already in the correct direction
|
||||
let resultObject = this.buildTreeItem(result, objectPath.reverse());
|
||||
|
||||
// we reverse the objectPath in the tree, so have to do it here first,
|
||||
// since this one is already in the correct direction
|
||||
let resultObject = this.buildTreeItem(result, objectPath.reverse());
|
||||
|
||||
this.searchResultItems.push(resultObject);
|
||||
this.searchResultItems.push(resultObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user