Let a PC be assigned a business unit, and a retired asset be found
The last two items from the run. The PC detail page has always rendered a Business Unit row, and the API has always accepted the field. Only the form had no control, so it could be read and never set from the UI - a value that appeared the moment somebody set it through the API and could not be reached otherwise. The form has the picker now, loaded with listAll() rather than a capped page. Global search excluded inactive assets, so a retired record existed, was reachable by URL, and could not be found by anybody who did not already know where it was - including whoever wanted to restore it, which the retire dialog promises they can. Retired assets are searchable now. That is only safe with the ordering, so it is part of the change rather than a follow-up: somebody searching a machine number almost always wants the machine still on the floor, so a retired match drops 60 points of relevance, sorts below every live one, and carries a 'retired' flag the results page renders as a badge. Indistinguishable retired results would be worse than none. Four tests, verified by planting the isactive filter back: three fail. Scope: product
This commit is contained in:
@@ -244,6 +244,18 @@ def _get_asset_result(asset, query, relevance=None):
|
||||
if relevance is None:
|
||||
relevance = 15
|
||||
|
||||
# A retired asset never outranks a live one, whatever it matched on: the
|
||||
# person searching almost always wants the machine that is still on the
|
||||
# floor. Flagged too, so the result can say so rather than looking like any
|
||||
# other hit.
|
||||
# getattr, because this builder is also called with lightweight
|
||||
# stand-ins that carry only the fields a result needs. An object that does
|
||||
# not say is treated as live, which is the safe direction: a live asset
|
||||
# ranked correctly beats a live asset buried as retired.
|
||||
retired = getattr(asset, 'isactive', True) is False
|
||||
if retired:
|
||||
relevance = max(1, relevance - 60)
|
||||
|
||||
return {
|
||||
'type': asset_type_name,
|
||||
'id': result_id,
|
||||
@@ -251,7 +263,8 @@ def _get_asset_result(asset, query, relevance=None):
|
||||
'subtitle': subtitle,
|
||||
'location': location_name,
|
||||
'url': url,
|
||||
'relevance': relevance
|
||||
'relevance': relevance,
|
||||
'retired': retired
|
||||
}
|
||||
|
||||
|
||||
@@ -499,11 +512,17 @@ def _search_assets(query, search_term):
|
||||
joinedload(Asset.assettype),
|
||||
joinedload(Asset.location),
|
||||
).filter(
|
||||
Asset.isactive == True,
|
||||
# Retired assets are INCLUDED, and ranked below live ones. Retire
|
||||
# is a soft delete whose confirm dialog promises the record can be
|
||||
# restored - and the one place somebody looks for a machine they
|
||||
# retired last month is the search box. Excluding them meant the
|
||||
# record existed, was reachable by URL, and could not be found by
|
||||
# anybody who did not already know where it was.
|
||||
_word_match(query, Asset.assetnumber, Asset.name,
|
||||
Asset.serialnumber, Asset.notes,
|
||||
Asset.gaugelabreference, Asset.maintenancereference)
|
||||
).order_by(Asset.assetnumber, Asset.assetid).limit(15).all()
|
||||
).order_by(Asset.isactive.desc(), Asset.assetnumber,
|
||||
Asset.assetid).limit(15).all()
|
||||
|
||||
for asset in assets:
|
||||
relevance = 15
|
||||
|
||||
Reference in New Issue
Block a user