Skip to content

Commit

Permalink
#19 add class opensearch
Browse files Browse the repository at this point in the history
  • Loading branch information
epointal committed Aug 21, 2019
1 parent fd3fafc commit 11a2b84
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/formater-requester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</i18n>
<template></template>
<script>
import Opensearch from './opensearch'
export default {
name: 'FormaterRequester',
Expand Down
7 changes: 1 addition & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@ import makeStore from './store'
var config = {}
if (typeof formaterConfig != 'undefined') {
config = JSON.parse(formaterConfig.innerHTML)
console.log(config)
}
let locale = navigator.language.substr(0, 2)
console.log(locale)
console.log(formaterConfig)
console.log(config)

if (config.lang) {
locale = config.lang
}
delete config.lang
console.log(config.style)


ljs.addAliases({
Expand Down
103 changes: 103 additions & 0 deletions src/opensearch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* Tools to read the opensearch describe xml and extract the api and parameters
* and process the response to match a geonetwork response
*
* @author epointal
*/
import Vue from 'vue'
import VueResource from 'vue-resource'

var opensearch = {
_options: {

},
reader: function(options) {
this._options = Object.assign(this._options, options)
}

}
opensearch.reader = {
load: function(describeUrl) {
this.$http.get(describeUrl)
.then(
response => { this.extractDescribeParameters(response.body);}
)
},
extract: function (parametersString) {
var parser = new DOMParser()
var xml = parser.parseFromString(parametersString, 'text/xml')
var urls = xml.firstChild.childNodes
var url = null
urls.forEach(function (node) {
if (node.tagName && node.tagName.toLowerCase() === 'url' && node.getAttribute('type').indexOf('json') >= 0) {
var template = node.getAttribute('template')
var extract = template.match(/^(.*(?:(?:search.json\?)|(?:\?format=FLATSIM))).*$/)
if( extract && extract[1] && extract[1] != ''){
url = node;
}
}
})
if (!url) {
return
}
var template = url.getAttribute('template')
var extract = template.match(/^(.*(?:(?:search.json\?)|(?:\?format=FLATSIM))).*$/)
if (!extract[1]) {
return
} else {
this.api = extract[1]
}
var parameters = url.getElementsByTagName('parameters:Parameter')
var self = this
for(var i=0; i < parameters.length; i++){
var name = parameters[i].getAttribute('name')
var obj= {
name: name,
title: parameters[i].getAttribute('title')
}
var pattern = parameters[i].getAttribute('pattern')
if (pattern) {
obj = Object.assign(obj, {pattern: pattern})
}
var min = parameters[i].getAttribute('minInclusive')
if (min) {
obj= Object.assign(obj, {min: min})
}
var max = parameters[i].getAttribute('maxInclusive')
if (max) {
obj = Object.assign(obj, {max: max})
}
var nodes = parameters[i].getElementsByTagName('parameters:Options')
if (nodes) {
var options= []
for(var k=0; k < nodes.length; k++) {
options.push(nodes[k].getAttribute('value'))
}
if (options.length > 0)
obj = Object.assign(obj, {options: options})
}
if (self.removedFields.indexOf(name) >=0) {

// }else if (name.toLowerCase() === 'platform') {
// this.platform = obj
// } else if (name.toLowerCase() === 'q'){
// this.hasQ = true
} else if (self.geographic.indexOf(name) >=0) {
self.geoParameters.push(obj)
} else if (self.paging.indexOf(name) >= 0) {
self.pagingParameters.push(obj)
}else if (name.indexOf('Date') === -1 && name.indexOf('Cover') === -1 && (!obj.options || obj.options.length > 1)) {
self.osParameters.push(obj)
}

}
var evt = new CustomEvent('fmt:changeParametersEvent', {detail: {parameters: this.osParameters}})
document.dispatchEvent(evt)
this.hasChild = true
this.$set(this.tabs, 'search', true)
this.currentTab = 'search'
this.getRecords()
// this.requestApi(searchParameters)
}
}
module.export = opensearch

0 comments on commit 11a2b84

Please sign in to comment.