openmct/e2e/helper/addInitFileInputObject.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

class DomainObjectViewProvider {
2023-06-23 20:52:03 +00:00
constructor(openmct) {
this.key = 'doViewProvider';
this.name = 'Domain Object View Provider';
this.openmct = openmct;
}
2023-06-23 20:52:03 +00:00
canView(domainObject) {
return domainObject.type === 'imageFileInput' || domainObject.type === 'jsonFileInput';
}
2023-06-23 20:52:03 +00:00
view(domainObject, objectPath) {
let content;
2023-06-23 20:52:03 +00:00
return {
show: function (element) {
const body = domainObject.selectFile.body;
const type = typeof body;
2023-06-23 20:52:03 +00:00
content = document.createElement('div');
content.id = 'file-input-type';
content.textContent = JSON.stringify(type);
element.appendChild(content);
},
destroy: function (element) {
element.removeChild(content);
content = undefined;
}
};
}
}
document.addEventListener('DOMContentLoaded', () => {
2023-06-23 20:52:03 +00:00
const openmct = window.openmct;
2023-06-23 20:52:03 +00:00
openmct.types.addType('jsonFileInput', {
key: 'jsonFileInput',
name: 'JSON File Input Object',
creatable: true,
form: [
{
name: 'Upload File',
key: 'selectFile',
control: 'file-input',
required: true,
text: 'Select File...',
type: 'application/json',
property: ['selectFile']
}
]
});
2023-06-23 20:52:03 +00:00
openmct.types.addType('imageFileInput', {
key: 'imageFileInput',
name: 'Image File Input Object',
creatable: true,
form: [
{
name: 'Upload File',
key: 'selectFile',
control: 'file-input',
required: true,
text: 'Select File...',
type: 'image/*',
property: ['selectFile']
}
]
});
2023-06-23 20:52:03 +00:00
openmct.objectViews.addProvider(new DomainObjectViewProvider(openmct));
});