mirror of
https://github.com/nasa/openmct.git
synced 2025-06-25 18:50:11 +00:00
Compare commits
4 Commits
emit-click
...
windowLayo
Author | SHA1 | Date | |
---|---|---|---|
5283d06e05 | |||
888695f636 | |||
9f0af90663 | |||
e93d36ff19 |
@ -82,6 +82,7 @@
|
||||
openmct.install(openmct.plugins.Filters(['table', 'telemetry.plot.overlay']));
|
||||
openmct.install(openmct.plugins.ObjectMigration());
|
||||
openmct.install(openmct.plugins.ClearData(['table', 'telemetry.plot.overlay', 'telemetry.plot.stacked']));
|
||||
openmct.install(openmct.plugins.WindowLayout());
|
||||
openmct.start();
|
||||
</script>
|
||||
</html>
|
||||
|
@ -51,7 +51,8 @@ define([
|
||||
'./conditionWidget/plugin',
|
||||
'./themes/espresso',
|
||||
'./themes/maelstrom',
|
||||
'./themes/snow'
|
||||
'./themes/snow',
|
||||
'./windowLayout/plugin'
|
||||
], function (
|
||||
_,
|
||||
UTCTimeSystem,
|
||||
@ -83,7 +84,8 @@ define([
|
||||
ConditionWidgetPlugin,
|
||||
Espresso,
|
||||
Maelstrom,
|
||||
Snow
|
||||
Snow,
|
||||
WindowLayout
|
||||
) {
|
||||
var bundleMap = {
|
||||
LocalStorage: 'platform/persistence/local',
|
||||
@ -192,6 +194,7 @@ define([
|
||||
plugins.Snow = Snow.default;
|
||||
plugins.Condition = ConditionPlugin.default;
|
||||
plugins.ConditionWidget = ConditionWidgetPlugin.default;
|
||||
plugins.WindowLayout = WindowLayout.default;
|
||||
|
||||
return plugins;
|
||||
});
|
||||
|
183
src/plugins/windowLayout/components/WindowLayout.vue
Normal file
183
src/plugins/windowLayout/components/WindowLayout.vue
Normal file
@ -0,0 +1,183 @@
|
||||
<template>
|
||||
<div v-if="!isOpener"
|
||||
class="c-indicator c-indicator--clickable icon-save s-status-caution"
|
||||
>
|
||||
<span class="label c-indicator__label">
|
||||
<button @click="open2Windows">Open 2 Windows</button>
|
||||
<button @click="closeAllWindows">Close Windows</button>
|
||||
<button @click="openSavedWindows">Open Saved Windows</button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
inject: ['openmct'],
|
||||
computed: {
|
||||
isOpener() {
|
||||
return window.opener;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.openWindows = {};
|
||||
this.windowFeatures = "menubar=yes,location=yes,tabs=yes, resizable=yes,scrollbars=yes, innerHeight=480,innerWidth=640,screenY=100";
|
||||
window.addEventListener("message", this.receiveMessage, false);
|
||||
if (window.opener) {
|
||||
window.opener.postMessage({
|
||||
status: 'READY',
|
||||
name: window.name
|
||||
},'*');
|
||||
window.addEventListener('beforeunload', () => {
|
||||
window.opener.postMessage({
|
||||
status: 'CLOSED',
|
||||
name: window.name
|
||||
},'*');
|
||||
});
|
||||
window.addEventListener('blur', () => {
|
||||
window.opener.postMessage({
|
||||
query: 'QUERY__SIZE',
|
||||
info: {
|
||||
innerHeight: window.innerHeight,
|
||||
innerWidth: window.innerWidth,
|
||||
screenLeft: window.screenLeft,
|
||||
screenTop: window.screenTop,
|
||||
screenWidth: screen.width,
|
||||
screenHeight: screen.height,
|
||||
screenAvailableWidth: screen.availWidth,
|
||||
screenAvailHeight: screen.availHeight,
|
||||
devicePixelRatio: window.devicePixelRatio,
|
||||
url: window.location.href
|
||||
},
|
||||
name: window.name
|
||||
},'*');
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
persistWindowInformation() {
|
||||
window.localStorage.setItem('openmct-windowlayout-items',
|
||||
JSON.stringify(this.getOpenWindowSpecifications()));
|
||||
},
|
||||
getScreenX() {
|
||||
return !Object.keys(this.openWindows).length ? 100: (screen.width - (Object.keys(this.openWindows).length*640));
|
||||
},
|
||||
open2Windows() {
|
||||
this.openWindow(`${this.windowFeatures},screenX=${this.getScreenX()}`);
|
||||
this.openWindow(`${this.windowFeatures},screenX=${this.getScreenX()}`);
|
||||
},
|
||||
openWindow(windowFeatures) {
|
||||
let newWindowName = `Open MCT Window ${Object.keys(this.openWindows).length+1}`;
|
||||
this.openWindows[newWindowName] = { windowReference: window.open(window.location.href, newWindowName, windowFeatures)};
|
||||
},
|
||||
moveWindow() {
|
||||
const key = Object.keys(this.openWindows)[0];
|
||||
this.openWindows[key].postMessage({
|
||||
command: 'moveTo',
|
||||
params: [window.screenLeft + 40, window.screenTop + 40]
|
||||
}, 'http://localhost:8080');
|
||||
},
|
||||
openSavedWindows() {
|
||||
const persistedWindowObjs = window.localStorage.getItem('openmct-windowlayout-items');
|
||||
if (persistedWindowObjs) {
|
||||
const windowObjs = JSON.parse(persistedWindowObjs);
|
||||
windowObjs.forEach(windowObj => {
|
||||
let newWindowName = windowObj.name;
|
||||
const features = `menubar=yes,location=yes,resizable=yes,scrollbars=yes,innerHeight=${windowObj.info.innerHeight || 480},innerWidth=${windowObj.info.innerWidth || 640},screenX=${windowObj.info.screenLeft || this.getScreenX()},screenY=${windowObj.info.screenTop || 100}`;
|
||||
const windowReference = window.open((windowObj.info.url || window.location.href), newWindowName, features);
|
||||
this.openWindows[newWindowName] = {
|
||||
windowReference,
|
||||
name: newWindowName,
|
||||
info: windowObj.info
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
closeAllWindows() {
|
||||
this.persistWindowInformation();
|
||||
Object.keys(this.openWindows).forEach((windowName => {
|
||||
const windowObj = this.openWindows[windowName];
|
||||
windowObj.closedByOpener = true;
|
||||
windowObj.windowReference.close();
|
||||
}));
|
||||
},
|
||||
receiveMessage(event) {
|
||||
const { data, origin, source} = event;
|
||||
switch(origin) {
|
||||
case 'http://localhost:8080':
|
||||
if (data) {
|
||||
if (data.status === 'READY') {
|
||||
let newWindowReference = this.openWindows[data.name].windowReference;
|
||||
newWindowReference.postMessage({
|
||||
command: 'QUERY__SIZE'
|
||||
}, 'http://localhost:8080');
|
||||
} else if (data.status === 'CLOSED') {
|
||||
const closedByOpener = this.openWindows[data.name].closedByOpener;
|
||||
this.openWindows[data.name] = undefined;
|
||||
delete this.openWindows[data.name];
|
||||
if (!closedByOpener) {
|
||||
this.persistWindowInformation();
|
||||
}
|
||||
} else if (data.command) {
|
||||
switch(data.command) {
|
||||
case 'QUERY__SIZE':
|
||||
source.postMessage({
|
||||
query: data.command,
|
||||
info: {
|
||||
innerHeight: window.innerHeight,
|
||||
innerWidth: window.innerWidth,
|
||||
screenLeft: window.screenLeft,
|
||||
screenTop: window.screenTop,
|
||||
screenWidth: screen.width,
|
||||
screenHeight: screen.height,
|
||||
screenAvailableWidth: screen.availWidth,
|
||||
screenAvailHeight: screen.availHeight,
|
||||
devicePixelRatio: window.devicePixelRatio,
|
||||
url: window.location.href
|
||||
},
|
||||
name: window.name
|
||||
}, origin);
|
||||
break;
|
||||
default:
|
||||
window[data.command](...data.params);
|
||||
this.$nextTick(() => {
|
||||
source.postMessage({
|
||||
query: data.command,
|
||||
name: window.name
|
||||
}, origin);
|
||||
});
|
||||
break;
|
||||
}
|
||||
} else if (data.query) {
|
||||
if (data.info) {
|
||||
if (!this.openWindows[data.name]) {
|
||||
return;
|
||||
}
|
||||
this.openWindows[data.name].info = data.info;
|
||||
this.persistWindowInformation();
|
||||
} else {
|
||||
if (!this.openWindows[data.name]) {
|
||||
return;
|
||||
}
|
||||
let newWindowReference = this.openWindows[data.name].windowReference;
|
||||
newWindowReference.postMessage({
|
||||
command: 'QUERY__SIZE'
|
||||
}, 'http://localhost:8080');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
getOpenWindowSpecifications() {
|
||||
return Object.keys(this.openWindows).map(key => {
|
||||
return {
|
||||
name: key,
|
||||
info: this.openWindows[key].info
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
43
src/plugins/windowLayout/plugin.js
Normal file
43
src/plugins/windowLayout/plugin.js
Normal file
@ -0,0 +1,43 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT, Copyright (c) 2014-2019, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
import Vue from 'vue';
|
||||
import WindowLayout from "./components/WindowLayout.vue";
|
||||
|
||||
export default function plugin() {
|
||||
|
||||
return function install(openmct) {
|
||||
let component = new Vue ({
|
||||
provide: {
|
||||
openmct
|
||||
},
|
||||
components: {
|
||||
WindowLayout: WindowLayout
|
||||
},
|
||||
template: '<WindowLayout></WindowLayout>'
|
||||
}),
|
||||
indicator = {
|
||||
element: component.$mount().$el
|
||||
};
|
||||
|
||||
openmct.indicators.add(indicator);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user