Skip to content

Commit 047db5f

Browse files
Zachary_KniebelZachary_Kniebel
authored andcommitted
Merge branch 'version/1.1' into release
2 parents be40fd2 + 4a0e11a commit 047db5f

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

app/generator/mdj-reverseengineer.js

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,10 @@ function _getJsonTemplates(jsonItem) {
465465
* @param {Canvas} canvas
466466
* @param {object} createdItemViewsCache
467467
* @param {object} jsonItemIDsCache
468+
* @param {object} inheritanceModelsCache
468469
* @param {object} layoutOptions
469470
*/
470-
function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, createdItemViewsCache, jsonItemIDsCache, layoutOptions) {
471+
function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, createdItemViewsCache, jsonItemIDsCache, inheritanceModelsCache, layoutOptions) {
471472
var __getLayerModuleByID = function(itemID) {
472473
var jsonItem = jsonItemIDsCache[itemID]; // note that the input item is a lean version of the JsonFolder object, without children
473474
return {
@@ -535,6 +536,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
535536

536537
// validates the dependency described by the given source and target hierarchy models
537538
var __validateDependency = function(sourceHierarchyModel, targetHierarchyModel) {
539+
// any template can depend on another template within the same layer
540+
if (sourceHierarchyModel.ModuleID == targetHierarchyModel.ModuleID) {
541+
return { IsValid: true };
542+
}
543+
538544
var sourceLayerID = sourceHierarchyModel.LayerID;
539545
var targetLayerID = targetHierarchyModel.LayerID;
540546

@@ -608,6 +614,7 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
608614
.map(function(baseTemplateId) {
609615
return {
610616
SourceJsonTemplate: jsonTemplate,
617+
SourceHierarchyModel: templateHierarchyIndex[jsonTemplate.ReferenceID],
611618
TargetHierarchyModel: templateHierarchyIndex[baseTemplateId]
612619
};
613620
})
@@ -616,11 +623,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
616623
logger.warn(`The dependency item with ID "${dependency.SourceJsonTemplate.ReferenceID}" was documented but does not belong to a specified Helix Module, and so it will be excluded from the dependencies of the "${jsonTemplate.ReferenceID}" item. If the dependency template belongs to a Helix module, please make sure that its module is selected in the Documentation Configuration item in Sitecore.`);
617624
return false;
618625
}
619-
return dependency && dependency.TargetHierarchyModel.ModuleID != helixModule.RootJsonItem.ReferenceID;
626+
return true;
620627
})
621628
.map(function(dependency) {
622629
var validationResult = __validateDependency(
623-
templateHierarchyIndex[dependency.SourceJsonTemplate.ReferenceID],
630+
dependency.SourceHierarchyModel,
624631
dependency.TargetHierarchyModel);
625632

626633
dependency.IsValid = validationResult.IsValid;
@@ -636,7 +643,8 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
636643
var dependencyId = dependencyJsonTemplate.ReferenceID;
637644

638645
(templateDependentsCache[dependencyId] || (templateDependentsCache[dependencyId] = [])).push({
639-
SourceHierarchyModel: templateHierarchyIndex[jsonTemplate.ReferenceID],
646+
SourceHierarchyModel: dependency.SourceHierarchyModel,
647+
TargetHierarchyModel: dependency.TargetHierarchyModel,
640648
TargetJsonTemplate: dependencyJsonTemplate,
641649
IsValid: dependency.IsValid,
642650
ValidationMessage: dependency.ValidationMessage
@@ -708,7 +716,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
708716
helixModule.JsonTemplates
709717
.forEach(function (jsonTemplate) {
710718
// get/add dependencies from/to cache for each template in the module
711-
var dependencies = templateDependenciesCache[jsonTemplate.ReferenceID];
719+
var dependencies = templateDependenciesCache[jsonTemplate.ReferenceID]
720+
// this is the module diagram, so we don't show dependencies from one template in the module on another template that's also in the module
721+
.filter(function(dependency) {
722+
return dependency.SourceHierarchyModel.ModuleID != dependency.TargetHierarchyModel.ModuleID;
723+
});
712724
if (!dependencies.length) {
713725
return;
714726
}
@@ -812,7 +824,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
812824
helixModule.JsonTemplates
813825
.forEach(function (jsonTemplate) {
814826
// get/add dependents from/to cache for each template in the module
815-
var dependents = templateDependentsCache[jsonTemplate.ReferenceID];
827+
var dependents = templateDependentsCache[jsonTemplate.ReferenceID]
828+
// this is the module dependents diagram, so we don't show dependents from one template in the module on another template that's also in the module
829+
.filter(function(dependent) {
830+
return dependent.SourceHierarchyModel.ModuleID != dependent.TargetHierarchyModel.ModuleID;
831+
});
816832
if (!dependents.length) {
817833
return;
818834
}
@@ -961,9 +977,6 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
961977
canvas,
962978
createdModuleTemplatesDiagramItemViewsCache);
963979

964-
// set the dependency's interface view to have the "none" stereotype (this ensures that the dashed lines and arrows will display properly)
965-
targetView.stereotypeDisplay = "none";
966-
967980
// create the containment view from the dependency's target interface to its module root folder
968981
_createContainmentRelationshipView(
969982
targetView,
@@ -974,12 +987,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
974987

975988
// create the dependency model if it doesn't already exist
976989
var dependencyModelCacheKey = `"${dependency.SourceJsonTemplate.ReferenceID}"->"${dependency.TargetHierarchyModel.JsonTemplate.ReferenceID}"`;
977-
var dependencyModel = createdDependencyModelCache[dependencyModelCacheKey];
990+
var dependencyModel = inheritanceModelsCache[dependencyModelCacheKey];
978991
if (!dependencyModel) {
979-
dependencyModel = _createDependencyRelationshipModel(
980-
sourceModel,
981-
targetView.model);
982-
createdDependencyModelCache[dependencyModelCacheKey] = dependencyModel;
992+
var msg = `Error: dependency model should already exist as a generalization for dependency with key "${dependencyModelCacheKey}"`;
993+
logger.error(msg);
994+
throw msg;
983995
}
984996

985997
// update the documentation for the dependency
@@ -990,7 +1002,7 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
9901002
dependencyModel.documentation = documentationEntry;
9911003

9921004
// create the dependency view
993-
var dependencyView = _createDependencyRelationshipView(
1005+
var dependencyView = _createBaseTemplateRelationshipView(
9941006
dependencyModel,
9951007
sourceTemplateView,
9961008
targetView,
@@ -1045,15 +1057,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
10451057
moduleTemplatesDependentsDiagram,
10461058
canvas,
10471059
createdModuleTemplatesDependentsDiagramItemViewsCache);
1048-
1049-
// set the dependent's interface view to have the "none" stereotype (this ensures that the dashed lines and arrows will display properly)
1050-
targetView.stereotypeDisplay = "none";
1051-
10521060

10531061
// add the containment view relating the source template to the module root package
10541062
_createContainmentRelationshipView(targetView, moduleRootView, moduleTemplatesDependentsDiagram, canvas);
10551063

1056-
// get the templates dependnets from the cache
1064+
// get the templates dependents from the cache
10571065
var dependents = templateDependentsCache[jsonTemplate.ReferenceID];
10581066
if (!dependents.length) {
10591067
return;
@@ -1110,19 +1118,18 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
11101118
moduleTemplatesDependentsDiagram,
11111119
canvas);
11121120
}
1113-
1121+
11141122
// create the dependency model if it doesn't already exist
11151123
var dependencyModelCacheKey = `"${dependent.SourceHierarchyModel.JsonTemplate.ReferenceID}"->"${dependent.TargetJsonTemplate.ReferenceID}"`;
1116-
var dependencyModel = createdDependencyModelCache[dependencyModelCacheKey];
1124+
var dependencyModel = inheritanceModelsCache[dependencyModelCacheKey];
11171125
if (!dependencyModel) {
1118-
dependencyModel = _createDependencyRelationshipModel(
1119-
sourceView.model,
1120-
targetModel);
1121-
createdDependencyModelCache[dependencyModelCacheKey] = dependencyModel;
1126+
var msg = `Error: dependency model should already exist as a generalization for dependency with key "${dependencyModelCacheKey}"`;
1127+
logger.error(msg);
1128+
throw msg;
11221129
}
11231130

11241131
// create the dependency view
1125-
var dependencyView = _createDependencyRelationshipView(
1132+
var dependencyView = _createBaseTemplateRelationshipView(
11261133
dependencyModel,
11271134
sourceView,
11281135
targetView,
@@ -1164,7 +1171,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
11641171
// loop though the module's templates and add the dependencies for each to the diagram
11651172
helixModule.JsonTemplates.forEach(function(jsonTemplate) {
11661173
// get the dependencies for the template from the cache
1167-
var dependencies = templateDependenciesCache[jsonTemplate.ReferenceID];
1174+
var dependencies = templateDependenciesCache[jsonTemplate.ReferenceID]
1175+
// this is the layer diagram, so we don't show dependencies from one template in a module on another template in the same module
1176+
.filter(function(dependency) {
1177+
return dependency.SourceHierarchyModel.ModuleID != dependency.TargetHierarchyModel.ModuleID;
1178+
});
11681179

11691180
// loop through the template's dependencies and add each (if not already added) to the diagram
11701181
dependencies.forEach(function (dependency) {
@@ -1262,7 +1273,11 @@ function _generateHelixDiagrams(documentationConfiguration, metaball, canvas, cr
12621273
// loop though the module's templates and add the dependents for each to the diagram
12631274
helixModule.JsonTemplates.forEach(function(jsonTemplate) {
12641275
// get the dependents for the template from the cache
1265-
var dependents = templateDependentsCache[jsonTemplate.ReferenceID];
1276+
var dependents = templateDependentsCache[jsonTemplate.ReferenceID]
1277+
// this is the layer dependents diagram, so we don't show dependents from one template in a module on another template in the same module
1278+
.filter(function(dependent) {
1279+
return dependent.SourceHierarchyModel.ModuleID != dependent.TargetHierarchyModel.ModuleID;
1280+
});
12661281

12671282
// loop through the template's dependents and add each (if not already added) to the diagram
12681283
dependents.forEach(function (dependent) {
@@ -1427,9 +1442,10 @@ var reverseEngineerMetaDataJsonFile = (architecture, outputFilePath, metaball, l
14271442

14281443
/* 2) CREATE ALL OF THE MODELS AND VIEWS FOR THE ITEMS */
14291444

1430-
// create the map objects to use for storing the mappings from the created items' IDs to their views and item IDs to JSON items
1445+
// create the map objects to use for storing the mappings from the created items' IDs to their models/views and item IDs to JSON items
14311446
var createdItemViewsCache = {};
14321447
var jsonItemIDsCache = {};
1448+
var createdInheritanceModelsCache = {};
14331449

14341450
// creates the folder, template and field models and views
14351451
architecture.Items.forEach(function (jsonItem) {
@@ -1453,7 +1469,10 @@ var reverseEngineerMetaDataJsonFile = (architecture, outputFilePath, metaball, l
14531469
jsonItem.BaseTemplates.forEach(function (jsonBaseTemplateId) {
14541470
var baseTemplateView = createdItemViewsCache[jsonBaseTemplateId];
14551471

1472+
// this is the first time looking at the base templates of the items and base templates can't be repeated so we know we need to do this every time
1473+
var modelCacheKey = `"${jsonItem.ReferenceID}"->"${jsonBaseTemplateId}"`;
14561474
var model = _createBaseTemplateRelationshipModel(view.model, baseTemplateView.model);
1475+
createdInheritanceModelsCache[modelCacheKey] = model;
14571476

14581477
_createBaseTemplateRelationshipView(model, view, baseTemplateView, templatesDiagram, canvas);
14591478
});
@@ -1483,6 +1502,7 @@ var reverseEngineerMetaDataJsonFile = (architecture, outputFilePath, metaball, l
14831502
canvas,
14841503
createdItemViewsCache,
14851504
jsonItemIDsCache,
1505+
createdInheritanceModelsCache,
14861506
layoutOptions);
14871507

14881508

0 commit comments

Comments
 (0)