Skip to content

Commit

Permalink
Add servers store and basic help text
Browse files Browse the repository at this point in the history
  • Loading branch information
geographika committed Aug 31, 2023
1 parent ac1fda0 commit cb6a606
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 100 deletions.
26 changes: 26 additions & 0 deletions app/store/Servers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Ext.define('OwsInspector.store.Servers', {
extend: 'Ext.data.Store',
alias: 'store.servers',
storeId: 'servers',
fields: [
{ name: 'name', type: 'string' },
{ name: 'url', type: 'string' },
{
name: 'displayName',
type: 'string',
depends: ['name', 'url'],
convert: function (value, record) {
return `${record.get('name')} - ${record.get('url')}`
}
}
],
data: [
{ name: 'MapServer Demo Server', url: 'https://demo.mapserver.org/cgi-bin/wms' },
{ name: 'MapServer msautotest', url: 'https://demo.mapserver.org/cgi-bin/msautotest' },
{ name: 'EPA Ireland WMS', url: 'https://gis.epa.ie/geoserver/wms?' },
{ name: 'EPA Ireland WFS', url: 'https://gis.epa.ie/geoserver/wfs?' },
{ name: 'European Marine Observation and Data Network Bathymetry', url: 'https://ows.emodnet-bathymetry.eu/' },
{ name: 'Terrestris OWS Demo', url: 'https://ows-demo.terrestris.de/geoserver/osm/ows' },
],
// sorters: ['name']
});
58 changes: 44 additions & 14 deletions app/view/ows/OwsWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ Ext.define('OwsInspector.view.ows.OwsWindow', {
title: 'Open Web Services Inspector',
width: 800,
height: 600,
maximizable: true,
closeAction: 'hide',
maximizable: false,
closable: false,
//bind: {
// closable: '{isFloatingWindow}',
//},
//closeAction: 'hide',
layout: 'border',
items: [
{
Expand All @@ -24,30 +28,26 @@ Ext.define('OwsInspector.view.ows.OwsWindow', {
type: 'hbox',
},
items: [

{
xtype: 'combo',
forceSelection: false,
editable: true,
fieldLabel: 'Server URL',
emptyText: 'To test against different servers enter the root URL here',
flex: 1,
valueField: 'url',
displayField: 'displayName',
bind: {
store: '{serverUrls}',
store: '{servers}',
value: '{mapserverUrl}'
},
listeners: {
change: function (textfield, newValue) {
textfield.setValue(newValue.trim());
if (newValue) {
textfield.setValue(newValue.trim());
}
}
}
},
{
xtype: 'button',
width: 150,
text: 'Update Capabilities',
handler: 'onUpdateCapabilities',
margin: '0 0 0 5' // Add some margin to separate the button from the textbox
}],
},
{
Expand Down Expand Up @@ -79,7 +79,7 @@ Ext.define('OwsInspector.view.ows.OwsWindow', {
listeners: {
parametersupdated: 'onParametersUpdated'
},
hidden: false
hidden: true
}]
},
{
Expand All @@ -88,6 +88,27 @@ Ext.define('OwsInspector.view.ows.OwsWindow', {
itemId: 'center',
layout: 'fit',
items: [{
xtype: 'container',
itemId: 'blank',
html: `<h2>Welcome to the Open Web Services Inspector!</h2>
<ol>
<li>Select or enter a "Server URL" - the server must use <b>https</b></li>
<li>Click "Send Request" to load the capabilities from the server</li>
<li>Try other OwS requests!</li>
</ol>
`,
style: {
backgroundColor: '#F5F5F5',
padding: '10px',
color: 'black',
fontSize: 'large',
//backgroundImage: 'linear-gradient(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)),url(/resources/images/watermark.png)',
backgroundImage: 'linear-gradient(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)),url(/resources/images/vector_tiles.png)',
//backgroundSize: 'cover',
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat'
},
}, {
xtype: 'container',
itemId: 'xml',
html: '<div id="xmlEditor" style="width: 100%; height: 100%" />',
Expand Down Expand Up @@ -150,14 +171,23 @@ Ext.define('OwsInspector.view.ows.OwsWindow', {
}]
}],
buttons: [
{
xtype: 'button',
text: 'Reset',
handler: 'onReset'
},
{
xtype: 'button',
text: 'Send Request',
handler: 'onSendRequest'
},
{
xtype: 'button',
text: 'Close',
handler: 'onClose'
handler: 'onClose',
bind: {
hidden: '{!isFloatingWindow}'
}
}
]
});
111 changes: 44 additions & 67 deletions app/view/ows/OwsWindowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
setEditorVisibilites: function (activeEditor) {

const me = this;
const containerIds = ['#imageOutput', '#xml', '#json', '#html'];
const containerIds = ['#blank', '#imageOutput', '#xml', '#json', '#html'];
var container;

Ext.each(containerIds, function (id) {
Expand All @@ -108,6 +108,11 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
});
},

onReset: function () {
const me = this;
me.setEditorVisibilites('#blank');
},

updateWmsCapabilities: function (text) {
const me = this;

Expand Down Expand Up @@ -144,72 +149,6 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
// https://github.com/openlayers/openlayers/issues/8909
},

/**
* Function to update the view models based on the response of a remote server
*/
onUpdateCapabilities: function () {

const me = this;
const xType = me.getView().down('tabpanel').getActiveTab().xtype;
var params = {
request: 'GetCapabilities',
};

switch (xType) {

case 'ms_wmspanel':
params.service = 'WMS';
break;
case 'ms_wfspanel':
params.service = 'WFS';
break;
default:
console.log(`xType ${xType} unknown`);
}

const vm = me.getViewModel();
const mapserverUrl = vm.get('mapserverUrl');
const separator = mapserverUrl.indexOf('?') === -1 ? '?' : '&';
const queryString = Ext.Object.toQueryString(params);
const outputUrl = mapserverUrl + separator + queryString;

me.setEditorVisibilites('#json');
me.setupJsonEditor();
const doc = me.jsonEditor.getSession().doc;

const centerRegion = me.getView().down('#center');
centerRegion.mask('Sending request...');

fetch(outputUrl)
.then(function (response) {
return response.text();
})
.then(function (text) {

switch (xType) {

case 'ms_wmspanel':
params.service = 'WMS';
me.updateWmsCapabilities(text);
break;
case 'ms_wfspanel':
params.service = 'WFS';
me.updateWfsCapabilities(text);
break;
default:
console.log(`xType ${xType} unknown`);
}
})
.catch(error => {
// Handle errors
const decodedUrl = decodeURIComponent(outputUrl);
doc.setValue(`Unable to read capabilities from: ${decodedUrl} - ${error}`);
})
.finally(() => {
centerRegion.unmask();
});
},

onParametersUpdated: function () {

var me = this;
Expand All @@ -233,6 +172,11 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
}

const mapserverUrl = me.getViewModel().get('mapserverUrl');

if (!mapserverUrl) {
return '';
}

var queryString = Ext.Object.toQueryString(params);

// Append the new parameters to the URL, with a ? or & as appropriate
Expand Down Expand Up @@ -275,6 +219,14 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
sendRequest: function (outputUrl) {

const me = this;

const mapserverUrl = me.getViewModel().get('mapserverUrl');
if (!mapserverUrl) {
// if there is no server url then display the default help HTML
me.setEditorVisibilites('#blank');
return;
}

var imageContainer = me.getView().down('#imageOutput');
var xmlContainer = me.getView().down('#xml');

Expand All @@ -288,6 +240,31 @@ Ext.define('OwsInspector.view.ows.OwsWindowController', {
})
.then(result => {
const { responseType, responseText } = result;

// if a GetCapabilities request was called then we update the UI
// with settings from the server
const params = Ext.Object.fromQueryString(outputUrl);
const lowercaseParams = {};
Ext.Object.each(params, function (key, value) {
lowercaseParams[key.toLowerCase()] = value.toLowerCase();
});

if (lowercaseParams.request === 'getcapabilities') {

switch (lowercaseParams.service) {

case 'wms':
me.updateWmsCapabilities(responseText);
break;
case 'wfs':
params.service = 'WFS';
me.updateWfsCapabilities(responseText);
break;
default:
console.log(`xType ${xType} unknown`);
}
}

if (responseType.includes('xml')) {
me.setEditorVisibilites('#xml');
me.setupXmlEditor();
Expand Down
15 changes: 10 additions & 5 deletions app/view/ows/OwsWindowModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ Ext.define('OwsInspector.view.ows.OwsWindowModel', {

alias: 'viewmodel.ms_owswindow',

requires: ['OwsInspector.store.Servers'],

data: {
serverUrls: [
'https://demo.mapserver.org/cgi-bin/msautotest',
'https://ows-demo.terrestris.de/geoserver/osm/ows',
'https://demo.mapserver.org/cgi-bin/wms'],
mapserverUrl: 'https://demo.mapserver.org/cgi-bin/wms',
requestUrl: ''
requestUrl: '',
isFloatingWindow: false
},

stores: {
servers: {
type: 'servers'
}
},

// https://demo.mapserver.org/cgi-bin/umn
Expand Down
19 changes: 6 additions & 13 deletions app/view/ows/wms/WmsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
xtype: 'multiselect',
name: 'layersCombo', // required for automatic updating
forceSelection: true,
editable: false,
editable: true,
fieldLabel: 'Layers (use CTRL to select many)',
valueField: 'value',
width: '90%',
Expand Down Expand Up @@ -101,16 +101,13 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
{
xtype: 'multiselect',
name: 'layersCombo', // required for automatic updating
forceSelection: true,
editable: false,
fieldLabel: 'Layers (use CTRL to select many)',
valueField: 'value',
displayField: 'value',
queryMode: 'local',
valueProperty: '{getMap.layers}', // a custom property added so the value binding can be set once the store is loaded
bind: {
store: '{layerNames}',
// value: '{getMap.layers}', // due to errors we bind this manually in the controller
//value: '{getMap.layers}', // due to errors we bind this manually in the controller
disabled: '{getMapDisabled}'
}
},
Expand All @@ -121,7 +118,8 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
bind: {
store: '{projections}',
value: '{getMap.crs}',
hidden: '{!useSrs}'
hidden: '{!useSrs}',
disabled: '{getMapDisabled}'
}
},
{
Expand All @@ -131,7 +129,8 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
bind: {
store: '{projections}',
value: '{getMap.srs}',
hidden: '{useSrs}'
hidden: '{useSrs}',
disabled: '{getMapDisabled}'
}
},
{
Expand Down Expand Up @@ -236,12 +235,9 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
items: [{
xtype: 'multiselect',
name: 'layersCombo', // required for automatic updating
forceSelection: true,
editable: false,
fieldLabel: 'Layers (use CTRL to select many)',
valueField: 'value',
displayField: 'value',
queryMode: 'local',
valueProperty: '{getStyles.layers}', // a custom property added so the value binding can be set once the store is loaded
bind: {
store: '{layerNames}',
Expand All @@ -260,12 +256,9 @@ Ext.define('OwsInspector.view.ows.wms.WmsPanel', {
items: [{
xtype: 'multiselect',
name: 'layersCombo', // required for automatic updating
forceSelection: true,
editable: false,
fieldLabel: 'Layers (use CTRL to select many)',
valueField: 'value',
displayField: 'value',
queryMode: 'local',
valueProperty: '{getStyles.layers}', // a custom property added so the value binding can be set once the store is loaded
bind: {
store: '{layerNames}',
Expand Down
Loading

0 comments on commit cb6a606

Please sign in to comment.