Compare commits

...

7 Commits

Author SHA1 Message Date
Michael Rogers
46c8c3ce6b Converted focusedImageIndex assignment to ternary and general cleanup 2021-12-07 16:48:40 -06:00
Michael Rogers
beebb7057e Cleaning up spacing and log statements 2021-12-07 16:48:32 -06:00
Michael Rogers
95e0747a8c SUpdate the image history index to previous selected image 2021-12-07 16:48:20 -06:00
Jamie Vigliotta
466162902d just testing the flow 2021-12-07 16:48:11 -06:00
Michael Rogers
52d502d257 WIP: adding assertions to catch negative index state 2021-12-07 16:47:53 -06:00
David Tsay
9cb743fb48 Bugfix/create tree node (#4472)
* Transaction fix (#4421)

* When transaction is active, objects.get should search in dirty object first.

Co-authored-by: Andrew Henry <akhenry@gmail.com>

* find insert location prior to adding item to tree

* no need to resort

add item should only add to direct descendants

* remove unused function

* copy composition before sorting

* remove unused var

* remove master pollution

* Revert "remove master pollution"

This reverts commit 93bee13915.

* add item to correct location

Co-authored-by: Nikhil <nikhil.k.mandlik@nasa.gov>
Co-authored-by: Andrew Henry <akhenry@gmail.com>
2021-11-18 12:30:42 -08:00
Shefali Joshi
9c52ec7233 Transaction fix (#4421) (#4461)
* When transaction is active, objects.get should search in dirty object first.
2021-11-15 14:27:23 -08:00
8 changed files with 99 additions and 28 deletions

View File

@@ -82,6 +82,7 @@
);
openmct.install(openmct.plugins.LocalStorage());
openmct.install(openmct.plugins.Espresso());
openmct.install(openmct.plugins.MyItems());
openmct.install(openmct.plugins.Generator());

View File

@@ -184,6 +184,15 @@ ObjectAPI.prototype.get = function (identifier, abortSignal) {
}
identifier = utils.parseKeyString(identifier);
let dirtyObject;
if (this.isTransactionActive()) {
dirtyObject = this.transaction.getDirtyObject(keystring);
}
if (dirtyObject) {
return Promise.resolve(dirtyObject);
}
const provider = this.getProvider(identifier);
if (!provider) {

View File

@@ -55,6 +55,17 @@ export default class Transaction {
});
}
getDirtyObject(keystring) {
let dirtyObject;
this.dirtyObjects.forEach(object => {
if (this.objectAPI.makeKeyString(object.identifier) === keystring) {
dirtyObject = object;
}
});
return dirtyObject;
}
start() {
this.dirtyObjects = new Set();
}

View File

@@ -414,7 +414,7 @@ export default {
if (this.indexForFocusedImage !== undefined) {
imageIndex = this.initFocusedImageIndex;
} else {
imageIndex = newSize - 1;
imageIndex = newSize > 0 ? newSize - 1 : undefined;
}
this.setFocusedImage(imageIndex, false);
@@ -510,6 +510,12 @@ export default {
this.timeContext.off("timeContext", this.setTimeContext);
}
},
boundsChange(bounds, isTick) {
if (!isTick) {
this.previousFocusedImage = this.focusedImage ? JSON.parse(JSON.stringify(this.focusedImage)) : undefined;
this.requestHistory();
}
},
expand() {
const actionCollection = this.openmct.actions.getActionsCollection(this.objectPath, this.currentView);
const visibleActions = actionCollection.getVisibleActions();
@@ -670,23 +676,47 @@ export default {
this.$refs.thumbsWrapper.scrollLeft = scrollWidth;
});
},
matchIndexOfPreviousImage(previous, imageHistory) {
// match logic uses a composite of url and time to account
// for example imagery not having fully unique urls
return imageHistory.findIndex((x) => (
x.url === previous.url
&& x.time === previous.time
));
},
setFocusedImage(index, thumbnailClick = false) {
let focusedIndex = index;
if (!(Number.isInteger(index) && index > -1)) {
return;
}
if (this.previousFocusedImage) {
// determine if the previous image exists in the new bounds of imageHistory
const matchIndex = this.matchIndexOfPreviousImage(
this.previousFocusedImage,
this.imageHistory
);
focusedIndex = matchIndex > -1 ? matchIndex : this.imageHistory.length - 1;
delete this.previousFocusedImage;
}
if (thumbnailClick) {
//We use the props till the user changes what they want to see
this.initFocusedImageIndex = undefined;
}
if (this.isPaused && !thumbnailClick && this.initFocusedImageIndex === undefined) {
this.nextImageIndex = index;
this.nextImageIndex = focusedIndex;
//this could happen if bounds changes
if (this.focusedImageIndex > this.imageHistory.length - 1) {
this.focusedImageIndex = index;
this.focusedImageIndex = focusedIndex;
}
return;
}
this.focusedImageIndex = index;
this.focusedImageIndex = focusedIndex;
if (thumbnailClick && !this.isPaused) {
this.paused(true);

View File

@@ -4,7 +4,7 @@ import NotebookSnapshotIndicator from './components/NotebookSnapshotIndicator.vu
import SnapshotContainer from './snapshot-container';
import monkeyPatchObjectAPIForNotebooks from './monkeyPatchObjectAPIForNotebooks.js';
import { notebookImageMigration } from '../notebook/utils/notebook-migration';
import { notebookImageMigration, IMAGE_MIGRATION_VER } from '../notebook/utils/notebook-migration';
import { NOTEBOOK_TYPE } from './notebook-constants';
import Vue from 'vue';
@@ -28,6 +28,7 @@ export default function NotebookPlugin() {
domainObject.configuration = {
defaultSort: 'oldest',
entries: {},
imageMigrationVer: IMAGE_MIGRATION_VER,
pageTitle: 'Page',
sections: [],
sectionTitle: 'Section',

View File

@@ -1,7 +1,7 @@
import { createNotebookImageDomainObject, getThumbnailURLFromimageUrl, saveNotebookImageDomainObject, updateNamespaceOfDomainObject } from './notebook-image';
import { mutateObject } from './notebook-entries';
const IMAGE_MIGRATION_VER = "v1";
export const IMAGE_MIGRATION_VER = "v1";
export function notebookImageMigration(openmct, domainObject) {
const configuration = domainObject.configuration;

View File

@@ -108,7 +108,7 @@ describe('the plugin', () => {
expect(result).toBeTrue();
});
it('updates an object', async () => {
xit('updates an object', async () => {
const result = await openmct.objects.save(mockDomainObject);
expect(result).toBeTrue();
expect(provider.create).toHaveBeenCalled();

View File

@@ -113,7 +113,6 @@ import search from '../components/search.vue';
const ITEM_BUFFER = 25;
const LOCAL_STORAGE_KEY__TREE_EXPANDED = 'mct-tree-expanded';
const RETURN_ALL_DESCENDANTS = true;
const SORT_MY_ITEMS_ALPH_ASC = true;
const TREE_ITEM_INDENT_PX = 18;
@@ -455,15 +454,16 @@ export default {
return 0;
},
isSortable(parentObjectPath) {
// determine if any part of the parent's path includes a key value of mine; aka My Items
return Boolean(parentObjectPath.find(path => path.identifier.key === 'mine'));
},
async loadAndBuildTreeItemsFor(domainObject, parentObjectPath, abortSignal) {
let collection = this.openmct.composition.get(domainObject);
let composition = await collection.load(abortSignal);
// determine if any part of the parent's path includes a key value of mine; aka My Items
const isNestedInMyItems = Boolean(parentObjectPath.find(path => path.identifier.key === 'mine'));
if (SORT_MY_ITEMS_ALPH_ASC && isNestedInMyItems) {
const sortedComposition = composition.sort(this.sortNameDescending);
if (SORT_MY_ITEMS_ALPH_ASC && this.isSortable(parentObjectPath)) {
const sortedComposition = composition.slice().sort(this.sortNameDescending);
composition = sortedComposition;
}
@@ -509,17 +509,35 @@ export default {
},
compositionAddHandler(navigationPath) {
return (domainObject) => {
let parentItem = this.getTreeItemByPath(navigationPath);
let newItem = this.buildTreeItem(domainObject, parentItem.objectPath, true);
let allDescendants = this.getChildrenInTreeFor(parentItem, RETURN_ALL_DESCENDANTS);
let afterItem = allDescendants.length ? allDescendants.pop() : parentItem;
const parentItem = this.getTreeItemByPath(navigationPath);
const newItem = this.buildTreeItem(domainObject, parentItem.objectPath, true);
const descendants = this.getChildrenInTreeFor(parentItem, true);
const directDescendants = this.getChildrenInTreeFor(parentItem);
this.addItemToTreeAfter(newItem, afterItem);
const isNestedInMyItems = Boolean(parentItem.objectPath && parentItem.objectPath.find(path => path.identifier.key === 'mine'));
if (directDescendants.length === 0) {
this.addItemToTreeAfter(newItem, parentItem);
if (SORT_MY_ITEMS_ALPH_ASC && isNestedInMyItems) {
this.sortTreeComposition(this.sortNameDescending, navigationPath);
return;
}
if (SORT_MY_ITEMS_ALPH_ASC && this.isSortable(parentItem.objectPath)) {
const newItemIndex = directDescendants
.findIndex(descendant => this.sortNameDescending(descendant, newItem) > 0);
const shouldInsertFirst = newItemIndex === 0;
const shouldInsertLast = newItemIndex === -1;
if (shouldInsertFirst) {
this.addItemToTreeAfter(newItem, parentItem);
} else if (shouldInsertLast) {
this.addItemToTreeAfter(newItem, descendants.pop());
} else {
this.addItemToTreeBefore(newItem, directDescendants[newItemIndex]);
}
return;
}
this.addItemToTreeAfter(newItem, descendants.pop());
};
},
compositionRemoveHandler(navigationPath) {
@@ -551,17 +569,18 @@ export default {
const removeIndex = this.getTreeItemIndex(item.navigationPath);
this.treeItems.splice(removeIndex, 1);
},
sortTreeComposition(algorithem, parentPath) {
const parentIndex = this.getTreeItemIndex(parentPath);
const parentItem = this.treeItems[parentIndex];
addItemToTreeBefore(addItem, beforeItem) {
const addIndex = this.getTreeItemIndex(beforeItem.navigationPath);
const allDescendants = this.getChildrenInTreeFor(parentItem);
const sortedChildren = allDescendants.sort(algorithem);
this.treeItems.splice(parentIndex + 1, allDescendants.length, ...sortedChildren);
this.addItemToTree(addItem, addIndex);
},
addItemToTreeAfter(addItem, afterItem) {
const addIndex = this.getTreeItemIndex(afterItem.navigationPath);
this.treeItems.splice(addIndex + 1, 0, addItem);
this.addItemToTree(addItem, addIndex + 1);
},
addItemToTree(addItem, index) {
this.treeItems.splice(index, 0, addItem);
if (this.isTreeItemOpen(addItem)) {
this.openTreeItem(addItem);