Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.95 KB | None | 0 0
  1. jQuery.sap.require('FactSheets.utils.Utils');
  2. jQuery.sap.require('FactSheets.controllers.BP._common');
  3. jQuery.sap.require('FactSheets.utils.GlobalProperties');
  4.  
  5. jQuery.sap.require("sap.ui.core.util.Export");
  6. jQuery.sap.require("sap.ui.core.util.ExportTypeCSV");
  7. jQuery.sap.require("sap.ui.core.routing.History");
  8. jQuery.sap.require("sap.ui.core.routing.Router");
  9. jQuery.sap.require("sap.ui.core.format.DateFormat");
  10. jQuery.sap.require("sap.ui.model.Sorter");
  11.  
  12. var that;
  13. var results;
  14. var bp;
  15.  
  16. //global value of the latest left list package selected
  17. var currentPackageState;
  18. //global value of the lasted radio button selected
  19. var currentButtonState;
  20.  
  21. sap.ui.controller("FactSheets.controllers.VersioningRoots.BP.footprint",
  22. {
  23. _common: new _Common(),
  24. GlobalProperties: new GlobalProperties(this),
  25.  
  26. _countryCount: 0,
  27.  
  28.  
  29. onInit : function()
  30. {
  31. this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
  32. this._oRouter.attachRoutePatternMatched(this._handleRouteMatched, this);
  33.  
  34. this.getView().setModel(new sap.ui.model.json.JSONModel(), "common");
  35. that = this;
  36.  
  37.  
  38. // var sortFragment = this._common.showIconFragment('SortDialog', 'DisplayTimeFrame_PackObjectDetailsss', this);
  39.  
  40.  
  41. ///??? var timeFrameFagment = this._common.showIconFragment('TimeFrame', 'DisplayTimeFrame_PackObjectDetails', this);
  42.  
  43. //Time Frame Filter
  44. // var timeFrameFagment = this._common.showIconFragment('TimeFrame', 'DisplayTimeFrame_PackCountry', this);
  45.  
  46. // Other
  47. currentButtonState = "include one Sublevel";
  48. currentPackageState = "UICORE";
  49. this._utils = new Utils(this);
  50. var oModel = new sap.ui.model.odata.ODataModel(serviceUrl, false);
  51. oModel.setDefaultCountMode(false);
  52. oModel.setSizeLimit(50000000);
  53. this.getView().setModel(oModel);
  54.  
  55.  
  56. },
  57.  
  58.  
  59. onAfterRendering : function(){
  60.  
  61. var oSplitCont = this.getView().byId(this.createId("splitContainer"));
  62. var ref = oSplitCont.getDomRef() && oSplitCont.getDomRef().parentNode;
  63. var oTable = this.getView().byId(this.createId("table"));
  64.  
  65. },
  66.  
  67. handleSortButtonPress: function(oEvent){
  68.  
  69. var sortFragment = sap.ui.jsfragment("FactSheets.fragments.BP.SortDialog", that);
  70. sortFragment.placeAt('DisplayTimeFrame_PackObjectDetailsss');
  71. sortFragment.open();
  72.  
  73. },
  74. handleSortDialogConfirm: function(oEvent){
  75.  
  76. var mParams = oEvent.getParameters();
  77. var sPath = mParams.sortItem.getKey();
  78.  
  79.  
  80. var desc = mParams.sortDescending;
  81.  
  82. var oTable = that.getView().byId(this.createId("table"));
  83.  
  84. oTable.removeAllItems();
  85.  
  86. if(sPath == "PACKAGE"){
  87.  
  88. var dataFilter = that._utils.MODEL.getAllMoBpPage(bp);
  89.  
  90.  
  91. if(desc) {
  92.  
  93. dataFilter = dataFilter.sort(function(a,b){
  94. if( a.PACKAGE_NAME > b.PACKAGE_NAME){
  95. return -1;
  96. }
  97. else{
  98. return 1;
  99. }
  100.  
  101. })
  102. }else{
  103.  
  104. dataFilter = dataFilter.sort(function(a,b){
  105. return b.PACKAGE_NAME - a.PACKAGE_NAME;
  106.  
  107. })
  108. }
  109.  
  110. for(var i = 0; i < dataFilter.length; i++){
  111. var pack = dataFilter[i].PACKAGE_NAME;
  112. var mos = dataFilter[i].MO_COUNT;
  113. var traffic = dataFilter[i].TRAFFIC;
  114.  
  115. var columnListItem = new sap.m.ColumnListItem({
  116.  
  117. cells: [
  118. new sap.m.Text({
  119. text : pack
  120. }),
  121. new sap.m.Text({
  122. text : mos
  123. }),
  124. new sap.m.Text({
  125. text: traffic
  126. })
  127. ],
  128. type: 'Active'
  129. })
  130.  
  131. oTable.addItem(columnListItem);
  132. }
  133. }
  134. if(sPath == "mos"){
  135.  
  136. var dataFilter = that._utils.MODEL.getAllMoBpPage(bp);
  137.  
  138. if(desc){
  139. dataFilter = dataFilter.sort(function(a,b){
  140. return b.MO_COUNT - a.MO_COUNT;
  141.  
  142. })
  143. }else{
  144. dataFilter = dataFilter.sort(function(a,b){
  145. return a.MO_COUNT - b.MO_COUNT;
  146.  
  147. })
  148. }
  149.  
  150.  
  151.  
  152. for(var i = 0; i < dataFilter.length; i++){
  153. var pack = dataFilter[i].PACKAGE_NAME;
  154. var mos = dataFilter[i].MO_COUNT;
  155. var traffic = dataFilter[i].TRAFFIC;
  156.  
  157. var columnListItem = new sap.m.ColumnListItem({
  158.  
  159. cells: [
  160. new sap.m.Text({
  161. text : pack
  162. }),
  163. new sap.m.Text({
  164. text : mos
  165. }),
  166. new sap.m.Text({
  167. text: traffic
  168. })
  169. ],
  170. type: 'Active'
  171. })
  172.  
  173. oTable.addItem(columnListItem);
  174. }
  175. }
  176. if(sPath == "TRAFFIC"){
  177.  
  178. var dataFilter = that._utils.MODEL.getAllMoBpPage(bp);
  179.  
  180. if(desc){
  181. dataFilter = dataFilter.sort(function(a,b){
  182. return b.TRAFFIC - a.TRAFFIC;
  183.  
  184. })
  185. }else{
  186. dataFilter = dataFilter.sort(function(a,b){
  187. return a.TRAFFIC - b.TRAFFIC;
  188.  
  189. })
  190. }
  191.  
  192. for(var i = 0; i < dataFilter.length; i++){
  193. var pack = dataFilter[i].PACKAGE_NAME;
  194. var mos = dataFilter[i].MO_COUNT;
  195. var traffic = dataFilter[i].TRAFFIC;
  196.  
  197. var columnListItem = new sap.m.ColumnListItem({
  198.  
  199. cells: [
  200. new sap.m.Text({
  201. text : pack
  202. }),
  203. new sap.m.Text({
  204. text : mos
  205. }),
  206. new sap.m.Text({
  207. text: traffic
  208. })
  209. ],
  210. type: 'Active'
  211. })
  212.  
  213. oTable.addItem(columnListItem);
  214. }
  215. }
  216.  
  217. },
  218.  
  219. handleGroupButtonPress: function(oEvent){
  220.  
  221. var sortFragment = sap.ui.jsfragment("FactSheets.fragments.BP.GroupDialog", that);
  222. sortFragment.placeAt('DisplayTimeFrame_PackObjectDetailsss');
  223. sortFragment.open();
  224. },
  225. handleGroupDialogConfirm: function(oEvent){
  226. //todo
  227. alert("group dialog confirm");
  228. },
  229.  
  230. //prepare the result for the treemap
  231. //for "comapre with other Business Partner" radio button
  232. fetchTreemapResultSetCompareOtherBp: function(packageName, depth, bp1, bp2){
  233. var model = "/CA_USAG_BP_PACKAGE_FOOTPRINT_V3Parameters";
  234.  
  235. var viewPath = model + "(IP_USAG_PACKAGE='"+packageName+"',IP_USAG_DEPTH="+depth+"" +
  236. ",IP_USAG_START_MONTH='201803',IP_USAG_END_MONTH='201902',IP_USAG_BP1='"+bp1+"', IP_USAG_BP2='"+bp2+"')/Results";
  237.  
  238.  
  239. $.ajax({
  240. async: true,
  241. url: serviceUrl + viewPath,
  242. type: 'GET',
  243. cache: false,
  244. dataType: 'JSON',
  245. success: function(data) {
  246. var results = data.d.results;
  247. if(results.length > 0) {
  248.  
  249. // that.loadHeatMap(results);
  250. that.loadTreeMap(results);
  251. }else{
  252.  
  253. }
  254. },
  255. error: function() {
  256.  
  257. }
  258. });
  259. },
  260.  
  261. //prepare the results for the treemap
  262. //for "include one Sublevel" or "include two Sublevels" --> depth = 1,2
  263. fetchTreemapResultSetLevels: function(packageName, depth,bp){
  264.  
  265. var model = "/CA_USAG_BP_PACKAGE_FOOTPRINTParameters";
  266.  
  267. var viewPath = model + "(IP_USAG_PACKAGE='"+packageName+"',IP_USAG_DEPTH="+depth+"" +
  268. ",IP_USAG_START_MONTH='201803',IP_USAG_END_MONTH='201902',IP_USAG_BP='"+bp+"')/Results";
  269.  
  270.  
  271.  
  272. $.ajax({
  273. async: true,
  274. url: serviceUrl + viewPath,
  275. type: 'GET',
  276. cache: false,
  277. dataType: 'JSON',
  278. success: function(data) {
  279. var results = data.d.results;
  280. if(results.length > 0) {
  281.  
  282. // that.loadHeatMap(results);
  283. that.loadTreeMap(results);
  284. }else{
  285.  
  286. }
  287. },
  288. error: function() {
  289.  
  290. }
  291. });
  292. },
  293.  
  294. //plot the treemap based on the resultSet(response) retrieved above
  295. loadTreeMap: function(response){
  296.  
  297. var CustomersPerIndustryChart = this.getView().byId(this.createId("treemap"));
  298.  
  299. var usageChart_1 = new sap.ui.model.json.JSONModel();
  300. var data = {"##data": response};
  301. usageChart_1.setData(data);
  302.  
  303. var treeDataset = new sap.viz.ui5.data.FlattenedDataset({
  304. dimensions : [
  305. {axis : 1,
  306. name : 'PACKAGE_NAME',
  307. value : '{PARENTPACKAGE}'
  308. },
  309. {axis : 1,
  310. name : 'PACKAGE_TECHNICAL_NAME',
  311. value : '{PACKAGE_TECHNICAL_NAME}'
  312. } ],
  313. measures : [ {
  314. group : 1,
  315. name : 'MO_FOOTPRINT',
  316. value : '{MO_FOOTPRINT}'
  317. } ],
  318. data : {
  319. path : "/##data"
  320. }
  321. });
  322.  
  323. CustomersPerIndustryChart.setDataset(treeDataset);
  324. CustomersPerIndustryChart.setModel(usageChart_1);
  325. CustomersPerIndustryChart.setBusy(false);
  326.  
  327.  
  328. },
  329.  
  330. loadHeatMap: function(response){
  331.  
  332. var that = this;
  333. var CustomersPerIndustryChart = this.getView().byId(this.createId("CustomersPerIndustryChartt"));
  334.  
  335. var usageChart_1 = new sap.ui.model.json.JSONModel();
  336. var data = {"##data": response};
  337. usageChart_1.setData(data);
  338.  
  339.  
  340. if (CustomersPerIndustryChart.getDataset() == null){
  341.  
  342. CustomersPerIndustryChart.setVizType('heatmap');
  343. var oDatasetCustomersPerIndustryChart = new sap.viz.ui5.data.FlattenedDataset(
  344. {
  345. dimensions : [ {
  346. axis : 1,
  347. name : "Country",
  348. value : "{PACKAGE_NAME}"
  349. },
  350. {
  351. axis : 1,
  352. name : "Industry",
  353. value : "{PACKAGE_TECHNICAL_NAME}"
  354. }],
  355. measures : [ {
  356. group: 1,
  357. name : "Count",
  358. value : '{MO_COUNT_TOTAL}'
  359. },
  360. {
  361. group:1,
  362. name: "CountBp",
  363. value: '{MO_COUNT_TOTAL}'
  364. }],
  365. data : {
  366. path: "/##data"
  367. }
  368. });
  369.  
  370. CustomersPerIndustryChart.setDataset(oDatasetCustomersPerIndustryChart);
  371. CustomersPerIndustryChart.setModel(usageChart_1);
  372. var feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem(
  373. { uid : "color",
  374. type : "Measure",
  375. values : [ "Count" ]
  376. }),
  377. feedColor2 = new sap.viz.ui5.controls.common.feeds.FeedItem(
  378. {
  379. uid : "color2",
  380. type : "Measure",
  381. values : [ "CountBp" ]
  382. }),
  383.  
  384. feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem(
  385. {
  386. uid : "categoryAxis",
  387. type : "Dimension",
  388. values : [ "Country" ]
  389. }),
  390. feedCategoryAxis2 = new sap.viz.ui5.controls.common.feeds.FeedItem(
  391. {uid : "categoryAxis2",
  392. type : "Dimension",
  393. values : [ "Industry" ]
  394.  
  395. });
  396.  
  397. CustomersPerIndustryChart.addFeed(feedColor);
  398. CustomersPerIndustryChart.addFeed(feedColor2);
  399. CustomersPerIndustryChart.addFeed(feedCategoryAxis);
  400. CustomersPerIndustryChart.addFeed(feedCategoryAxis2);
  401.  
  402.  
  403. CustomersPerIndustryChart.setVizProperties(
  404. {
  405.  
  406. plotArea : {
  407. gap : {
  408. visible : true
  409. },
  410. dataLabel:{
  411. visible: true
  412. }
  413. },
  414.  
  415. legend : {
  416. title : {
  417. visible : true
  418. }
  419. },
  420.  
  421. title : {
  422. visible : true,
  423. text : ''
  424. }
  425. });
  426. }
  427. else
  428. {
  429.  
  430. CustomersPerIndustryChart.destroyDataset();
  431. var oDatasetCustomersPerIndustryChart = new sap.viz.ui5.data.FlattenedDataset(
  432. {
  433. dimensions : [ {
  434. axis : 1,
  435. name : "Country",
  436. value : "{PACKAGE_NAME}"
  437. },
  438. {
  439. axis : 1,
  440. name : "Industry",
  441. value : "{PACKAGE_TECHNICAL_NAME}"
  442. }],
  443. measures : [ {
  444. name : "Count",
  445. value : '{MO_COUNT_TOTAL}'
  446. },
  447. {
  448. name : "CountBp",
  449. value : '{MO_COUNT_TOTAL}'
  450. }],
  451. data : {
  452. path: "/##data"
  453. }
  454. });
  455.  
  456. CustomersPerIndustryChart.setDataset(oDatasetCustomersPerIndustryChart);
  457. CustomersPerIndustryChart.setModel(usageChart_1);
  458. }
  459. },
  460. onRadioButtonSelect: function(oEvent){
  461.  
  462. var radioButtonGroup = that.getView().byId(this.createId("radioButtonGroup"));
  463. var heatMapChart = that.getView().byId(this.createId("CustomersPerIndustryChartt"));
  464. var searchField = that.getView().byId(this.createId("inputField"));
  465.  
  466. //check all radio buttons
  467. var selectedButton = radioButtonGroup.getSelectedButton();
  468.  
  469. //set the global currentButtonState to the latest selected value->
  470. //now we know what was the latest radio button selected
  471. currentButtonState = selectedButton.getText();
  472.  
  473. if(selectedButton.getText() == "include 2 Sublevels"){
  474. that.fetchTreemapResultSetLevels(currentPackageState, 2,bp);
  475. }
  476. if(selectedButton.getText() == "include one Sublevel"){
  477. that.fetchTreemapResultSetLevels(currentPackageState, 1,bp);
  478. }
  479. if(selectedButton.getText() == "compare with other Business Partner"){
  480. searchField.setVisible(true);
  481. }else{
  482. searchField.setVisible(false);
  483. }
  484.  
  485. },
  486.  
  487.  
  488.  
  489. onSearch: function(oEvent){
  490.  
  491. var query = oEvent.getParameter("query");
  492. var model = "/CA_USAG_BP_PACKAGE_BPListParameters";
  493. var packageName = currentPackageState;
  494.  
  495. var viewPath = model + "(IP_USAG_PACKAGE='"+packageName+"',IP_USAG_DEPTH=2,IP_USAG_START_MONTH='201803',IP_USAG_END_MONTH='201902')/Results";
  496.  
  497. $.ajax({
  498. async: true,
  499. url: serviceUrl + viewPath,
  500. type: 'GET',
  501. cache: false,
  502. dataType: 'JSON',
  503. success: function(data) {
  504. var results = data.d.results;
  505. if(results.length!=0)
  506. {
  507. var sf = that.getView().byId(that.createId("inputField"));
  508. sf.removeAllSuggestionItems();
  509. for(var i = 0 ; i < results.length; i++){
  510. if(results[i].BP_NAME.includes(query)){
  511.  
  512. var sugest = new sap.m.SuggestionItem({
  513. description: results[i].BP_ID,
  514. text: results[i].BP_NAME
  515. });
  516. sf.addSuggestionItem(sugest);
  517. }
  518. }
  519.  
  520. sf.suggest();
  521. }
  522.  
  523. },
  524. error: function() {
  525.  
  526. }
  527. });
  528.  
  529. //retrueve the other BP of the item searchd
  530. //plot treemap based on the BP
  531. var item = oEvent.getParameter("suggestionItem");
  532. if(item != null){
  533. var bpId = item.getDescription();
  534. that.fetchTreemapResultSetCompareOtherBp(packageName,1,bp,bpId);
  535. }
  536. },
  537.  
  538.  
  539. //bind CV to the left table list
  540. bindList: function(bp, packageName){
  541.  
  542. var data = this._utils.MODEL.getAllMoBpPage(bp,packageName);
  543. results = data;
  544.  
  545. var oTable = this.getView().byId(this.createId("table"));
  546. // oTable.setBusy(true);
  547.  
  548. oTable.removeAllItems();
  549.  
  550.  
  551.  
  552. for(var i = 0; i < data.length; i++){
  553.  
  554. var pack = data[i].PACKAGE_NAME;
  555. var mos = data[i].MO_COUNT;
  556. var traffic = data[i].TRAFFIC;
  557. var packKey = data[i].PACK_KEY;
  558. var technicalName = data[i].PACK_TECHNICAL_NAME;
  559. var bp = Number(data[i].BPARTNER);
  560.  
  561.  
  562. var columnListItem = new sap.m.ColumnListItem({
  563.  
  564. press:this.press,
  565. //the counter is the BP of the item (we need to set the bp on the item)
  566. counter: bp,
  567. customData: [
  568. new sap.ui.core.CustomData({
  569. key:"KEY",
  570. value: packKey
  571. }),
  572. new sap.ui.core.CustomData({
  573. key:"packName",
  574. value: technicalName
  575. })
  576.  
  577. ],
  578. cells: [
  579. new sap.m.Text({
  580. text : pack
  581. }),
  582. new sap.m.Text({
  583. text : mos
  584. }),
  585. new sap.m.Text({
  586. text: traffic
  587. }),
  588. new sap.m.Text({
  589. text: bp,
  590. visible: false
  591. })
  592. ],
  593. type: 'Active'
  594. })
  595.  
  596.  
  597. oTable.addItem(columnListItem);
  598.  
  599. }
  600.  
  601.  
  602. },
  603.  
  604. //on table list item pressed
  605. press: function(oEvent){
  606. var oTable = that.getView().byId(that.createId("table"));
  607. var radioButtonGroup = that.getView().byId(that.createId("radioButtonGroup"));
  608.  
  609. //when we convert string-> integer, we miss all the zeros ex: 000123->123, there are 4 zeros lost-> add them back
  610. var customData = oEvent.getSource().getCustomData()[0];
  611. var secondCustom = oEvent.getSource().getCustomData()[1];
  612. var bpInteger = oEvent.getSource().getCounter();
  613. var counterString = bpInteger.toString();
  614. var zeroNumber = 10 - counterString.length;
  615. var zeroString = '';
  616.  
  617. for(var i = 0 ; i < zeroNumber; i++){
  618. zeroString += '0';
  619. }
  620. var bpString = zeroString + counterString;
  621.  
  622. currentPackageState = secondCustom.getValue();
  623.  
  624.  
  625. that.bindList(bpString, customData.getValue());
  626.  
  627. //check what is the latest radio button selected
  628. //based on that we know on what scenario we should render the Treemap
  629.  
  630. if(currentButtonState == "include one Sublevel"){
  631. that.fetchTreemapResultSetLevels(secondCustom.getValue(), 1,bp);
  632.  
  633. }
  634. if(currentButtonState == "include 2 Sublevels") {
  635. that.fetchTreemapResultSetLevels(secondCustom.getValue(), 2,bp);
  636. }
  637.  
  638.  
  639. },
  640.  
  641.  
  642. buttonPress: function(){
  643.  
  644. var detailButton = that.getView().byId(this.createId("masterButton"));
  645. detailButton.setText('ce faci manutz');
  646.  
  647. var radioButtonGroup = that.getView().byId(this.createId("radioButtonGroup"));
  648.  
  649. },
  650.  
  651.  
  652. _handleRouteMatched : function(oEvent)
  653. {
  654.  
  655. // Get global data
  656. this.GlobalProperties.parseQueryURL(oEvent);
  657.  
  658. // Load detail data from MO service
  659. this._common.getDetailOfObject(this.GlobalProperties._currentMO_ID,this.GlobalProperties._typeMO);
  660.  
  661. // log Usage
  662. // var insertLogViews = this._utils.MODEL.insertLogViews('PackageDetail.Country',this.GlobalProperties._typeMO,this.GlobalProperties._currentMO_ID);
  663. var insertLogViews = this._utils.MODEL.insertLogViews('BP.Details',this.GlobalProperties._typeMO,this.GlobalProperties._currentMO_ID);
  664.  
  665.  
  666. // this._common.showIconFragment('IconFragment', 'DisplayIconPackCountryy', this);
  667. // this._common.showIconFragment('IconFragment', 'DisplayIconPackObjectDetails', this);
  668. // this.setSelectedIcon();
  669.  
  670. // this.setFilterData(this);
  671. var bpp = oEvent.getParameter("arguments").id;
  672. bp = bpp;
  673. this.bindList(bpp, '*');
  674. this.fetchTreemapResultSetLevels('UICORE',1,bp);
  675.  
  676.  
  677. },
  678.  
  679.  
  680.  
  681.  
  682. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement