Skip to content

Commit fbd4a3a

Browse files
improved searchhandling
1 parent 2829e02 commit fbd4a3a

File tree

1 file changed

+118
-47
lines changed

1 file changed

+118
-47
lines changed

src/webfrontend/CustomDataTypeIconclass.coffee

Lines changed: 118 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,37 @@ class CustomDataTypeIconclass extends CustomDataTypeWithCommons
161161
activeFrontendLanguage = that.getFrontendLanguage()
162162

163163
searchUrl = 'https://iconclass.org/api/search?q=' + encodeURIComponent(input_searchstring) + '&lang=' + activeFrontendLanguage + '&size=999&page=1&sort=rank&keys=0';
164+
###
165+
result is like
166+
{
167+
"result": [
168+
"11H(JULIAN)131",
169+
"11H(JULIAN)13",
170+
"11H(JULIAN)119",
171+
"11H(JULIAN)84",...
172+
],
173+
"total": 148
174+
}
175+
###
164176

165177
if searchStringIsNotation
166178
searchUrl = 'https://iconclass.org/' + encodeURIComponent(input_searchstring) + '.json'
167179

180+
###
181+
result is like
182+
{
183+
"n": "11H(JULIAN)2",
184+
"p": [
185+
"1",
186+
"11",
187+
"11H",
188+
"11H(...)",
189+
"11H(JULIAN)",
190+
"11H(JULIAN)2"
191+
],
192+
"b": "11H(JULIAN)2",
193+
###
194+
168195
# start request
169196
searchsuggest_xhr.xhr = new (CUI.XHR)(url: searchUrl)
170197
searchsuggest_xhr.xhr.start().done((data, status, statusText) ->
@@ -216,34 +243,81 @@ class CustomDataTypeIconclass extends CustomDataTypeWithCommons
216243
onClick: (ev2, btn) ->
217244
iconclassInfo = btn.getOpt("value")
218245
###############################################
219-
# brackets with dots provided?
246+
# if search string is a notation
220247
###############################################
221-
if iconclassInfo?.n
222-
if iconclassInfo.n.includes '(...)'
223-
# open popup and force user to input bracketsvalue
224-
# Example: 25G4(...)
225-
chosenTempUri = 'https://iconclass.org/' + iconclassInfo.n
226-
CUI.prompt(text: $$('custom.data.type.iconclass.modal.form.popup.brackets.select') + " " + chosenTempUri + "\n\n" + $$('custom.data.type.iconclass.modal.form.popup.brackets.choose'), "1")
227-
.done (input) =>
228-
inputUpperCase = input.toUpperCase()
229-
inputLowerCase = input.toLowerCase()
230-
231-
# replace in notation
232-
iconclassInfo.n = iconclassInfo.n.replace('(...)', "(" + inputUpperCase + ")")
233-
# replace in labels
234-
for iconclassLabelKey, iconclassLabelValue of iconclassInfo.txt
235-
newLabel = iconclassLabelValue
236-
newLabel = newLabel.replace(" (mit NAMEN)", ': ' + inputLowerCase)
237-
newLabel = newLabel.replace(" (with NAME)", ': ' + inputLowerCase)
238-
newLabel = newLabel.replace(" (avec NOM)", ': ' + inputLowerCase)
239-
newLabel = newLabel.replace(" (col NOME)", ': ' + inputLowerCase)
240-
newLabel = newLabel.replace(" (NIMEN kanssa)", ': ' + inputLowerCase)
241-
iconclassInfo.txt[iconclassLabelKey] = newLabel
242-
248+
if searchStringIsNotation
249+
if iconclassInfo?.n
250+
###############################################
251+
# brackets with dots provided?
252+
###############################################
253+
if iconclassInfo.n.includes '(...)'
254+
# open popup and force user to input bracketsvalue
255+
# Example: 25G4(...)
256+
chosenTempUri = 'https://iconclass.org/' + iconclassInfo.n
257+
CUI.prompt(text: $$('custom.data.type.iconclass.modal.form.popup.brackets.select') + " " + chosenTempUri + "\n\n" + $$('custom.data.type.iconclass.modal.form.popup.brackets.choose'), "1")
258+
.done (input) =>
259+
inputUpperCase = input.toUpperCase()
260+
inputLowerCase = input.toLowerCase()
261+
262+
# replace in notation
263+
iconclassInfo.n = iconclassInfo.n.replace('(...)', "(" + inputUpperCase + ")")
264+
# replace in labels
265+
for iconclassLabelKey, iconclassLabelValue of iconclassInfo.txt
266+
newLabel = iconclassLabelValue
267+
newLabel = newLabel.replace(" (mit NAMEN)", ': ' + inputLowerCase)
268+
newLabel = newLabel.replace(" (with NAME)", ': ' + inputLowerCase)
269+
newLabel = newLabel.replace(" (avec NOM)", ': ' + inputLowerCase)
270+
newLabel = newLabel.replace(" (col NOME)", ': ' + inputLowerCase)
271+
newLabel = newLabel.replace(" (NIMEN kanssa)", ': ' + inputLowerCase)
272+
iconclassInfo.txt[iconclassLabelKey] = newLabel
273+
274+
# lock conceptURI in savedata
275+
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo.n
276+
cdata.frontendLanguage = activeFrontendLanguage
277+
278+
# lock conceptName in savedata
279+
cdata.conceptName = IconclassUtil.getConceptNameFromObject iconclassInfo, cdata
280+
281+
cdata.conceptAncestors = []
282+
# if treeview, add ancestors
283+
if iconclassInfo?.p?.length > 0
284+
# save ancestor-uris to cdata
285+
for ancestor in iconclassInfo.p
286+
cdata.conceptAncestors.push 'https://iconclass.org/' + ancestor
287+
# add own uri to ancestor-uris
288+
cdata.conceptAncestors.push 'https://iconclass.org/' + iconclassInfo.n
289+
290+
cdata.conceptAncestors = cdata.conceptAncestors.join(' ')
291+
292+
# facetTerm
293+
cdata.facetTerm = IconclassUtil.getFacetTerm(iconclassInfo, that.getDatabaseLanguages())
294+
295+
# lock conceptFulltext in savedata
296+
cdata._fulltext = IconclassUtil.getFullTextFromObject iconclassInfo, false
297+
# lock standard in savedata
298+
cdata._standard = IconclassUtil.getStandardTextFromObject that, iconclassInfo, cdata, false
299+
300+
# update the layout in form
301+
that.__updateResult(cdata, layout, opts)
302+
@
303+
.fail =>
304+
cdata = {}
305+
that.__updateResult(cdata, layout, opts)
306+
@
307+
###############################################
308+
# if no bracketsvalue in chosen record
309+
###############################################
310+
else
243311
# lock conceptURI in savedata
244-
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo.n
312+
if iconclassInfo?.n
313+
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo.n
314+
else
315+
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo
316+
245317
cdata.frontendLanguage = activeFrontendLanguage
246318

319+
fullInfoUrl = 'https://iconclass.org/' + iconclassInfo + '.json'
320+
247321
# lock conceptName in savedata
248322
cdata.conceptName = IconclassUtil.getConceptNameFromObject iconclassInfo, cdata
249323

@@ -266,51 +340,48 @@ class CustomDataTypeIconclass extends CustomDataTypeWithCommons
266340
# lock standard in savedata
267341
cdata._standard = IconclassUtil.getStandardTextFromObject that, iconclassInfo, cdata, false
268342

269-
# update the layout in form
270-
that.__updateResult(cdata, layout, opts)
271-
@
272-
.fail =>
273-
cdata = {}
274343
that.__updateResult(cdata, layout, opts)
275344
@
276-
###############################################
277-
# if no bracketsvalue in chosen record
278-
###############################################
279-
else
345+
###############################################
346+
# if search string is NOT a notation
347+
###############################################
348+
else if !searchStringIsNotation
349+
# get full data from iconclass
350+
351+
fullInfoUrl = 'https://iconclass.org/' + iconclassInfo + '.json'
352+
# start request
353+
searchsuggest_xhr.xhr = new (CUI.XHR)(url: fullInfoUrl)
354+
searchsuggest_xhr.xhr.start().done((data, status, statusText) ->
280355
# lock conceptURI in savedata
281-
if iconclassInfo?.n
282-
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo.n
283-
else
284-
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo
285-
356+
cdata.conceptURI = 'https://iconclass.org/' + iconclassInfo
286357
cdata.frontendLanguage = activeFrontendLanguage
287358

288-
fullInfoUrl = 'https://iconclass.org/' + iconclassInfo + '.json'
289-
290359
# lock conceptName in savedata
291-
cdata.conceptName = IconclassUtil.getConceptNameFromObject iconclassInfo, cdata
360+
cdata.conceptName = IconclassUtil.getConceptNameFromObject data, cdata
292361

293362
cdata.conceptAncestors = []
294363
# if treeview, add ancestors
295-
if iconclassInfo?.p?.length > 0
364+
if data?.p?.length > 0
296365
# save ancestor-uris to cdata
297-
for ancestor in iconclassInfo.p
366+
for ancestor in data.p
298367
cdata.conceptAncestors.push 'https://iconclass.org/' + ancestor
299368
# add own uri to ancestor-uris
300-
cdata.conceptAncestors.push 'https://iconclass.org/' + iconclassInfo.n
369+
cdata.conceptAncestors.push 'https://iconclass.org/' + iconclassInfo
301370

302371
cdata.conceptAncestors = cdata.conceptAncestors.join(' ')
303372

304373
# facetTerm
305-
cdata.facetTerm = IconclassUtil.getFacetTerm(iconclassInfo, that.getDatabaseLanguages())
374+
cdata.facetTerm = IconclassUtil.getFacetTerm(data, that.getDatabaseLanguages())
306375

307376
# lock conceptFulltext in savedata
308-
cdata._fulltext = IconclassUtil.getFullTextFromObject iconclassInfo, false
377+
cdata._fulltext = IconclassUtil.getFullTextFromObject data, false
309378
# lock standard in savedata
310-
cdata._standard = IconclassUtil.getStandardTextFromObject that, iconclassInfo, cdata, false
379+
cdata._standard = IconclassUtil.getStandardTextFromObject that, data, cdata, false
311380

312381
that.__updateResult(cdata, layout, opts)
313382
@
383+
)
384+
314385
items: menu_items
315386

316387
# if no suggestions: set "empty" message to menu

0 commit comments

Comments
 (0)