123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443 |
- /*
- IBM Confidential
- OCO Source Materials
- IBM Cognos Products: rs
- (C) Copyright IBM Corp. 2018, 2020
- The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office.
- */
- define(['q', 'bi/authoring/nls/StringResource'], function (Q, StringResource)
- // define(['q'], function (Q) // For Intern tests
- {
- var V5ToDashboard = {};
- V5ToDashboard.K_iNODE_ELEMENT = 1;
- var v_bRunInProduction = false; // Intern is using querySelector and Launch in Explore is using Xpath (selectSingleNode)
- V5ToDashboard.LaunchInExploration = function (v_nReport, v_oAuthoringApp, v_aSelectionIids, v_sReportSpec, v_sExploreStoreID, v_oGlassContext)
- {
- var v_oDBSpec;
- v_bRunInProduction = true;
- var v_sStoreID = v_oAuthoringApp.SharedState.Get("storeID");
- var v_sExistingExploreSpec = null;
- return this.f_getExploreSpec(v_sExploreStoreID, v_oGlassContext)
- .then(function(v_oExploreData)
- {
- if (v_oExploreData && v_oExploreData.data[0] && v_oExploreData.data[0].specification)
- {
- v_sExistingExploreSpec = v_oExploreData.data[0].specification;
- }
- return this.ConvertV5toDBFrag(v_nReport, v_sStoreID, v_aSelectionIids, v_sReportSpec, v_oGlassContext);
- }.bind(this))
- .then(function(v_oDBFragSpec)
- {
- v_oDBSpec = v_oDBFragSpec;
- return v_oGlassContext.getSvc('.ConversionService');
- })
- .then(function(conversionSvc)
- {
- return conversionSvc.convert('DASHBOARD', 'EXPLORE', JSON.stringify(v_oDBSpec));
- })
- .then(function(v_sExploreSpec)
- {
- console.log("RS->DB->EX spec: " + v_sExploreSpec);
- var v_oEXSpec = JSON.parse(v_sExploreSpec);
- if (v_sExistingExploreSpec)
- {
- v_oEXSpec = this.f_mergeNewExplorationIntoExisting(v_oEXSpec, JSON.parse(v_sExistingExploreSpec));
- console.log("Merged exploration spec: " + JSON.stringify(v_oEXSpec));
- }
- var perspectiveOptions =
- {
- content : {
- // addOnSpec : v_oEXSpec,
- boardSpec : v_oEXSpec,
- // boardSpec : {
- // layout: {
- // items: [],
- // type: 'exploreContainer'
- // },
- // name: 'New Exploration',
- // version: 1008,
- // widgets: {},
- // _meta: {
- // bundleID: null
- // }
- // },
- isAuthoringMode : true,
- openAppViewCallback: function() {}
- },
- id: "Explore_" + Date.now()
- };
- return v_oGlassContext.openAppView("explore", perspectiveOptions);
- }.bind(this))
- .then(function(view)
- {
- if (view)
- {
- if (v_nReport.selectSingleNode("./layouts//dataSource/reportExpression"))
- {
- v_oGlassContext.showToast(v_oAuthoringApp.GetString("IDS_MSG_UNSUPPORTED_LAYOUT_CALC_IN_EXPLORE"), {'type':'warning'});
- }
- return view.currentContentView.openDatasetpane(false);
- }
- });
- };
- V5ToDashboard.f_getExploreSpec = function(v_sExploreStoreID, v_oGlassContext)
- {
- if (!v_sExploreStoreID)
- {
- return Q.resolve(null);
- }
- return v_oGlassContext.services.ajax.ajax(
- {
- url: "v1/objects/" + v_sExploreStoreID + "?fields=specification",
- type: 'GET'
- });
- };
- V5ToDashboard.f_mergeNewExplorationIntoExisting = function(v_oNewExploreSpec, v_oExistingExploreSpec)
- {
- // add the new widgets to existing ones
- var v_aNewWidgetsKeys = Object.keys(v_oNewExploreSpec.widgets);
- for (var i = 0; i < v_aNewWidgetsKeys.length; i++)
- {
- v_oExistingExploreSpec.widgets[v_aNewWidgetsKeys[i]] = (v_oNewExploreSpec.widgets[v_aNewWidgetsKeys[i]]);
- }
- // add the new data sources to existing ones
- for (i = 0; i < v_oNewExploreSpec.dataSources.sources.length; i++)
- {
- v_oExistingExploreSpec.dataSources.sources.push(v_oNewExploreSpec.dataSources.sources[i]);
- }
- // add the new layout item(s) to existing ones
- for (i = 0; i < v_oNewExploreSpec.layout.items.length; i++)
- {
- v_oExistingExploreSpec.layout.items.push(v_oNewExploreSpec.layout.items[i]);
- }
- return v_oExistingExploreSpec;
- };
- V5ToDashboard.ConvertV5toDBFrag = function (v_nReport, v_sStoreID, v_aSelectionIids, v_sReportSpec, v_oGlassContext)
- {
- // pass to Moser's normalizedspec either the report full spec or the report storeID and stubbed spec
- var v_oData = {};
- if (v_nReport.getAttribute("stubbed") == "true")
- {
- v_oData.objectPath = 'storeID("' + v_sStoreID + '")';
- }
- v_oData.specification = v_sReportSpec;
- return v_oGlassContext.services.ajax.post("v1/metadata/reports/normalizedspec", {
- contentType: "application/json",
- processData: false,
- dataType: "json",
- data: JSON.stringify(v_oData)
- })
- .then(function(v_oReportModelInfo)
- {
- var v_oDBSpec = this.f_doConvert(v_nReport, v_aSelectionIids, v_oReportModelInfo.id);
- return Q.resolve(v_oDBSpec);
- }.bind(this))
- .fail(function(err)
- {
- return Q.reject(err);
- });
- };
- V5ToDashboard.f_doConvert = function (v_nReport, v_aSelectionIids, v_sReportTempStoreId)
- {
- console.log(v_nReport.outerHTML);
- console.log("Report selection: " + JSON.stringify(v_aSelectionIids));
- console.log("Report temp store ID: " + v_sReportTempStoreId);
- var v_oDBSpec = {};
- this.f_setName(v_oDBSpec);
- this.f_setVersion(v_oDBSpec);
- this.f_setLayout(v_oDBSpec);
- this.f_setPalette(v_oDBSpec);
- this.f_setDBDataSource(v_oDBSpec, v_sReportTempStoreId);
- var v_aValidSelectionIids = this.f_validateReportSelections(v_nReport, v_aSelectionIids);
- this.f_convertV5SelectionToDB(v_oDBSpec, v_nReport, v_aValidSelectionIids, v_sReportTempStoreId);
- console.log("RS->DB spec: " + JSON.stringify(v_oDBSpec));
- return v_oDBSpec;
- };
- V5ToDashboard.f_validateReportSelections = function (v_nReport, v_aSelectionIids)
- {
- var v_aValidSelectionIids = v_aSelectionIids;
- // Replace page body selection with its data containers
- if (v_aSelectionIids.length === 1)
- {
- var v_nSingleNodeSelection = v_bRunInProduction ? v_nReport.selectSingleNode(".//*[@iid='" + v_aSelectionIids[0] + "']") : v_nReport.querySelector("[iid=" + v_aSelectionIids[0] + "]");
- if (v_nSingleNodeSelection.nodeName === "pageBody" || v_nSingleNodeSelection.nodeName === "table")
- {
- v_aValidSelectionIids = [];
- var nlContents = v_bRunInProduction ? v_nSingleNodeSelection.selectNodes(".//contents") : v_nSingleNodeSelection.querySelectorAll("contents");
- for (var i = 0; i < nlContents.length; i++)
- {
- var v_nlChildNodes = nlContents.item(i).childNodes;
- for (var j = 0; j < v_nlChildNodes.length; j++)
- {
- var v_nChildNode = v_nlChildNodes.item(j);
- if (v_nChildNode.nodeType != V5ToDashboard.K_iNODE_ELEMENT || !this.f_isSupportedLayoutSelection(v_nChildNode.nodeName))
- {
- continue;
- }
- v_aValidSelectionIids.push(v_nChildNode.getAttribute("iid"));
- }
- }
- }
- }
- return v_aValidSelectionIids;
- };
- V5ToDashboard.f_isSupportedLayoutSelection = function (v_sName)
- {
- switch (v_sName)
- {
- case "list":
- case "crosstab":
- case "viz":
- case "vizControl":
- case "mapChart":
- return true;
- }
- return false;
- };
- V5ToDashboard.f_setName = function (v_oDBSpec)
- {
- v_oDBSpec.name = StringResource.get('new_exploration'); // This doesn't work with Intern
- // v_oDBSpec.name = 'New exploration'; // For Intern tests
- };
- V5ToDashboard.f_setVersion = function (v_oDBSpec)
- {
- v_oDBSpec.version = 1402;
- };
- V5ToDashboard.f_setPalette = function (v_oDBSpec)
- {
- // TODO: how do you get the palette?
- // v_oDBSpec.fredIsRed = {};
- // v_oDBSpec.fredIsRed.id = "model0000016176037fb1_00000001";
- // v_oDBSpec.fredIsRed.colorMap = "";
- // v_oDBSpec.fredIsRed.saveId = 1;
- };
- V5ToDashboard.f_setLayout = function (v_oDBSpec)
- {
- v_oDBSpec.layout = [];
- };
- V5ToDashboard.f_setDBDataSource = function (v_oDBSpec, v_sReportTempStoreId)
- {
- v_oDBSpec.dataSources = {};
- v_oDBSpec.dataSources.version = "1.0";
- v_oDBSpec.dataSources.sources = [];
-
- v_oDBSpec.dataSources.sources.push({
- id: v_sReportTempStoreId,
- assetId: v_sReportTempStoreId,
- type: "report",
- name: "",
- shaping: {
- embeddedModuleUpToDate: true
- }
- });
- };
- V5ToDashboard.f_convertV5SelectionToDB = function (v_oDBSpec, v_nReport, v_aSelectionIids, v_sReportTempStoreId)
- {
- // The V5 objects converted to DB widgets will be placed in a vertical column, one below the other,
- // and the offest is given by v_iHeightOffset
- var v_iHeightOffset = 0;
- v_oDBSpec.widgets = [];
- for (var i = 0; i < v_aSelectionIids.length; i++)
- {
- // a single selection may have multiple queries (to be converted to multiple data views) - e.g. Vida map with 3 layers has 3 queries
- var v_aQueries = [], v_aDataViews = [];
- var v_nSelection = v_bRunInProduction ? v_nReport.selectSingleNode(".//*[@iid='" + v_aSelectionIids[i] + "']") : v_nReport.querySelector("[iid=" + v_aSelectionIids[i] + "]");
- if (!v_nSelection)
- {
- continue;
- }
- v_aQueries = this.f_getQueriesForSelection(v_nReport, v_nSelection);
- for (var j = 0; j < v_aQueries.length; j++)
- {
- var v_oDataView = this.f_createEmptyWidgetDataViewForV5Query(v_sReportTempStoreId, j);
- if (!v_oDataView)
- {
- continue;
- }
- v_aDataViews.push(v_oDataView);
- }
- var v_iIndex = i + 1;
- var v_sWidgetId = "widget" + v_iIndex;
- if (v_bRunInProduction)
- {
- // add timestamp for unique widget id in case we launch in existing exploration
- v_sWidgetId += '-' + Date.now();
- }
- var v_oWidget = this.f_createWidget(v_sWidgetId);
- switch (v_nSelection.nodeName)
- {
- case "list":
- this.f_setListWidget(v_oWidget, v_nSelection, v_aQueries[0], v_aDataViews[0]);
- break;
- case "crosstab":
- this.f_setCrosstabWidget(v_oWidget, v_nSelection, v_aQueries[0], v_aDataViews[0]);
- break;
- case "vizControl":
- var v_nlReportDataStore = v_bRunInProduction ? v_nReport.selectNodes(".//reportDataStore") : v_nReport.querySelectorAll("reportDataStore");
- this.f_setVizControlWidget(v_oWidget, v_nSelection, v_aQueries, v_aDataViews, v_nlReportDataStore);
- break;
- default:
- // ignore selection
- continue;
- }
- v_oDBSpec.widgets.push(v_oWidget);
- var v_oWidthHeight = this.f_getV5ObjectWidthHeight(v_nSelection);
- this.f_addWidgetToLayout(v_oDBSpec, v_sWidgetId, v_oWidthHeight, v_iHeightOffset);
- v_iHeightOffset += parseInt(v_oWidthHeight.height);
- }
- };
- V5ToDashboard.f_getV5ObjectWidthHeight = function (v_nSelection)
- {
- var v_nCSS, v_sWidth, v_sHeight, i;
- var v_nlSelectionChildren = v_nSelection.childNodes;
- for (i = 0; i < v_nlSelectionChildren.length; i++)
- {
- var v_nSelectionChild = v_nlSelectionChildren.item(i);
- if (v_nSelectionChild.nodeName == 'style')
- {
- v_nCSS = v_bRunInProduction ? v_nSelectionChild.selectSingleNode(".//CSS") : v_nSelectionChild.querySelector('CSS');
- break;
- }
- }
- if (v_nCSS)
- {
- var v_aCSSValueAttr = v_nCSS.getAttribute('value').split(';');
- for (i = 0; i < v_aCSSValueAttr.length; i++)
- {
- var v_sAttr = v_aCSSValueAttr[i];
- if (v_sAttr.indexOf('width:', 0) != -1)
- {
- v_sWidth = v_sAttr.substring(v_sAttr.indexOf(':') + 1);
- }
- else if (v_sAttr.indexOf('height:', 0) != -1)
- {
- v_sHeight = v_sAttr.substring(v_sAttr.indexOf(':') + 1);
- }
- }
- }
- v_sWidth = (v_sWidth ? v_sWidth : "500px");
- v_sHeight = (v_sHeight ? v_sHeight : "500px");
- return {width: v_sWidth, height: v_sHeight};
- };
- V5ToDashboard.f_addWidgetToLayout = function (v_oDBSpec, v_sWidgetId, v_oWidthHeight, v_iHeightOffset)
- {
- v_oDBSpec.layout.push({
- id: v_sWidgetId,
- style: {
- left: '0px',
- top: v_iHeightOffset + 'px',
- height: v_oWidthHeight.height,
- width: v_oWidthHeight.width
- },
- type: "widget"
- });
- };
- V5ToDashboard.f_createWidget = function (v_sWidgetId)
- {
- return {
- type : "live",
- id : v_sWidgetId,
- visId : "",
- name : v_sWidgetId,
- data : {
- dataViews : []
- },
- visTypeLocked : true,
- slotmapping : {
- slots : []
- },
- localFilters : [],
- properties : []
- };
- };
- V5ToDashboard.f_createEmptyWidgetDataViewForV5Query = function (v_sReportTempStoreId, v_iQueryIndex)
- {
- var v_oDataView = {};
- v_oDataView.modelRef = v_sReportTempStoreId;
- v_oDataView.modelType = "report";
- v_oDataView.searchPath = "";
- v_oDataView.dataItems = [];
- v_oDataView.id = "dataView" + (v_iQueryIndex + 1);
- return v_oDataView;
- };
- V5ToDashboard.f_isDataItemUsedInSelection = function (v_nDataItem, v_nSelection, v_sRefName)
- {
- if (v_nDataItem.nodeName == '#text')
- {
- return false;
- }
- return !!(v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@" + v_sRefName + "='" + v_nDataItem.getAttribute("name") + "']") :
- v_nSelection.querySelector("[" + v_sRefName + "='" + v_nDataItem.getAttribute("name") + "']"));
- };
- V5ToDashboard.f_getRefDataItemExpression = function (v_nDataItem)
- {
- switch (v_nDataItem.nodeName)
- {
- case 'dataItemMeasure':
- var v_nMUN = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//MUN") : v_nDataItem.querySelector("MUN");
- return (v_nMUN ? v_nMUN.childNodes[0].nodeValue : null);
- case 'dataItemLevelSet':
- case 'dataItemMemberSet':
- var v_nLUN = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//LUN") : v_nDataItem.querySelector("LUN");
- return (v_nLUN ? v_nLUN.childNodes[0].nodeValue : null);
- case 'dataItem':
- var v_nExpression = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//expression") : v_nDataItem.querySelector("expression");
- return (v_nExpression ? v_nExpression.childNodes[0].nodeValue : null);
- default:
- return null;
- }
- };
- V5ToDashboard.f_getQueriesForSelection = function (v_nReport, v_nSelection)
- {
- var v_sRefQueryName, v_aRefQueryNames = [], v_aQueries = [];
- switch (v_nSelection.nodeName)
- {
- case "list":
- case "crosstab":
- v_sRefQueryName = v_nSelection.getAttribute("refQuery");
- v_aRefQueryNames.push(v_sRefQueryName);
- break;
- case "viz":
- v_sRefQueryName = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizDataSet").getAttribute("refQuery") :
- v_nSelection.querySelector("vizDataSet").getAttribute("refQuery");
- v_aRefQueryNames.push(v_sRefQueryName);
- break;
- case "vizControl":
- var v_nlRefDataStore = v_bRunInProduction ? v_nSelection.selectNodes(".//vcDataSet") : v_nSelection.querySelectorAll("vcDataSet");
- for (var i = 0; i < v_nlRefDataStore.length; i++)
- {
- var v_sRefDataStore = v_nlRefDataStore.item(i).getAttribute("refDataStore");
- if (!v_sRefDataStore)
- {
- // empty layer
- continue;
- }
- var v_nReportDataStore = v_bRunInProduction ? v_nReport.selectSingleNode(".//reportDataStore[@name='" + v_sRefDataStore + "']"):
- v_nReport.querySelector("reportDataStore[name='" + v_sRefDataStore + "']");
- v_sRefQueryName = v_bRunInProduction ? v_nReportDataStore.selectSingleNode(".//dsV5ListQuery").getAttribute("refQuery") :
- v_nReportDataStore.querySelector("dsV5ListQuery").getAttribute("refQuery");
- v_aRefQueryNames.push(v_sRefQueryName);
- }
- break;
- case "mapChart":
- // TODO: Rave 2 map, not Vida
- break;
- }
- for (var j = 0; j < v_aRefQueryNames.length; j++)
- {
- var v_nQuery = v_bRunInProduction ? v_nReport.selectSingleNode("./queries/query[@name='" + v_aRefQueryNames[j] + "']") :
- v_nReport.querySelector("queries > query[name='" + v_aRefQueryNames[j] + "']");
- v_aQueries.push(v_nQuery);
- }
- return v_aQueries;
- };
- V5ToDashboard.f_convertV5DataItemSortToDB = function (v_nSelection, v_nDataItem, v_sDataItemName, v_sDataItemIndex)
- {
- // For old dataItem as used in non-dimensional the sort is specified in the layout: sortList/sortItem[@sortOrder="descending"]
- // For new/specialized data items as used in dimensional the sort is specified in the query data item: /setSorting[@ascending="false"]
- // First try to get the sort from layout and if not found try to get the sort from data item
- var v_aSelection = [];
- var v_nLayoutSortItem;
- var v_bIsDescending = null;
- switch (v_nSelection.nodeName)
- {
- case "list":
- v_nLayoutSortItem = v_bRunInProduction ? v_nSelection.selectSingleNode(".//sortList/sortItem[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("sortList > sortItem[refDataItem='" + v_sDataItemName + "']");
- break;
- case "crosstab":
- case "viz":
- case "vizControl":
- case "mapChart":
- v_nLayoutSortItem = v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDataItem='" + v_sDataItemName + "']//sortList/sortItem") :
- v_nSelection.querySelector("* > [refDataItem='" + v_sDataItemName + "'] > sortList > sortItem");
- break;
- }
- if (v_nLayoutSortItem)
- {
- v_bIsDescending = (v_nLayoutSortItem.getAttribute("sortOrder") == "descending");
- }
- else
- {
- // try to get the sort from query
- var v_nSetSorting = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//setSorting") : v_nDataItem.querySelector("setSorting");
- if (v_nSetSorting)
- {
- v_bIsDescending = (v_nSetSorting.getAttribute("ascending") == "false");
- }
- }
- if (v_bIsDescending != null)
- {
- v_aSelection.push({
- "operation": "order",
- "sort": {
- "type": v_bIsDescending ? "desc" : "asc",
- "priority": v_sDataItemIndex,
- "by": "caption"
- }
- });
- }
- return v_aSelection;
- };
- V5ToDashboard.f_getXMLAttribute = function (v_nParent, v_sName)
- {
- if (!v_nParent || !v_sName)
- {
- return null;
- }
- var v_nXMLAttribute = v_bRunInProduction ? v_nParent.selectSingleNode(".//XMLAttributes/XMLAttribute[@name='" + v_sName + "']") :
- v_nParent.querySelector("XMLAttributes > XMLAttribute[name='" + v_sName + "']");
- var v_sXMLAttributeValue = v_nXMLAttribute ? v_nXMLAttribute.getAttribute("value") : null;
- return v_sXMLAttributeValue;
- };
- // From the usage attribute in metadata responses.
- V5ToDashboard.K_iDataUsage_Fact = 2;
- V5ToDashboard.K_sDataUsage_Fact = "fact";
- V5ToDashboard.f_getDataUsage = function (v_nDataItem)
- {
- return this.f_getXMLAttribute(v_nDataItem, "RS_dataUsage") || this.K_sDataUsage_Unknown;
- };
- V5ToDashboard.F_IsLikelyMeasure = function (v_nDataItem)
- {
- switch (v_nDataItem.nodeName)
- {
- case "dataItem":
- return (this.f_getDataUsage(v_nDataItem) == this.K_iDataUsage_Fact || this.f_getDataUsage(v_nDataItem) == this.K_sDataUsage_Fact);
- case "dataItemMeasure":
- case "dataItemCalculatedMeasure":
- case "dataItemMeasurePercentage":
- return true;
- }
- return false;
- };
- V5ToDashboard.F_IsLikelyCalculation = function (v_nDataItem)
- {
- switch (v_nDataItem.nodeName)
- {
- case "dataItemCalculatedMember":
- case "dataItemCalculatedMeasure":
- case "dataItemMeasurePercentage":
- return true;
- }
- return false;
- };
- V5ToDashboard.f_convertV5FormatToDB = function (v_nSelection, v_nDataItem, v_sDataItemName)
- {
- var v_oFormat = {};
- // DB only has measure format
- if (this.F_IsLikelyMeasure(v_nDataItem))
- {
- var v_nDataFormat;
- switch (v_nSelection.nodeName)
- {
- case "list":
- var v_nListColumnBody = this.f_getAncestorNode(
- v_bRunInProduction ? v_nSelection.selectSingleNode(".//listColumnBody//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("listColumnBody * [refDataItem='" + v_sDataItemName + "']"),
- "listColumnBody");
- v_nDataFormat = v_bRunInProduction ? v_nListColumnBody.selectSingleNode(".//style//dataFormat") : v_nListColumnBody.querySelector("style > dataFormat");
- break;
- case "crosstab":
- v_nDataFormat = v_bRunInProduction ? v_nSelection.selectSingleNode(".//crosstabFactCell//style//dataFormat") :
- v_nSelection.querySelector("crosstabFactCell > style > dataFormat");
- break;
- case "viz":
- // TODO
- break;
- case "vizControl":
- // TODO
- break;
- case "mapChart":
- // TODO
- break;
- }
- if (v_nDataFormat && v_nDataFormat.firstElementChild)
- {
- v_oFormat.formatSpec = {};
- this.f_convertV5DataFormatToDB(v_nDataFormat.firstElementChild, v_oFormat.formatSpec);
- }
- }
- return v_oFormat;
- };
- V5ToDashboard.f_getAncestorNode = function (v_nCurrentNode, v_sAncestorName)
- {
- // recursion exit conditions
- if (!v_nCurrentNode || !v_nCurrentNode.parentNode)
- {
- return null;
- }
- if (v_nCurrentNode.parentNode.nodeName == v_sAncestorName)
- {
- return v_nCurrentNode.parentNode;
- }
- return this.f_getAncestorNode(v_nCurrentNode.parentNode, v_sAncestorName);
- };
- V5ToDashboard.f_getDataItems = function (v_nQuery)
- {
- return v_bRunInProduction ? v_nQuery.selectNodes(".//selection/*") : v_nQuery.querySelector("selection").childNodes;
- };
- V5ToDashboard.f_getDataItem = function (v_nQuery, v_sDataItemName)
- {
- return v_bRunInProduction ? v_nQuery.selectSingleNode(".//*[@name='" + v_sDataItemName + "']") : v_nQuery.querySelector("* [name='" + v_sDataItemName + "']");
- };
- V5ToDashboard.f_escapeEndBracket = function (v_sName)
- {
- return v_sName.replace(/\]/g, ']]');
- };
- V5ToDashboard.f_addV5DataItemToDBDataView = function (v_nSelection, v_sQueryName, v_nDataItem, v_sRefName, v_oDataView, v_iIndex)
- {
- if (!this.f_isDataItemUsedInSelection(v_nDataItem, v_nSelection, v_sRefName))
- {
- return false;
- }
- var v_sDataItemName = v_nDataItem.getAttribute("name");
- var v_aSelection = this.f_convertV5DataItemSortToDB(v_nSelection, v_nDataItem, v_sDataItemName, v_iIndex);
- var v_oFormat = this.f_convertV5FormatToDB(v_nSelection, v_nDataItem, v_sDataItemName);
- var v_sV5DataItemAggregate = v_nDataItem.getAttribute("aggregate");
- var v_sDBDataItemAggregate = v_sV5DataItemAggregate ? this.f_convertAggregateOpToDB(v_sV5DataItemAggregate) : "";
- var v_sDataItemNameFull = '[' + this.f_escapeEndBracket(v_sQueryName) + '].[' + this.f_escapeEndBracket(v_sDataItemName) + ']';
- var v_oDataItem = {
- id: v_sDataItemNameFull,
- itemId: v_sDataItemNameFull,
- itemLabel: v_sDataItemName
- };
- if (v_aSelection && v_aSelection.length > 0)
- {
- v_oDataItem.selection = v_aSelection;
- }
- if (v_oFormat && v_oFormat.formatSpec)
- {
- v_oDataItem.format = v_oFormat;
- }
- if (v_sDBDataItemAggregate)
- {
- v_oDataItem.aggregate = v_sDBDataItemAggregate;
- }
- v_oDataView.dataItems.push(v_oDataItem);
- return true;
- };
- V5ToDashboard.f_setListWidget = function (v_oWidget, v_nSelection, v_nQuery, v_oDataView)
- {
- var v_oSlot = {};
- v_oSlot.name = "grid_cols";
- v_oSlot.dataItems = [];
- var v_sQueryName = v_nQuery.getAttribute("name");
- // v_oSlot.dataItemSettings = [];
- // v_oSlot.caption = "Columns";
- // v_oSlot.id = "grid_cols";
- var v_nlDataItemValue = v_bRunInProduction ? v_nSelection.selectNodes(".//listColumnBody//*[@refDataItem]") : v_nSelection.querySelectorAll("* listColumnBody * [refDataItem]");
- for (var i = 0; i < v_nlDataItemValue.length; i++)
- {
- if (v_nlDataItemValue.item(i).nodeName != 'dataItemValue')
- {
- continue;
- }
- var v_sRefDataItem = v_nlDataItemValue.item(i).getAttribute("refDataItem");
- var v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
- if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
- {
- continue;
- }
- v_oSlot.dataItems.push(v_sRefDataItem);
- }
-
- v_oWidget.data.dataViews.push(v_oDataView);
- v_oWidget.slotmapping.slots.push(v_oSlot);
- v_oWidget.visId = "JQGrid";
- };
- V5ToDashboard.f_convertV5DataFormatToDB = function (v_nV5Format, v_oDBFormat)
- {
- switch (v_nV5Format.nodeName)
- {
- case "currencyFormat":
- v_oDBFormat.type = "currency";
- var v_sCurrencyCode = v_nV5Format.getAttribute("currencyCode");
- if (v_sCurrencyCode)
- {
- v_oDBFormat.currencyCode = v_sCurrencyCode;
- v_oDBFormat.currencyDisplay = "symbol";
- }
- break;
- case "numberFormat":
- v_oDBFormat.type = "number";
- break;
- case "percentFormat":
- v_oDBFormat.type = "percent";
- break;
- }
- var v_sDecimalSize = v_nV5Format.getAttribute("decimalSize");
- if (v_sDecimalSize)
- {
- v_oDBFormat.maximumFractionDigits = v_oDBFormat.minimumFractionDigits = parseInt(v_sDecimalSize);
- }
- };
- // Note. We may have a combined filter that uses few data items, thus this method doesn't take a data item as input
- V5ToDashboard.f_addV5VidaFiltersToDBWidgetLocalFilters = function (v_nQuery, v_nSelection, v_aLocalFilters, v_nlReportDataStore)
- {
- for (var i = 0; i < v_nlReportDataStore.length; i++)
- {
- var v_nReportDataStore = v_nlReportDataStore.item(i);
- var v_nDsFilters = v_bRunInProduction ? v_nReportDataStore.selectNodes(".//dsFilters/dsFilter") : v_nReportDataStore.querySelectorAll("* > dsFilters > dsFilter");
- for (var j = 0; j < v_nDsFilters.length; j++)
- {
- var v_nDsFilter = v_nDsFilters.item(j);
-
- // dsFilter can have 1 filterExpression (TODO: we ignore for now) or 1 dsFilterDefinition (which we convert to DB)
- // dsFilterDefinition defines 1 filter that we call filterRoot (which may contain other filters)
- var v_nFilterRoot;
- var v_nlFilterDefinition = v_bRunInProduction ? v_nDsFilter.selectNodes(".//dsFilterDefinition") : v_nDsFilter.querySelector("dsFilterDefinition");
- if (!v_nlFilterDefinition)
- {
- continue;
- }
- var v_nlFilterDefChildren = v_bRunInProduction ? v_nDsFilter.selectNodes(".//dsFilterDefinition/*") : v_nDsFilter.querySelector("dsFilterDefinition").childNodes;
- for (var k = 0; k < v_nlFilterDefChildren.length; k++)
- {
- if (v_nlFilterDefChildren.item(k).nodeType == V5ToDashboard.K_iNODE_ELEMENT)
- {
- v_nFilterRoot = v_nlFilterDefChildren.item(k);
- break;
- }
- }
- if (!v_nFilterRoot)
- {
- continue;
- }
-
- var v_oDBFilter = {};
- v_oDBFilter.id = "Filter" + (i + 1);
- v_oDBFilter.values = [];
-
- // TODO: Is this needed? Doesn't seem to work in DB
- // v_oDBFilter.preOrPost = (v_nDsFilter.getAttribute("postAutoAggregation") == "post" ? "true" : "false");
-
- this.f_convertV5DetailFilterToDBFilter(v_nFilterRoot, v_oDBFilter, v_nQuery, v_nSelection);
- if (!this.f_filterIsInvalid(v_oDBFilter))
- {
- v_aLocalFilters.push(v_oDBFilter);
- }
- }
- }
- };
- V5ToDashboard.f_filterIsInvalid = function (v_oDBFilter)
- {
- // Note. v_oDBFilter.values is always an array, but only for combined filters is an array of filters
- for (var i = 0; i < v_oDBFilter.values.length; i++)
- {
- if (!v_oDBFilter.values[i].id)
- {
- // the value is not a filter - this is a basic filter element
- return false;
- }
- if (this.f_filterIsInvalid(v_oDBFilter.values[i]))
- {
- return true;
- }
- }
- return false;
- };
- V5ToDashboard.f_convertV5CombineFilterOperatorToDB = function (v_sV5CombineFilterOperator)
- {
- switch (v_sV5CombineFilterOperator)
- {
- case "filterAnd":
- return "and";
- case "filterOr":
- return "or";
- case "filterNot":
- return "not";
- default:
- alert("V5 filter not supported: " + v_sV5CombineFilterOperator);
- return null;
- }
- };
- V5ToDashboard.f_convertV5DetailFilterToDBFilter = function (v_nFilter, v_oDBFilter, v_nQuery, v_nSelection)
- {
- switch (v_nFilter.nodeName)
- {
- case "filterAnd":
- case "filterOr":
- case "filterNot":
- var v_nlFilterChildren = v_nFilter.childNodes;
- for (var i = 0; i < v_nlFilterChildren.length; i++)
- {
- if (v_nlFilterChildren.item(i).nodeType != V5ToDashboard.K_iNODE_ELEMENT)
- {
- continue;
- }
- var v_nFilterChild = v_nlFilterChildren.item(i);
- var v_oDBFilterChild = {};
- v_oDBFilterChild.id = v_oDBFilter.id + '_' + (i + 1);
- v_oDBFilterChild.values = [];
- v_oDBFilter.values.push(v_oDBFilterChild);
- // recursion to get children filters
- this.f_convertV5DetailFilterToDBFilter(v_nFilterChild, v_oDBFilterChild, v_nQuery, v_nSelection);
- }
- v_oDBFilter.operator = this.f_convertV5CombineFilterOperatorToDB(v_nFilter.nodeName);
- break;
- case "#text":
- break;
- default:
- this.f_convertV5VidaFilterElementToDB(v_nFilter, v_oDBFilter, v_nQuery);
- break;
- }
- };
- V5ToDashboard.f_convertV5VidaFilterElementToDB = function (v_nFilter, v_oDBFilter, v_nQuery)
- {
- var v_sRefDataItem = v_nFilter.getAttribute("refDsColumn");
- var v_sQueryName = v_nQuery.getAttribute("name");
- v_oDBFilter.id = v_oDBFilter.columnId = '[' + this.f_escapeEndBracket(v_sQueryName) + '].[' + this.f_escapeEndBracket(v_sRefDataItem) + ']';
- var v_nFilterValue, i;
- switch (v_nFilter.nodeName)
- {
- case "dsFilterIn":
- var v_nlFilterValues = v_bRunInProduction ? v_nFilter.selectNodes(".//dsFilterInValues/dsFilterInValue") : v_nFilter.querySelectorAll("dsFilterInValues > dsFilterInValue");
- for (i = 0; i < v_nlFilterValues.length; i++)
- {
- v_nFilterValue = v_nlFilterValues.item(i);
- if (!v_nFilterValue)
- {
- continue;
- }
- var v_sFilterValue = v_nFilterValue.childNodes[0].nodeValue;
- v_oDBFilter.values.push({
- "d": v_sFilterValue,
- "u": v_sFilterValue
- });
- }
- v_oDBFilter.operator = (v_nFilter.getAttribute("not") === "true" ? "notin" : "in");
- break;
- case "dsFilterCompare":
- v_nFilterValue = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterCompareValue") : v_nFilter.querySelector("dsFilterCompareValue");
- if (!v_nFilterValue)
- {
- break;
- }
- var v_FilterValue = Number(v_nFilterValue.childNodes[0].nodeValue);
- v_oDBFilter.values.push({
- "d": v_FilterValue,
- "u": v_FilterValue
- });
- v_oDBFilter.operator = this.f_convertCompareOperatorToDB(v_nFilter);
- break;
- case "dsFilterRange":
- var v_nFilterFrom = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterFromValue") : v_nFilter.querySelector("dsFilterFromValue");
- var v_nFilterTo = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterToValue") : v_nFilter.querySelector("dsFilterToValue");
- if (!v_nFilterFrom && !v_nFilterTo || v_nFilterFrom.childNodes.length == 0 && v_nFilterTo.childNodes.length == 0)
- {
- break;
- }
- var v_FilterFrom, v_FilterTo;
- if (v_nFilterFrom.childNodes.length > 0 && v_nFilterTo.childNodes.length > 0)
- {
- v_FilterFrom = Number(v_nFilterFrom.childNodes[0].nodeValue);
- v_FilterTo = Number(v_nFilterTo.childNodes[0].nodeValue);
- v_oDBFilter.values.push({
- "d": v_FilterFrom,
- "u": v_FilterFrom
- }, {
- "d": v_FilterTo,
- "u": v_FilterTo
- });
- v_oDBFilter.operator = (v_nFilter.getAttribute("not") === "true" ? "notbetween" : "between");
- break;
- }
- if (v_nFilterFrom.childNodes.length > 0 && v_nFilterTo.childNodes.length == 0)
- {
- v_FilterFrom = Number(v_nFilterFrom.childNodes[0].nodeValue);
- v_oDBFilter.values.push({
- "d": v_FilterFrom,
- "u": v_FilterFrom
- });
- v_oDBFilter.operator = "gt";
- break;
- }
- if (v_nFilterFrom.childNodes.length == 0 && v_nFilterTo.childNodes.length > 0)
- {
- v_FilterTo = Number(v_nFilterTo.childNodes[0].nodeValue);
- v_oDBFilter.values.push({
- "d": v_FilterTo,
- "u": v_FilterTo
- });
- v_oDBFilter.operator = "lt";
- break;
- }
- break;
- }
- };
- V5ToDashboard.f_convertCompareOperatorToDB = function (v_nFilterCompare)
- {
- var v_bIsNot = v_nFilterCompare.getAttribute("not") === "true";
- switch (v_nFilterCompare.getAttribute("operator"))
- {
- case "greaterThan":
- case "greaterThanEqual":
- return v_bIsNot ? "lt" : "gt";
- case "lessThan":
- case "lessThanEqual":
- return v_bIsNot ? "gt" : "lt";
- case "equal":
- return "eq";
- }
- return "eq";
- };
- V5ToDashboard.f_setCrosstabWidget = function (v_oWidget, v_nSelection, v_nQuery, v_oDataView)
- {
- var v_sQueryName = v_nQuery.getAttribute("name");
- v_oWidget.slotmapping.slots = [
- {
- "name": "row_level1",
- "dataItems": [],
- "caption": "Rows",
- "id": "row_level1"
- },
- {
- "name": "column_level1",
- "dataItems": [],
- "caption": "Columns",
- "id": "column_level1"
- },
- {
- "name": "values",
- "dataItems": [],
- "caption": "Values",
- "id": "values"
- }
- ];
- var v_sRefDataItem, v_nDataItem, i;
- var v_nlRowsCrosstabNodeMember = v_bRunInProduction ? v_nSelection.selectNodes(".//crosstabRows//crosstabNodeMember") :
- v_nSelection.querySelectorAll("crosstabRows * crosstabNodeMember");
- for (i = v_nlRowsCrosstabNodeMember.length - 1; i >= 0; i--)
- {
- // to preserve the nesting order must loop descending
- v_sRefDataItem = v_nlRowsCrosstabNodeMember.item(i).getAttribute("refDataItem");
- v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
- if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
- {
- continue;
- }
- // slot 0 is for rows
- v_oWidget.slotmapping.slots[0].dataItems.push(v_sRefDataItem);
- }
- var v_nlColsCrosstabNodeMember = v_bRunInProduction ? v_nSelection.selectNodes(".//crosstabColumns//crosstabNodeMember") :
- v_nSelection.querySelectorAll("crosstabColumns * crosstabNodeMember");
- for (i = v_nlColsCrosstabNodeMember.length - 1; i >= 0; i--)
- {
- // to preserve the nesting order must loop descending
- v_sRefDataItem = v_nlColsCrosstabNodeMember.item(i).getAttribute("refDataItem");
- v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
- if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
- {
- continue;
- }
- var v_iSlotIndex = 1;
- if (this.F_IsLikelyMeasure(v_nDataItem))
- {
- v_iSlotIndex = 2;
- }
- v_oWidget.slotmapping.slots[v_iSlotIndex].dataItems.push(v_sRefDataItem);
- }
-
- var v_nCrosstabCornerDataItemLabel = v_bRunInProduction ? v_nSelection.selectSingleNode(".//crosstabCorner//*[@refDataItem]") : v_nSelection.querySelector("crosstabCorner * [refDataItem]");
- if (v_nCrosstabCornerDataItemLabel)
- {
- v_sRefDataItem = v_nCrosstabCornerDataItemLabel.getAttribute("refDataItem");
- v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
- this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, 0);
- v_oWidget.slotmapping.slots[2].dataItems.push(v_sRefDataItem);
- }
- v_oWidget.data.dataViews.push(v_oDataView);
- v_oWidget.visId = "crosstab";
- };
- V5ToDashboard.f_convertAggregateOpToDB = function (v_sV5AggregateOp)
- {
- switch (v_sV5AggregateOp)
- {
- case "average":
- return "avg";
- case "summarize":
- return "sum";
- case "minimum":
- return "min";
- case "maximum":
- return "max";
- case "count":
- return "count";
- case "countDistinct":
- return "countdistinct";
- default:
- return null;
- }
- };
- V5ToDashboard.f_setVizControlWidget = function (v_oWidget, v_nSelection, v_aQueries, v_aDataViews, v_nlReportDataStore)
- {
- v_oWidget.visId = this.f_convertV5VidaTypeToDB(v_nSelection);
- this.f_addVizControlPropertiesToWidget(v_oWidget, v_nSelection);
- var v_aLayers = [];
- if (v_oWidget.visId == "com.ibm.vis.rave2bundletiledmap")
- {
- v_oWidget.slotmapping.layers = [];
- }
- for (var i = 0; i < v_aQueries.length; i++)
- {
- var v_nQuery = v_aQueries[i];
- var v_sQueryName = v_nQuery.getAttribute("name");
- var v_oDataView = v_aDataViews[i];
- var v_nlDataItems = this.f_getDataItems(v_nQuery);
- for (var j = 0; j < v_nlDataItems.length; j++)
- {
- var v_nDataItem = v_nlDataItems.item(j);
- if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDsColumn", v_oDataView, j))
- {
- continue;
- }
- var v_oSlot = this.f_createVizControlSlot(v_nSelection, v_nDataItem, v_oWidget.visId);
- v_oWidget.slotmapping.slots.push(v_oSlot);
- if (v_oWidget.visId == "com.ibm.vis.rave2bundletiledmap" && v_aLayers.indexOf(v_oSlot.layerId) == -1)
- {
- v_aLayers.push(v_oSlot.layerId);
- v_oWidget.slotmapping.layers.push(
- {
- type: v_oSlot.layerId,
- id: v_oSlot.layerId,
- dataViewId: v_oDataView.id
- });
- }
- }
- this.f_addV5VidaFiltersToDBWidgetLocalFilters(v_nQuery, v_nSelection, v_oWidget.localFilters, v_nlReportDataStore);
- v_oWidget.data.dataViews.push(v_oDataView);
- }
- };
- V5ToDashboard.f_convertV5VidaTypeToDB = function (v_nSelection)
- {
- var v_sType = v_nSelection.getAttribute('type');
- switch (v_sType)
- {
- case "com.ibm.vis.clusteredColumn":
- return "com.ibm.vis.rave2bundlecolumn";
- case "com.ibm.vis.clusteredBar":
- return "com.ibm.vis.rave2bundlebar";
- case "com.ibm.vis.stackedColumn":
- return "com.ibm.vis.rave2bundlestackedcolumn";
- case "com.ibm.vis.stackedBar":
- return "com.ibm.vis.rave2bundlestackedbar";
- case "com.ibm.vis.area":
- return "com.ibm.vis.rave2bundlearea";
- case "com.ibm.vis.treemap":
- return "com.ibm.vis.rave2bundletreemap";
- case "com.ibm.vis.bubble":
- return "com.ibm.vis.ravebubble";
- case "com.ibm.vis.bullet":
- return "com.ibm.vis.rave2bundlebullet";
- case "com.ibm.vis.point":
- return "com.ibm.vis.rave2point";
- case "com.ibm.vis.packedBubble":
- return "com.ibm.vis.rave2bundlepackedbubble";
- case "com.ibm.vis.hierarchicalPackedBubble":
- return "com.ibm.vis.rave2bundlehierarchicalpackedbubble";
- case "com.ibm.vis.marimekko":
- return "com.ibm.vis.rave2marimekko";
- case "com.ibm.vis.heatmap":
- return "com.ibm.vis.rave2heat";
- case "com.ibm.vis.line":
- return "com.ibm.vis.rave2line";
- case "com.ibm.vis.simpleCombination":
- return "com.ibm.vis.rave2bundlecomposite";
- case "com.ibm.vis.pie":
- return "com.ibm.vis.rave2bundlepie";
- case "com.ibm.vis.dial":
- return "com.ibm.vis.rave2bundleradialbar";
- case "com.ibm.vis.radar":
- return "com.ibm.vis.rave2bundleradar";
- case "com.ibm.vis.scatter":
- return "com.ibm.vis.ravescatter";
- case "com.ibm.vis.wordcloud":
- return "com.ibm.vis.rave2bundlewordcloud";
- case "com.ibm.vis.boxplot":
- return "com.ibm.vis.rave2bundleboxplot";
- case "com.ibm.vis.smoothArea":
- return "com.ibm.vis.rave2bundlesmootharea";
- case "com.ibm.vis.waterfall":
- return "com.ibm.vis.rave2bundlewaterfall";
- case "com.ibm.vis.tiledmap":
- return "com.ibm.vis.rave2bundletiledmap";
- default:
- return v_sType;
- }
- };
- V5ToDashboard.f_addVizPropertiesToWidget = function (v_oWidget, v_nSelection)
- {
- var v_nlVizPropertyValues = v_bRunInProduction ? v_nSelection.selectNodes(".//vizPropertyValues/*") : v_nSelection.querySelectorAll("vizPropertyValues > *");
- for (var i = 0; i < v_nlVizPropertyValues.length; i++)
- {
- var v_nVizProperty = v_nlVizPropertyValues.item(i);
- if (!v_nVizProperty)
- {
- continue;
- }
- switch (v_nVizProperty.getAttribute('name'))
- {
- case "color.palette":
- this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "colorPalette");
- break;
- case "legend.position":
- this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "widget.legend.position");
- break;
- case "legend.display":
- this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "widget.legend.display");
- break;
- default:
- break;
- }
- }
- };
- V5ToDashboard.f_addVizControlPropertiesToWidget = function (v_oWidget, v_nSelection, v_sWidgetId)
- {
- var v_nlVizPropertyValues = v_bRunInProduction ? v_nSelection.selectNodes(".//vizPropertyValues/*") : v_nSelection.querySelectorAll("vizPropertyValues > *");
- for (var i = 0; i < v_nlVizPropertyValues.length; i++)
- {
- var v_nVizProperty = v_nlVizPropertyValues.item(i);
- if (!v_nVizProperty)
- {
- continue;
- }
- var v_sDBVizPropertyName = v_nVizProperty.getAttribute('name');
- if (!v_sDBVizPropertyName)
- {
- return;
- }
- v_sDBVizPropertyName = v_sDBVizPropertyName.substring(v_sDBVizPropertyName.indexOf('_') + 1);
- this.f_setDBVizProperty(v_oWidget, v_nVizProperty, v_sDBVizPropertyName);
- }
- };
- V5ToDashboard.f_setDBVizProperty = function (v_oWidget, v_nVizProperty, v_sDBVizPropertyName)
- {
- if (!v_nVizProperty || !v_nVizProperty.childNodes || !v_nVizProperty.childNodes[0])
- {
- return;
- }
- var v_sValue = v_nVizProperty.childNodes[0].nodeValue;
- if (!v_sValue)
- {
- return;
- }
- switch (v_sDBVizPropertyName)
- {
- case "color_cat":
- v_oWidget.properties.push({
- "id": "colorPalette",
- "value": v_sValue
- });
- break;
- default:
- v_oWidget.properties.push({
- "id": v_sDBVizPropertyName,
- "value": v_sValue
- });
- break;
- }
- };
- V5ToDashboard.f_setDBVizType = function (v_oWidget, v_sVizType)
- {
- switch (v_sVizType)
- {
- case "rave-library-column,clusteredcolumn":
- v_oWidget.visId = "com.ibm.vis.rave2bundlecolumn";
- break;
- case "rave-library-column,clusteredbar":
- v_oWidget = "com.ibm.vis.rave2bundlebar";
- break;
- case "rave-library-column,stackedcolumn":
- v_oWidget.visId = "com.ibm.vis.rave2bundlestackedcolumn";
- break;
- case "rave-library-column,stackedbar":
- v_oWidget.visId = "com.ibm.vis.rave2bundlestackedbar";
- break;
- case "rave-library-area,area":
- v_oWidget.visId = "com.ibm.vis.rave2bundlearea";
- break;
- case "rave-library-line,line":
- v_oWidget.visId = "com.ibm.vis.rave2line";
- break;
- case "rave-library-bubble,point":
- v_oWidget.visId = "com.ibm.vis.rave2point";
- break;
- case "rave-library-bubble,scatter":
- v_oWidget.visId = "com.ibm.vis.ravescatter";
- break;
- case "rave-library-dial,dial":
- v_oWidget.visId = "com.ibm.vis.rave2bundleradialbar";
- break;
- case "rave-library-bubble,packedBubble":
- v_oWidget.visId = "com.ibm.vis.rave2bundlepackedbubble";
- break;
- case "rave-library-wordcloud,wordcloud":
- v_oWidget.visId = "com.ibm.vis.rave2bundlewordcloud";
- break;
- case "rave-library-pie,pie":
- v_oWidget.visId = "com.ibm.vis.rave2bundlepie";
- break;
- case "rave-library-heatmap,heatmap":
- v_oWidget.visId = "com.ibm.vis.rave2heat";
- break;
- case "rave-library-bubble,bubble":
- v_oWidget.visId = "com.ibm.vis.ravebubble";
- break;
- case "rave-library-composite,compositeOneDataSet":
- v_oWidget.visId = "com.ibm.vis.rave2bundlecomposite";
- break;
- }
- };
- V5ToDashboard.f_createVizSlot = function (v_nSelection, v_sVizType, v_nDataItem)
- {
- if (v_nSelection.nodeName !== 'viz')
- {
- return null;
- }
- var v_sDataItemName = v_nDataItem.getAttribute("name");
- var v_oSlot = {};
- v_oSlot.dataItems = [];
- v_oSlot.dataItems.push(v_sDataItemName);
- var v_bIsMeasure = this.F_IsLikelyMeasure(v_nDataItem);
- var v_nVizValue;
- switch (v_sVizType)
- {
- case "rave-library-column,clusteredcolumn":
- case "rave-library-column,clusteredbar":
- case "rave-library-column,stackedcolumn":
- case "rave-library-column,stackedbar":
- case "rave-library-area,area":
- case "rave-library-line,line":
- case "rave-library-bubble,point":
- if (v_bIsMeasure)
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
- } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='xEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizCategoryEdge[refEdge='xEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- } else
- {
- switch (v_sVizType)
- {
- case "rave-library-area,area":
- case "rave-library-line,line":
- case "rave-library-bubble,point":
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "series";
- break;
- default:
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- break;
- }
- }
- v_oSlot.dataItems = [];
- v_oSlot.dataItems.push(v_sDataItemName);
- break;
- case "rave-library-bubble,scatter":
- if (v_bIsMeasure)
- {
- v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_nVizValue.getAttribute('idField');
- } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- }
- break;
- case "rave-library-dial,dial":
- if (v_bIsMeasure)
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
- } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- }
- break;
- case "rave-library-bubble,packedBubble":
- case "rave-library-wordcloud,wordcloud":
- if (v_bIsMeasure)
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "size";
- } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- }
- break;
- case "rave-library-pie,pie":
- if (v_bIsMeasure)
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- }
- break;
- case "rave-library-heatmap,heatmap":
- if (v_bIsMeasure)
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='xEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizCategoryEdge[refEdge='xEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "series";
- }
- break;
- case "rave-library-bubble,bubble":
- if (v_bIsMeasure)
- {
- v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_nVizValue.getAttribute('idField');
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
- }
- break;
- case "rave-library-composite,compositeOneDataSet":
- if (v_bIsMeasure)
- {
- v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
- v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = (v_nVizValue.getAttribute('idField') == 'yLine' ? 'lineValue' : 'columnValue');
- } else
- {
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
- }
- break;
- default:
- return null;
- }
- return v_oSlot;
- };
- V5ToDashboard.f_createVizControlSlot = function (v_nSelection, v_nDataItem, v_sVisId)
- {
- var v_sDataItemName = v_nDataItem.getAttribute("name");
- var v_oSlot = {};
- v_oSlot.dataItems = [];
- v_oSlot.dataItems.push(v_sDataItemName);
-
- // TODO: support multiple data stores
- var v_nVcSlotData = this.f_getAncestorNode(
- v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDsColumn='" + v_sDataItemName + "']") : v_nSelection.querySelector("[refDsColumn='" + v_sDataItemName + "']"),
- "vcSlotData");
-
- if (v_sVisId == "com.ibm.vis.rave2bundletiledmap")
- {
- var v_nVcSlotDataSet = this.f_getAncestorNode(
- v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDsColumn='" + v_sDataItemName + "']") : v_nSelection.querySelector("[refDsColumn='" + v_sDataItemName + "']"),
- "vcDataSet");
- v_oSlot.layerId = v_nVcSlotDataSet.getAttribute("idDataSet");
- }
- var v_sRefDataStore = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vcDataSet").getAttribute("refDataStore") :
- v_nSelection.querySelector("vcDataSet").getAttribute("refDataStore");
- var v_sIdSlot = v_nVcSlotData.getAttribute("idSlot");
- v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_sIdSlot;
- return v_oSlot;
- };
- return V5ToDashboard;
- });
|