<commit_before>if (!window.wps) {
  window.wps = {};
}
var wps = window.wps;

wps.editor = function(ui) {
  this.ui_ = ui;
};

wps.backgroundLayer = new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: "http://maps.opengeo.org/geowebcache/service/wms",
    params: {
      'VERSION': '1.1.1',
      'LAYERS': 'openstreetmap',
      'FORMAT': 'image/png'
    }
  })
});

wps.mapSettings = {
  projection: 'EPSG:4326',
  center: [0, 0],
  zoom: 1,
  minZoom: 1
};

// apparently axis order is not what we expect when using WPS
var projection = new ol.proj.Projection({
  code: 'http://www.opengis.net/gml/srs/epsg.xml#4326',
  extent: [-180, -90, 180, 90],
  units: 'degrees',
  axisOrientation: 'enu'
});
ol.proj.addProjection(projection);

wps.editor.PREFIX = "node-input-";
wps.SUBPROCESS = 'process|';
wps.VECTORLAYER = 'vector|';
wps.RASTERLAYER = 'raster|';

wps.editor.prototype.addRasterLayer = function(id, node, value) {
  var mapId = node._parent;
  var values = value.split('|');
  var layer = values[1];
  var extent = new Array(4);
  for (var i=0, ii=this.ui_.coverages.length; i<ii; ++i) {
    var c = this.ui_.coverages[i];
    if (c.name === layer) {
      extent[0] = c.lowerCorner[0];
      extent[1] = c.lowerCorner[1];
      extent[2] = c.upperCorner[0];
      extent[3] = c.upperCorner[1];
      break;
    }
  }
  var map;
  if (this.ui_.inputMaps[mapId]) {
    map = this.ui_.inputMaps[mapId].map;
  } else {
    return;
  }
  if (!this.ui_.inputMaps[mapId].rasterWMS[id]) {
    this.ui_.inputMaps[mapId].rasterWMS[id] = new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: '/geoserver/wms',
        params: {'LAYERS': layer},
        serverType: 'geoserver'
      })
    });
    map.getLayers().insertAt(map.getLayers().getLength()-1, this.ui_.inputMaps[mapId].rasterWMS[id]);
  } else {
    this.ui_.inputMaps[mapId].rasterWMS[id].getSource().updateParams({'LAYERS': layer});
  }
  map.getView().fitExtent(extent, map.getSize());
};

wps.editor.prototype.addVectorLayer = function(id, node, value) {
  var mapId = node._parent;
  var values = value.split('|');
  var layer = values[1];
  var extent = new Array(4);
  for (var i=0, ii=this.ui_.featureTypes.length; i<ii; ++i) {
    var ft = this.ui_.featureTypes[i];
    if (ft.name === layer) {
      extent[0] = ft.lowerCorner[0];
      extent[1] = ft.lowerCorner[1];
      extent[2] = ft.upperCorner[0];
      extent[3] = ft.upperCorner[1];
      break;
    }
  }
  var map = this.ui_.inputMaps[mapId].map;
  if (!this.ui_.inputMaps[mapId].vectorWMS[id]) {
    this.ui_.inputMaps[mapId].vectorWMS[id] = new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: '/geoserver/wms',
        params: {'LAYERS': layer},
        serverType: 'geoserver'
      })
    });
    map.getLayers().insertAt(map.getLayers().getLength()-1, this.ui_.inputMaps[mapId].vectorWMS[id]);
  } else {
    this.ui_.inputMaps[mapId].vectorWMS[id].getSource().updateParams({'LAYERS': layer});
  }
  map.getView().fitExtent(extent, map.getSize());
};

wps.editor.prototype.setValue = function(geom, id, val, node) {
  var me = this, ui = this.ui_;
  if (node === undefined) {
    node = me.editingNode_;
  }
  var name = node._info.identifier.value;
  var processId = node._parent;
  var formField;
  if (id) {
    formField = $('#' + id);
  } else {
    formField = $('#' + wps.editor.PREFIX + processId + '-' + name);
  }
  var value;
  node._geom = geom;
  if (geom !== true && formField.length > 0) {
    value = formField.val();
    if (value.indexOf(wps.VECTORLAYER) !== -1 || value.indexOf(wps.RASTERLAYER) !== -1) {
      $('#bbox-filter-clear').parent().removeClass('disabled');
      $('#bbox-filter').parent().removeClass('disabled');
    } else {
      $('#bbox-filter-clear').parent().addClass('disabled');
      $('#bbox-filter').parent().addClass('disabled');
    }
    if (value.indexOf(wps.VECTORLAYER) !== -1) {
      this.addVectorLayer(id, node, value);
    }
    if (value.indexOf(wps.RASTERLAYER) !== -1) {
      this.addRasterLayer(id, node, value);
    }
    if (id.indexOf('-txt') !== -1) {
      if (value.indexOf('>') !== -1) {
        value = jQuery.parseXML(value);
      }
    }
    if (value.indexOf(wps.VECTORLAYER) !== -1) {
      // check if node has a BBOX filter on it
      if (node.value && node.value.split('|').length === 3) {
        node.value = value + '|' + node.value.split('|')[2];
      }  else {
        node.value = value;
      }
    } else {
      node.value = value;
    }
  } else if (node._info.boundingBoxData) {
    node.value = val;
  } else if (id === false) {
    node.value = val;
  }
  ui.afterSetValue(node);
};

wps.editor.prototype.validateNodeProperty = function(info, value) {
  if (info.literalData) {
    if (info.literalData.dataType) {
      var dataType = info.literalData.dataType.value;
      if (dataType === 'xs:double') {
        return (value.match(/^-?\d*(\.\d+)?$/) !== null);
      } else if (dataType === 'xs:int') {
        return value.length > 0 && (Math.floor(value) == value);
      } else if (dataType === 'xs:boolean') {
        return (value === "true" || value === "false");
      } else {
        return true;
      }
    } else if (info.literalData.anyValue) {
      return value.length > 0;
    } else if (info.literalData.allowedValues) {
      return value !== null;
    }
  } else if (info.boundingBoxData) {
    var valid = false;
    valid = value.length === 4 && !isNaN(parseFloat(value[0])) &&
      !isNaN(parseFloat(value[1])) && !isNaN(parseFloat(value[2])) &&
      !isNaN(parseFloat(value[3])) && parseFloat(value[0]) < parseFloat(value[2]) &&
      parseFloat(value[1]) < parseFloat(value[3]);
    return valid;
  }
  return true;
};

wps.editor.prototype.showEditForm = function(node) {
  if (node['type'] !== 'input') {
    return;
  }
  this.editingNode_ = node;

  // begin form
  var html = '<form class="form-horizontal">';
  var hasMap = false, bboxTool = false, i, ii;
  // simple input
  var name = node._info.identifier.value;
  var nameText = name;
  if (node.required !== true) {
    nameText += ' (optional)';
  }
  var pId, id = wps.editor.PREFIX + node._parent + '-' + name.replace(/ /g, '_');
  var saveButton = '<div class="form-row input-validate"><button type="button" class="btn btn-success btn-sm" id="input-save" onclick="window.wpsui.checkInput(\'' + node.id + '\',\'' + name + '\',\'' + id + '\')">Save</button></div>';
  var selected;
<commit_msg>if subprocess, do not show map (see #149)<commit_after>if (!window.wps) {
  window.wps = {};
}
var wps = window.wps;

wps.editor = function(ui) {
  this.ui_ = ui;
};

wps.backgroundLayer = new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: "http://maps.opengeo.org/geowebcache/service/wms",
    params: {
      'VERSION': '1.1.1',
      'LAYERS': 'openstreetmap',
      'FORMAT': 'image/png'
    }
  })
});

wps.mapSettings = {
  projection: 'EPSG:4326',
  center: [0, 0],
  zoom: 1,
  minZoom: 1
};

// apparently axis order is not what we expect when using WPS
var projection = new ol.proj.Projection({
  code: 'http://www.opengis.net/gml/srs/epsg.xml#4326',
  extent: [-180, -90, 180, 90],
  units: 'degrees',
  axisOrientation: 'enu'
});
ol.proj.addProjection(projection);

wps.editor.PREFIX = "node-input-";
wps.SUBPROCESS = 'process|';
wps.VECTORLAYER = 'vector|';
wps.RASTERLAYER = 'raster|';

wps.editor.prototype.addRasterLayer = function(id, node, value) {
  var mapId = node._parent;
  var values = value.split('|');
  var layer = values[1];
  var extent = new Array(4);
  for (var i=0, ii=this.ui_.coverages.length; i<ii; ++i) {
    var c = this.ui_.coverages[i];
    if (c.name === layer) {
      extent[0] = c.lowerCorner[0];
      extent[1] = c.lowerCorner[1];
      extent[2] = c.upperCorner[0];
      extent[3] = c.upperCorner[1];
      break;
    }
  }
  var map;
  if (this.ui_.inputMaps[mapId]) {
    map = this.ui_.inputMaps[mapId].map;
  } else {
    return;
  }
  if (!this.ui_.inputMaps[mapId].rasterWMS[id]) {
    this.ui_.inputMaps[mapId].rasterWMS[id] = new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: '/geoserver/wms',
        params: {'LAYERS': layer},
        serverType: 'geoserver'
      })
    });
    map.getLayers().insertAt(map.getLayers().getLength()-1, this.ui_.inputMaps[mapId].rasterWMS[id]);
  } else {
    this.ui_.inputMaps[mapId].rasterWMS[id].getSource().updateParams({'LAYERS': layer});
  }
  map.getView().fitExtent(extent, map.getSize());
};

wps.editor.prototype.addVectorLayer = function(id, node, value) {
  var mapId = node._parent;
  var values = value.split('|');
  var layer = values[1];
  var extent = new Array(4);
  for (var i=0, ii=this.ui_.featureTypes.length; i<ii; ++i) {
    var ft = this.ui_.featureTypes[i];
    if (ft.name === layer) {
      extent[0] = ft.lowerCorner[0];
      extent[1] = ft.lowerCorner[1];
      extent[2] = ft.upperCorner[0];
      extent[3] = ft.upperCorner[1];
      break;
    }
  }
  var map = this.ui_.inputMaps[mapId].map;
  if (!this.ui_.inputMaps[mapId].vectorWMS[id]) {
    this.ui_.inputMaps[mapId].vectorWMS[id] = new ol.layer.Image({
      source: new ol.source.ImageWMS({
        url: '/geoserver/wms',
        params: {'LAYERS': layer},
        serverType: 'geoserver'
      })
    });
    map.getLayers().insertAt(map.getLayers().getLength()-1, this.ui_.inputMaps[mapId].vectorWMS[id]);
  } else {
    this.ui_.inputMaps[mapId].vectorWMS[id].getSource().updateParams({'LAYERS': layer});
  }
  map.getView().fitExtent(extent, map.getSize());
};

wps.editor.prototype.setValue = function(geom, id, val, node) {
  var me = this, ui = this.ui_;
  if (node === undefined) {
    node = me.editingNode_;
  }
  var name = node._info.identifier.value;
  var processId = node._parent;
  var formField;
  if (id) {
    formField = $('#' + id);
  } else {
    formField = $('#' + wps.editor.PREFIX + processId + '-' + name);
  }
  var value;
  node._geom = geom;
  if (geom !== true && formField.length > 0) {
    value = formField.val();
    if (value.indexOf(wps.VECTORLAYER) !== -1 || value.indexOf(wps.RASTERLAYER) !== -1) {
      $('#bbox-filter-clear').parent().removeClass('disabled');
      $('#bbox-filter').parent().removeClass('disabled');
    } else {
      $('#bbox-filter-clear').parent().addClass('disabled');
      $('#bbox-filter').parent().addClass('disabled');
    }
    if (value.indexOf(wps.VECTORLAYER) !== -1) {
      this.addVectorLayer(id, node, value);
    }
    if (value.indexOf(wps.RASTERLAYER) !== -1) {
      this.addRasterLayer(id, node, value);
    }
    if (id.indexOf('-txt') !== -1) {
      if (value.indexOf('>') !== -1) {
        value = jQuery.parseXML(value);
      }
    }
    if (value.indexOf(wps.VECTORLAYER) !== -1) {
      // check if node has a BBOX filter on it
      if (node.value && node.value.split('|').length === 3) {
        node.value = value + '|' + node.value.split('|')[2];
      }  else {
        node.value = value;
      }
    } else {
      node.value = value;
    }
  } else if (node._info.boundingBoxData) {
    node.value = val;
  } else if (id === false) {
    node.value = val;
  }
  ui.afterSetValue(node);
};

wps.editor.prototype.validateNodeProperty = function(info, value) {
  if (info.literalData) {
    if (info.literalData.dataType) {
      var dataType = info.literalData.dataType.value;
      if (dataType === 'xs:double') {
        return (value.match(/^-?\d*(\.\d+)?$/) !== null);
      } else if (dataType === 'xs:int') {
        return value.length > 0 && (Math.floor(value) == value);
      } else if (dataType === 'xs:boolean') {
        return (value === "true" || value === "false");
      } else {
        return true;
      }
    } else if (info.literalData.anyValue) {
      return value.length > 0;
    } else if (info.literalData.allowedValues) {
      return value !== null;
    }
  } else if (info.boundingBoxData) {
    var valid = false;
    valid = value.length === 4 && !isNaN(parseFloat(value[0])) &&
      !isNaN(parseFloat(value[1])) && !isNaN(parseFloat(value[2])) &&
      !isNaN(parseFloat(value[3])) && parseFloat(value[0]) < parseFloat(value[2]) &&
      parseFloat(value[1]) < parseFloat(value[3]);
    return valid;
  }
  return true;
};

wps.editor.prototype.showEditForm = function(node) {
  if (node['type'] !== 'input' || (typeof node.value === "string" && node.value.indexOf(wps.SUBPROCESS) !== -1)) {
    $('#tab-inputs').html('');
    return;
  }
  this.editingNode_ = node;

  // begin form
  var html = '<form class="form-horizontal">';
  var hasMap = false, bboxTool = false, i, ii;
  // simple input
  var name = node._info.identifier.value;
  var nameText = name;
  if (node.required !== true) {
    nameText += ' (optional)';
  }
  var pId, id = wps.editor.PREFIX + node._parent + '-' + name.replace(/ /g, '_');
  var saveButton = '<div class="form-row input-validate"><button type="button" class="btn btn-success btn-sm" id="input-save" onclick="window.wpsui.checkInput(\'' + node.id + '\',\'' + name + '\',\'' + id + '\')">Save</button></div>';
  var selected;

{'fraction_non_alphanumeric': 0.195565749235474, 'fraction_numerical': 0.011009174311926606, 'mean_word_length': 2.9820395738203955, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2300612', 'n_tokens_mistral': 4863, 'n_tokens_neox': 4844, 'n_words': 891}