Skip to content

Commit

Permalink
Finish preparing for Web API v2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Jul 25, 2024
1 parent 9f46952 commit 0d85be8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
40 changes: 29 additions & 11 deletions src/components/GrampsjsFormSelectObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,7 @@ class GrampsjsFormSelectObject extends GrampsjsTranslateMixin(LitElement) {
indeterminate
density="-3"
></mwc-circular-progress>`
const url = textField.value
? `/api/search/?locale=${
this.strings?.__lang__ || 'en'
}&profile=all&query=${encodeURIComponent(
`${textField.value}* AND type:${this.objectType || '*'}`
)}&profile=all&page=1&pagesize=20`
: `/api/search/?sort=-change&locale=${
this.strings?.__lang__ || 'en'
}&profile=all&query=${encodeURIComponent(
`type:${this.objectType || '*'}`
)}&profile=all&page=1&pagesize=20`
const url = this._getFetchUrl(textField.value)
const data = await apiGet(url)
if ('data' in data) {
this.data = data.data.filter(
Expand All @@ -186,6 +176,34 @@ class GrampsjsFormSelectObject extends GrampsjsTranslateMixin(LitElement) {
}
}

_getFetchUrl(value) {
if (window._oldSearchBackend) {
return value
? `/api/search/?locale=${
this.strings?.__lang__ || 'en'
}&profile=all&query=${encodeURIComponent(
`${value}* AND type:${this.objectType || '*'}`
)}&profile=all&page=1&pagesize=20`
: `/api/search/?sort=-change&locale=${
this.strings?.__lang__ || 'en'
}&profile=all&query=${encodeURIComponent(
`type:${this.objectType || '*'}`
)}&profile=all&page=1&pagesize=20`
}
let url = `/api/search/?locale=${
this.strings?.__lang__ || 'en'
}&profile=all&page=1&pagesize=20`
if (value) {
url = `${url}&query=${encodeURIComponent(`${value}*`)}`
} else {
url = `${url}&sort=-change&query=${encodeURIComponent('*')}`
}
if (this.objectType) {
url = `${url}&type=${this.objectType}`
}
return url
}

firstUpdated() {
const btn = this.shadowRoot.getElementById('button')
const menu = this.shadowRoot.getElementById('menu-search-results')
Expand Down
12 changes: 10 additions & 2 deletions src/views/GrampsjsViewRecentlyChanged.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ export class GrampsjsViewRecentlyChanged extends GrampsjsConnectedComponent {
}

getUrl() {
const query = "change:'-1 year to tomorrow'"
return `/api/search/?sort=-change&query=${query}&locale=${
if (window._oldSearchBackend) {
const query = "change:'-1 year to tomorrow'"
return `/api/search/?sort=-change&query=${query}&locale=${
this.strings.__lang__ || 'en'
}&profile=all&page=1&pagesize=8`
}
const ts = Math.floor(Date.now() / 1000) - 365 * 24 * 60 * 60 // ~1 year ago
return `/api/search/?sort=-change&query=${encodeURIComponent(
'*'
)}&change=${encodeURIComponent(`>${ts}`)}&locale=${
this.strings.__lang__ || 'en'
}&profile=all&page=1&pagesize=8`
}
Expand Down

0 comments on commit 0d85be8

Please sign in to comment.