Skip to content

Commit

Permalink
#19 opensearch more generic ok
Browse files Browse the repository at this point in the history
  • Loading branch information
epointal committed Aug 23, 2019
1 parent 73660f8 commit 6e30826
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 157 deletions.
4 changes: 3 additions & 1 deletion src/formater-catalogue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default {
var metadata = this.metadatas[this.metadatas.length -1]
this.currentUuid = metadata['geonet:info'].uuid
var parameters = metadata.osParameters
var mapping = metadata.mapping
var min = null
var max = null
if (metadata.tempExtentBegin) {
Expand All @@ -173,9 +174,10 @@ export default {
} else {
this.currentUuid = null
var parameters = []
var mapping = []
this.$store.commit('temporalChange', this.temporalExtent)
}
this.$store.commit('parametersChange', parameters)
this.$store.commit('parametersChange', {parameters: parameters, mapping: mapping})
var event = new CustomEvent('fmt:closeMetadataEvent', {detail: {depth: this.metadatas.length }})
document.dispatchEvent(event)
},
Expand Down
124 changes: 53 additions & 71 deletions src/formater-metadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@
<div v-if="tabs.search" v-show="currentTab === 'search'">

<formater-paging :nb-record="nbRecord" :type="type" :record-by-line="recordByLine" :depth="depth + 1"></formater-paging>
<formater-list-metadata :depth="depth + 1" :capsule-width="capsuleWidth"></formater-list-metadata>
<formater-list-metadata :depth="depth + 1" :capsule-width="capsuleWidth"></formater-list-metadata>
</div>
<!-- others tab -->
<div v-if="currentTab === 'main'" style="margin-top:20px;">
<div class="mtdt-description">
<formater-quicklooks :quicklooks="meta.images"></formater-quicklooks>
<span v-html="meta.description"></span>
</div>
<div class="mtdt-temporalExtent" style="clear:both;" v-if="meta.tempExtentBegin">
<h2><i class="fa fa-clock-o"></i>{{$t('temporal_extent')}}</h2>
<div>
{{date2str(meta.tempExtentBegin)}}
<i class="fa fa-long-arrow-right" ></i>
{{date2str(meta.tempExtentEnd)}}
</div>
</div>
<div >
<formater-list-contact :responsible-party="meta.responsibleParty" :responsible-party2="metaLang2.responsibleParty"></formater-list-contact>
</div>
<div class="mtdt-description">
<formater-quicklooks :quicklooks="meta.images"></formater-quicklooks>
<span v-html="meta.description"></span>
</div>
<div class="mtdt-temporalExtent" style="clear:both;" v-if="meta.tempExtentBegin">
<h2><i class="fa fa-clock-o"></i>{{$t('temporal_extent')}}</h2>
<div>
{{date2str(meta.tempExtentBegin)}}
<i class="fa fa-long-arrow-right" ></i>
{{date2str(meta.tempExtentEnd)}}
</div>
</div>
<div >
<formater-list-contact :responsible-party="meta.responsibleParty" :responsible-party2="metaLang2.responsibleParty"></formater-list-contact>
</div>
</div>
<div v-if="currentTab === 'complement'" >
<formater-list-contact :responsible-party="meta.responsibleParty" :responsible-party2="metaLang2.responsibleParty"></formater-list-contact>
Expand Down Expand Up @@ -143,25 +143,9 @@ export default {
metaLang2: {},
popstateListener: null,
keydownListener: null,
searchEventListener: null,
// srv: process.env.GEONETWORK + 'srv/' + (this.lang === 'fr'? 'fre' : 'eng') + '/',
// api: process.env.GEONETWORK + '/srv/api/',
headers: {
'Accept': 'application/json, text/plain, */*',
'Accept-Language': this.$i18n.locale === 'fr' ? 'fre': 'eng'
},
describe: null,
// parameters: {},
// recordByLine: 4,
nbRecord: 12,
// use for opensearch api
// api: null,
// geographic: ['geometry', 'box', 'lat', 'lon', 'radius'],
// paging: ['maxRecords', 'index', 'page'],
// removedFields: ['lang', 'name', 'q', 'organisationName', 'parentIdentifier'],
// osParameters: [],
// geoParameters: [],
// pagingParameters: [],
type: 'geonetwork'
}
},
Expand Down Expand Up @@ -244,8 +228,9 @@ export default {
this.setHasChild(false)
}
},
setParameters(value) {
this.metadata.osParameters = value
setParameters(osParameters) {
this.metadata.osParameters = osParameters.parameters
this.metadata.mapping = osParameters.mapping
this.setHasChild(true)
},
setHasChild(value) {
Expand All @@ -255,42 +240,39 @@ export default {
this.currentTab = 'search'
this.getRecords()
} else {
this.$store.commit('parametersChange', [])
this.$store.commit('parametersChange', {parameters: [], mapping:[]})
}
},
fillMetadata () {
//get meta from other language if meta._locale != meta.docLocale
if (this.meta['geonet:info']) {
this.uuid = this.meta['geonet:info'].uuid;
} else {
this.uuid = this.meta.id
}
fillMetadata () {
//get meta from other language if meta._locale != meta.docLocale
if (this.meta['geonet:info']) {
this.uuid = this.meta['geonet:info'].uuid;
} else {
this.uuid = this.meta.id
}
if (this.meta._locale === this.meta.docLocale) {
return
}
var url = this.$store.state.geonetwork + 'srv/'+this.meta.docLocale+'/q?_content_type=json&fast=index&uuid=' + this.uuid;
var _this = this
this.$http.get(url).then(
if (this.meta._locale === this.meta.docLocale) {
return
}
var url = this.$store.state.geonetwork + 'srv/'+this.meta.docLocale+'/q?_content_type=json&fast=index&uuid=' + this.uuid;
var _this = this
this.$http.get(url).then(
response => {
// _this.extract(response.body.metadata)
_this.metaLang2 = response.body.metadata
}
)
if (this.meta.related && this.meta.related.children) {
this.hasChild = true
this.getRecords()
}
},
getRecords () {
)
if (this.meta.related && this.meta.related.children) {
this.hasChild = true
this.getRecords()
}
},
getRecords () {
// useless, it's trigger when load formater-page-changed
// lance le requeteur
// console.log('search child from metadata')
var event = new CustomEvent('fmt:metadataWithChildEvent', {detail: {uuid: this.uuid, depth: this.depth}})
document.dispatchEvent(event)
var event = new CustomEvent('fmt:metadataWithChildEvent', {detail: {uuid: this.uuid, depth: this.depth}})
document.dispatchEvent(event)
},
}
Expand Down Expand Up @@ -332,8 +314,8 @@ export default {
.mtdt-metadata h2,
.mtdt-metadata h3,
.mtdt-metadata h4{
max-width: 100%;
color:#754a15;
max-width: 100%;
color:#754a15;
}
.mtdt-metadata h2 {
Expand Down Expand Up @@ -363,13 +345,13 @@ export default {
line-height:1.5;
}
.mtdt-metadata .mtdt-group-logo{
float:right;
margin-top:-5px;
margin-right: 15px;
float:right;
margin-top:-5px;
margin-right: 15px;
}
.mtdt-metadata .mtdt-group-logo img{
max-width:100px;
height:40px;
max-width:100px;
height:40px;
}
.mtdt-metadata .mtdt-contacts h3{
margin-bottom:0;
Expand Down
107 changes: 35 additions & 72 deletions src/formater-opensearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

<template></template>
<script>
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
export default {
name: 'FormaterOpensearch',
props: {
Expand Down Expand Up @@ -38,12 +40,12 @@ export default {
return {
searchEventListener: null,
api: null,
geographic: ['geometry', 'box', 'lat', 'lon', 'radius'],
paging: ['maxRecords', 'index', 'page'],
osParameters: [],
geoParameters: [],
pagingParameters: [],
parameters: []
// associative array of: parameter name in this application => name in the opensearch api
// for the predefined parameters like box, temporalExtent, and paging (common for all api)
mappingParameters: [],
// list of others specific opensearch api parameters
// { name, title, pattern, min, max, options}
osParameters: []
}
},
methods: {
Expand All @@ -53,12 +55,22 @@ export default {
response => { this.extractDescribeParameters(response.body);}
)
},
extractParameter (parameterNode) {
extractParameter (parameterNode, specName) {
var listPredefined = this.$store.state.parameters.predefined
// name in this application
var appName = getKeyByValue(listPredefined, specName)
// name in the opensearch api
var name = parameterNode.getAttribute('name')
if (typeof appName !== 'undefined') {
this.mappingParameters[appName] = name
return
}
var obj= {
name: name,
title: parameterNode.getAttribute('title')
}
var pattern = parameterNode.getAttribute('pattern')
if (pattern) {
obj = Object.assign(obj, {pattern: pattern})
Expand Down Expand Up @@ -87,11 +99,12 @@ export default {
// } else if (name.toLowerCase() === 'q'){
// this.hasQ = true
// } else
if (this.geographic.indexOf(name) >=0) {
this.geoParameters.push(obj)
} else if (this.paging.indexOf(name) >= 0) {
this.pagingParameters.push(obj)
}else if (name.indexOf('Date') === -1 && name.indexOf('Cover') === -1 && (!obj.options || obj.options.length > 1)) {
// if (this.geographic.indexOf(name) >=0) {
// this.geoParameters.push(obj)
// } else if (this.paging.indexOf(name) >= 0) {
// this.pagingParameters.push(obj)
// }else
if (!obj.options || obj.options.length > 1) {
this.osParameters.push(obj)
}
},
Expand All @@ -100,7 +113,8 @@ export default {
var parser = new DOMParser()
var xml = parser.parseFromString(parametersString, 'text/xml')
var urls = xml.firstChild.childNodes
var url = null
var url = null
// loop to find the good url
urls.forEach(function (node) {
if (node.tagName && node.tagName.toLowerCase() === 'url' && node.getAttribute('type').indexOf('json') >= 0) {
var template = node.getAttribute('template')
Expand All @@ -123,72 +137,21 @@ export default {
var parameters = url.getElementsByTagName('parameters:Parameter')
var self = this
var regexList = this.$store.state.parameters.excluedRegex
// loop on the parameters node
for(var i=0; i < parameters.length; i++){
var value = parameters[i].getAttribute('value')
var specName = parameters[i].getAttribute('value')
// search if the parameter is exclued (@see list in store/index.js)
var isExclued = regexList.some(function(str) {
var rx = new RegExp(str)
return rx.test(value)
return rx.test(specName)
})
if (isExclued) {
console.log(value)
}
if (!isExclued) {
var obj = self.extractParameter(parameters[i])
var obj = self.extractParameter(parameters[i] , specName)
}
// 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)
// }
}
console.log('FIN DU DESCRIBE 2')
this.$emit('parametersChange', this.osParameters)
this.$store.commit('parametersChange', this.osParameters)
// modification des paramètres
// var evt = new CustomEvent('fmt:changeParametersEvent', {detail: {parameters: this.osParameters}})
// document.dispatchEvent(evt)
// var event = new CustomEvent('fmt:metadataWithChildEvent', {detail: {uuid: this.uuid, depth: this.depth}})
// document.dispatchEvent(event)
// this.requestApi(searchParameters)
this.$emit('parametersChange', {parameters:this.osParameters, mapping: this.mappingParameters})
this.$store.commit('parametersChange', {parameters:this.osParameters, mapping: this.mappingParameters})
},
handleSearch(e) {
if (this.api && e.detail.parentUuid === this.uuid) {
Expand Down
Loading

0 comments on commit 6e30826

Please sign in to comment.