V5ToDashboard.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. /*
  2. IBM Confidential
  3. OCO Source Materials
  4. IBM Cognos Products: rs
  5. (C) Copyright IBM Corp. 2018, 2020
  6. 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.
  7. */
  8. define(['q', 'bi/authoring/nls/StringResource'], function (Q, StringResource)
  9. // define(['q'], function (Q) // For Intern tests
  10. {
  11. var V5ToDashboard = {};
  12. V5ToDashboard.K_iNODE_ELEMENT = 1;
  13. var v_bRunInProduction = false; // Intern is using querySelector and Launch in Explore is using Xpath (selectSingleNode)
  14. V5ToDashboard.LaunchInExploration = function (v_nReport, v_oAuthoringApp, v_aSelectionIids, v_sReportSpec, v_sExploreStoreID, v_oGlassContext)
  15. {
  16. var v_oDBSpec;
  17. v_bRunInProduction = true;
  18. var v_sStoreID = v_oAuthoringApp.SharedState.Get("storeID");
  19. var v_sExistingExploreSpec = null;
  20. return this.f_getExploreSpec(v_sExploreStoreID, v_oGlassContext)
  21. .then(function(v_oExploreData)
  22. {
  23. if (v_oExploreData && v_oExploreData.data[0] && v_oExploreData.data[0].specification)
  24. {
  25. v_sExistingExploreSpec = v_oExploreData.data[0].specification;
  26. }
  27. return this.ConvertV5toDBFrag(v_nReport, v_sStoreID, v_aSelectionIids, v_sReportSpec, v_oGlassContext);
  28. }.bind(this))
  29. .then(function(v_oDBFragSpec)
  30. {
  31. v_oDBSpec = v_oDBFragSpec;
  32. return v_oGlassContext.getSvc('.ConversionService');
  33. })
  34. .then(function(conversionSvc)
  35. {
  36. return conversionSvc.convert('DASHBOARD', 'EXPLORE', JSON.stringify(v_oDBSpec));
  37. })
  38. .then(function(v_sExploreSpec)
  39. {
  40. console.log("RS->DB->EX spec: " + v_sExploreSpec);
  41. var v_oEXSpec = JSON.parse(v_sExploreSpec);
  42. if (v_sExistingExploreSpec)
  43. {
  44. v_oEXSpec = this.f_mergeNewExplorationIntoExisting(v_oEXSpec, JSON.parse(v_sExistingExploreSpec));
  45. console.log("Merged exploration spec: " + JSON.stringify(v_oEXSpec));
  46. }
  47. var perspectiveOptions =
  48. {
  49. content : {
  50. // addOnSpec : v_oEXSpec,
  51. boardSpec : v_oEXSpec,
  52. // boardSpec : {
  53. // layout: {
  54. // items: [],
  55. // type: 'exploreContainer'
  56. // },
  57. // name: 'New Exploration',
  58. // version: 1008,
  59. // widgets: {},
  60. // _meta: {
  61. // bundleID: null
  62. // }
  63. // },
  64. isAuthoringMode : true,
  65. openAppViewCallback: function() {}
  66. },
  67. id: "Explore_" + Date.now()
  68. };
  69. return v_oGlassContext.openAppView("explore", perspectiveOptions);
  70. }.bind(this))
  71. .then(function(view)
  72. {
  73. if (view)
  74. {
  75. if (v_nReport.selectSingleNode("./layouts//dataSource/reportExpression"))
  76. {
  77. v_oGlassContext.showToast(v_oAuthoringApp.GetString("IDS_MSG_UNSUPPORTED_LAYOUT_CALC_IN_EXPLORE"), {'type':'warning'});
  78. }
  79. return view.currentContentView.openDatasetpane(false);
  80. }
  81. });
  82. };
  83. V5ToDashboard.f_getExploreSpec = function(v_sExploreStoreID, v_oGlassContext)
  84. {
  85. if (!v_sExploreStoreID)
  86. {
  87. return Q.resolve(null);
  88. }
  89. return v_oGlassContext.services.ajax.ajax(
  90. {
  91. url: "v1/objects/" + v_sExploreStoreID + "?fields=specification",
  92. type: 'GET'
  93. });
  94. };
  95. V5ToDashboard.f_mergeNewExplorationIntoExisting = function(v_oNewExploreSpec, v_oExistingExploreSpec)
  96. {
  97. // add the new widgets to existing ones
  98. var v_aNewWidgetsKeys = Object.keys(v_oNewExploreSpec.widgets);
  99. for (var i = 0; i < v_aNewWidgetsKeys.length; i++)
  100. {
  101. v_oExistingExploreSpec.widgets[v_aNewWidgetsKeys[i]] = (v_oNewExploreSpec.widgets[v_aNewWidgetsKeys[i]]);
  102. }
  103. // add the new data sources to existing ones
  104. for (i = 0; i < v_oNewExploreSpec.dataSources.sources.length; i++)
  105. {
  106. v_oExistingExploreSpec.dataSources.sources.push(v_oNewExploreSpec.dataSources.sources[i]);
  107. }
  108. // add the new layout item(s) to existing ones
  109. for (i = 0; i < v_oNewExploreSpec.layout.items.length; i++)
  110. {
  111. v_oExistingExploreSpec.layout.items.push(v_oNewExploreSpec.layout.items[i]);
  112. }
  113. return v_oExistingExploreSpec;
  114. };
  115. V5ToDashboard.ConvertV5toDBFrag = function (v_nReport, v_sStoreID, v_aSelectionIids, v_sReportSpec, v_oGlassContext)
  116. {
  117. // pass to Moser's normalizedspec either the report full spec or the report storeID and stubbed spec
  118. var v_oData = {};
  119. if (v_nReport.getAttribute("stubbed") == "true")
  120. {
  121. v_oData.objectPath = 'storeID("' + v_sStoreID + '")';
  122. }
  123. v_oData.specification = v_sReportSpec;
  124. return v_oGlassContext.services.ajax.post("v1/metadata/reports/normalizedspec", {
  125. contentType: "application/json",
  126. processData: false,
  127. dataType: "json",
  128. data: JSON.stringify(v_oData)
  129. })
  130. .then(function(v_oReportModelInfo)
  131. {
  132. var v_oDBSpec = this.f_doConvert(v_nReport, v_aSelectionIids, v_oReportModelInfo.id);
  133. return Q.resolve(v_oDBSpec);
  134. }.bind(this))
  135. .fail(function(err)
  136. {
  137. return Q.reject(err);
  138. });
  139. };
  140. V5ToDashboard.f_doConvert = function (v_nReport, v_aSelectionIids, v_sReportTempStoreId)
  141. {
  142. console.log(v_nReport.outerHTML);
  143. console.log("Report selection: " + JSON.stringify(v_aSelectionIids));
  144. console.log("Report temp store ID: " + v_sReportTempStoreId);
  145. var v_oDBSpec = {};
  146. this.f_setName(v_oDBSpec);
  147. this.f_setVersion(v_oDBSpec);
  148. this.f_setLayout(v_oDBSpec);
  149. this.f_setPalette(v_oDBSpec);
  150. this.f_setDBDataSource(v_oDBSpec, v_sReportTempStoreId);
  151. var v_aValidSelectionIids = this.f_validateReportSelections(v_nReport, v_aSelectionIids);
  152. this.f_convertV5SelectionToDB(v_oDBSpec, v_nReport, v_aValidSelectionIids, v_sReportTempStoreId);
  153. console.log("RS->DB spec: " + JSON.stringify(v_oDBSpec));
  154. return v_oDBSpec;
  155. };
  156. V5ToDashboard.f_validateReportSelections = function (v_nReport, v_aSelectionIids)
  157. {
  158. var v_aValidSelectionIids = v_aSelectionIids;
  159. // Replace page body selection with its data containers
  160. if (v_aSelectionIids.length === 1)
  161. {
  162. var v_nSingleNodeSelection = v_bRunInProduction ? v_nReport.selectSingleNode(".//*[@iid='" + v_aSelectionIids[0] + "']") : v_nReport.querySelector("[iid=" + v_aSelectionIids[0] + "]");
  163. if (v_nSingleNodeSelection.nodeName === "pageBody" || v_nSingleNodeSelection.nodeName === "table")
  164. {
  165. v_aValidSelectionIids = [];
  166. var nlContents = v_bRunInProduction ? v_nSingleNodeSelection.selectNodes(".//contents") : v_nSingleNodeSelection.querySelectorAll("contents");
  167. for (var i = 0; i < nlContents.length; i++)
  168. {
  169. var v_nlChildNodes = nlContents.item(i).childNodes;
  170. for (var j = 0; j < v_nlChildNodes.length; j++)
  171. {
  172. var v_nChildNode = v_nlChildNodes.item(j);
  173. if (v_nChildNode.nodeType != V5ToDashboard.K_iNODE_ELEMENT || !this.f_isSupportedLayoutSelection(v_nChildNode.nodeName))
  174. {
  175. continue;
  176. }
  177. v_aValidSelectionIids.push(v_nChildNode.getAttribute("iid"));
  178. }
  179. }
  180. }
  181. }
  182. return v_aValidSelectionIids;
  183. };
  184. V5ToDashboard.f_isSupportedLayoutSelection = function (v_sName)
  185. {
  186. switch (v_sName)
  187. {
  188. case "list":
  189. case "crosstab":
  190. case "viz":
  191. case "vizControl":
  192. case "mapChart":
  193. return true;
  194. }
  195. return false;
  196. };
  197. V5ToDashboard.f_setName = function (v_oDBSpec)
  198. {
  199. v_oDBSpec.name = StringResource.get('new_exploration'); // This doesn't work with Intern
  200. // v_oDBSpec.name = 'New exploration'; // For Intern tests
  201. };
  202. V5ToDashboard.f_setVersion = function (v_oDBSpec)
  203. {
  204. v_oDBSpec.version = 1402;
  205. };
  206. V5ToDashboard.f_setPalette = function (v_oDBSpec)
  207. {
  208. // TODO: how do you get the palette?
  209. // v_oDBSpec.fredIsRed = {};
  210. // v_oDBSpec.fredIsRed.id = "model0000016176037fb1_00000001";
  211. // v_oDBSpec.fredIsRed.colorMap = "";
  212. // v_oDBSpec.fredIsRed.saveId = 1;
  213. };
  214. V5ToDashboard.f_setLayout = function (v_oDBSpec)
  215. {
  216. v_oDBSpec.layout = [];
  217. };
  218. V5ToDashboard.f_setDBDataSource = function (v_oDBSpec, v_sReportTempStoreId)
  219. {
  220. v_oDBSpec.dataSources = {};
  221. v_oDBSpec.dataSources.version = "1.0";
  222. v_oDBSpec.dataSources.sources = [];
  223. v_oDBSpec.dataSources.sources.push({
  224. id: v_sReportTempStoreId,
  225. assetId: v_sReportTempStoreId,
  226. type: "report",
  227. name: "",
  228. shaping: {
  229. embeddedModuleUpToDate: true
  230. }
  231. });
  232. };
  233. V5ToDashboard.f_convertV5SelectionToDB = function (v_oDBSpec, v_nReport, v_aSelectionIids, v_sReportTempStoreId)
  234. {
  235. // The V5 objects converted to DB widgets will be placed in a vertical column, one below the other,
  236. // and the offest is given by v_iHeightOffset
  237. var v_iHeightOffset = 0;
  238. v_oDBSpec.widgets = [];
  239. for (var i = 0; i < v_aSelectionIids.length; i++)
  240. {
  241. // a single selection may have multiple queries (to be converted to multiple data views) - e.g. Vida map with 3 layers has 3 queries
  242. var v_aQueries = [], v_aDataViews = [];
  243. var v_nSelection = v_bRunInProduction ? v_nReport.selectSingleNode(".//*[@iid='" + v_aSelectionIids[i] + "']") : v_nReport.querySelector("[iid=" + v_aSelectionIids[i] + "]");
  244. if (!v_nSelection)
  245. {
  246. continue;
  247. }
  248. v_aQueries = this.f_getQueriesForSelection(v_nReport, v_nSelection);
  249. for (var j = 0; j < v_aQueries.length; j++)
  250. {
  251. var v_oDataView = this.f_createEmptyWidgetDataViewForV5Query(v_sReportTempStoreId, j);
  252. if (!v_oDataView)
  253. {
  254. continue;
  255. }
  256. v_aDataViews.push(v_oDataView);
  257. }
  258. var v_iIndex = i + 1;
  259. var v_sWidgetId = "widget" + v_iIndex;
  260. if (v_bRunInProduction)
  261. {
  262. // add timestamp for unique widget id in case we launch in existing exploration
  263. v_sWidgetId += '-' + Date.now();
  264. }
  265. var v_oWidget = this.f_createWidget(v_sWidgetId);
  266. switch (v_nSelection.nodeName)
  267. {
  268. case "list":
  269. this.f_setListWidget(v_oWidget, v_nSelection, v_aQueries[0], v_aDataViews[0]);
  270. break;
  271. case "crosstab":
  272. this.f_setCrosstabWidget(v_oWidget, v_nSelection, v_aQueries[0], v_aDataViews[0]);
  273. break;
  274. case "vizControl":
  275. var v_nlReportDataStore = v_bRunInProduction ? v_nReport.selectNodes(".//reportDataStore") : v_nReport.querySelectorAll("reportDataStore");
  276. this.f_setVizControlWidget(v_oWidget, v_nSelection, v_aQueries, v_aDataViews, v_nlReportDataStore);
  277. break;
  278. default:
  279. // ignore selection
  280. continue;
  281. }
  282. v_oDBSpec.widgets.push(v_oWidget);
  283. var v_oWidthHeight = this.f_getV5ObjectWidthHeight(v_nSelection);
  284. this.f_addWidgetToLayout(v_oDBSpec, v_sWidgetId, v_oWidthHeight, v_iHeightOffset);
  285. v_iHeightOffset += parseInt(v_oWidthHeight.height);
  286. }
  287. };
  288. V5ToDashboard.f_getV5ObjectWidthHeight = function (v_nSelection)
  289. {
  290. var v_nCSS, v_sWidth, v_sHeight, i;
  291. var v_nlSelectionChildren = v_nSelection.childNodes;
  292. for (i = 0; i < v_nlSelectionChildren.length; i++)
  293. {
  294. var v_nSelectionChild = v_nlSelectionChildren.item(i);
  295. if (v_nSelectionChild.nodeName == 'style')
  296. {
  297. v_nCSS = v_bRunInProduction ? v_nSelectionChild.selectSingleNode(".//CSS") : v_nSelectionChild.querySelector('CSS');
  298. break;
  299. }
  300. }
  301. if (v_nCSS)
  302. {
  303. var v_aCSSValueAttr = v_nCSS.getAttribute('value').split(';');
  304. for (i = 0; i < v_aCSSValueAttr.length; i++)
  305. {
  306. var v_sAttr = v_aCSSValueAttr[i];
  307. if (v_sAttr.indexOf('width:', 0) != -1)
  308. {
  309. v_sWidth = v_sAttr.substring(v_sAttr.indexOf(':') + 1);
  310. }
  311. else if (v_sAttr.indexOf('height:', 0) != -1)
  312. {
  313. v_sHeight = v_sAttr.substring(v_sAttr.indexOf(':') + 1);
  314. }
  315. }
  316. }
  317. v_sWidth = (v_sWidth ? v_sWidth : "500px");
  318. v_sHeight = (v_sHeight ? v_sHeight : "500px");
  319. return {width: v_sWidth, height: v_sHeight};
  320. };
  321. V5ToDashboard.f_addWidgetToLayout = function (v_oDBSpec, v_sWidgetId, v_oWidthHeight, v_iHeightOffset)
  322. {
  323. v_oDBSpec.layout.push({
  324. id: v_sWidgetId,
  325. style: {
  326. left: '0px',
  327. top: v_iHeightOffset + 'px',
  328. height: v_oWidthHeight.height,
  329. width: v_oWidthHeight.width
  330. },
  331. type: "widget"
  332. });
  333. };
  334. V5ToDashboard.f_createWidget = function (v_sWidgetId)
  335. {
  336. return {
  337. type : "live",
  338. id : v_sWidgetId,
  339. visId : "",
  340. name : v_sWidgetId,
  341. data : {
  342. dataViews : []
  343. },
  344. visTypeLocked : true,
  345. slotmapping : {
  346. slots : []
  347. },
  348. localFilters : [],
  349. properties : []
  350. };
  351. };
  352. V5ToDashboard.f_createEmptyWidgetDataViewForV5Query = function (v_sReportTempStoreId, v_iQueryIndex)
  353. {
  354. var v_oDataView = {};
  355. v_oDataView.modelRef = v_sReportTempStoreId;
  356. v_oDataView.modelType = "report";
  357. v_oDataView.searchPath = "";
  358. v_oDataView.dataItems = [];
  359. v_oDataView.id = "dataView" + (v_iQueryIndex + 1);
  360. return v_oDataView;
  361. };
  362. V5ToDashboard.f_isDataItemUsedInSelection = function (v_nDataItem, v_nSelection, v_sRefName)
  363. {
  364. if (v_nDataItem.nodeName == '#text')
  365. {
  366. return false;
  367. }
  368. return !!(v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@" + v_sRefName + "='" + v_nDataItem.getAttribute("name") + "']") :
  369. v_nSelection.querySelector("[" + v_sRefName + "='" + v_nDataItem.getAttribute("name") + "']"));
  370. };
  371. V5ToDashboard.f_getRefDataItemExpression = function (v_nDataItem)
  372. {
  373. switch (v_nDataItem.nodeName)
  374. {
  375. case 'dataItemMeasure':
  376. var v_nMUN = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//MUN") : v_nDataItem.querySelector("MUN");
  377. return (v_nMUN ? v_nMUN.childNodes[0].nodeValue : null);
  378. case 'dataItemLevelSet':
  379. case 'dataItemMemberSet':
  380. var v_nLUN = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//LUN") : v_nDataItem.querySelector("LUN");
  381. return (v_nLUN ? v_nLUN.childNodes[0].nodeValue : null);
  382. case 'dataItem':
  383. var v_nExpression = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//expression") : v_nDataItem.querySelector("expression");
  384. return (v_nExpression ? v_nExpression.childNodes[0].nodeValue : null);
  385. default:
  386. return null;
  387. }
  388. };
  389. V5ToDashboard.f_getQueriesForSelection = function (v_nReport, v_nSelection)
  390. {
  391. var v_sRefQueryName, v_aRefQueryNames = [], v_aQueries = [];
  392. switch (v_nSelection.nodeName)
  393. {
  394. case "list":
  395. case "crosstab":
  396. v_sRefQueryName = v_nSelection.getAttribute("refQuery");
  397. v_aRefQueryNames.push(v_sRefQueryName);
  398. break;
  399. case "viz":
  400. v_sRefQueryName = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizDataSet").getAttribute("refQuery") :
  401. v_nSelection.querySelector("vizDataSet").getAttribute("refQuery");
  402. v_aRefQueryNames.push(v_sRefQueryName);
  403. break;
  404. case "vizControl":
  405. var v_nlRefDataStore = v_bRunInProduction ? v_nSelection.selectNodes(".//vcDataSet") : v_nSelection.querySelectorAll("vcDataSet");
  406. for (var i = 0; i < v_nlRefDataStore.length; i++)
  407. {
  408. var v_sRefDataStore = v_nlRefDataStore.item(i).getAttribute("refDataStore");
  409. if (!v_sRefDataStore)
  410. {
  411. // empty layer
  412. continue;
  413. }
  414. var v_nReportDataStore = v_bRunInProduction ? v_nReport.selectSingleNode(".//reportDataStore[@name='" + v_sRefDataStore + "']"):
  415. v_nReport.querySelector("reportDataStore[name='" + v_sRefDataStore + "']");
  416. v_sRefQueryName = v_bRunInProduction ? v_nReportDataStore.selectSingleNode(".//dsV5ListQuery").getAttribute("refQuery") :
  417. v_nReportDataStore.querySelector("dsV5ListQuery").getAttribute("refQuery");
  418. v_aRefQueryNames.push(v_sRefQueryName);
  419. }
  420. break;
  421. case "mapChart":
  422. // TODO: Rave 2 map, not Vida
  423. break;
  424. }
  425. for (var j = 0; j < v_aRefQueryNames.length; j++)
  426. {
  427. var v_nQuery = v_bRunInProduction ? v_nReport.selectSingleNode("./queries/query[@name='" + v_aRefQueryNames[j] + "']") :
  428. v_nReport.querySelector("queries > query[name='" + v_aRefQueryNames[j] + "']");
  429. v_aQueries.push(v_nQuery);
  430. }
  431. return v_aQueries;
  432. };
  433. V5ToDashboard.f_convertV5DataItemSortToDB = function (v_nSelection, v_nDataItem, v_sDataItemName, v_sDataItemIndex)
  434. {
  435. // For old dataItem as used in non-dimensional the sort is specified in the layout: sortList/sortItem[@sortOrder="descending"]
  436. // For new/specialized data items as used in dimensional the sort is specified in the query data item: /setSorting[@ascending="false"]
  437. // First try to get the sort from layout and if not found try to get the sort from data item
  438. var v_aSelection = [];
  439. var v_nLayoutSortItem;
  440. var v_bIsDescending = null;
  441. switch (v_nSelection.nodeName)
  442. {
  443. case "list":
  444. v_nLayoutSortItem = v_bRunInProduction ? v_nSelection.selectSingleNode(".//sortList/sortItem[@refDataItem='" + v_sDataItemName + "']") :
  445. v_nSelection.querySelector("sortList > sortItem[refDataItem='" + v_sDataItemName + "']");
  446. break;
  447. case "crosstab":
  448. case "viz":
  449. case "vizControl":
  450. case "mapChart":
  451. v_nLayoutSortItem = v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDataItem='" + v_sDataItemName + "']//sortList/sortItem") :
  452. v_nSelection.querySelector("* > [refDataItem='" + v_sDataItemName + "'] > sortList > sortItem");
  453. break;
  454. }
  455. if (v_nLayoutSortItem)
  456. {
  457. v_bIsDescending = (v_nLayoutSortItem.getAttribute("sortOrder") == "descending");
  458. }
  459. else
  460. {
  461. // try to get the sort from query
  462. var v_nSetSorting = v_bRunInProduction ? v_nDataItem.selectSingleNode(".//setSorting") : v_nDataItem.querySelector("setSorting");
  463. if (v_nSetSorting)
  464. {
  465. v_bIsDescending = (v_nSetSorting.getAttribute("ascending") == "false");
  466. }
  467. }
  468. if (v_bIsDescending != null)
  469. {
  470. v_aSelection.push({
  471. "operation": "order",
  472. "sort": {
  473. "type": v_bIsDescending ? "desc" : "asc",
  474. "priority": v_sDataItemIndex,
  475. "by": "caption"
  476. }
  477. });
  478. }
  479. return v_aSelection;
  480. };
  481. V5ToDashboard.f_getXMLAttribute = function (v_nParent, v_sName)
  482. {
  483. if (!v_nParent || !v_sName)
  484. {
  485. return null;
  486. }
  487. var v_nXMLAttribute = v_bRunInProduction ? v_nParent.selectSingleNode(".//XMLAttributes/XMLAttribute[@name='" + v_sName + "']") :
  488. v_nParent.querySelector("XMLAttributes > XMLAttribute[name='" + v_sName + "']");
  489. var v_sXMLAttributeValue = v_nXMLAttribute ? v_nXMLAttribute.getAttribute("value") : null;
  490. return v_sXMLAttributeValue;
  491. };
  492. // From the usage attribute in metadata responses.
  493. V5ToDashboard.K_iDataUsage_Fact = 2;
  494. V5ToDashboard.K_sDataUsage_Fact = "fact";
  495. V5ToDashboard.f_getDataUsage = function (v_nDataItem)
  496. {
  497. return this.f_getXMLAttribute(v_nDataItem, "RS_dataUsage") || this.K_sDataUsage_Unknown;
  498. };
  499. V5ToDashboard.F_IsLikelyMeasure = function (v_nDataItem)
  500. {
  501. switch (v_nDataItem.nodeName)
  502. {
  503. case "dataItem":
  504. return (this.f_getDataUsage(v_nDataItem) == this.K_iDataUsage_Fact || this.f_getDataUsage(v_nDataItem) == this.K_sDataUsage_Fact);
  505. case "dataItemMeasure":
  506. case "dataItemCalculatedMeasure":
  507. case "dataItemMeasurePercentage":
  508. return true;
  509. }
  510. return false;
  511. };
  512. V5ToDashboard.F_IsLikelyCalculation = function (v_nDataItem)
  513. {
  514. switch (v_nDataItem.nodeName)
  515. {
  516. case "dataItemCalculatedMember":
  517. case "dataItemCalculatedMeasure":
  518. case "dataItemMeasurePercentage":
  519. return true;
  520. }
  521. return false;
  522. };
  523. V5ToDashboard.f_convertV5FormatToDB = function (v_nSelection, v_nDataItem, v_sDataItemName)
  524. {
  525. var v_oFormat = {};
  526. // DB only has measure format
  527. if (this.F_IsLikelyMeasure(v_nDataItem))
  528. {
  529. var v_nDataFormat;
  530. switch (v_nSelection.nodeName)
  531. {
  532. case "list":
  533. var v_nListColumnBody = this.f_getAncestorNode(
  534. v_bRunInProduction ? v_nSelection.selectSingleNode(".//listColumnBody//*[@refDataItem='" + v_sDataItemName + "']") :
  535. v_nSelection.querySelector("listColumnBody * [refDataItem='" + v_sDataItemName + "']"),
  536. "listColumnBody");
  537. v_nDataFormat = v_bRunInProduction ? v_nListColumnBody.selectSingleNode(".//style//dataFormat") : v_nListColumnBody.querySelector("style > dataFormat");
  538. break;
  539. case "crosstab":
  540. v_nDataFormat = v_bRunInProduction ? v_nSelection.selectSingleNode(".//crosstabFactCell//style//dataFormat") :
  541. v_nSelection.querySelector("crosstabFactCell > style > dataFormat");
  542. break;
  543. case "viz":
  544. // TODO
  545. break;
  546. case "vizControl":
  547. // TODO
  548. break;
  549. case "mapChart":
  550. // TODO
  551. break;
  552. }
  553. if (v_nDataFormat && v_nDataFormat.firstElementChild)
  554. {
  555. v_oFormat.formatSpec = {};
  556. this.f_convertV5DataFormatToDB(v_nDataFormat.firstElementChild, v_oFormat.formatSpec);
  557. }
  558. }
  559. return v_oFormat;
  560. };
  561. V5ToDashboard.f_getAncestorNode = function (v_nCurrentNode, v_sAncestorName)
  562. {
  563. // recursion exit conditions
  564. if (!v_nCurrentNode || !v_nCurrentNode.parentNode)
  565. {
  566. return null;
  567. }
  568. if (v_nCurrentNode.parentNode.nodeName == v_sAncestorName)
  569. {
  570. return v_nCurrentNode.parentNode;
  571. }
  572. return this.f_getAncestorNode(v_nCurrentNode.parentNode, v_sAncestorName);
  573. };
  574. V5ToDashboard.f_getDataItems = function (v_nQuery)
  575. {
  576. return v_bRunInProduction ? v_nQuery.selectNodes(".//selection/*") : v_nQuery.querySelector("selection").childNodes;
  577. };
  578. V5ToDashboard.f_getDataItem = function (v_nQuery, v_sDataItemName)
  579. {
  580. return v_bRunInProduction ? v_nQuery.selectSingleNode(".//*[@name='" + v_sDataItemName + "']") : v_nQuery.querySelector("* [name='" + v_sDataItemName + "']");
  581. };
  582. V5ToDashboard.f_escapeEndBracket = function (v_sName)
  583. {
  584. return v_sName.replace(/\]/g, ']]');
  585. };
  586. V5ToDashboard.f_addV5DataItemToDBDataView = function (v_nSelection, v_sQueryName, v_nDataItem, v_sRefName, v_oDataView, v_iIndex)
  587. {
  588. if (!this.f_isDataItemUsedInSelection(v_nDataItem, v_nSelection, v_sRefName))
  589. {
  590. return false;
  591. }
  592. var v_sDataItemName = v_nDataItem.getAttribute("name");
  593. var v_aSelection = this.f_convertV5DataItemSortToDB(v_nSelection, v_nDataItem, v_sDataItemName, v_iIndex);
  594. var v_oFormat = this.f_convertV5FormatToDB(v_nSelection, v_nDataItem, v_sDataItemName);
  595. var v_sV5DataItemAggregate = v_nDataItem.getAttribute("aggregate");
  596. var v_sDBDataItemAggregate = v_sV5DataItemAggregate ? this.f_convertAggregateOpToDB(v_sV5DataItemAggregate) : "";
  597. var v_sDataItemNameFull = '[' + this.f_escapeEndBracket(v_sQueryName) + '].[' + this.f_escapeEndBracket(v_sDataItemName) + ']';
  598. var v_oDataItem = {
  599. id: v_sDataItemNameFull,
  600. itemId: v_sDataItemNameFull,
  601. itemLabel: v_sDataItemName
  602. };
  603. if (v_aSelection && v_aSelection.length > 0)
  604. {
  605. v_oDataItem.selection = v_aSelection;
  606. }
  607. if (v_oFormat && v_oFormat.formatSpec)
  608. {
  609. v_oDataItem.format = v_oFormat;
  610. }
  611. if (v_sDBDataItemAggregate)
  612. {
  613. v_oDataItem.aggregate = v_sDBDataItemAggregate;
  614. }
  615. v_oDataView.dataItems.push(v_oDataItem);
  616. return true;
  617. };
  618. V5ToDashboard.f_setListWidget = function (v_oWidget, v_nSelection, v_nQuery, v_oDataView)
  619. {
  620. var v_oSlot = {};
  621. v_oSlot.name = "grid_cols";
  622. v_oSlot.dataItems = [];
  623. var v_sQueryName = v_nQuery.getAttribute("name");
  624. // v_oSlot.dataItemSettings = [];
  625. // v_oSlot.caption = "Columns";
  626. // v_oSlot.id = "grid_cols";
  627. var v_nlDataItemValue = v_bRunInProduction ? v_nSelection.selectNodes(".//listColumnBody//*[@refDataItem]") : v_nSelection.querySelectorAll("* listColumnBody * [refDataItem]");
  628. for (var i = 0; i < v_nlDataItemValue.length; i++)
  629. {
  630. if (v_nlDataItemValue.item(i).nodeName != 'dataItemValue')
  631. {
  632. continue;
  633. }
  634. var v_sRefDataItem = v_nlDataItemValue.item(i).getAttribute("refDataItem");
  635. var v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
  636. if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
  637. {
  638. continue;
  639. }
  640. v_oSlot.dataItems.push(v_sRefDataItem);
  641. }
  642. v_oWidget.data.dataViews.push(v_oDataView);
  643. v_oWidget.slotmapping.slots.push(v_oSlot);
  644. v_oWidget.visId = "JQGrid";
  645. };
  646. V5ToDashboard.f_convertV5DataFormatToDB = function (v_nV5Format, v_oDBFormat)
  647. {
  648. switch (v_nV5Format.nodeName)
  649. {
  650. case "currencyFormat":
  651. v_oDBFormat.type = "currency";
  652. var v_sCurrencyCode = v_nV5Format.getAttribute("currencyCode");
  653. if (v_sCurrencyCode)
  654. {
  655. v_oDBFormat.currencyCode = v_sCurrencyCode;
  656. v_oDBFormat.currencyDisplay = "symbol";
  657. }
  658. break;
  659. case "numberFormat":
  660. v_oDBFormat.type = "number";
  661. break;
  662. case "percentFormat":
  663. v_oDBFormat.type = "percent";
  664. break;
  665. }
  666. var v_sDecimalSize = v_nV5Format.getAttribute("decimalSize");
  667. if (v_sDecimalSize)
  668. {
  669. v_oDBFormat.maximumFractionDigits = v_oDBFormat.minimumFractionDigits = parseInt(v_sDecimalSize);
  670. }
  671. };
  672. // Note. We may have a combined filter that uses few data items, thus this method doesn't take a data item as input
  673. V5ToDashboard.f_addV5VidaFiltersToDBWidgetLocalFilters = function (v_nQuery, v_nSelection, v_aLocalFilters, v_nlReportDataStore)
  674. {
  675. for (var i = 0; i < v_nlReportDataStore.length; i++)
  676. {
  677. var v_nReportDataStore = v_nlReportDataStore.item(i);
  678. var v_nDsFilters = v_bRunInProduction ? v_nReportDataStore.selectNodes(".//dsFilters/dsFilter") : v_nReportDataStore.querySelectorAll("* > dsFilters > dsFilter");
  679. for (var j = 0; j < v_nDsFilters.length; j++)
  680. {
  681. var v_nDsFilter = v_nDsFilters.item(j);
  682. // dsFilter can have 1 filterExpression (TODO: we ignore for now) or 1 dsFilterDefinition (which we convert to DB)
  683. // dsFilterDefinition defines 1 filter that we call filterRoot (which may contain other filters)
  684. var v_nFilterRoot;
  685. var v_nlFilterDefinition = v_bRunInProduction ? v_nDsFilter.selectNodes(".//dsFilterDefinition") : v_nDsFilter.querySelector("dsFilterDefinition");
  686. if (!v_nlFilterDefinition)
  687. {
  688. continue;
  689. }
  690. var v_nlFilterDefChildren = v_bRunInProduction ? v_nDsFilter.selectNodes(".//dsFilterDefinition/*") : v_nDsFilter.querySelector("dsFilterDefinition").childNodes;
  691. for (var k = 0; k < v_nlFilterDefChildren.length; k++)
  692. {
  693. if (v_nlFilterDefChildren.item(k).nodeType == V5ToDashboard.K_iNODE_ELEMENT)
  694. {
  695. v_nFilterRoot = v_nlFilterDefChildren.item(k);
  696. break;
  697. }
  698. }
  699. if (!v_nFilterRoot)
  700. {
  701. continue;
  702. }
  703. var v_oDBFilter = {};
  704. v_oDBFilter.id = "Filter" + (i + 1);
  705. v_oDBFilter.values = [];
  706. // TODO: Is this needed? Doesn't seem to work in DB
  707. // v_oDBFilter.preOrPost = (v_nDsFilter.getAttribute("postAutoAggregation") == "post" ? "true" : "false");
  708. this.f_convertV5DetailFilterToDBFilter(v_nFilterRoot, v_oDBFilter, v_nQuery, v_nSelection);
  709. if (!this.f_filterIsInvalid(v_oDBFilter))
  710. {
  711. v_aLocalFilters.push(v_oDBFilter);
  712. }
  713. }
  714. }
  715. };
  716. V5ToDashboard.f_filterIsInvalid = function (v_oDBFilter)
  717. {
  718. // Note. v_oDBFilter.values is always an array, but only for combined filters is an array of filters
  719. for (var i = 0; i < v_oDBFilter.values.length; i++)
  720. {
  721. if (!v_oDBFilter.values[i].id)
  722. {
  723. // the value is not a filter - this is a basic filter element
  724. return false;
  725. }
  726. if (this.f_filterIsInvalid(v_oDBFilter.values[i]))
  727. {
  728. return true;
  729. }
  730. }
  731. return false;
  732. };
  733. V5ToDashboard.f_convertV5CombineFilterOperatorToDB = function (v_sV5CombineFilterOperator)
  734. {
  735. switch (v_sV5CombineFilterOperator)
  736. {
  737. case "filterAnd":
  738. return "and";
  739. case "filterOr":
  740. return "or";
  741. case "filterNot":
  742. return "not";
  743. default:
  744. alert("V5 filter not supported: " + v_sV5CombineFilterOperator);
  745. return null;
  746. }
  747. };
  748. V5ToDashboard.f_convertV5DetailFilterToDBFilter = function (v_nFilter, v_oDBFilter, v_nQuery, v_nSelection)
  749. {
  750. switch (v_nFilter.nodeName)
  751. {
  752. case "filterAnd":
  753. case "filterOr":
  754. case "filterNot":
  755. var v_nlFilterChildren = v_nFilter.childNodes;
  756. for (var i = 0; i < v_nlFilterChildren.length; i++)
  757. {
  758. if (v_nlFilterChildren.item(i).nodeType != V5ToDashboard.K_iNODE_ELEMENT)
  759. {
  760. continue;
  761. }
  762. var v_nFilterChild = v_nlFilterChildren.item(i);
  763. var v_oDBFilterChild = {};
  764. v_oDBFilterChild.id = v_oDBFilter.id + '_' + (i + 1);
  765. v_oDBFilterChild.values = [];
  766. v_oDBFilter.values.push(v_oDBFilterChild);
  767. // recursion to get children filters
  768. this.f_convertV5DetailFilterToDBFilter(v_nFilterChild, v_oDBFilterChild, v_nQuery, v_nSelection);
  769. }
  770. v_oDBFilter.operator = this.f_convertV5CombineFilterOperatorToDB(v_nFilter.nodeName);
  771. break;
  772. case "#text":
  773. break;
  774. default:
  775. this.f_convertV5VidaFilterElementToDB(v_nFilter, v_oDBFilter, v_nQuery);
  776. break;
  777. }
  778. };
  779. V5ToDashboard.f_convertV5VidaFilterElementToDB = function (v_nFilter, v_oDBFilter, v_nQuery)
  780. {
  781. var v_sRefDataItem = v_nFilter.getAttribute("refDsColumn");
  782. var v_sQueryName = v_nQuery.getAttribute("name");
  783. v_oDBFilter.id = v_oDBFilter.columnId = '[' + this.f_escapeEndBracket(v_sQueryName) + '].[' + this.f_escapeEndBracket(v_sRefDataItem) + ']';
  784. var v_nFilterValue, i;
  785. switch (v_nFilter.nodeName)
  786. {
  787. case "dsFilterIn":
  788. var v_nlFilterValues = v_bRunInProduction ? v_nFilter.selectNodes(".//dsFilterInValues/dsFilterInValue") : v_nFilter.querySelectorAll("dsFilterInValues > dsFilterInValue");
  789. for (i = 0; i < v_nlFilterValues.length; i++)
  790. {
  791. v_nFilterValue = v_nlFilterValues.item(i);
  792. if (!v_nFilterValue)
  793. {
  794. continue;
  795. }
  796. var v_sFilterValue = v_nFilterValue.childNodes[0].nodeValue;
  797. v_oDBFilter.values.push({
  798. "d": v_sFilterValue,
  799. "u": v_sFilterValue
  800. });
  801. }
  802. v_oDBFilter.operator = (v_nFilter.getAttribute("not") === "true" ? "notin" : "in");
  803. break;
  804. case "dsFilterCompare":
  805. v_nFilterValue = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterCompareValue") : v_nFilter.querySelector("dsFilterCompareValue");
  806. if (!v_nFilterValue)
  807. {
  808. break;
  809. }
  810. var v_FilterValue = Number(v_nFilterValue.childNodes[0].nodeValue);
  811. v_oDBFilter.values.push({
  812. "d": v_FilterValue,
  813. "u": v_FilterValue
  814. });
  815. v_oDBFilter.operator = this.f_convertCompareOperatorToDB(v_nFilter);
  816. break;
  817. case "dsFilterRange":
  818. var v_nFilterFrom = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterFromValue") : v_nFilter.querySelector("dsFilterFromValue");
  819. var v_nFilterTo = v_bRunInProduction ? v_nFilter.selectSingleNode(".//dsFilterToValue") : v_nFilter.querySelector("dsFilterToValue");
  820. if (!v_nFilterFrom && !v_nFilterTo || v_nFilterFrom.childNodes.length == 0 && v_nFilterTo.childNodes.length == 0)
  821. {
  822. break;
  823. }
  824. var v_FilterFrom, v_FilterTo;
  825. if (v_nFilterFrom.childNodes.length > 0 && v_nFilterTo.childNodes.length > 0)
  826. {
  827. v_FilterFrom = Number(v_nFilterFrom.childNodes[0].nodeValue);
  828. v_FilterTo = Number(v_nFilterTo.childNodes[0].nodeValue);
  829. v_oDBFilter.values.push({
  830. "d": v_FilterFrom,
  831. "u": v_FilterFrom
  832. }, {
  833. "d": v_FilterTo,
  834. "u": v_FilterTo
  835. });
  836. v_oDBFilter.operator = (v_nFilter.getAttribute("not") === "true" ? "notbetween" : "between");
  837. break;
  838. }
  839. if (v_nFilterFrom.childNodes.length > 0 && v_nFilterTo.childNodes.length == 0)
  840. {
  841. v_FilterFrom = Number(v_nFilterFrom.childNodes[0].nodeValue);
  842. v_oDBFilter.values.push({
  843. "d": v_FilterFrom,
  844. "u": v_FilterFrom
  845. });
  846. v_oDBFilter.operator = "gt";
  847. break;
  848. }
  849. if (v_nFilterFrom.childNodes.length == 0 && v_nFilterTo.childNodes.length > 0)
  850. {
  851. v_FilterTo = Number(v_nFilterTo.childNodes[0].nodeValue);
  852. v_oDBFilter.values.push({
  853. "d": v_FilterTo,
  854. "u": v_FilterTo
  855. });
  856. v_oDBFilter.operator = "lt";
  857. break;
  858. }
  859. break;
  860. }
  861. };
  862. V5ToDashboard.f_convertCompareOperatorToDB = function (v_nFilterCompare)
  863. {
  864. var v_bIsNot = v_nFilterCompare.getAttribute("not") === "true";
  865. switch (v_nFilterCompare.getAttribute("operator"))
  866. {
  867. case "greaterThan":
  868. case "greaterThanEqual":
  869. return v_bIsNot ? "lt" : "gt";
  870. case "lessThan":
  871. case "lessThanEqual":
  872. return v_bIsNot ? "gt" : "lt";
  873. case "equal":
  874. return "eq";
  875. }
  876. return "eq";
  877. };
  878. V5ToDashboard.f_setCrosstabWidget = function (v_oWidget, v_nSelection, v_nQuery, v_oDataView)
  879. {
  880. var v_sQueryName = v_nQuery.getAttribute("name");
  881. v_oWidget.slotmapping.slots = [
  882. {
  883. "name": "row_level1",
  884. "dataItems": [],
  885. "caption": "Rows",
  886. "id": "row_level1"
  887. },
  888. {
  889. "name": "column_level1",
  890. "dataItems": [],
  891. "caption": "Columns",
  892. "id": "column_level1"
  893. },
  894. {
  895. "name": "values",
  896. "dataItems": [],
  897. "caption": "Values",
  898. "id": "values"
  899. }
  900. ];
  901. var v_sRefDataItem, v_nDataItem, i;
  902. var v_nlRowsCrosstabNodeMember = v_bRunInProduction ? v_nSelection.selectNodes(".//crosstabRows//crosstabNodeMember") :
  903. v_nSelection.querySelectorAll("crosstabRows * crosstabNodeMember");
  904. for (i = v_nlRowsCrosstabNodeMember.length - 1; i >= 0; i--)
  905. {
  906. // to preserve the nesting order must loop descending
  907. v_sRefDataItem = v_nlRowsCrosstabNodeMember.item(i).getAttribute("refDataItem");
  908. v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
  909. if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
  910. {
  911. continue;
  912. }
  913. // slot 0 is for rows
  914. v_oWidget.slotmapping.slots[0].dataItems.push(v_sRefDataItem);
  915. }
  916. var v_nlColsCrosstabNodeMember = v_bRunInProduction ? v_nSelection.selectNodes(".//crosstabColumns//crosstabNodeMember") :
  917. v_nSelection.querySelectorAll("crosstabColumns * crosstabNodeMember");
  918. for (i = v_nlColsCrosstabNodeMember.length - 1; i >= 0; i--)
  919. {
  920. // to preserve the nesting order must loop descending
  921. v_sRefDataItem = v_nlColsCrosstabNodeMember.item(i).getAttribute("refDataItem");
  922. v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
  923. if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, i))
  924. {
  925. continue;
  926. }
  927. var v_iSlotIndex = 1;
  928. if (this.F_IsLikelyMeasure(v_nDataItem))
  929. {
  930. v_iSlotIndex = 2;
  931. }
  932. v_oWidget.slotmapping.slots[v_iSlotIndex].dataItems.push(v_sRefDataItem);
  933. }
  934. var v_nCrosstabCornerDataItemLabel = v_bRunInProduction ? v_nSelection.selectSingleNode(".//crosstabCorner//*[@refDataItem]") : v_nSelection.querySelector("crosstabCorner * [refDataItem]");
  935. if (v_nCrosstabCornerDataItemLabel)
  936. {
  937. v_sRefDataItem = v_nCrosstabCornerDataItemLabel.getAttribute("refDataItem");
  938. v_nDataItem = this.f_getDataItem(v_nQuery, v_sRefDataItem);
  939. this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDataItem", v_oDataView, 0);
  940. v_oWidget.slotmapping.slots[2].dataItems.push(v_sRefDataItem);
  941. }
  942. v_oWidget.data.dataViews.push(v_oDataView);
  943. v_oWidget.visId = "crosstab";
  944. };
  945. V5ToDashboard.f_convertAggregateOpToDB = function (v_sV5AggregateOp)
  946. {
  947. switch (v_sV5AggregateOp)
  948. {
  949. case "average":
  950. return "avg";
  951. case "summarize":
  952. return "sum";
  953. case "minimum":
  954. return "min";
  955. case "maximum":
  956. return "max";
  957. case "count":
  958. return "count";
  959. case "countDistinct":
  960. return "countdistinct";
  961. default:
  962. return null;
  963. }
  964. };
  965. V5ToDashboard.f_setVizControlWidget = function (v_oWidget, v_nSelection, v_aQueries, v_aDataViews, v_nlReportDataStore)
  966. {
  967. v_oWidget.visId = this.f_convertV5VidaTypeToDB(v_nSelection);
  968. this.f_addVizControlPropertiesToWidget(v_oWidget, v_nSelection);
  969. var v_aLayers = [];
  970. if (v_oWidget.visId == "com.ibm.vis.rave2bundletiledmap")
  971. {
  972. v_oWidget.slotmapping.layers = [];
  973. }
  974. for (var i = 0; i < v_aQueries.length; i++)
  975. {
  976. var v_nQuery = v_aQueries[i];
  977. var v_sQueryName = v_nQuery.getAttribute("name");
  978. var v_oDataView = v_aDataViews[i];
  979. var v_nlDataItems = this.f_getDataItems(v_nQuery);
  980. for (var j = 0; j < v_nlDataItems.length; j++)
  981. {
  982. var v_nDataItem = v_nlDataItems.item(j);
  983. if (!this.f_addV5DataItemToDBDataView(v_nSelection, v_sQueryName, v_nDataItem, "refDsColumn", v_oDataView, j))
  984. {
  985. continue;
  986. }
  987. var v_oSlot = this.f_createVizControlSlot(v_nSelection, v_nDataItem, v_oWidget.visId);
  988. v_oWidget.slotmapping.slots.push(v_oSlot);
  989. if (v_oWidget.visId == "com.ibm.vis.rave2bundletiledmap" && v_aLayers.indexOf(v_oSlot.layerId) == -1)
  990. {
  991. v_aLayers.push(v_oSlot.layerId);
  992. v_oWidget.slotmapping.layers.push(
  993. {
  994. type: v_oSlot.layerId,
  995. id: v_oSlot.layerId,
  996. dataViewId: v_oDataView.id
  997. });
  998. }
  999. }
  1000. this.f_addV5VidaFiltersToDBWidgetLocalFilters(v_nQuery, v_nSelection, v_oWidget.localFilters, v_nlReportDataStore);
  1001. v_oWidget.data.dataViews.push(v_oDataView);
  1002. }
  1003. };
  1004. V5ToDashboard.f_convertV5VidaTypeToDB = function (v_nSelection)
  1005. {
  1006. var v_sType = v_nSelection.getAttribute('type');
  1007. switch (v_sType)
  1008. {
  1009. case "com.ibm.vis.clusteredColumn":
  1010. return "com.ibm.vis.rave2bundlecolumn";
  1011. case "com.ibm.vis.clusteredBar":
  1012. return "com.ibm.vis.rave2bundlebar";
  1013. case "com.ibm.vis.stackedColumn":
  1014. return "com.ibm.vis.rave2bundlestackedcolumn";
  1015. case "com.ibm.vis.stackedBar":
  1016. return "com.ibm.vis.rave2bundlestackedbar";
  1017. case "com.ibm.vis.area":
  1018. return "com.ibm.vis.rave2bundlearea";
  1019. case "com.ibm.vis.treemap":
  1020. return "com.ibm.vis.rave2bundletreemap";
  1021. case "com.ibm.vis.bubble":
  1022. return "com.ibm.vis.ravebubble";
  1023. case "com.ibm.vis.bullet":
  1024. return "com.ibm.vis.rave2bundlebullet";
  1025. case "com.ibm.vis.point":
  1026. return "com.ibm.vis.rave2point";
  1027. case "com.ibm.vis.packedBubble":
  1028. return "com.ibm.vis.rave2bundlepackedbubble";
  1029. case "com.ibm.vis.hierarchicalPackedBubble":
  1030. return "com.ibm.vis.rave2bundlehierarchicalpackedbubble";
  1031. case "com.ibm.vis.marimekko":
  1032. return "com.ibm.vis.rave2marimekko";
  1033. case "com.ibm.vis.heatmap":
  1034. return "com.ibm.vis.rave2heat";
  1035. case "com.ibm.vis.line":
  1036. return "com.ibm.vis.rave2line";
  1037. case "com.ibm.vis.simpleCombination":
  1038. return "com.ibm.vis.rave2bundlecomposite";
  1039. case "com.ibm.vis.pie":
  1040. return "com.ibm.vis.rave2bundlepie";
  1041. case "com.ibm.vis.dial":
  1042. return "com.ibm.vis.rave2bundleradialbar";
  1043. case "com.ibm.vis.radar":
  1044. return "com.ibm.vis.rave2bundleradar";
  1045. case "com.ibm.vis.scatter":
  1046. return "com.ibm.vis.ravescatter";
  1047. case "com.ibm.vis.wordcloud":
  1048. return "com.ibm.vis.rave2bundlewordcloud";
  1049. case "com.ibm.vis.boxplot":
  1050. return "com.ibm.vis.rave2bundleboxplot";
  1051. case "com.ibm.vis.smoothArea":
  1052. return "com.ibm.vis.rave2bundlesmootharea";
  1053. case "com.ibm.vis.waterfall":
  1054. return "com.ibm.vis.rave2bundlewaterfall";
  1055. case "com.ibm.vis.tiledmap":
  1056. return "com.ibm.vis.rave2bundletiledmap";
  1057. default:
  1058. return v_sType;
  1059. }
  1060. };
  1061. V5ToDashboard.f_addVizPropertiesToWidget = function (v_oWidget, v_nSelection)
  1062. {
  1063. var v_nlVizPropertyValues = v_bRunInProduction ? v_nSelection.selectNodes(".//vizPropertyValues/*") : v_nSelection.querySelectorAll("vizPropertyValues > *");
  1064. for (var i = 0; i < v_nlVizPropertyValues.length; i++)
  1065. {
  1066. var v_nVizProperty = v_nlVizPropertyValues.item(i);
  1067. if (!v_nVizProperty)
  1068. {
  1069. continue;
  1070. }
  1071. switch (v_nVizProperty.getAttribute('name'))
  1072. {
  1073. case "color.palette":
  1074. this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "colorPalette");
  1075. break;
  1076. case "legend.position":
  1077. this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "widget.legend.position");
  1078. break;
  1079. case "legend.display":
  1080. this.f_setDBVizProperty(v_oWidget, v_nVizProperty, "widget.legend.display");
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. }
  1086. };
  1087. V5ToDashboard.f_addVizControlPropertiesToWidget = function (v_oWidget, v_nSelection, v_sWidgetId)
  1088. {
  1089. var v_nlVizPropertyValues = v_bRunInProduction ? v_nSelection.selectNodes(".//vizPropertyValues/*") : v_nSelection.querySelectorAll("vizPropertyValues > *");
  1090. for (var i = 0; i < v_nlVizPropertyValues.length; i++)
  1091. {
  1092. var v_nVizProperty = v_nlVizPropertyValues.item(i);
  1093. if (!v_nVizProperty)
  1094. {
  1095. continue;
  1096. }
  1097. var v_sDBVizPropertyName = v_nVizProperty.getAttribute('name');
  1098. if (!v_sDBVizPropertyName)
  1099. {
  1100. return;
  1101. }
  1102. v_sDBVizPropertyName = v_sDBVizPropertyName.substring(v_sDBVizPropertyName.indexOf('_') + 1);
  1103. this.f_setDBVizProperty(v_oWidget, v_nVizProperty, v_sDBVizPropertyName);
  1104. }
  1105. };
  1106. V5ToDashboard.f_setDBVizProperty = function (v_oWidget, v_nVizProperty, v_sDBVizPropertyName)
  1107. {
  1108. if (!v_nVizProperty || !v_nVizProperty.childNodes || !v_nVizProperty.childNodes[0])
  1109. {
  1110. return;
  1111. }
  1112. var v_sValue = v_nVizProperty.childNodes[0].nodeValue;
  1113. if (!v_sValue)
  1114. {
  1115. return;
  1116. }
  1117. switch (v_sDBVizPropertyName)
  1118. {
  1119. case "color_cat":
  1120. v_oWidget.properties.push({
  1121. "id": "colorPalette",
  1122. "value": v_sValue
  1123. });
  1124. break;
  1125. default:
  1126. v_oWidget.properties.push({
  1127. "id": v_sDBVizPropertyName,
  1128. "value": v_sValue
  1129. });
  1130. break;
  1131. }
  1132. };
  1133. V5ToDashboard.f_setDBVizType = function (v_oWidget, v_sVizType)
  1134. {
  1135. switch (v_sVizType)
  1136. {
  1137. case "rave-library-column,clusteredcolumn":
  1138. v_oWidget.visId = "com.ibm.vis.rave2bundlecolumn";
  1139. break;
  1140. case "rave-library-column,clusteredbar":
  1141. v_oWidget = "com.ibm.vis.rave2bundlebar";
  1142. break;
  1143. case "rave-library-column,stackedcolumn":
  1144. v_oWidget.visId = "com.ibm.vis.rave2bundlestackedcolumn";
  1145. break;
  1146. case "rave-library-column,stackedbar":
  1147. v_oWidget.visId = "com.ibm.vis.rave2bundlestackedbar";
  1148. break;
  1149. case "rave-library-area,area":
  1150. v_oWidget.visId = "com.ibm.vis.rave2bundlearea";
  1151. break;
  1152. case "rave-library-line,line":
  1153. v_oWidget.visId = "com.ibm.vis.rave2line";
  1154. break;
  1155. case "rave-library-bubble,point":
  1156. v_oWidget.visId = "com.ibm.vis.rave2point";
  1157. break;
  1158. case "rave-library-bubble,scatter":
  1159. v_oWidget.visId = "com.ibm.vis.ravescatter";
  1160. break;
  1161. case "rave-library-dial,dial":
  1162. v_oWidget.visId = "com.ibm.vis.rave2bundleradialbar";
  1163. break;
  1164. case "rave-library-bubble,packedBubble":
  1165. v_oWidget.visId = "com.ibm.vis.rave2bundlepackedbubble";
  1166. break;
  1167. case "rave-library-wordcloud,wordcloud":
  1168. v_oWidget.visId = "com.ibm.vis.rave2bundlewordcloud";
  1169. break;
  1170. case "rave-library-pie,pie":
  1171. v_oWidget.visId = "com.ibm.vis.rave2bundlepie";
  1172. break;
  1173. case "rave-library-heatmap,heatmap":
  1174. v_oWidget.visId = "com.ibm.vis.rave2heat";
  1175. break;
  1176. case "rave-library-bubble,bubble":
  1177. v_oWidget.visId = "com.ibm.vis.ravebubble";
  1178. break;
  1179. case "rave-library-composite,compositeOneDataSet":
  1180. v_oWidget.visId = "com.ibm.vis.rave2bundlecomposite";
  1181. break;
  1182. }
  1183. };
  1184. V5ToDashboard.f_createVizSlot = function (v_nSelection, v_sVizType, v_nDataItem)
  1185. {
  1186. if (v_nSelection.nodeName !== 'viz')
  1187. {
  1188. return null;
  1189. }
  1190. var v_sDataItemName = v_nDataItem.getAttribute("name");
  1191. var v_oSlot = {};
  1192. v_oSlot.dataItems = [];
  1193. v_oSlot.dataItems.push(v_sDataItemName);
  1194. var v_bIsMeasure = this.F_IsLikelyMeasure(v_nDataItem);
  1195. var v_nVizValue;
  1196. switch (v_sVizType)
  1197. {
  1198. case "rave-library-column,clusteredcolumn":
  1199. case "rave-library-column,clusteredbar":
  1200. case "rave-library-column,stackedcolumn":
  1201. case "rave-library-column,stackedbar":
  1202. case "rave-library-area,area":
  1203. case "rave-library-line,line":
  1204. case "rave-library-bubble,point":
  1205. if (v_bIsMeasure)
  1206. {
  1207. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
  1208. } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='xEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
  1209. v_nSelection.querySelector("vizCategoryEdge[refEdge='xEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
  1210. {
  1211. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1212. } else
  1213. {
  1214. switch (v_sVizType)
  1215. {
  1216. case "rave-library-area,area":
  1217. case "rave-library-line,line":
  1218. case "rave-library-bubble,point":
  1219. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "series";
  1220. break;
  1221. default:
  1222. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1223. break;
  1224. }
  1225. }
  1226. v_oSlot.dataItems = [];
  1227. v_oSlot.dataItems.push(v_sDataItemName);
  1228. break;
  1229. case "rave-library-bubble,scatter":
  1230. if (v_bIsMeasure)
  1231. {
  1232. v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
  1233. v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
  1234. v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_nVizValue.getAttribute('idField');
  1235. } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
  1236. v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
  1237. {
  1238. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1239. } else
  1240. {
  1241. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1242. }
  1243. break;
  1244. case "rave-library-dial,dial":
  1245. if (v_bIsMeasure)
  1246. {
  1247. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
  1248. } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
  1249. v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
  1250. {
  1251. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1252. } else
  1253. {
  1254. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1255. }
  1256. break;
  1257. case "rave-library-bubble,packedBubble":
  1258. case "rave-library-wordcloud,wordcloud":
  1259. if (v_bIsMeasure)
  1260. {
  1261. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "size";
  1262. } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='labelEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
  1263. v_nSelection.querySelector("vizCategoryEdge[refEdge='labelEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
  1264. {
  1265. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1266. } else
  1267. {
  1268. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1269. }
  1270. break;
  1271. case "rave-library-pie,pie":
  1272. if (v_bIsMeasure)
  1273. {
  1274. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "values";
  1275. } else
  1276. {
  1277. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1278. }
  1279. break;
  1280. case "rave-library-heatmap,heatmap":
  1281. if (v_bIsMeasure)
  1282. {
  1283. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1284. } else if (v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizCategoryEdge[@refEdge='xEdge']//*[@refDataItem='" + v_sDataItemName + "']") :
  1285. v_nSelection.querySelector("vizCategoryEdge[refEdge='xEdge'] > * [refDataItem='" + v_sDataItemName + "']"))
  1286. {
  1287. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1288. } else
  1289. {
  1290. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "series";
  1291. }
  1292. break;
  1293. case "rave-library-bubble,bubble":
  1294. if (v_bIsMeasure)
  1295. {
  1296. v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
  1297. v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
  1298. v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_nVizValue.getAttribute('idField');
  1299. } else
  1300. {
  1301. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "color";
  1302. }
  1303. break;
  1304. case "rave-library-composite,compositeOneDataSet":
  1305. if (v_bIsMeasure)
  1306. {
  1307. v_nVizValue = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vizValue[@refDataItem='" + v_sDataItemName + "']") :
  1308. v_nSelection.querySelector("vizValue[refDataItem='" + v_sDataItemName + "']");
  1309. v_oSlot.name = v_oSlot.caption = v_oSlot.id = (v_nVizValue.getAttribute('idField') == 'yLine' ? 'lineValue' : 'columnValue');
  1310. } else
  1311. {
  1312. v_oSlot.name = v_oSlot.caption = v_oSlot.id = "categories";
  1313. }
  1314. break;
  1315. default:
  1316. return null;
  1317. }
  1318. return v_oSlot;
  1319. };
  1320. V5ToDashboard.f_createVizControlSlot = function (v_nSelection, v_nDataItem, v_sVisId)
  1321. {
  1322. var v_sDataItemName = v_nDataItem.getAttribute("name");
  1323. var v_oSlot = {};
  1324. v_oSlot.dataItems = [];
  1325. v_oSlot.dataItems.push(v_sDataItemName);
  1326. // TODO: support multiple data stores
  1327. var v_nVcSlotData = this.f_getAncestorNode(
  1328. v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDsColumn='" + v_sDataItemName + "']") : v_nSelection.querySelector("[refDsColumn='" + v_sDataItemName + "']"),
  1329. "vcSlotData");
  1330. if (v_sVisId == "com.ibm.vis.rave2bundletiledmap")
  1331. {
  1332. var v_nVcSlotDataSet = this.f_getAncestorNode(
  1333. v_bRunInProduction ? v_nSelection.selectSingleNode(".//*[@refDsColumn='" + v_sDataItemName + "']") : v_nSelection.querySelector("[refDsColumn='" + v_sDataItemName + "']"),
  1334. "vcDataSet");
  1335. v_oSlot.layerId = v_nVcSlotDataSet.getAttribute("idDataSet");
  1336. }
  1337. var v_sRefDataStore = v_bRunInProduction ? v_nSelection.selectSingleNode(".//vcDataSet").getAttribute("refDataStore") :
  1338. v_nSelection.querySelector("vcDataSet").getAttribute("refDataStore");
  1339. var v_sIdSlot = v_nVcSlotData.getAttribute("idSlot");
  1340. v_oSlot.name = v_oSlot.caption = v_oSlot.id = v_sIdSlot;
  1341. return v_oSlot;
  1342. };
  1343. return V5ToDashboard;
  1344. });