2018-09-11 17:10:59 +00:00
|
|
|
<template>
|
2021-03-29 17:49:49 +00:00
|
|
|
<div ref="createButton"
|
|
|
|
class="c-create-button--w"
|
|
|
|
>
|
2019-12-04 20:39:09 +00:00
|
|
|
<button
|
|
|
|
class="c-create-button c-button--menu c-button--major icon-plus"
|
2021-03-29 17:49:49 +00:00
|
|
|
@click.prevent.stop="showCreateMenu"
|
2019-12-04 20:39:09 +00:00
|
|
|
>
|
|
|
|
<span class="c-button__label">Create</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
2018-09-11 17:10:59 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-12-07 20:27:23 +00:00
|
|
|
import CreateAction from '@/plugins/formActions/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 = {
|
2021-03-29 17:49:49 +00:00
|
|
|
cssClass: menuItem.cssClass,
|
2019-12-04 20:39:09 +00:00
|
|
|
name: menuItem.name,
|
2021-03-29 17:49:49 +00:00
|
|
|
description: menuItem.description,
|
2021-07-29 16:19:07 +00:00
|
|
|
onItemClicked: () => this.create(key)
|
2019-12-04 20:39:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-03-29 17:49:49 +00:00
|
|
|
showCreateMenu() {
|
|
|
|
const elementBoundingClientRect = this.$refs.createButton.getBoundingClientRect();
|
|
|
|
const x = elementBoundingClientRect.x;
|
|
|
|
const y = elementBoundingClientRect.y + elementBoundingClientRect.height;
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2021-03-29 17:49:49 +00:00
|
|
|
const menuOptions = {
|
|
|
|
menuClass: 'c-create-menu'
|
|
|
|
};
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2021-03-29 17:49:49 +00:00
|
|
|
this.openmct.menus.showSuperMenu(x, y, this.sortedItems, menuOptions);
|
2019-12-04 20:39:09 +00:00
|
|
|
},
|
2021-03-29 17:49:49 +00:00
|
|
|
create(key) {
|
2019-12-04 20:39:09 +00:00
|
|
|
// 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) => {
|
2021-12-07 20:27:23 +00:00
|
|
|
const createAction = new CreateAction(this.openmct, key, currentObject);
|
2020-07-31 19:11:03 +00:00
|
|
|
|
2021-12-07 20:27:23 +00:00
|
|
|
createAction.invoke();
|
2019-12-04 20:39:09 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
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>
|