Skip to content

Commit

Permalink
Add supportsScheme function to BaseProvider and adjust MappingBrowser…
Browse files Browse the repository at this point in the history
… accordingly

Preparation for #289.
  • Loading branch information
stefandesu committed Mar 13, 2019
1 parent f5335f1 commit 07f488d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/MappingBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,14 @@ export default {
return object
},
mappingRegistries() {
let registries = this.config.registries.filter(registry => registry.provider && (registry.provider.has.mappings || registry.provider.has.occurrences) && (registry.scheme == null || this.$jskos.compare(this.selected.scheme[true], registry.scheme) || this.$jskos.compare(this.selected.scheme[false], registry.scheme)))
let registries = this.config.registries.filter(registry =>
registry.provider &&
(registry.provider.has.mappings || registry.provider.has.occurrences) &&
(
(registry.provider.supportsScheme && registry.provider.supportsScheme(this.selected.scheme[true])) ||
(registry.provider.supportsScheme && registry.provider.supportsScheme(this.selected.scheme[false]))
)
)
let currentRegistryIndex = registries.findIndex(registry => this.$jskos.compare(registry, this.currentRegistry))
if (currentRegistryIndex !== -1) {
let current = registries[currentRegistryIndex]
Expand Down
19 changes: 19 additions & 0 deletions src/providers/base-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,25 @@ class BaseProvider {
}).then(this.adjustMappings)
}

/**
* Returns a boolean whether a certain target scheme is supported or not.
*
* @param {object} scheme
*/
supportsScheme(scheme) {
if (!scheme) {
return false
}
if (this.registry.scheme == null && !jskos.isContainedIn(scheme, this.registry.excludedSchemes || [])) {
return true
}
let schemes = _.isArray(this.registry.scheme) ? this.registry.scheme : [this.registry.scheme]
if (jskos.isContainedIn(scheme, schemes)) {
return true
}
return false
}

}

BaseProvider.providerName = "Base"
Expand Down

0 comments on commit 07f488d

Please sign in to comment.