Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Jan 14, 2020
2 parents 70b5858 + 66973f1 commit 1e59efa
Show file tree
Hide file tree
Showing 33 changed files with 621 additions and 149 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -106,6 +106,9 @@ gem 'logic_tools'
gem 'chunky_png', '~> 1.3.11'
gem 'namecase', '~> 2.0'

# www
gem 'wikidata-client', '~> 0.0.12', require: 'wikidata'

group :test, :development do
gem 'faker', '~> 2.7'
gem 'rspec-rails', '~> 4.0.0.beta2'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Expand Up @@ -156,6 +156,7 @@ GEM
exception_notification (4.4.0)
actionmailer (>= 4.0, < 7)
activesupport (>= 4.0, < 7)
excon (0.71.1)
execjs (2.7.0)
factory_bot (5.1.1)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -200,6 +201,7 @@ GEM
concurrent-ruby (~> 1.0)
hashdiff (1.0.0)
hashery (2.1.2)
hashie (3.6.0)
hiredis (0.6.3)
i18n (1.7.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -518,6 +520,11 @@ GEM
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
wikidata-client (0.0.12)
excon (~> 0.40)
faraday (~> 0.9)
faraday_middleware (~> 0.9)
hashie (~> 3.3)
with_advisory_lock (4.6.0)
activerecord (>= 4.2)
xpath (3.2.0)
Expand Down Expand Up @@ -634,6 +641,7 @@ DEPENDENCIES
web-console (~> 4.0, >= 4.0.1)
webmock (~> 3.6, >= 3.6.2)
webpacker (>= 4.0.x)
wikidata-client (~> 0.0.12)

RUBY VERSION
ruby 2.6.5p114
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/taxon_names_controller.rb
Expand Up @@ -210,7 +210,7 @@ def parse
@result = TaxonWorks::Vendor::Biodiversity::Result.new(
query_string: params.require(:query_string),
project_id: sessions_current_project_id,
nomenclature_code: :iczn # !! TODO:
code: :iczn # !! TODO:
).result
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/collecting_events_helper.rb
Expand Up @@ -21,7 +21,7 @@ def collecting_event_autocomplete_tag(collecting_event, join_string = '<br>')
collecting_event_collectors_tag(collecting_event),
collecting_event_coordinates_tag(collecting_event),
collecting_event_method_habitat_tag(collecting_event),
].compact.join(join_string)
].compact.join(join_string).html_safe
end

def collecting_event_identifiers_tag(collecting_event)
Expand Down
18 changes: 3 additions & 15 deletions app/helpers/otus_helper.rb
Expand Up @@ -54,34 +54,22 @@ def otus_radial(object)
# of OTUs
def next_otus(otu)
if otu.taxon_name_id
if t = otu.taxon_name.next_sibling&.otus
t
else
[]
end
otu.taxon_name.next_sibling&.otus || []
else
Otu.where(project_id: otu.id).where('id > ?', otu.id).all
end
end

def previous_otus(otu)
if otu.taxon_name_id
if t = otu.taxon_name.previous_sibling&.otus
t
else
[]
end
otu.taxon_name.previous_sibling&.otus || []
else
Otu.where(project_id: otu.id).where('id < ?', otu.id).all
end
end

def parent_otus(otu)
if otu.taxon_name_id
otu.taxon_name.parent.otus.all
else
[]
end
otu.taxon_name&.parent&.otus&.all || []
end

def parents_by_nomenclature(otu)
Expand Down
67 changes: 67 additions & 0 deletions app/javascript/vue/components/georeferences/geolocateComponent.vue
@@ -0,0 +1,67 @@
<template>
<div>
<button
class="button normal-input button-default"
@click="show = true">GEOLocate</button>
<modal-component
v-if="show"
@close="show = false">
<h3 slot="header">GEOLocate</h3>
<div slot="body">
<div class="field">
<label>Coordinates:</label>
<textarea
class="full_width"
rows="5"
v-model="iframe_response">
</textarea>
</div>
</div>
<div slot="footer">
<button
type="button"
class="normal-input button button-submit"
:disabled="!validateFields"
@click="createShape">
Add
</button>
</div>
</modal-component>
</div>
</template>

<script>
import ModalComponent from 'components/modal'
import convertDMS from 'helpers/parseDMS.js'
export default {
components: {
ModalComponent
},
computed: {
validateFields () {
return this.iframe_response
}
},
data () {
return {
show: false,
iframe_response: undefined
}
},
methods: {
createShape () {
this.$emit('create', this.iframe_response)
this.iframe_response = undefined
this.show = false
}
}
}
</script>

<style lang="scss" scoped>
/deep/ .modal-container {
max-width: 500px;
}
</style>
88 changes: 76 additions & 12 deletions app/javascript/vue/components/georeferences/georeferences.vue
Expand Up @@ -15,12 +15,14 @@
:legend="!collectingEventId ? 'Need collecting event ID' : 'Saving...'"/>
<map-component
ref="leaflet"
v-if="show"
:height="height"
:width="width"
:geojson="shapes['features']"
:lat="lat"
:lng="lng"
:zoom="zoom"
:fit-bounds="true"
:resize="true"
:draw-controls="true"
:draw-polyline="false"
Expand All @@ -29,14 +31,22 @@
@geoJsonLayersEdited="updateGeoreference($event)"
@geoJsonLayerCreated="saveGeoreference($event)"/>
</div>
<button
type="button"
v-if="verbatimLat && verbatimLng"
:disabled="verbatimGeoreferenceAlreadyCreated"
@click="createVerbatimShape"
class="button normal-input button-submit separate-bottom separate-top">
Create georeference from verbatim
</button>
<div class="horizontal-left-content margin-medium-top margin-medium-bottom">
<manually-component
class="margin-small-right"
@create="saveGeoreference"/>
<geolocate-component
class="margin-small-right"
@create="createGEOLocate"/>
<button
type="button"
v-if="verbatimLat && verbatimLng"
:disabled="verbatimGeoreferenceAlreadyCreated"
@click="createVerbatimShape"
class="button normal-input button-submit separate-bottom separate-top">
Create georeference from verbatim
</button>
</div>
<display-list
:list="georeferences"
@delete="removeGeoreference"
Expand All @@ -50,17 +60,21 @@ import MapComponent from './map'
import SpinnerComponent from 'components/spinner'
import DisplayList from './list'
import convertDMS from 'helpers/parseDMS.js'
import ManuallyComponent from './manuallyComponent'
import GeolocateComponent from './geolocateComponent'
export default {
components: {
MapComponent,
SpinnerComponent,
DisplayList
DisplayList,
ManuallyComponent,
GeolocateComponent
},
props: {
collectingEventId: {
type: [String, Number],
required: true,
default: undefined,
},
height: {
type: String,
Expand Down Expand Up @@ -91,6 +105,14 @@ export default {
zoom: {
type: Number,
default: 1
},
show: {
type: Boolean,
default: true
},
geographicArea: {
type: Object,
default: undefined
}
},
computed: {
Expand All @@ -113,8 +135,30 @@ export default {
}
}
},
mounted () {
this.getGeoreferences()
watch: {
collectingEventId: {
handler (newVal) {
if (newVal) {
this.getGeoreferences()
}
},
immediate: true
},
geographicArea: {
handler(newVal) {
if(newVal) {
let index = this.shapes.features.findIndex(item => {
return item.properties.hasOwnProperty('geographic_area')
})
if(index > -1) {
this.shapes.features.splice(index, 1)
}
this.shapes.features.push(newVal)
}
},
immediate: true,
deep: true
}
},
methods: {
saveGeoreference (shape) {
Expand All @@ -129,6 +173,9 @@ export default {
this.showSpinner = true
this.$http.post('/georeferences.json', data).then(response => {
this.showSpinner = false
if(response.body.error_radius) {
response.body.geo_json.properties.radius = response.body.error_radius
}
this.georeferences.push(response.body)
this.$refs.leaflet.addGeoJsonLayer(response.body.geo_json)
this.$emit('created', response.body)
Expand Down Expand Up @@ -210,6 +257,23 @@ export default {
this.showSpinner = false
TW.workbench.alert.create(response.bodyText, 'error')
})
},
createGEOLocate(iframe_data) {
this.showSpinner = true
this.$http.post('/georeferences.json', { georeference: {
iframe_response: iframe_data,
collecting_event_id: this.collectingEventId,
type: 'Georeference::GeoLocate'
}}).then(response => {
this.showSpinner = false
this.georeferences.push(response.body)
this.populateShapes()
this.$emit('created', response.body)
}, response => {
this.showSpinner = false
TW.workbench.alert.create(response.bodyText, 'error')
})
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/vue/components/georeferences/list.vue
Expand Up @@ -4,6 +4,8 @@
<thead>
<tr>
<th>Georeference ID</th>
<th>Shape</th>
<th>Error radius</th>
<th>Type</th>
<th></th>
</tr>
Expand All @@ -17,6 +19,8 @@
class="list-complete-item">
<td>{{ item.id }}</td>
<td>{{ item.geo_json.geometry.type }}</td>
<td>{{ item.error_radius }}</td>
<td>{{ item.type }}</td>
<td class="vue-table-options">
<radial-annotator
:global-id="item.global_id"/>
Expand Down

0 comments on commit 1e59efa

Please sign in to comment.