Skip to content

Commit

Permalink
exclude NavItems 'Einstieg in das projektspezifische V-Modell' and 'P…
Browse files Browse the repository at this point in the history
…rojektdurchführungsstrategie' (#463)

do not show discipline NavItems which should not be there in current tailoring
fixed discipline parameter for product calls
  • Loading branch information
Bock4Soft authored Sep 19, 2023
1 parent 0242ee0 commit 881201d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { AnchorLinkItemProps } from 'antd/es/anchor/Anchor';
import axios from 'axios';
import XMLParser, { XMLElement } from 'react-xml-parser';
import { IndexTypeEnum, NavTypeEnum } from '../navigation/Navigation';
import { IndexTypeEnum, NavMenuItem, NavTypeEnum } from '../navigation/Navigation';
import { ColumnsType } from 'antd/es/table';
import { useTranslation } from 'react-i18next';
import { useTailoring } from '../../../../context/TailoringContext';
Expand Down Expand Up @@ -321,7 +321,7 @@ export function Content() {
}, [entryId]);

async function getResponsibleRolesForProducts(productIds: string[]): Promise<any[]> {
const filterProductDataTypes = flatten(navigationData).filter((item: any) =>
const filterProductDataTypes: NavMenuItem[] = flatten(navigationData).filter((item: any) =>
[NavTypeEnum.PRODUCT].includes(item.dataType)
);

Expand All @@ -335,6 +335,9 @@ export function Content() {
for (const productId of productIds) {
const currentProduct = filterProductDataTypes.filter((product) => product.key === productId)?.[0];

const productDiscipline = currentProduct.parent.key;
const disciplineId = productDiscipline?.replace('productDiscipline_', '');

const responsibleRolesForProductsUrl =
weitApiUrl +
'/Tailoring/V-Modellmetamodell/mm_2021/V-Modellvariante/' +
Expand All @@ -344,7 +347,7 @@ export function Content() {
'/Projekttypvariante/' +
tailoringParameter.projectTypeVariantId +
'/Disziplin/' +
currentProduct.parent.key +
disciplineId +
'/Produkt/' +
currentProduct.key +
'?' +
Expand Down Expand Up @@ -396,7 +399,7 @@ export function Content() {
}

async function getContributeRolesForProducts(productIds: string[]): Promise<any[]> {
const filterProductDataTypes = flatten(navigationData).filter((item: any) =>
const filterProductDataTypes: NavMenuItem[] = flatten(navigationData).filter((item: any) =>
[NavTypeEnum.PRODUCT].includes(item.dataType)
);

Expand All @@ -410,6 +413,9 @@ export function Content() {
for (const productId of productIds) {
const currentProduct = filterProductDataTypes.filter((product) => product.key === productId)?.[0];

const productDiscipline = currentProduct.parent.key;
const disciplineId = productDiscipline?.replace('productDiscipline_', '');

const contributeRolesForProductsUrl =
weitApiUrl +
'/Tailoring/V-Modellmetamodell/mm_2021/V-Modellvariante/' +
Expand All @@ -419,7 +425,7 @@ export function Content() {
'/Projekttypvariante/' +
tailoringParameter.projectTypeVariantId +
'/Disziplin/' +
currentProduct.parent.key +
disciplineId +
'/Produkt/' +
currentProduct.key +
'?' +
Expand Down Expand Up @@ -551,12 +557,30 @@ export function Content() {
'?' +
getProjectFeaturesString();

let idCounter = 2000;

const jsonDataFromXml = await getJsonDataFromXml(projectTypeUrl);

const sinnUndZweck = decodeXml(jsonDataFromXml.getElementsByTagName('Sinn_und_Zweck')[0]?.value);

const tableEntries: TableEntry[] = [];

const products = jsonDataFromXml.getElementsByTagName('Produkt').map((productRef) => {
return {
id: productRef.attributes.id,
title: productRef.attributes.name,
};
});

const productsToRoles = await getResponsibleRolesForProducts(products.map((product) => product.id));

if (productsToRoles.length > 0) {
tableEntries.push({
id: (idCounter++).toString(),
descriptionEntry: 'Verantwortliche und Produkte',
dataEntries: [productsToRoles],
});
}
//////////////////////////////////////////////

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export type NavMenuItem = {
parent?: NavMenuItem;
};

const excludeNavItemLabels = ['Einstieg in das projektspezifische V-Modell', 'Projektdurchführungsstrategie'];

// @withRouter
export function Navigation() {
const { t } = useTranslation();
Expand Down Expand Up @@ -139,6 +141,7 @@ export function Navigation() {
async function mount() {
if (tailoringParameter.modelVariantId) {
setLoading(true);
//TODO: getDisciplineIds
await fetchData();
setLoading(false);
}
Expand Down Expand Up @@ -242,7 +245,7 @@ export function Navigation() {

let replacedContent;
let mergedChildren; // for merging children
let addedChildren; // for adding children
let addedChildren: NavMenuItem[]; // for adding children

// TODO: anders lösen
let indexItem;
Expand All @@ -258,7 +261,11 @@ export function Navigation() {

if (generatedContent) {
if (generatedContent === 'Spezialkapitel:Disziplingruppe') {
addedChildren = getDisciplineGroup(childItem.parent, jsonDataFromXml);
// TODO
const disciplineIds = await getDisciplineIds();
addedChildren = getDisciplineGroup(childItem.parent, jsonDataFromXml).filter((navMenuItem) =>
disciplineIds.includes(navMenuItem.key)
);
} else {
switch (generatedContent) {
case 'Index:Produkte': {
Expand Down Expand Up @@ -386,20 +393,52 @@ export function Navigation() {
};
}

function removeFromArrayOfObj(array: NavMenuItem[], labelsToRemove: string[]) {
for (const [i, e] of array.entries()) {
if (labelsToRemove.includes(e.label)) {
array.splice(i, 1);
continue;
}
if (e.children) {
removeFromArrayOfObj(e.children, labelsToRemove);
}
}
return array;
}

async function fetchData(): Promise<void> {
const sectionUrl =
weitApiUrl + '/V-Modellmetamodell/mm_2021/V-Modellvariante/' + tailoringParameter.modelVariantId + '/Kapitel/';

const jsonDataFromXml = await getJsonDataFromXml(sectionUrl);

const navMenuItems = await xmlDataToNavMenuItem(jsonDataFromXml);
console.log('navMenuItems', navMenuItems);
const navMenuItems = xmlDataToNavMenuItem(jsonDataFromXml);
const filteredNavMenuItems = removeFromArrayOfObj(navMenuItems.children, excludeNavItemLabels);

const xmlDataWithParent = await addParentRecursive(navMenuItems.children || []);
const xmlDataWithParent = await addParentRecursive(filteredNavMenuItems || []);

setNavigationData(xmlDataWithParent);
}

async function getDisciplineIds(): Promise<string[]> {
const disciplinesUrl =
weitApiUrl +
'/Tailoring/V-Modellmetamodell/mm_2021/V-Modellvariante/' +
tailoringParameter.modelVariantId +
'/Projekttyp/' +
tailoringParameter.projectTypeId +
'/Projekttypvariante/' +
tailoringParameter.projectTypeVariantId +
'/Disziplin?' +
getProjectFeaturesQueryString();

const jsonDataFromXml = await getJsonDataFromXml(disciplinesUrl);

return jsonDataFromXml.getElementsByTagName('Disziplin').map((disciplineValue) => {
return disciplineValue.attributes.id;
});
}

async function getReferenceProducts(target: NavMenuItem): Promise<NavMenuItem[]> {
const referenceProductsUrl =
weitApiUrl +
Expand Down

0 comments on commit 881201d

Please sign in to comment.