Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LinkAhead Sample Management
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
LinkAhead Sample Management
Commits
9f35b090
Commit
9f35b090
authored
2 months ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Add custom reference resolver
parent
fede2cbc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sample-management-custom/caosdb-server/caosdb-webui/src/ext/js/bis_custom_reference_resolver.js
+107
-0
107 additions, 0 deletions
.../caosdb-webui/src/ext/js/bis_custom_reference_resolver.js
with
107 additions
and
0 deletions
sample-management-custom/caosdb-server/caosdb-webui/src/ext/js/bis_custom_reference_resolver.js
0 → 100644
+
107
−
0
View file @
9f35b090
var
bis_custom_reference_resolver
=
new
function
(
getEntityID
,
getEntityName
,
getParents
,
getProperty
,
query
)
{
const
lastname_prop_name
=
"
Last name
"
;
const
firstname_prop_name
=
"
First name
"
;
const
person_rt_name
=
"
Person
"
;
const
bis_label_prop_name
=
"
BIS label
"
;
const
custom_label_prop_name
=
"
Custom label
"
const
container_rt_name
=
"
Container
"
;
const
value_p_name
=
'
enumValue
'
const
fixation_rt_name
=
"
Fixation
"
const
temp_storage_rt_name
=
"
StorageTemperature
"
/*
* Collect the names of gear types dynamically
*/
this
.
_getGearTypeNames
=
async
function
()
{
const
gearTypeNames
=
await
query
(
'
SELECT name FROM RECORDTYPE Gear
'
);
return
gearTypeNames
.
map
(
e
=>
getEntityName
(
e
));
};
/**
* Return the name of the record type and value
*/
this
.
rt_with_val
=
function
(
el
)
{
return
this
.
rt_with_prop_value
(
el
,
value_p_name
);
};
this
.
rt_with_prop_value
=
function
(
el
,
propName
)
{
var
text
=
getParents
(
el
)[
0
].
name
;
var
valpr
=
getProperty
(
el
,
propName
,
false
);
if
(
valpr
==
undefined
)
{
return
text
;
}
return
text
+
"
:
"
+
valpr
;
};
this
.
resolve_person_reference
=
function
(
entity
)
{
var
properties
=
getProperties
(
entity
);
if
(
properties
==
undefined
)
{
return
;
}
const
firstName
=
getProperty
(
entity
,
firstname_prop_name
,
false
);
const
lastName
=
getProperty
(
entity
,
lastname_prop_name
,
false
);
if
(
firstName
==
undefined
)
{
if
(
lastName
==
undefined
)
{
return
;
}
return
lastName
;
}
if
(
lastName
==
undefined
)
{
return
lastName
;
}
return
firstName
+
"
"
+
lastName
;
};
this
.
resolve_default
=
function
(
entity
)
{
// This is the BIS default: If an entity has a valid BIS label, the
// preview should be "id, BIS label". If there is no BIS label but the
// entity has a name, the preview is "id, name". Fallback is "id".
const
bisLabel
=
getProperty
(
entity
,
bis_label_prop_name
,
false
);
const
customLabel
=
getProperty
(
entity
,
custom_label_prop_name
,
false
);
const
name
=
getEntityName
(
entity
);
const
id
=
getEntityID
(
entity
);
var
label
=
customLabel
;
if
(
label
==
undefined
)
{
label
=
bisLabel
;
}
if
(
label
==
undefined
)
{
if
(
name
==
undefined
||
name
===
""
)
{
return
id
;
}
return
`
${
id
}
,
${
name
}
`
;
}
if
(
`
${
id
}
`
===
`
${
label
}
`
)
{
// prevent special case of BisLabel = BisID resulting in a preview that looks like "id, id".
return
id
;
}
return
`
${
id
}
,
${
label
}
`
;
};
this
.
resolve
=
async
function
(
id
)
{
const
entity
=
(
await
resolve_references
.
retrieve
(
id
))[
0
];
const
gearTypeNames
=
await
this
.
_getGearTypeNames
();
if
(
gearTypeNames
.
some
(
name
=>
resolve_references
.
is_child
(
entity
,
name
)))
{
return
{
"
text
"
:
this
.
rt_with_prop_value
(
entity
,
"
Configuration
"
)
};
}
else
if
(
resolve_references
.
is_child
(
entity
,
person_rt_name
))
{
return
{
"
text
"
:
this
.
resolve_person_reference
(
entity
)
};
}
else
if
(
resolve_references
.
is_child
(
entity
,
temp_storage_rt_name
))
{
return
{
"
text
"
:
this
.
rt_with_val
(
entity
)
};
}
else
if
(
resolve_references
.
is_child
(
entity
,
fixation_rt_name
))
{
return
{
"
text
"
:
this
.
rt_with_val
(
entity
)
};
}
else
{
return
{
"
text
"
:
this
.
resolve_default
(
entity
)
}
}
};
}(
getEntityID
,
getEntityName
,
getParents
,
getProperty
,
query
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment