mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 05:07:52 +00:00
[Notebook] Add active user to entries (#4764)
* if user provider, user added to notebook enntries and snapshot entries, updated code to work with asynnc nature of user api Co-authored-by: Andrew Henry <akhenry@gmail.com> Co-authored-by: Nikhil <nikhil.k.mandlik@nasa.gov>
This commit is contained in:
parent
384e36920c
commit
4e7debabb1
@ -596,8 +596,9 @@ export default {
|
||||
this.resetSearch();
|
||||
const notebookStorage = this.createNotebookStorageObject();
|
||||
this.updateDefaultNotebook(notebookStorage);
|
||||
const id = addNotebookEntry(this.openmct, this.domainObject, notebookStorage, embed);
|
||||
this.focusEntryId = id;
|
||||
addNotebookEntry(this.openmct, this.domainObject, notebookStorage, embed).then(id => {
|
||||
this.focusEntryId = id;
|
||||
});
|
||||
},
|
||||
orientationChange() {
|
||||
this.formatSidebar();
|
||||
|
@ -28,6 +28,9 @@
|
||||
>
|
||||
<div class="c-ne__time-and-content">
|
||||
<div class="c-ne__time">
|
||||
<template v-if="entry.createdBy">
|
||||
<span class="c-icon icon-person">{{ entry.createdBy }}</span>
|
||||
</template>
|
||||
<span>{{ createdOnDate }}</span>
|
||||
<span>{{ createdOnTime }}</span>
|
||||
</div>
|
||||
@ -182,7 +185,7 @@ export default {
|
||||
this.dropOnEntry = this.dropOnEntry.bind(this);
|
||||
},
|
||||
methods: {
|
||||
addNewEmbed(objectPath) {
|
||||
async addNewEmbed(objectPath) {
|
||||
const bounds = this.openmct.time.bounds();
|
||||
const snapshotMeta = {
|
||||
bounds,
|
||||
@ -190,7 +193,7 @@ export default {
|
||||
objectPath,
|
||||
openmct: this.openmct
|
||||
};
|
||||
const newEmbed = createNewEmbed(snapshotMeta);
|
||||
const newEmbed = await createNewEmbed(snapshotMeta);
|
||||
this.entry.embeds.push(newEmbed);
|
||||
},
|
||||
cancelEditMode(event) {
|
||||
@ -206,7 +209,7 @@ export default {
|
||||
deleteEntry() {
|
||||
this.$emit('deleteEntry', this.entry.id);
|
||||
},
|
||||
dropOnEntry($event) {
|
||||
async dropOnEntry($event) {
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
const snapshotId = $event.dataTransfer.getData('openmct/snapshot/id');
|
||||
@ -221,7 +224,7 @@ export default {
|
||||
} else {
|
||||
const data = $event.dataTransfer.getData('openmct/domain-object-path');
|
||||
const objectPath = JSON.parse(data);
|
||||
this.addNewEmbed(objectPath);
|
||||
await this.addNewEmbed(objectPath);
|
||||
}
|
||||
|
||||
this.$emit('updateEntry', this.entry);
|
||||
|
@ -41,16 +41,17 @@ export default class Snapshot {
|
||||
fullSizeImageObjectIdentifier: object.identifier,
|
||||
thumbnailImage
|
||||
};
|
||||
const embed = createNewEmbed(snapshotMeta, snapshot);
|
||||
if (notebookType === NOTEBOOK_DEFAULT) {
|
||||
const notebookStorage = getDefaultNotebook();
|
||||
createNewEmbed(snapshotMeta, snapshot).then(embed => {
|
||||
if (notebookType === NOTEBOOK_DEFAULT) {
|
||||
const notebookStorage = getDefaultNotebook();
|
||||
|
||||
this._saveToDefaultNoteBook(notebookStorage, embed);
|
||||
const notebookImageDomainObject = updateNamespaceOfDomainObject(object, notebookStorage.identifier.namespace);
|
||||
saveNotebookImageDomainObject(this.openmct, notebookImageDomainObject);
|
||||
} else {
|
||||
this._saveToNotebookSnapshots(object, embed);
|
||||
}
|
||||
this._saveToDefaultNoteBook(notebookStorage, embed);
|
||||
const notebookImageDomainObject = updateNamespaceOfDomainObject(object, notebookStorage.identifier.namespace);
|
||||
saveNotebookImageDomainObject(this.openmct, notebookImageDomainObject);
|
||||
} else {
|
||||
this._saveToNotebookSnapshots(object, embed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,26 +59,26 @@ export default class Snapshot {
|
||||
*/
|
||||
_saveToDefaultNoteBook(notebookStorage, embed) {
|
||||
this.openmct.objects.get(notebookStorage.identifier)
|
||||
.then(async (domainObject) => {
|
||||
addNotebookEntry(this.openmct, domainObject, notebookStorage, embed);
|
||||
.then((domainObject) => {
|
||||
return addNotebookEntry(this.openmct, domainObject, notebookStorage, embed).then(async () => {
|
||||
let link = notebookStorage.link;
|
||||
|
||||
let link = notebookStorage.link;
|
||||
// Backwards compatibility fix (old notebook model without link)
|
||||
if (!link) {
|
||||
link = await getDefaultNotebookLink(this.openmct, domainObject);
|
||||
notebookStorage.link = link;
|
||||
setDefaultNotebook(this.openmct, notebookStorage);
|
||||
}
|
||||
|
||||
// Backwards compatibility fix (old notebook model without link)
|
||||
if (!link) {
|
||||
link = await getDefaultNotebookLink(this.openmct, domainObject);
|
||||
notebookStorage.link = link;
|
||||
setDefaultNotebook(this.openmct, notebookStorage);
|
||||
}
|
||||
const { section, page } = getNotebookSectionAndPage(domainObject, notebookStorage.defaultSectionId, notebookStorage.defaultPageId);
|
||||
if (!section || !page) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { section, page } = getNotebookSectionAndPage(domainObject, notebookStorage.defaultSectionId, notebookStorage.defaultPageId);
|
||||
if (!section || !page) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultPath = `${domainObject.name} - ${section.name} - ${page.name}`;
|
||||
const msg = `Saved to Notebook ${defaultPath}`;
|
||||
this._showNotification(msg, link);
|
||||
const defaultPath = `${domainObject.name} - ${section.name} - ${page.name}`;
|
||||
const msg = `Saved to Notebook ${defaultPath}`;
|
||||
this._showNotification(msg, link);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,17 @@
|
||||
import objectLink from '../../../ui/mixins/object-link';
|
||||
|
||||
async function getUsername(openmct) {
|
||||
let username = '';
|
||||
|
||||
if (openmct.user.hasProvider()) {
|
||||
const user = await openmct.user.getCurrentUser();
|
||||
username = user.getName();
|
||||
}
|
||||
|
||||
return username;
|
||||
|
||||
}
|
||||
|
||||
export const DEFAULT_CLASS = 'notebook-default';
|
||||
const TIME_BOUNDS = {
|
||||
START_BOUND: 'tc.startBound',
|
||||
@ -61,7 +73,7 @@ export function getHistoricLinkInFixedMode(openmct, bounds, historicLink) {
|
||||
return params.join('&');
|
||||
}
|
||||
|
||||
export function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||
export async function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||
const {
|
||||
bounds,
|
||||
link,
|
||||
@ -83,10 +95,12 @@ export function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||
});
|
||||
const name = domainObject.name;
|
||||
const type = domainObject.identifier.key;
|
||||
const createdBy = await getUsername(openmct);
|
||||
|
||||
return {
|
||||
bounds,
|
||||
createdOn: date,
|
||||
createdBy,
|
||||
cssClass,
|
||||
domainObject,
|
||||
historicLink,
|
||||
@ -97,7 +111,7 @@ export function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||
};
|
||||
}
|
||||
|
||||
export function addNotebookEntry(openmct, domainObject, notebookStorage, embed = null, entryText = '') {
|
||||
export async function addNotebookEntry(openmct, domainObject, notebookStorage, embed = null, entryText = '') {
|
||||
if (!openmct || !domainObject || !notebookStorage) {
|
||||
return;
|
||||
}
|
||||
@ -109,10 +123,12 @@ export function addNotebookEntry(openmct, domainObject, notebookStorage, embed =
|
||||
? [embed]
|
||||
: [];
|
||||
|
||||
const createdBy = await getUsername(openmct);
|
||||
const id = `entry-${date}`;
|
||||
const entry = {
|
||||
id,
|
||||
createdOn: date,
|
||||
createdBy,
|
||||
text: entryText,
|
||||
embeds
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ describe('Notebook Entries:', () => {
|
||||
expect(entries.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('addNotebookEntry adds entry', () => {
|
||||
it('addNotebookEntry adds entry', async () => {
|
||||
const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => {
|
||||
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
@ -135,17 +135,38 @@ describe('Notebook Entries:', () => {
|
||||
unlisten();
|
||||
});
|
||||
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
});
|
||||
|
||||
it('getEntryPosById returns valid position', () => {
|
||||
const entryId1 = NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
it('addNotebookEntry adds active user to entry', async () => {
|
||||
const USER = 'Timmy';
|
||||
openmct.user.hasProvider = () => true;
|
||||
openmct.user.getCurrentUser = () => {
|
||||
return Promise.resolve({
|
||||
getName: () => {
|
||||
return USER;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => {
|
||||
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
expect(entries[0].createdBy).toEqual(USER);
|
||||
unlisten();
|
||||
});
|
||||
|
||||
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
});
|
||||
|
||||
it('getEntryPosById returns valid position', async () => {
|
||||
const entryId1 = await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const position1 = NotebookEntries.getEntryPosById(entryId1, notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
const entryId2 = NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const entryId2 = await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const position2 = NotebookEntries.getEntryPosById(entryId2, notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
const entryId3 = NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const entryId3 = await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
const position3 = NotebookEntries.getEntryPosById(entryId3, notebookDomainObject, selectedSection, selectedPage);
|
||||
|
||||
const success = position1 === 0
|
||||
@ -155,9 +176,9 @@ describe('Notebook Entries:', () => {
|
||||
expect(success).toBe(true);
|
||||
});
|
||||
|
||||
it('deleteNotebookEntries deletes correct page entries', () => {
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
it('deleteNotebookEntries deletes correct page entries', async () => {
|
||||
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||
|
||||
NotebookEntries.deleteNotebookEntries(openmct, notebookDomainObject, selectedSection, selectedPage);
|
||||
const afterEntries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||
|
Loading…
Reference in New Issue
Block a user