Skip to content

Commit

Permalink
move related child in corresponding div
Browse files Browse the repository at this point in the history
  • Loading branch information
mind84 authored and github-actions[bot] committed Oct 8, 2024
1 parent 5b93e92 commit 1f7cc55
Show file tree
Hide file tree
Showing 4 changed files with 2,758 additions and 0 deletions.
32 changes: 32 additions & 0 deletions assets/src/legacy/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,38 @@ window.lizMap = function() {
.siblings('.popupAllFeaturesCompact, .lizmapPopupSingleFeature').toggle();
});

// place children in the right div, if any
let relations = parentDiv.children('.container.popup_lizmap_dd').find(".popup_lizmap_dd_relation");
relations.each((ind,relation) => {
let referencingLayerId = $(relation).attr('data-referencing-layer-id');
if (referencingLayerId) {
let relLayerId = null;
let referencingLayerConfig = lizMap.getLayerConfigById( referencingLayerId, lizMap.config.attributeLayers, 'layerId' );
if (referencingLayerConfig && referencingLayerConfig[1]?.pivot == 'True' && config.relations.pivot && config.relations.pivot[referencingLayerId]) {
// relation is a pivot, search for "m" child layers
let mLayer = Object.keys(config.relations.pivot[referencingLayerId]).filter((k)=>{ return k !== layerId})
if (mLayer.length == 1) {
relLayerId = mLayer[0];
}
} else {
// relation is 1:n, search for n layer
relLayerId = referencingLayerId;
}

if (relLayerId) {
let childLayer = childPopupElements.filter((child)=>{
let lName = child.attr("data-layername");
let lId = lName ? lizMap.config.layers?.[lName]?.id : '';
return relLayerId == lId;
})

if(childLayer.length == 1) {
$(relation).append(childLayer[0])
}
}
}
});

// Trigger event for all popup children
lizMap.events.triggerEvent(
"lizmappopupallchildrendisplayed",
Expand Down
24 changes: 24 additions & 0 deletions tests/end2end/playwright/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,27 @@ test.describe('Popup max features', () => {
await expect(page.locator('.lizmapPopupSingleFeature')).toHaveCount(15);
});
});

test.describe('Drag and drop design with relations', () => {
test('Children are placed in the correct div container', async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=children_in_relation_div';
await gotoMap(url, page);

let getFeatureInfoRequestBirdsPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData()?.includes('GetFeatureInfo') === true && request.postData()?.includes('birds') === true);
let getFeatureInfoRequestSpotsPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData()?.includes('GetFeatureInfo') === true && request.postData()?.includes('birds_spot') === true);
await page.locator('#newOlMap').click({
position: {
x: 358,
y: 248
}
});

await getFeatureInfoRequestBirdsPromise;
await getFeatureInfoRequestSpotsPromise;

await expect(page.locator('div.popup_lizmap_dd_relation[id="popup_relation_birds_area_natural_area_id_natural_ar_id"] > div.lizmapPopupChildren.birds')).toHaveCount(1);
await expect(page.locator('div.popup_lizmap_dd_relation[id="popup_relation_birds_spot_area_id_natural_ar_id"] > div.lizmapPopupChildren.birds_spots')).toHaveCount(1);

});
});

Loading

0 comments on commit 1f7cc55

Please sign in to comment.