-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates RequestHandling and WidgetHandling to composables and util fu…
…nctions
- Loading branch information
Showing
6 changed files
with
602 additions
and
0 deletions.
There are no files selected for viewing
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,41 @@ | ||
import { useConceptDescriptionHandling } from './ConceptDescriptionHandling'; | ||
|
||
export function useChartHandling() { | ||
const { unitSuffix } = useConceptDescriptionHandling(); | ||
|
||
function prepareYValueTooltip(chartData: any, yVariables: any) { | ||
return chartData.map((_series: any, index: number) => { | ||
// Use optional chaining and nullish coalescing to simplify the retrieval of the unit | ||
let unit = ''; | ||
if (yVariables[index]) { | ||
unit = unitSuffix(yVariables[index]); | ||
} | ||
return { | ||
formatter: (value: any) => `${value} ${unit}`, | ||
}; | ||
}); | ||
} | ||
|
||
function prepareLegend(yVariables: any) { | ||
return { | ||
formatter: (seriesName: any, opts: any) => { | ||
let unit = ''; | ||
const index = opts.seriesIndex; | ||
|
||
// check if the yVariable exists | ||
if (yVariables.length > index) { | ||
// check if the yVariable has an unit (embeddedDataSpecification) -> take the first one (TODO: make this more generic in the future) | ||
if (yVariables[index]) { | ||
unit = '[' + unitSuffix(yVariables[index]) + ']'; | ||
} | ||
} | ||
return seriesName + ' ' + unit; | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
prepareYValueTooltip, | ||
prepareLegend, | ||
}; | ||
} |
113 changes: 113 additions & 0 deletions
113
aas-web-ui/src/composables/ConceptDescriptionHandling.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,113 @@ | ||
import { computed } from 'vue'; | ||
import { useNavigationStore } from '@/store/NavigationStore'; | ||
import { URLEncode } from '@/utils/EncodeDecodeUtils'; | ||
import { getEquivalentEclassSemanticIds, getEquivalentIriSemanticIds } from '@/utils/SemanticIdUtils'; | ||
import { useRequestHandling } from './RequestHandling'; | ||
|
||
export function useConceptDescriptionHandling() { | ||
const { getRequest } = useRequestHandling(); | ||
|
||
const navigationStore = useNavigationStore(); | ||
|
||
const CDRepoURL = computed(() => { | ||
return navigationStore.getConceptDescriptionRepoURL; | ||
}); | ||
|
||
// Get the Unit from the EmbeddedDataSpecification of the ConceptDescription of the Property (if available) | ||
function unitSuffix(prop: any) { | ||
if (!prop.conceptDescriptions) { | ||
getConceptDescriptions(prop).then((conceptDescriptions) => { | ||
prop.conceptDescriptions = conceptDescriptions; | ||
}); | ||
} | ||
if (!prop.conceptDescriptions || prop.conceptDescriptions.length == 0) { | ||
return ''; | ||
} | ||
for (const conceptDescription of prop.conceptDescriptions) { | ||
if (!conceptDescription.embeddedDataSpecifications) { | ||
continue; | ||
} | ||
for (const embeddedDataSpecification of conceptDescription.embeddedDataSpecifications) { | ||
if ( | ||
embeddedDataSpecification.dataSpecificationContent && | ||
embeddedDataSpecification.dataSpecificationContent.unit | ||
) { | ||
return embeddedDataSpecification.dataSpecificationContent.unit; | ||
} | ||
} | ||
} | ||
return ''; | ||
} | ||
|
||
// Get all ConceptDescriptions for the SubmodelElement from the ConceptDescription Repository | ||
async function getConceptDescriptions(SelectedNode: any) { | ||
let conceptDescriptionRepoURL = ''; | ||
if (CDRepoURL.value && CDRepoURL.value != '') { | ||
conceptDescriptionRepoURL = CDRepoURL.value; | ||
} else { | ||
return Promise.resolve([]); // Return an empty object wrapped in a resolved promise | ||
} | ||
|
||
// return if no SemanticID is available | ||
if (!SelectedNode.semanticId || !SelectedNode.semanticId.keys || SelectedNode.semanticId.keys.length == 0) { | ||
return Promise.resolve([]); | ||
} | ||
|
||
const semanticIdsToFetch = SelectedNode.semanticId.keys.map((key: any) => { | ||
return key.value; | ||
}); | ||
|
||
semanticIdsToFetch.forEach((semanticId: string) => { | ||
if ( | ||
semanticId.startsWith('0173-1#') || | ||
semanticId.startsWith('0173/1///') || | ||
semanticId.startsWith('https://api.eclass-cdp.com/0173-1') | ||
) { | ||
semanticIdsToFetch.push(...getEquivalentEclassSemanticIds(semanticId)); | ||
} else if (semanticId.startsWith('http://') || semanticId.startsWith('https://')) { | ||
semanticIdsToFetch.push(...getEquivalentIriSemanticIds(semanticId)); | ||
} | ||
}); | ||
|
||
const semanticIdsUniqueToFetch = semanticIdsToFetch.filter( | ||
(value: string, index: number, self: string) => self.indexOf(value) === index | ||
); | ||
|
||
const cdPromises = semanticIdsUniqueToFetch.map((semanticId: string) => { | ||
const path = conceptDescriptionRepoURL + '/' + URLEncode(semanticId); | ||
const context = 'retrieving ConceptDescriptions'; | ||
const disableMessage = true; | ||
|
||
return getRequest(path, context, disableMessage).then((response: any) => { | ||
if (response.success) { | ||
// console.log('ConceptDescription Data: ', response.data); | ||
const conceptDescription = response.data; | ||
conceptDescription.path = path; | ||
// Check if ConceptDescription has data to be displayed | ||
if ( | ||
(conceptDescription.displayName && conceptDescription.displayName.length > 0) || | ||
(conceptDescription.description && conceptDescription.description.length > 0) || | ||
(conceptDescription.embeddedDataSpecifications && | ||
conceptDescription.embeddedDataSpecifications.length > 0) | ||
) { | ||
return conceptDescription; | ||
} | ||
return {}; | ||
} else { | ||
return {}; | ||
} | ||
}); | ||
}); | ||
|
||
let conceptDescriptions = await Promise.all(cdPromises); | ||
conceptDescriptions = conceptDescriptions.filter( | ||
(conceptDescription: any) => Object.keys(conceptDescription).length !== 0 | ||
); // Filter empty Objects | ||
return conceptDescriptions; | ||
} | ||
|
||
return { | ||
unitSuffix, | ||
getConceptDescriptions, | ||
}; | ||
} |
Oops, something went wrong.