2018-09-11 17:10:59 +00:00
|
|
|
<template>
|
2019-12-04 20:39:09 +00:00
|
|
|
<div class="c-create-button--w">
|
|
|
|
<button
|
|
|
|
class="c-create-button c-button--menu c-button--major icon-plus"
|
|
|
|
@click="open"
|
|
|
|
>
|
|
|
|
<span class="c-button__label">Create</span>
|
|
|
|
</button>
|
|
|
|
<div
|
|
|
|
v-if="opened"
|
|
|
|
class="c-create-menu c-super-menu"
|
|
|
|
>
|
|
|
|
<div class="c-super-menu__menu">
|
|
|
|
<ul>
|
|
|
|
<li
|
|
|
|
v-for="(item, index) in sortedItems"
|
|
|
|
:key="index"
|
|
|
|
:class="item.class"
|
2020-09-14 19:05:22 +00:00
|
|
|
:aria-label="item.name"
|
|
|
|
role="button"
|
|
|
|
tabindex="0"
|
2019-12-04 20:39:09 +00:00
|
|
|
@mouseover="showItemDescription(item)"
|
|
|
|
@click="create(item)"
|
|
|
|
>
|
|
|
|
{{ item.name }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="c-super-menu__item-description">
|
|
|
|
<div :class="['l-item-description__icon', 'bg-' + selectedMenuItem.class]"></div>
|
|
|
|
<div class="l-item-description__name">
|
|
|
|
{{ selectedMenuItem.name }}
|
2018-09-11 17:10:59 +00:00
|
|
|
</div>
|
2019-12-04 20:39:09 +00:00
|
|
|
<div class="l-item-description__description">
|
|
|
|
{{ selectedMenuItem.title }}
|
2018-09-11 17:10:59 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-04 20:39:09 +00:00
|
|
|
</div>
|
2018-09-11 17:10:59 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-12-04 20:39:09 +00:00
|
|
|
import CreateAction from '../../../platform/commonUI/edit/src/creation/CreateAction';
|
2020-05-27 17:59:02 +00:00
|
|
|
import objectUtils from 'objectUtils';
|
2018-10-19 22:07:30 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
export default {
|
|
|
|
inject: ['openmct'],
|
|
|
|
data: function () {
|
|
|
|
let items = [];
|
2018-09-13 22:15:01 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
this.openmct.types.listKeys().forEach(key => {
|
|
|
|
let menuItem = this.openmct.types.get(key).definition;
|
2018-09-13 22:15:01 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
if (menuItem.creatable) {
|
|
|
|
let menuItemTemplate = {
|
|
|
|
key: key,
|
|
|
|
name: menuItem.name,
|
|
|
|
class: menuItem.cssClass,
|
|
|
|
title: menuItem.description
|
|
|
|
};
|
|
|
|
|
|
|
|
items.push(menuItemTemplate);
|
|
|
|
}
|
|
|
|
});
|
2018-09-13 22:15:01 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
return {
|
|
|
|
items: items,
|
|
|
|
selectedMenuItem: {},
|
|
|
|
opened: false
|
2020-07-31 19:11:03 +00:00
|
|
|
};
|
2019-12-04 20:39:09 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
sortedItems() {
|
2020-07-31 19:11:03 +00:00
|
|
|
return this.items.slice().sort((a, b) => {
|
2019-12-04 20:39:09 +00:00
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
} else if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2018-09-13 22:15:01 +00:00
|
|
|
}
|
|
|
|
});
|
2019-12-04 20:39:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
document.removeEventListener('click', this.close);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
open: function () {
|
|
|
|
if (this.opened) {
|
|
|
|
return;
|
2018-09-11 17:10:59 +00:00
|
|
|
}
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
this.opened = true;
|
|
|
|
setTimeout(() => document.addEventListener('click', this.close));
|
2019-03-26 01:26:39 +00:00
|
|
|
},
|
2019-12-04 20:39:09 +00:00
|
|
|
close: function () {
|
|
|
|
if (!this.opened) {
|
|
|
|
return;
|
2019-03-26 01:26:39 +00:00
|
|
|
}
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
this.opened = false;
|
|
|
|
document.removeEventListener('click', this.close);
|
|
|
|
},
|
|
|
|
showItemDescription: function (menuItem) {
|
|
|
|
this.selectedMenuItem = menuItem;
|
|
|
|
},
|
|
|
|
create: function (item) {
|
|
|
|
// Hack for support. TODO: rewrite create action.
|
|
|
|
// 1. Get contextual object from navigation
|
|
|
|
// 2. Get legacy type from legacy api
|
|
|
|
// 3. Instantiate create action with type, parent, context
|
|
|
|
// 4. perform action.
|
|
|
|
return this.openmct.objects.get(this.openmct.router.path[0].identifier)
|
|
|
|
.then((currentObject) => {
|
|
|
|
let legacyContextualParent = this.convertToLegacy(currentObject);
|
|
|
|
let legacyType = this.openmct.$injector.get('typeService').getType(item.key);
|
|
|
|
let context = {
|
|
|
|
key: "create",
|
|
|
|
domainObject: legacyContextualParent // should be same as parent object.
|
|
|
|
};
|
|
|
|
let action = new CreateAction(
|
|
|
|
legacyType,
|
|
|
|
legacyContextualParent,
|
|
|
|
context,
|
|
|
|
this.openmct
|
|
|
|
);
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
return action.perform();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
convertToLegacy(domainObject) {
|
|
|
|
let keyString = objectUtils.makeKeyString(domainObject.identifier);
|
|
|
|
let oldModel = objectUtils.toOldFormat(domainObject);
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2019-12-04 20:39:09 +00:00
|
|
|
return this.openmct.$injector.get('instantiate')(oldModel, keyString);
|
2018-09-11 17:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-31 19:11:03 +00:00
|
|
|
};
|
2018-09-11 17:10:59 +00:00
|
|
|
</script>
|