mirror of
https://github.com/nasa/openmct.git
synced 2024-12-22 06:27:48 +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();
|
this.resetSearch();
|
||||||
const notebookStorage = this.createNotebookStorageObject();
|
const notebookStorage = this.createNotebookStorageObject();
|
||||||
this.updateDefaultNotebook(notebookStorage);
|
this.updateDefaultNotebook(notebookStorage);
|
||||||
const id = addNotebookEntry(this.openmct, this.domainObject, notebookStorage, embed);
|
addNotebookEntry(this.openmct, this.domainObject, notebookStorage, embed).then(id => {
|
||||||
this.focusEntryId = id;
|
this.focusEntryId = id;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
orientationChange() {
|
orientationChange() {
|
||||||
this.formatSidebar();
|
this.formatSidebar();
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
>
|
>
|
||||||
<div class="c-ne__time-and-content">
|
<div class="c-ne__time-and-content">
|
||||||
<div class="c-ne__time">
|
<div class="c-ne__time">
|
||||||
|
<template v-if="entry.createdBy">
|
||||||
|
<span class="c-icon icon-person">{{ entry.createdBy }}</span>
|
||||||
|
</template>
|
||||||
<span>{{ createdOnDate }}</span>
|
<span>{{ createdOnDate }}</span>
|
||||||
<span>{{ createdOnTime }}</span>
|
<span>{{ createdOnTime }}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -182,7 +185,7 @@ export default {
|
|||||||
this.dropOnEntry = this.dropOnEntry.bind(this);
|
this.dropOnEntry = this.dropOnEntry.bind(this);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addNewEmbed(objectPath) {
|
async addNewEmbed(objectPath) {
|
||||||
const bounds = this.openmct.time.bounds();
|
const bounds = this.openmct.time.bounds();
|
||||||
const snapshotMeta = {
|
const snapshotMeta = {
|
||||||
bounds,
|
bounds,
|
||||||
@ -190,7 +193,7 @@ export default {
|
|||||||
objectPath,
|
objectPath,
|
||||||
openmct: this.openmct
|
openmct: this.openmct
|
||||||
};
|
};
|
||||||
const newEmbed = createNewEmbed(snapshotMeta);
|
const newEmbed = await createNewEmbed(snapshotMeta);
|
||||||
this.entry.embeds.push(newEmbed);
|
this.entry.embeds.push(newEmbed);
|
||||||
},
|
},
|
||||||
cancelEditMode(event) {
|
cancelEditMode(event) {
|
||||||
@ -206,7 +209,7 @@ export default {
|
|||||||
deleteEntry() {
|
deleteEntry() {
|
||||||
this.$emit('deleteEntry', this.entry.id);
|
this.$emit('deleteEntry', this.entry.id);
|
||||||
},
|
},
|
||||||
dropOnEntry($event) {
|
async dropOnEntry($event) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
const snapshotId = $event.dataTransfer.getData('openmct/snapshot/id');
|
const snapshotId = $event.dataTransfer.getData('openmct/snapshot/id');
|
||||||
@ -221,7 +224,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
const data = $event.dataTransfer.getData('openmct/domain-object-path');
|
const data = $event.dataTransfer.getData('openmct/domain-object-path');
|
||||||
const objectPath = JSON.parse(data);
|
const objectPath = JSON.parse(data);
|
||||||
this.addNewEmbed(objectPath);
|
await this.addNewEmbed(objectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$emit('updateEntry', this.entry);
|
this.$emit('updateEntry', this.entry);
|
||||||
|
@ -41,16 +41,17 @@ export default class Snapshot {
|
|||||||
fullSizeImageObjectIdentifier: object.identifier,
|
fullSizeImageObjectIdentifier: object.identifier,
|
||||||
thumbnailImage
|
thumbnailImage
|
||||||
};
|
};
|
||||||
const embed = createNewEmbed(snapshotMeta, snapshot);
|
createNewEmbed(snapshotMeta, snapshot).then(embed => {
|
||||||
if (notebookType === NOTEBOOK_DEFAULT) {
|
if (notebookType === NOTEBOOK_DEFAULT) {
|
||||||
const notebookStorage = getDefaultNotebook();
|
const notebookStorage = getDefaultNotebook();
|
||||||
|
|
||||||
this._saveToDefaultNoteBook(notebookStorage, embed);
|
this._saveToDefaultNoteBook(notebookStorage, embed);
|
||||||
const notebookImageDomainObject = updateNamespaceOfDomainObject(object, notebookStorage.identifier.namespace);
|
const notebookImageDomainObject = updateNamespaceOfDomainObject(object, notebookStorage.identifier.namespace);
|
||||||
saveNotebookImageDomainObject(this.openmct, notebookImageDomainObject);
|
saveNotebookImageDomainObject(this.openmct, notebookImageDomainObject);
|
||||||
} else {
|
} else {
|
||||||
this._saveToNotebookSnapshots(object, embed);
|
this._saveToNotebookSnapshots(object, embed);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,26 +59,26 @@ export default class Snapshot {
|
|||||||
*/
|
*/
|
||||||
_saveToDefaultNoteBook(notebookStorage, embed) {
|
_saveToDefaultNoteBook(notebookStorage, embed) {
|
||||||
this.openmct.objects.get(notebookStorage.identifier)
|
this.openmct.objects.get(notebookStorage.identifier)
|
||||||
.then(async (domainObject) => {
|
.then((domainObject) => {
|
||||||
addNotebookEntry(this.openmct, domainObject, notebookStorage, embed);
|
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)
|
const { section, page } = getNotebookSectionAndPage(domainObject, notebookStorage.defaultSectionId, notebookStorage.defaultPageId);
|
||||||
if (!link) {
|
if (!section || !page) {
|
||||||
link = await getDefaultNotebookLink(this.openmct, domainObject);
|
return;
|
||||||
notebookStorage.link = link;
|
}
|
||||||
setDefaultNotebook(this.openmct, notebookStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { section, page } = getNotebookSectionAndPage(domainObject, notebookStorage.defaultSectionId, notebookStorage.defaultPageId);
|
const defaultPath = `${domainObject.name} - ${section.name} - ${page.name}`;
|
||||||
if (!section || !page) {
|
const msg = `Saved to Notebook ${defaultPath}`;
|
||||||
return;
|
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';
|
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';
|
export const DEFAULT_CLASS = 'notebook-default';
|
||||||
const TIME_BOUNDS = {
|
const TIME_BOUNDS = {
|
||||||
START_BOUND: 'tc.startBound',
|
START_BOUND: 'tc.startBound',
|
||||||
@ -61,7 +73,7 @@ export function getHistoricLinkInFixedMode(openmct, bounds, historicLink) {
|
|||||||
return params.join('&');
|
return params.join('&');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createNewEmbed(snapshotMeta, snapshot = '') {
|
export async function createNewEmbed(snapshotMeta, snapshot = '') {
|
||||||
const {
|
const {
|
||||||
bounds,
|
bounds,
|
||||||
link,
|
link,
|
||||||
@ -83,10 +95,12 @@ export function createNewEmbed(snapshotMeta, snapshot = '') {
|
|||||||
});
|
});
|
||||||
const name = domainObject.name;
|
const name = domainObject.name;
|
||||||
const type = domainObject.identifier.key;
|
const type = domainObject.identifier.key;
|
||||||
|
const createdBy = await getUsername(openmct);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bounds,
|
bounds,
|
||||||
createdOn: date,
|
createdOn: date,
|
||||||
|
createdBy,
|
||||||
cssClass,
|
cssClass,
|
||||||
domainObject,
|
domainObject,
|
||||||
historicLink,
|
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) {
|
if (!openmct || !domainObject || !notebookStorage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -109,10 +123,12 @@ export function addNotebookEntry(openmct, domainObject, notebookStorage, embed =
|
|||||||
? [embed]
|
? [embed]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const createdBy = await getUsername(openmct);
|
||||||
const id = `entry-${date}`;
|
const id = `entry-${date}`;
|
||||||
const entry = {
|
const entry = {
|
||||||
id,
|
id,
|
||||||
createdOn: date,
|
createdOn: date,
|
||||||
|
createdBy,
|
||||||
text: entryText,
|
text: entryText,
|
||||||
embeds
|
embeds
|
||||||
};
|
};
|
||||||
|
@ -127,7 +127,7 @@ describe('Notebook Entries:', () => {
|
|||||||
expect(entries.length).toEqual(0);
|
expect(entries.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('addNotebookEntry adds entry', () => {
|
it('addNotebookEntry adds entry', async () => {
|
||||||
const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => {
|
const unlisten = openmct.objects.observe(notebookDomainObject, '*', (object) => {
|
||||||
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
const entries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||||
|
|
||||||
@ -135,17 +135,38 @@ describe('Notebook Entries:', () => {
|
|||||||
unlisten();
|
unlisten();
|
||||||
});
|
});
|
||||||
|
|
||||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getEntryPosById returns valid position', () => {
|
it('addNotebookEntry adds active user to entry', async () => {
|
||||||
const entryId1 = NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
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 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 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 position3 = NotebookEntries.getEntryPosById(entryId3, notebookDomainObject, selectedSection, selectedPage);
|
||||||
|
|
||||||
const success = position1 === 0
|
const success = position1 === 0
|
||||||
@ -155,9 +176,9 @@ describe('Notebook Entries:', () => {
|
|||||||
expect(success).toBe(true);
|
expect(success).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deleteNotebookEntries deletes correct page entries', () => {
|
it('deleteNotebookEntries deletes correct page entries', async () => {
|
||||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||||
NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
await NotebookEntries.addNotebookEntry(openmct, notebookDomainObject, notebookStorage);
|
||||||
|
|
||||||
NotebookEntries.deleteNotebookEntries(openmct, notebookDomainObject, selectedSection, selectedPage);
|
NotebookEntries.deleteNotebookEntries(openmct, notebookDomainObject, selectedSection, selectedPage);
|
||||||
const afterEntries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
const afterEntries = NotebookEntries.getNotebookEntries(notebookDomainObject, selectedSection, selectedPage);
|
||||||
|
Loading…
Reference in New Issue
Block a user