Dynamically generate create menu items (#2163)

* dynamically generate create menu items, populate before mount

* make reviewer requested changes:
1.Use type.get to get type definition
2.Fix type adapter for creatable properties
3.populate menu items in data function, and inject openmct

* use simpler data name (item) and remove prefix string from key
This commit is contained in:
Deep Tailor 2018-09-13 15:15:01 -07:00 committed by Pete Richards
parent 08cd6b1d99
commit 07ca60e13a
2 changed files with 31 additions and 30 deletions

View File

@ -89,12 +89,13 @@ define(function () {
} }
} }
} }
if (Array.isArray(legacyDefinition.creatable) && 'creation' in legacyDefinition.creatable) {
if (legacyDefinition.features && legacyDefinition.features.includes("creation")) {
definition.creatable = true; definition.creatable = true;
} }
return definition; return definition;
} };
return Type; return Type;
}); });

View File

@ -8,23 +8,19 @@
v-if="showCreateMenu"> v-if="showCreateMenu">
<div class="c-super-menu__menu"> <div class="c-super-menu__menu">
<ul> <ul>
<li v-for="item in createMenuItems" <li v-for="(item, index) in items"
:key="index"
:class="item.class" :class="item.class"
:title="item.title" :title="item.title"
@mouseover="showItemDescription"> @mouseover="showItemDescription(item)">
{{ item.name }} {{ item.name }}
</li> </li>
</ul> </ul>
</div> </div>
<div class="c-super-menu__item-description"> <div class="c-super-menu__item-description">
<div class="l-item-description__icon bg-icon-plot-stacked"></div> <div :class="['l-item-description__icon', 'bg-' + selectedMenuItem.class]"></div>
<div class="l-item-description__name">Name</div> <div class="l-item-description__name">{{selectedMenuItem.name}}</div>
<div class="l-item-description__description"> <div class="l-item-description__description">{{selectedMenuItem.title}}</div>
A timer that counts up or down to a datetime.
Timers can be started, stopped and reset whenever needed,
and support a variety of display formats.
Each Timer displays the same value to all users.
Timers can be added to Display Layouts.</div>
</div> </div>
</div> </div>
</div> </div>
@ -65,6 +61,7 @@
<script> <script>
export default { export default {
inject: ['openmct'],
props: { props: {
showCreateMenu: { showCreateMenu: {
type: Boolean, type: Boolean,
@ -75,27 +72,30 @@
toggleCreateMenu: function () { toggleCreateMenu: function () {
this.showCreateMenu = !this.showCreateMenu; this.showCreateMenu = !this.showCreateMenu;
}, },
showItemDescription: function (menuItem) {
this.selectedMenuItem = menuItem;
}
}, },
data: function() { data: function() {
let items = [];
this.openmct.types.listKeys().forEach(key => {
let menuItem = openmct.types.get(key).definition;
if (menuItem.creatable) {
let menuItemTemplate = {
name: menuItem.name,
class: menuItem.cssClass,
title: menuItem.description
};
items.push(menuItemTemplate);
}
});
return { return {
createMenuItems: [ items: items,
{ name: 'Folder', class: 'icon-folder', title: 'Details will go here' }, selectedMenuItem: {}
{ name: 'Display Layout', class: 'icon-layout', title: 'Details will go here' },
{ name: 'Fixed Position Display', class: 'icon-box-with-dashed-lines', title: 'Details will go here' },
{ name: 'Overlay Plot', class: 'icon-plot-overlay', title: 'Details will go here' },
{ name: 'Stacked Plot', class: 'icon-plot-stacked', title: 'Details will go here' },
{ name: 'Telemetry Table', class: 'icon-tabular-realtime', title: 'Details will go here' },
{ name: 'Clock', class: 'icon-clock', title: 'Details will go here' },
{ name: 'Timer', class: 'icon-timer', title: 'Details will go here' },
{ name: 'Web Page', class: 'icon-page', title: 'Details will go here' },
{ name: 'Event Message Generator', class: 'icon-folder-new', title: 'Details will go here' },
{ name: 'Hyperlink', class: 'icon-chain-links', title: 'Details will go here' },
{ name: 'Notebook', class: 'icon-notebook', title: 'Details will go here' },
{ name: 'State Generator', class: 'icon-telemetry', title: 'Details will go here' },
{ name: 'Sine Wave Generator', class: 'icon-telemetry', title: 'Details will go here' },
{ name: 'Example Imagery', class: 'icon-image', title: 'Details will go here' },
{ name: 'Summary Widget', class: 'icon-summary-widget', title: 'Details will go here' }
]
} }
} }
} }