//Language:JavaScript //MegaContext(Fields,Types) function MainRoot(mgRoot) { var sObjectId = ""; var sWebsiteId = ""; var sTemplateId = ""; var oObject = mgRoot.GetObjectFromId(sObjectId); var oWebsiteContext = {} oWebsiteContext.WebSite = function () { return mgRoot.GetObjectFromId(sWebsiteId); }; oWebsiteContext.HtmlFile = function (mgObj, i) { return mgObj.GetProp("~H20000000550[_HexaIdAbs]") + ".htm"; } var mgcolGeneratedObjects = oWebsiteContext.WebSite().WebsiteDescription().GetGeneratedObjects(); oWebsiteContext.GeneratedObjects = function () { return mgcolGeneratedObjects; } oWebsiteContext.StdFileCopy = function (sName, s1, s2) { return sName; } oWebsiteContext.StdPath = function (i, b) { return "../standard/"; } var sOut = Generate(oObject, oWebsiteContext, sTemplateId); mgRoot.Print(sOut); } function Generate(mgobjObject, oWebsiteContext, sIn) { oWebsiteContext.cache = 0; var mgRoot = mgobjObject.GetRoot(); var mgobjSource = mgRoot.GetObjectFromId(sIn); if (!mgobjSource.Exists()) return ""; var mgcolGeneratedObjects = mgRoot.GetSelection(""); mgcolGeneratedObjects.Insert(oWebsiteContext.GeneratedObjects()); var oWebsite = mgRoot.GetObjectFromId(oWebsiteContext.WebSite().MegaField); var strMegaEnvPath = mgRoot.CurrentEnvironment.Path; var strENV = "%ENV%"; var strWebSitePath = oWebsite.GetProp("~dAChvzAqqq00[Web Site Path]"); strWebSitePath = strWebSitePath.toLowerCase().replace(strENV.toLowerCase(), strMegaEnvPath); var sJsonPath = strWebSitePath + "\\json" var fsObj = new ActiveXObject("Scripting.FileSystemObject") if (!fsObj.FolderExists(sJsonPath)) { fsObj.CreateFolder(sJsonPath); } var jDbdMain = {} try{ jDbdMain = JSON.parse(mgobjSource.GetProp("~X52u0HUuzu10[Translatable Code Template]")); }catch(e){ return ""; } jDbdMain.id = mgobjSource.GetProp("~H20000000550[_HexaIdAbs]"); if (jDbdMain.getObjectsFromSource){ jDbdMain.mgobjSource = mgobjObject.GetType(""); jDbdMain.id += "_" + mgobjObject.GetProp("~H20000000550[_HexaIdAbs]"); } var sOptions = JSON.stringify(createDashboardJson(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain, sJsonPath + "\\")); var id = mgobjSource.GetProp("~H20000000550[_HexaIdAbs]"); return "
\r\n" + "\r\n"; } function createDashboardJson(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain, sJsonPath){ var urlPrefix = "../json/"; var sFileName = jDbdMain.id + "_" + "dashboard.json"; var options = getDashboardOptions(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain); options.dataURL = urlPrefix + sFileName; mgRoot.Print(JSON.stringify(options)); var data = getDashboardData(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain); WriteTextToFile(JSON.stringify(data), sJsonPath + sFileName); return options; } function getDashboardOptions(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain){ var jTemplate = jDbdMain.optionsExtraction; var options = { filters:getDashboardFilters(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate), buttons:getDashboardButtons(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate), charts:getDashboardCharts(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate), drillDowns:getDashboardDrillDowns(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate), chartDisplaySingleMode:jTemplate.chartDisplaySingleMode?true:false }; return options; } function getDashboardFilters(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate){ var filters = []; var jFilters = jTemplate.filters || []; for (var i = 0; i < jFilters.length; i++){ var jFilter = jFilters[i]; var filter = { type: jFilter.type, datastructureSelect: jFilter.datastructureSelect, values:[] } var mgLabel = mgRoot.GetObjectFromId(jFilter.name); filter.name = mgLabel.Exists()?mgLabel.GetProp("~hXFYOdOKsC00[_GUIName]"):jFilter.name; filter.id = mgLabel.Exists()?mgLabel.GetProp("~H20000000550[_HexaIdAbs]"):jFilter.id || jFilter.name + "_" + i; filter.label = filter.name; if (jFilter.values){ var jValues = jFilter.values; for (var j = 0; j < jValues.length; j++){ var jValue = jValues[j]; var value = { logic:jValue.logic } var mgValueLabel = mgRoot.GetObjectFromId(jValue.name); value.name = mgValueLabel.Exists()?mgValueLabel.GetProp("~hXFYOdOKsC00[_GUIName]"):jValue.name; value.id = mgValueLabel.Exists()?mgValueLabel.GetProp("~H20000000550[_HexaIdAbs]"):jValue.id || jValue.name + "_" + i; filter.values.push(value); } }else if (jFilter.valuesFromCollection){ var jValueTemplate = jFilter.valuesFromCollection; var jLogic = jValueTemplate.logic; jLogic.fields = jLogic.fields.indexOf(".id") == jLogic.fields.length -3?jLogic.fields:jLogic.fields+".id"; var mgAttId = jValueTemplate.mgAttId || "~Z20000000D60[Short Name]"; var mgcolValues = mgRoot.GetCollection(jValueTemplate.mgColId, "~Z20000000D60[Short Name]"); for (var j = 1, jMax = mgcolValues.Count; j <= jMax; j++){ var mgValueLabel = mgcolValues.Item(j); if (jValueTemplate.withPages && !mgcolGeneratedObjects.Item(mgValueLabel).Exists()) continue; var value = { id: mgValueLabel.GetProp("~H20000000550[_HexaIdAbs]"), name: mgValueLabel.GetProp(mgAttId), logic:{ fields:jLogic.fields, operator: "==", value: mgValueLabel.GetProp("~H20000000550[_HexaIdAbs]") } } filter.values.push(value); } } filters.push(filter); } return filters; } function getDashboardButtons(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate){ var buttons = []; var jButtons = jTemplate.buttons || []; for (var i = 0; i < jButtons.length; i++){ var jButton = jButtons[i]; var button = jButton; var mgLabel = mgRoot.GetObjectFromId(button.name); button.name = mgLabel.Exists()?mgLabel.GetProp("~hXFYOdOKsC00[_GUIName]"):button.name; button.id = mgLabel.Exists()?mgLabel.GetProp("~H20000000550[_HexaIdAbs]"):button.id || button.name + "_" + i; button.label = button.name; buttons.push(button); } return buttons; } function getDashboardCharts(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate){ var charts = []; var jCharts = jTemplate.charts || []; for (var i = 0; i < jCharts.length; i++){ var jChart = jCharts[i]; var chart = jChart; var mgLabel = mgRoot.GetObjectFromId(chart.name); chart.name = mgLabel.Exists()?mgLabel.GetProp("~hXFYOdOKsC00[_GUIName]"):chart.name; chart.id = mgLabel.Exists()?mgLabel.GetProp("~H20000000550[_HexaIdAbs]"):chart.id || chart.name + "_" + i; chart.label = chart.name; charts.push(chart); } return charts; } function getDashboardDrillDowns(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jTemplate){ var drillDowns = []; var jDrillDowns = jTemplate.drillDowns || []; for (var i = 0; i < jDrillDowns.length; i++){ var jDrillDown = jDrillDowns[i]; var drillDown = jDrillDown; var mgLabel = mgRoot.GetObjectFromId(drillDown.name); drillDown.name = mgLabel.Exists()?mgLabel.GetProp("~hXFYOdOKsC00[_GUIName]"):drillDown.name; drillDown.id = mgLabel.Exists()?mgLabel.GetProp("~H20000000550[_HexaIdAbs]"):drillDown.id || drillDown.name + "_" + i; drillDown.label = drillDown.name; drillDowns.push(drillDown); } return drillDowns; } function getDashboardData(mgRoot, oWebsiteContext, mgcolGeneratedObjects, jDbdMain){ var data = []; var jTemplate = jDbdMain.dataExtraction; var mgcolObjects = (jDbdMain.getObjectsFromSource)?jDbdMain.mgobjSource.GetCollection(jTemplate.mgColId, "~Z20000000D60[Short Name]"):mgRoot.GetCollection(jTemplate.mgColId, "~Z20000000D60[Short Name]"); for (var i = 1, iMax = mgcolObjects.Count; i <= iMax; i++){ var mgobjObject = mgcolObjects.Item(i); mgRoot.Print("Checking Object: " + mgobjObject.ShortName); if ((jTemplate.withPages && mgcolGeneratedObjects.Item(mgobjObject).Exists()) || !jTemplate.withPages){ mgRoot.Print("Processing Object: " + mgobjObject.ShortName); var jObject = getDashboardObject(mgRoot, oWebsiteContext, mgcolGeneratedObjects, mgobjObject, jTemplate); mgRoot.Print("Adding Object: " + mgobjObject.ShortName); data.push(jObject); mgRoot.Print("Completing Object: " + mgobjObject.ShortName); } } return data; } function getDashboardObject(mgRoot, oWebsiteContext, mgcolGeneratedObjects, mgobjObject, jTemplate){ var jObject = { id:mgobjObject.GetProp("~H20000000550[_HexaIdAbs]"), name:mgobjObject.GetProp("~Z20000000D60[Short Name]"), icon:GetObjectImage(oWebsiteContext, mgobjObject), href:GetObjectHref(oWebsiteContext, mgcolGeneratedObjects, mgobjObject), } jTemplate.attributes = jTemplate.attributes?jTemplate.attributes:[]; for (var i = 0, iMax = jTemplate.attributes.length; i < iMax; i++){ if (!jObject.attributes) jObject.attributes = {}; var jAttTemplate = jTemplate.attributes[i]; var mgobjForAttribute = mgobjObject; if (jAttTemplate.mgColId){ mgobjForAttribute = mgobjObject.GetCollection(jAttTemplate.mgColId).Item(1); } if (mgobjForAttribute.Exists()){ var value = ""; var format = jAttTemplate.mgAttFormat; if (format && (format == "display" || format == "internal")){ value = mgobjForAttribute.GetProp(jAttTemplate.mgAttId, format); }else if (format && format == "html"){ value = mgobjForAttribute.GetFormatted(jAttTemplate.mgAttId, format); }else{ value = mgobjForAttribute.GetProp(jAttTemplate.mgAttId); } var jSubAttTemplate = (jAttTemplate.subAttribute)?jAttTemplate.subAttribute:null; while(jSubAttTemplate){ if (jSubAttTemplate.mgColId){ mgobjForAttribute = mgobjForAttribute.GetCollection(jSubAttTemplate.mgColId).Item(1); } if (mgobjForAttribute.Exists()){ format = jSubAttTemplate.mgAttFormat; if (format && (format == "display" || format == "internal")){ value += ((jSubAttTemplate.separator)?jSubAttTemplate.separator:"") + mgobjForAttribute.GetProp(jSubAttTemplate.mgAttId, format); }else if (format && format == "html"){ value += ((jSubAttTemplate.separator)?jSubAttTemplate.separator:"") + mgobjForAttribute.GetFormatted(jSubAttTemplate.mgAttId, format); }else{ value += ((jSubAttTemplate.separator)?jSubAttTemplate.separator:"") + mgobjForAttribute.GetProp(jSubAttTemplate.mgAttId); } jSubAttTemplate = (jSubAttTemplate.subAttribute)?jSubAttTemplate.subAttribute:null; }else{ jSubAttTemplate = null; } } jObject.attributes[jAttTemplate.keyId] = value; } } jTemplate.collections =jTemplate.collections?jTemplate.collections:[]; for (var i = 0, iMax = jTemplate.collections.length; i < iMax; i++){ var jColTemplate = jTemplate.collections[i]; var keyId = jColTemplate.keyId; var mgcolObjects = mgobjObject.GetCollection(jColTemplate.mgColId, "~Z20000000D60[Short Name]"); for (var j = 1, jMax = mgcolObjects.Count; j <= jMax; j++){ var mgobjColObject = mgcolObjects.Item(j); if ((jColTemplate.withPages && mgcolGeneratedObjects.Item(mgobjColObject).Exists()) || !jColTemplate.withPages){ var jColObject = getDashboardObject(mgRoot, oWebsiteContext, mgcolGeneratedObjects, mgobjColObject, jColTemplate); if (!jObject.collections) jObject.collections = {}; if (!jObject.collections[keyId])jObject.collections[keyId] = []; jObject.collections[keyId].push(jColObject); } } } if (jTemplate.lifecycleExtractionMethod){ if (jTemplate.lifecycleExtractionMethod == "default"){ jObject.lifecycle = getObjectLife(mgobjObject); }else if (jTemplate.lifecycleExtractionMethod == "custom"){ jObject.lifecycle = getObjectLife(mgobjObject, jTemplate.lifecycle); } } return jObject; } function getObjectLife(mgobjObject, jLifeCycle){ var jLC = jLifeCycle || [ { "mgColId": "~wXUKMAimVvh2[HOPEX360_Time Period of Object with Stereotype Preparation