Compare commits

...

4 Commits

Author SHA1 Message Date
5283d06e05 Save window location 2020-05-18 10:43:18 -07:00
888695f636 Saves indicator buttons 2020-05-14 14:37:30 -07:00
9f0af90663 WIP - Open 2 windows, close them and open the saved 2 windows 2020-05-14 11:53:53 -07:00
e93d36ff19 WIP windowLayouts 2020-05-12 10:43:20 -07:00
4 changed files with 232 additions and 2 deletions

View File

@ -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>

View File

@ -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;
});

View 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>

View 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);
};
}