-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: divide object dating field in two - era & period
- Loading branch information
Showing
29 changed files
with
566 additions
and
202 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
euphrosyne/assets/js/web-components/dating-open-theso-type-ahead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Result } from "../type-ahead-list.component"; | ||
import { | ||
OpenThesoTypeAhead, | ||
SearchType, | ||
OpenThesoResult, | ||
} from "./open-theso-type-ahead"; | ||
|
||
export class DatingOpenThesoTypeAhead extends OpenThesoTypeAhead { | ||
searchType: SearchType = "fullpathSearch"; | ||
|
||
connectedCallback(): void { | ||
this.thesorusId = this.getAttribute("thesorus-id") || ""; | ||
super.connectedCallback(); | ||
} | ||
|
||
async fetchResults(query: string): Promise<Result[]> { | ||
const data = await this.doFetch<OpenThesoResult[]>(query); | ||
return data.map((item: OpenThesoResult[]) => ({ | ||
label: item.map((i) => i.label).join(" > "), | ||
id: item.slice(-1)[0].id, | ||
})) as Result[]; | ||
} | ||
} | ||
|
||
customElements.define( | ||
"dating-open-theso-type-ahead", | ||
DatingOpenThesoTypeAhead, | ||
{ | ||
extends: "div", | ||
}, | ||
); |
37 changes: 12 additions & 25 deletions
37
euphrosyne/assets/js/web-components/material-type-ahead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
euphrosyne/assets/js/web-components/open-theso-type-ahead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { TypeAheadList } from "../type-ahead-list.component"; | ||
|
||
export type SearchType = "fullpathSearch" | "autocomplete"; | ||
|
||
export interface OpenThesoResult { | ||
id: string; | ||
arkId: string; | ||
label: string; | ||
} | ||
|
||
export abstract class OpenThesoTypeAhead extends TypeAheadList { | ||
thesorusId?: string; | ||
abstract searchType: SearchType; | ||
|
||
async doFetch<T>(query: string): Promise<T[]> { | ||
if (!this.thesorusId) { | ||
throw new Error("thesorus-id attribute is required"); | ||
} | ||
const q = encodeURIComponent(query); | ||
|
||
let url; | ||
|
||
if (this.searchType === "fullpathSearch") { | ||
url = `https://opentheso.huma-num.fr/opentheso/openapi/v1/concept/${this.thesorusId}/search/fullpath?q=${q}&lang=fr&exactMatch=false`; | ||
} else { | ||
// autocomplete | ||
url = `https://opentheso.huma-num.fr/opentheso/openapi/v1/concept/${this.thesorusId}/autocomplete/${q}?lang=fr&exactMatch=false`; | ||
} | ||
const response = await fetch(url); | ||
|
||
if (response && response.status === 404) { | ||
return []; | ||
} | ||
if (!response || !response.ok) { | ||
throw new Error("Failed to fetch results"); | ||
} | ||
|
||
const data = await response.json(); | ||
if (!data || !data.length) { | ||
return []; | ||
} | ||
return data; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.