Skip to content

Commit

Permalink
Add collection_object_ids and identifier_ids params to Match collecti…
Browse files Browse the repository at this point in the history
…on object task #2917
  • Loading branch information
jlpereira committed Apr 19, 2022
1 parent e6a562e commit b2b763d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
42 changes: 29 additions & 13 deletions app/javascript/vue/tasks/collection_objects/match/app.vue
Expand Up @@ -49,6 +49,7 @@ import LineComponent from './components/LineComponent'
import AssignComponent from './components/AssignComponent'
import SpinnerComponent from 'components/spinner'
import { CollectionObject } from 'routes/endpoints'
import { URLParamsToJSON } from 'helpers/url/parse'
export default {
name: 'CollectionObjectMatch',
Expand Down Expand Up @@ -82,19 +83,29 @@ export default {
}
},
created () {
const urlParams = URLParamsToJSON(location.href)
const coIds = urlParams.collection_object_ids || []
const identifierIds = urlParams.identifier_ids || []
this.GetMatchesById(coIds)
this.GetMatchesByIdentifier(identifierIds)
},
methods: {
GetMatchesById (arrayIds = this.lines.filter(line => Number(line))) {
const ids = arrayIds.splice(0, this.maxPerCall)
const nextIds = arrayIds.slice(this.maxPerCall)
const promises = ids.map(id => CollectionObject.find(id).then(response => {
this.matches[id] = [response.body]
}, () => {
this.matches[id] = []
}))
const promises = ids.map(id =>
CollectionObject.find(id).then(response => {
this.matches[id] = [response.body]
}, () => {
this.matches[id] = []
})
)
Promise.allSettled(promises).then(() => {
if (nextIds.length) {
this.GetMatchesById(nextIds)
if (arrayIds.length) {
this.GetMatchesById(arrayIds)
} else {
this.isLoading = false
}
Expand All @@ -103,11 +114,16 @@ export default {
GetMatchesByIdentifier (arrayIdentifiers = this.lines.filter(line => line)) {
const identifiers = arrayIdentifiers.splice(0, this.maxPerCall)
const promises = identifiers.map(identifier => CollectionObject.where({ identifier_exact: true, identifier }).then(response => {
this.matches[identifier] = response.body
}, () => {
this.matches[identifier] = []
}))
const promises = identifiers.map(identifier =>
CollectionObject.where({
identifier_exact: true,
identifier
}).then(response => {
this.matches[identifier] = response.body
}, () => {
this.matches[identifier] = []
})
)
Promise.allSettled(promises).then(() => {
if (arrayIdentifiers.length) {
Expand Down
Expand Up @@ -10,6 +10,8 @@
</template>

<script>
import { URLParamsToJSON } from 'helpers/url/parse'
export default {
emits: ['lines'],
Expand All @@ -23,6 +25,17 @@ export default {
text (newVal) {
this.$emit('lines', newVal.split('\n').filter(line => line.trim().length))
}
},
created () {
const urlParams = URLParamsToJSON(location.href)
const coIds = urlParams.collection_object_ids || []
const identifierIds = urlParams.identifier_ids || []
this.text = [
...coIds,
...identifierIds
].join('\n')
}
}
</script>

0 comments on commit b2b763d

Please sign in to comment.