mirror of
https://github.com/nasa/openmct.git
synced 2025-04-10 21:00:16 +00:00
Create menu (#2195)
* Wire up create with old create action * refactor grid and list view to listen on composition, use lodash for sorts, remove item count * remove item count on grid view item count needs to be supported by composition API and not by inspecting model, otherwise it will be inconsistent. * close menu after create or clickaway
This commit is contained in:
parent
4374a6fa28
commit
06b9e0fa97
@ -82,6 +82,7 @@ define(
|
||||
*/
|
||||
EditorCapability.prototype.save = function () {
|
||||
console.warn('DEPRECATED: cannot save via edit capability, use openmct.editor instead.');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
EditorCapability.prototype.invoke = EditorCapability.prototype.edit;
|
||||
@ -93,6 +94,7 @@ define(
|
||||
*/
|
||||
EditorCapability.prototype.finish = function () {
|
||||
console.warn('DEPRECATED: cannot finish via edit capability, use openmct.editor instead.');
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ define(
|
||||
* @param {ActionContext} context the context in which the
|
||||
* action is being performed
|
||||
*/
|
||||
function CreateAction(type, parent, context) {
|
||||
function CreateAction(type, parent, context, openmct) {
|
||||
this.metadata = {
|
||||
key: 'create',
|
||||
cssClass: type.getCssClass(),
|
||||
@ -55,6 +55,7 @@ define(
|
||||
};
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
this.openmct = openmct;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,37 +64,28 @@ define(
|
||||
*/
|
||||
CreateAction.prototype.perform = function () {
|
||||
var newModel = this.type.getInitialModel(),
|
||||
openmct = this.openmct,
|
||||
newObject,
|
||||
editAction,
|
||||
editorCapability;
|
||||
|
||||
function closeEditor() {
|
||||
return editorCapability.finish();
|
||||
}
|
||||
editAction;
|
||||
|
||||
function onSave() {
|
||||
return editorCapability.save()
|
||||
.then(closeEditor);
|
||||
openmct.editor.save();
|
||||
}
|
||||
|
||||
function onCancel() {
|
||||
return closeEditor();
|
||||
openmct.editor.cancel();
|
||||
}
|
||||
|
||||
newModel.type = this.type.getKey();
|
||||
newModel.location = this.parent.getId();
|
||||
newObject = this.parent.useCapability('instantiation', newModel);
|
||||
editorCapability = newObject.hasCapability('editor') && newObject.getCapability("editor");
|
||||
|
||||
openmct.editor.edit();
|
||||
editAction = newObject.getCapability("action").getActions("edit")[0];
|
||||
//If an edit action is available, perform it
|
||||
if (editAction) {
|
||||
return editAction.perform();
|
||||
} else if (editorCapability) {
|
||||
//otherwise, use the save as action
|
||||
editorCapability.edit();
|
||||
return newObject.getCapability("action").perform("save-as").then(onSave, onCancel);
|
||||
}
|
||||
newObject.getCapability("action").perform("save-as").then(onSave, onCancel);
|
||||
// TODO: support editing object without saving object first.
|
||||
// Which means we have to toggle createwizard afterwards. For now,
|
||||
// We will disable this.
|
||||
};
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
v-bind:key="index"
|
||||
class="l-grid-view__item c-grid-item"
|
||||
:class="{ 'is-alias': item.isAlias === true }"
|
||||
@click="navigate(item.model.identifier.key)">
|
||||
@click="navigate(item)">
|
||||
<div class="c-grid-item__type-icon"
|
||||
:class="(item.type.cssClass != undefined) ? 'bg-' + item.type.cssClass : 'bg-icon-object-unknown'">
|
||||
</div>
|
||||
@ -15,9 +15,6 @@
|
||||
<div class="c-grid-item__metadata"
|
||||
:title="item.type.name">
|
||||
<span class="c-grid-item__metadata__type">{{item.type.name}}</span>
|
||||
<span class="c-grid-item__metadata__item-count" v-if="item.model.composition !== undefined">
|
||||
{{item.model.composition.length}} item<span v-if="item.model.composition.length !== 1">s</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="c-grid-item__controls">
|
||||
@ -177,45 +174,17 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
import compositionLoader from './composition-loader';
|
||||
|
||||
export default {
|
||||
inject: ['openmct', 'domainObject'],
|
||||
data() {
|
||||
var items = [],
|
||||
unknownObjectType = {
|
||||
definition: {
|
||||
cssClass: 'icon-object-unknown',
|
||||
name: 'Unknown Type'
|
||||
}
|
||||
};
|
||||
|
||||
var composition = this.openmct.composition.get(this.domainObject);
|
||||
|
||||
if (composition) {
|
||||
|
||||
composition.load().then((array) => {
|
||||
if (Array.isArray(array)) {
|
||||
array.forEach((model) => {
|
||||
var type = this.openmct.types.get(model.type) || unknownObjectType;
|
||||
|
||||
items.push({
|
||||
model: model,
|
||||
type: type.definition,
|
||||
isAlias: this.domainObject.identifier.key !== model.location
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
items: items
|
||||
}
|
||||
},
|
||||
mixins: [compositionLoader],
|
||||
inject: ['domainObject', 'openmct'],
|
||||
methods: {
|
||||
navigate(identifier) {
|
||||
navigate(item) {
|
||||
let currentLocation = this.openmct.router.currentLocation.path,
|
||||
navigateToPath = `${currentLocation}/${identifier}`;
|
||||
|
||||
navigateToPath = `${currentLocation}/${this.openmct.objects.makeKeyString(item.model.identifier)}`;
|
||||
|
||||
this.openmct.router.setPath(navigateToPath);
|
||||
}
|
||||
}
|
||||
|
@ -4,30 +4,41 @@
|
||||
<thead class="c-table__header">
|
||||
<tr>
|
||||
<th class="is-sortable"
|
||||
v-bind:class="[orderByField == 'name' ? 'is-sorting' : '', sortClass]"
|
||||
@click="sortTrigger('name', 'asc')">
|
||||
:class="{
|
||||
'is-sorting': sortBy === 'model.name',
|
||||
'asc': ascending,
|
||||
'desc': !ascending
|
||||
}"
|
||||
@click="sort('model.name', true)">
|
||||
Name
|
||||
</th>
|
||||
<th class="is-sortable"
|
||||
v-bind:class="[orderByField == 'type' ? 'is-sorting' : '', sortClass]"
|
||||
@click="sortTrigger('type', 'asc')">
|
||||
:class="{
|
||||
'is-sorting': sortBy === 'type.name',
|
||||
'asc': ascending,
|
||||
'desc': !ascending
|
||||
}"
|
||||
@click="sort('type.name', true)">
|
||||
Type
|
||||
</th>
|
||||
<th class="is-sortable"
|
||||
v-bind:class="[orderByField == 'createdDate' ? 'is-sorting' : '', sortClass]"
|
||||
@click="sortTrigger('createdDate', 'desc')">
|
||||
:class="{
|
||||
'is-sorting': sortBy === 'model.persisted',
|
||||
'asc': ascending,
|
||||
'desc': !ascending
|
||||
}"
|
||||
@click="sort('model.persisted', false)">
|
||||
Created Date
|
||||
</th>
|
||||
<th class="is-sortable"
|
||||
v-bind:class="[orderByField == 'updatedDate' ? 'is-sorting' : '', sortClass]"
|
||||
@click="sortTrigger('updatedDate', 'desc')">
|
||||
:class="{
|
||||
'is-sorting': sortBy === 'model.modified',
|
||||
'asc': ascending,
|
||||
'desc': !ascending
|
||||
}"
|
||||
@click="sort('model.modified', false)">
|
||||
Updated Date
|
||||
</th>
|
||||
<th class="is-sortable"
|
||||
v-bind:class="[orderByField == 'items' ? 'is-sorting' : '', sortClass]"
|
||||
@click="sortTrigger('items', 'asc')">
|
||||
Items
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -35,15 +46,15 @@
|
||||
v-for="(item,index) in sortedItems"
|
||||
v-bind:key="index"
|
||||
:class="{ 'is-alias': item.isAlias === true }"
|
||||
@click="navigate(item.identifier)">
|
||||
@click="navigate(item)">
|
||||
<td class="c-list-item__name">
|
||||
<div class="c-list-item__type-icon" :class="(item.cssClass != undefined) ? item.cssClass : 'icon-object-unknown'"></div>
|
||||
{{item.name}}
|
||||
<div class="c-list-item__type-icon"
|
||||
:class="item.type.cssClass"></div>
|
||||
{{item.model.name}}
|
||||
</td>
|
||||
<td class="c-list-item__type">{{ item.type }}</td>
|
||||
<td class="c-list-item__date-created">{{ formatTime(item.createdDate, 'YYYY-MM-DD HH:mm:ss:SSS') }}Z</td>
|
||||
<td class="c-list-item__date-updated">{{ formatTime(item.updatedDate, 'YYYY-MM-DD HH:mm:ss:SSS') }}Z</td>
|
||||
<td class="c-list-item__items">{{ item.items }}</td>
|
||||
<td class="c-list-item__type">{{ item.type.name }}</td>
|
||||
<td class="c-list-item__date-created">{{ formatTime(item.model.persisted, 'YYYY-MM-DD HH:mm:ss:SSS') }}Z</td>
|
||||
<td class="c-list-item__date-updated">{{ formatTime(item.model.modified, 'YYYY-MM-DD HH:mm:ss:SSS') }}Z</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -122,94 +133,46 @@
|
||||
|
||||
<script>
|
||||
|
||||
import lodash from 'lodash';
|
||||
import moment from 'moment';
|
||||
import compositionLoader from './composition-loader';
|
||||
|
||||
export default {
|
||||
inject: ['openmct', 'domainObject', 'Moment'],
|
||||
mixins: [compositionLoader],
|
||||
inject: ['domainObject', 'openmct'],
|
||||
data() {
|
||||
var items = [],
|
||||
unknownObjectType = {
|
||||
definition: {
|
||||
cssClass: 'icon-object-unknown',
|
||||
name: 'Unknown Type'
|
||||
}
|
||||
},
|
||||
composition = this.openmct.composition.get(this.domainObject);
|
||||
|
||||
if (composition) {
|
||||
|
||||
composition.load().then((array) => {
|
||||
if (Array.isArray(array)) {
|
||||
array.forEach(model => {
|
||||
var type = this.openmct.types.get(model.type) || unknownObjectType;
|
||||
|
||||
items.push({
|
||||
name: model.name,
|
||||
identifier: model.identifier.key,
|
||||
type: type.definition.name,
|
||||
isAlias: false,
|
||||
cssClass: type.definition.cssClass,
|
||||
createdDate: model.persisted,
|
||||
updatedDate: model.modified,
|
||||
items: model.composition ? model.composition.length : 0,
|
||||
isAlias: this.domainObject.identifier.key !== model.location
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
items: items,
|
||||
orderByField: 'name',
|
||||
sortClass: 'asc',
|
||||
}
|
||||
sortBy: 'model.name',
|
||||
ascending: true
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
sortedItems () {
|
||||
if (this.sortClass === 'asc') {
|
||||
return this.items.sort(this.ascending.bind(this));
|
||||
} else if (this.sortClass === 'desc') {
|
||||
return this.items.sort(this.descending.bind(this));
|
||||
}
|
||||
},
|
||||
formatTime () {
|
||||
return function (timestamp, format) {
|
||||
return this.Moment(timestamp).format(format);
|
||||
let sortedItems = _.sortBy(this.items, this.sortBy);
|
||||
if (!this.ascending) {
|
||||
sortedItems = sortedItems.reverse();
|
||||
}
|
||||
return sortedItems;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
navigate(identifier) {
|
||||
formatTime(timestamp, format) {
|
||||
return moment(timestamp).format(format);
|
||||
},
|
||||
navigate(item) {
|
||||
let currentLocation = this.openmct.router.currentLocation.path,
|
||||
navigateToPath = `${currentLocation}/${identifier}`;
|
||||
|
||||
navigateToPath = `${currentLocation}/${this.openmct.objects.makeKeyString(item.model.identifier)}`;
|
||||
|
||||
this.openmct.router.setPath(navigateToPath);
|
||||
},
|
||||
sortTrigger(field, sortOrder) {
|
||||
if (this.orderByField === field) {
|
||||
this.sortClass = (this.sortClass === 'asc') ? 'desc' : 'asc';
|
||||
sort(field, defaultDirection) {
|
||||
if (this.sortBy === field) {
|
||||
this.ascending = !this.ascending;
|
||||
} else {
|
||||
this.sortClass = sortOrder;
|
||||
}
|
||||
this.orderByField = field;
|
||||
},
|
||||
ascending(first, second) {
|
||||
if (first[this.orderByField] < second[this.orderByField]) {
|
||||
return -1;
|
||||
} else if (first[this.orderByField] > second[this.orderByField]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
descending(first, second) {
|
||||
if (first[this.orderByField] > second[this.orderByField]) {
|
||||
return -1;
|
||||
} else if (first[this.orderByField] < second[this.orderByField]) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
this.sortBy = field;
|
||||
this.ascending = defaultDirection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
46
src/plugins/folderView/components/composition-loader.js
Normal file
46
src/plugins/folderView/components/composition-loader.js
Normal file
@ -0,0 +1,46 @@
|
||||
const unknownObjectType = {
|
||||
definition: {
|
||||
cssClass: 'icon-object-unknown',
|
||||
name: 'Unknown Type'
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
inject: ['openmct', 'domainObject'],
|
||||
data() {
|
||||
return {
|
||||
items: []
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.composition = this.openmct.composition.get(this.domainObject);
|
||||
if (!this.composition) {
|
||||
return;
|
||||
}
|
||||
this.composition.on('add', this.add);
|
||||
this.composition.on('remove', this.remove);
|
||||
this.composition.load();
|
||||
},
|
||||
destroyed() {
|
||||
if (!this.composition) {
|
||||
return;
|
||||
}
|
||||
this.composition.off('add', this.add);
|
||||
this.composition.off('remove', this.remove);
|
||||
},
|
||||
methods: {
|
||||
add(child, index, anything) {
|
||||
var type = this.openmct.types.get(child.type) || unknownObjectType;
|
||||
|
||||
this.items.push({
|
||||
model: child,
|
||||
type: type.definition,
|
||||
isAlias: this.domainObject.identifier.key !== child.location
|
||||
});
|
||||
},
|
||||
remove(child) {
|
||||
// TODO: implement remove action
|
||||
console.log('remove child? might be identifier');
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
<template>
|
||||
<div class="c-create-button--w">
|
||||
<button class="c-create-button c-button--menu c-button--major icon-plus"
|
||||
@click="toggleCreateMenu">
|
||||
@click="open">
|
||||
<span class="c-button__label">Create</span>
|
||||
</button>
|
||||
<div class="c-create-menu c-super-menu"
|
||||
v-if="showCreateMenu">
|
||||
v-if="opened">
|
||||
<div class="c-super-menu__menu">
|
||||
<ul>
|
||||
<li v-for="(item, index) in items"
|
||||
:key="index"
|
||||
:class="item.class"
|
||||
:title="item.title"
|
||||
@mouseover="showItemDescription(item)">
|
||||
@mouseover="showItemDescription(item)"
|
||||
@click="create(item)">
|
||||
{{ item.name }}
|
||||
</li>
|
||||
</ul>
|
||||
@ -56,22 +57,63 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import CreateAction from '../../../../platform/commonUI/edit/src/creation/CreateAction';
|
||||
import objectUtils from '../../../api/objects/object-utils';
|
||||
|
||||
function convertToLegacyObject(domainObject) {
|
||||
let keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||
let oldModel = objectUtils.toOldFormat(domainObject);
|
||||
return instantiate(oldModel, keyString);
|
||||
}
|
||||
export default {
|
||||
inject: ['openmct'],
|
||||
props: {
|
||||
showCreateMenu: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleCreateMenu: function () {
|
||||
this.showCreateMenu = !this.showCreateMenu;
|
||||
open: function () {
|
||||
if (this.opened) {
|
||||
return;
|
||||
}
|
||||
this.opened = true;
|
||||
setTimeout(() => document.addEventListener('click', this.close));
|
||||
},
|
||||
close: function () {
|
||||
if (!this.opened) {
|
||||
return;
|
||||
}
|
||||
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.
|
||||
let legacyContextualParent = this.convertToLegacy(openmct.router.path[0]);
|
||||
let legacyType = 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
|
||||
);
|
||||
return action.perform();
|
||||
},
|
||||
convertToLegacy (domainObject) {
|
||||
let keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||
let oldModel = objectUtils.toOldFormat(domainObject);
|
||||
return openmct.$injector.get('instantiate')(oldModel, keyString);
|
||||
}
|
||||
},
|
||||
destroyed () {
|
||||
document.removeEventListener('click', this.close);
|
||||
},
|
||||
data: function() {
|
||||
let items = [];
|
||||
|
||||
@ -80,6 +122,7 @@
|
||||
|
||||
if (menuItem.creatable) {
|
||||
let menuItemTemplate = {
|
||||
key: key,
|
||||
name: menuItem.name,
|
||||
class: menuItem.cssClass,
|
||||
title: menuItem.description
|
||||
@ -91,7 +134,8 @@
|
||||
|
||||
return {
|
||||
items: items,
|
||||
selectedMenuItem: {}
|
||||
selectedMenuItem: {},
|
||||
opened: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ define([
|
||||
}
|
||||
|
||||
let navigatedObject = objects[objects.length - 1];
|
||||
// FIXME: this is a hack to support create action, intended to
|
||||
// expose the current routed path. We need to rewrite the
|
||||
// navigation service and router to expose a clear and minimal
|
||||
// API for this.
|
||||
openmct.router.path = objects.reverse();
|
||||
|
||||
openmct.layout.$refs.browseBar.domainObject = navigatedObject;
|
||||
browseObject = navigatedObject;
|
||||
|
Loading…
x
Reference in New Issue
Block a user