Skip to content

Commit

Permalink
feat: support saving and loading of TEI relationship maps (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
amcgee committed Apr 24, 2019
1 parent 0b44b02 commit 38b9581
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/loaders/trackedEntityLoader.js
Expand Up @@ -30,6 +30,19 @@ const geometryTypes = Object.keys(geometryTypesMap);

//TODO: Refactor to share code with other loaders
const trackedEntityLoader = async config => {
if (config.config && typeof config.config === 'string') {
try {
const customConfig = JSON.parse(config.config);
config.relationshipType = customConfig.relationships.type;
config.relatedPointColor = customConfig.relationships.pointColor;
config.relatedPointRadius = customConfig.relationships.pointRadius;
config.relationshipLineColor = customConfig.relationships.lineColor;
} catch (e) {
// Failed to load JSON relationship config, assuming no relationships
}
delete config.config;
}

const {
trackedEntityType,
program,
Expand Down
18 changes: 18 additions & 0 deletions src/util/favorites.js
Expand Up @@ -61,6 +61,10 @@ const validLayerProperties = [
'styleDataItem',
'trackedEntityType',
'valueType',
'relationshipType',
'relatedPointColor',
'relatedPointRadius',
'relationshipLineColor',
];

const models = ['program', 'programStage', 'organisationUnitGroupSet'];
Expand Down Expand Up @@ -122,6 +126,20 @@ const models2objects = config => {
delete config.params;
delete config.filter;
delete config.periodName;
} else if (config.relationshipType) {
config.config = JSON.stringify({
relationships: {
type: config.relationshipType,
pointColor: config.relatedPointColor,
pointRadius: config.relatedPointRadius,
lineColor: config.relationshipLineColor,
},
});

delete config.relationshipType;
delete config.relatedPointColor;
delete config.relatedPointRadius;
delete config.relationshipLineColor;
}

if (isObject(config.config)) {
Expand Down

0 comments on commit 38b9581

Please sign in to comment.