Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dccviewer-js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
Benedikt
dccviewer-js
Commits
d02a0070
Commit
d02a0070
authored
2 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
added measEQ render
parent
337f4b73
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#52238
passed
2 months ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/renderers/MeasuringEquipmentRenderer.js
+189
-0
189 additions, 0 deletions
src/renderers/MeasuringEquipmentRenderer.js
with
189 additions
and
0 deletions
src/renderers/MeasuringEquipmentRenderer.js
0 → 100644
+
189
−
0
View file @
d02a0070
// src/renderers/MeasuringEquipmentRenderer.js
import
{
DCCRealListQuantity
}
from
"
../dccQuantity.js
"
;
export
class
MeasuringEquipmentRenderer
{
constructor
(
equipmentData
,
language
)
{
// equipmentData may be a single object or an array of measuringEquipment elements
this
.
data
=
Array
.
isArray
(
equipmentData
)
?
equipmentData
:
[
equipmentData
];
this
.
language
=
language
;
}
render
()
{
const
container
=
document
.
createElement
(
"
div
"
);
container
.
innerHTML
=
`<h3>Measuring Equipment</h3>`
;
this
.
data
.
forEach
((
equip
)
=>
{
// Create collapsible section for each equipment
const
details
=
document
.
createElement
(
"
details
"
);
details
.
style
.
border
=
"
1px solid #ccc
"
;
details
.
style
.
padding
=
"
8px
"
;
details
.
style
.
marginBottom
=
"
10px
"
;
// Build the summary (collapsed view)
const
summary
=
document
.
createElement
(
"
summary
"
);
summary
.
style
.
fontWeight
=
"
bold
"
;
// Equipment name
const
equipName
=
this
.
_getText
(
equip
[
"
dcc:name
"
]);
// Manufacturer name (if available)
let
manufacturerName
=
""
;
if
(
equip
[
"
dcc:manufacturer
"
]
&&
equip
[
"
dcc:manufacturer
"
][
"
dcc:name
"
])
{
manufacturerName
=
this
.
_getText
(
equip
[
"
dcc:manufacturer
"
][
"
dcc:name
"
]);
}
// Model
const
model
=
equip
[
"
dcc:model
"
]
?
equip
[
"
dcc:model
"
].
trim
()
:
""
;
// First identification (if available)
let
firstId
=
""
;
if
(
equip
[
"
dcc:identifications
"
]
&&
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
]
)
{
let
ids
=
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
];
if
(
!
Array
.
isArray
(
ids
))
{
ids
=
[
ids
];
}
const
id0
=
ids
[
0
];
// Get identification name (small label) and value
const
idName
=
this
.
_getText
(
id0
[
"
dcc:name
"
]);
const
idValue
=
id0
[
"
dcc:value
"
]
?
id0
[
"
dcc:value
"
].
trim
()
:
""
;
firstId
=
`<span style="font-size:smaller;">
${
idName
}
:
${
idValue
}
</span>`
;
}
summary
.
innerHTML
=
`
${
equipName
}
–
${
manufacturerName
}
–
${
model
}
${
firstId
}
`
;
details
.
appendChild
(
summary
);
// Expanded content
const
contentDiv
=
document
.
createElement
(
"
div
"
);
contentDiv
.
style
.
marginTop
=
"
8px
"
;
contentDiv
.
style
.
fontFamily
=
"
sans-serif
"
;
// Render full identifications table
if
(
equip
[
"
dcc:identifications
"
]
&&
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
])
{
const
ids
=
Array
.
isArray
(
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
])
?
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
]
:
[
equip
[
"
dcc:identifications
"
][
"
dcc:identification
"
]];
const
idTable
=
document
.
createElement
(
"
table
"
);
idTable
.
style
.
width
=
"
100%
"
;
idTable
.
style
.
borderCollapse
=
"
collapse
"
;
// Header row
const
idHeaderRow
=
document
.
createElement
(
"
tr
"
);
[
"
Identification
"
,
"
Issuer
"
,
"
Value
"
].
forEach
((
text
)
=>
{
const
th
=
document
.
createElement
(
"
th
"
);
th
.
textContent
=
text
;
th
.
style
.
border
=
"
1px solid #ccc
"
;
th
.
style
.
padding
=
"
4px
"
;
idHeaderRow
.
appendChild
(
th
);
});
idTable
.
appendChild
(
idHeaderRow
);
// Data rows
ids
.
forEach
((
id
)
=>
{
const
tr
=
document
.
createElement
(
"
tr
"
);
// Identification name (small label)
const
tdName
=
document
.
createElement
(
"
td
"
);
tdName
.
style
.
border
=
"
1px solid #ccc
"
;
tdName
.
style
.
padding
=
"
4px
"
;
tdName
.
style
.
fontSize
=
"
smaller
"
;
tdName
.
textContent
=
this
.
_getText
(
id
[
"
dcc:name
"
]);
tr
.
appendChild
(
tdName
);
// Issuer
const
tdIssuer
=
document
.
createElement
(
"
td
"
);
tdIssuer
.
style
.
border
=
"
1px solid #ccc
"
;
tdIssuer
.
style
.
padding
=
"
4px
"
;
tdIssuer
.
textContent
=
id
[
"
dcc:issuer
"
]
?
id
[
"
dcc:issuer
"
].
trim
()
:
""
;
tr
.
appendChild
(
tdIssuer
);
// Value
const
tdValue
=
document
.
createElement
(
"
td
"
);
tdValue
.
style
.
border
=
"
1px solid #ccc
"
;
tdValue
.
style
.
padding
=
"
4px
"
;
tdValue
.
textContent
=
id
[
"
dcc:value
"
]
?
id
[
"
dcc:value
"
].
trim
()
:
""
;
tr
.
appendChild
(
tdValue
);
idTable
.
appendChild
(
tr
);
});
contentDiv
.
appendChild
(
idTable
);
}
// Render measuring equipment quantities table (if available)
if
(
equip
[
"
dcc:measuringEquipmentQuantities
"
]
&&
equip
[
"
dcc:measuringEquipmentQuantities
"
][
"
dcc:measuringEquipmentQuantity
"
]
)
{
const
qtys
=
Array
.
isArray
(
equip
[
"
dcc:measuringEquipmentQuantities
"
][
"
dcc:measuringEquipmentQuantity
"
]
)
?
equip
[
"
dcc:measuringEquipmentQuantities
"
][
"
dcc:measuringEquipmentQuantity
"
]
:
[
equip
[
"
dcc:measuringEquipmentQuantities
"
][
"
dcc:measuringEquipmentQuantity
"
]];
const
qtyTable
=
document
.
createElement
(
"
table
"
);
qtyTable
.
style
.
width
=
"
100%
"
;
qtyTable
.
style
.
borderCollapse
=
"
collapse
"
;
// Header row
const
qtyHeaderRow
=
document
.
createElement
(
"
tr
"
);
[
"
Quantity
"
,
"
Value
"
,
"
Unit
"
,
"
Uncertainty
"
].
forEach
((
text
)
=>
{
const
th
=
document
.
createElement
(
"
th
"
);
th
.
textContent
=
text
;
th
.
style
.
border
=
"
1px solid #ccc
"
;
th
.
style
.
padding
=
"
4px
"
;
qtyHeaderRow
.
appendChild
(
th
);
});
qtyTable
.
appendChild
(
qtyHeaderRow
);
// Data rows: use DCCRealListQuantity for each measuringEquipmentQuantity
qtys
.
forEach
((
q
)
=>
{
const
row
=
document
.
createElement
(
"
tr
"
);
// Quantity name
const
tdName
=
document
.
createElement
(
"
td
"
);
tdName
.
style
.
border
=
"
1px solid #ccc
"
;
tdName
.
style
.
padding
=
"
4px
"
;
tdName
.
textContent
=
this
.
_getText
(
q
[
"
dcc:name
"
]);
row
.
appendChild
(
tdName
);
// Value
const
tdValue
=
document
.
createElement
(
"
td
"
);
tdValue
.
style
.
border
=
"
1px solid #ccc
"
;
tdValue
.
style
.
padding
=
"
4px
"
;
// Create a DCCRealListQuantity instance to extract values, unit, uncertainty
const
realQty
=
new
DCCRealListQuantity
(
q
);
const
values
=
realQty
.
getValues
();
tdValue
.
textContent
=
values
.
join
(
"
/
"
);
row
.
appendChild
(
tdValue
);
// Unit
const
tdUnit
=
document
.
createElement
(
"
td
"
);
tdUnit
.
style
.
border
=
"
1px solid #ccc
"
;
tdUnit
.
style
.
padding
=
"
4px
"
;
const
rawUnit
=
q
[
"
si:realListXMLList
"
]
&&
q
[
"
si:realListXMLList
"
][
"
si:unitXMLList
"
]
?
q
[
"
si:realListXMLList
"
][
"
si:unitXMLList
"
].
trim
()
:
""
;
if
(
rawUnit
)
{
const
unitObj
=
new
DSIUnit
(
rawUnit
);
// Here we return plain text instead of HTML markup for the table cell
tdUnit
.
textContent
=
unitObj
.
toString
();
}
row
.
appendChild
(
tdUnit
);
// Uncertainty
const
tdUnc
=
document
.
createElement
(
"
td
"
);
tdUnc
.
style
.
border
=
"
1px solid #ccc
"
;
tdUnc
.
style
.
padding
=
"
4px
"
;
const
uncValues
=
realQty
.
getUncertainty
();
tdUnc
.
textContent
=
uncValues
.
length
?
uncValues
.
join
(
"
/
"
)
:
""
;
row
.
appendChild
(
tdUnc
);
qtyTable
.
appendChild
(
row
);
});
contentDiv
.
appendChild
(
qtyTable
);
}
// Append expanded content to details
details
.
appendChild
(
contentDiv
);
container
.
appendChild
(
details
);
});
return
container
;
}
// Helper to extract language-specific text from a node
_getText
(
node
)
{
if
(
!
node
)
return
""
;
const
content
=
node
[
"
dcc:content
"
];
if
(
Array
.
isArray
(
content
))
{
const
match
=
content
.
find
((
item
)
=>
item
.
$
&&
item
.
$
.
lang
===
this
.
language
)
||
content
[
0
];
return
match
.
_
||
match
;
}
return
content
.
_
||
content
;
}
// (Optional) You can add additional helper methods to render other parts of the data
}
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