Repository navigation
Expand file tree
/
Copy pathtemp.js
More file actions
3062 lines (2675 loc) · 116 KB
/
Copy pathtemp.js
File metadata and controls
3062 lines (2675 loc) · 116 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*global jQuery:false */
/*global huawei:false */
/*global sap:false */
/*global localStorage:false */
/*global setTimeout:false */
/*global $:false */
/*global window:false */
/*global document:false */
(function () {
"use strict";
//import library
jQuery.sap.declare("huawei.cmes.quality.QualityPage");
//jQuery.sap.require("huawei.cmes.fragment.quality.Report");
jQuery.sap.require("huawei.cmes.util.settings.Authorization");
jQuery.sap.require("huawei.cmes.util.parameters.QualityChartsParameters");
jQuery.sap.require("huawei.cmes.util.commons.Formatters");
jQuery.sap.require("huawei.cmes.util.chart.Helper");
jQuery.sap.require("huawei.cmes.util.services.Provider");
jQuery.sap.require("huawei.cmes.util.services.Proxy");
jQuery.sap.require("huawei.cmes.control.charts.QualityCharts");
jQuery.sap.require("huawei.cmes.control.charts.KPIChart");
jQuery.sap.require("huawei.cmes.control.Filter.MESFilter");
jQuery.sap.require("huawei.cmes.util.services.Http");
jQuery.sap.require("sap.ui.core.format.DateFormat");
jQuery.sap.require("huawei.cmes.quality.setting.Config");
//constant variable
var PROXY = huawei.cmes.util.services.Proxy;
var QUALITY_SERVICE = huawei.cmes.util.services.Provider.QualityService;
var QUALITY_ODATA = huawei.cmes.util.services.Provider.QualityOData;
var HTTP = huawei.cmes.util.http;
var HELPER = huawei.cmes.util.commons.Helper;
var CHART_HELPER = huawei.cmes.util.chart.Helper;
var AUTHORIZATION = huawei.cmes.util.settings.Authorization;
sap.ui.controller(
"huawei.cmes.quality.view.QualityPage",
/**
* @author lWX209333
* $("#__xmlview0--Column2ChartVBox .v-row[class*='ID_0'] text").text(':');
*
*/
{
pageName: 'quality',
onInit: function () {
this.initCategory();
this.initialURLs();
this.initMappings();
this.initGlobalTime();
AUTHORIZATION.checkAuthorization('quality');
/**
* Fragments
*/
//the fragment for the chart on column2
this._chartDlg = sap.ui.xmlfragment(
"huawei.cmes.fragment.quality.Sub1ChartDlg", this);
//the fragment for drop-down list of dimensions on upper part of column3
this._dimensionDDL = sap.ui.xmlfragment(
"huawei.cmes.fragment.quality.DimensionDDL", this);
//the fragment for all warning messages
this._warnMsgDlg = sap.ui.xmlfragment(
"huawei.cmes.fragment.quality.WarningMsg", this);
//the fragment for defect chart type popover
this._defectChartTypePopover = sap.ui.xmlfragment(
"huawei.cmes.fragment.quality.DefectChartTypePopover", this);
//the fragment for report
this._reportPage = sap.ui.jsfragment(
"huawei.cmes.fragment.quality.Report", this);
if (sap.ui.getCore().byId("InformationDlg") !== undefined) {
sap.ui.getCore().byId("InformationDlg").destroy();
}
//the fragment for information popover/dialog
this.informationMsg = sap.ui.xmlfragment(
"huawei.cmes.fragment.commons.InformationMsg", this);
this.getView().addDependent(this.informationMsg);
this.getView().addDependent(this._chartDlg);
this.getView().addDependent(this._dimensionDDL);
this.getView().addDependent(this._warnMsgDlg);
this.getView().addDependent(this._defectChartTypePopover);
this.getView().addDependent(this._reportPage);
this.bus = sap.ui.getCore().getEventBus();
//set displaying language
this.languageSetting();
//Initialize Quality Charts
this.initPage();
},
/**
* Ajax Get Method
*
* @param url
* @param model
* @param func
*/
ajaxGet: HTTP.ajaxGet,
deepClone: HELPER.deepClone,
/**
* [onReportOpen - open the report]
* @param {[type]} oEvent [description]
* @return {[type]} [description]
*/
onReportOpen: function (oEvent) {
this._reportPage.open();
},
/**
* Initial Service URLs
*/
initialURLs: function () {
//get the
this._dimValueService = QUALITY_SERVICE.getm;
this._settingService = QUALITY_SERVICE.getDimColloection;
//URL to get all dimensions of a KPI for build filter
this._filterDims = QUALITY_SERVICE.getv;
//URL for tiles' data on first column
this._column1Service = QUALITY_SERVICE.getKPIL1;
//URL for color set on tile data
this._column1ColorService = QUALITY_SERVICE.getKPIL1RYG;
//URL for KPI Charts on second column
this._column2Service = QUALITY_SERVICE.getKPIL2;
//URL for Dimension Charts on third column
this._column3Service = QUALITY_SERVICE.getKPIL3;
this._kpiNameService = QUALITY_ODATA.kpiName;
},
/**
* Initialize the category: network - default
*/
initCategory: function () {
var kpiType = huawei.cmes.util.commons.Helper
.getURLParameters('kpiType');
if (kpiType) {//if kpiType is exist
if (kpiType !== '00' && kpiType !== '01') {// if kpiType is not '00' or '01', show error
sap.ui.commons.MessageBox.alert(
'URL Invalid Parameter Value For: kpiType');
this._sCategory = 0;
sap.category = this._sCategory;
} else {//if kpiType is '00' or '01', get the key -- 0 or 1
this._sCategory = parseInt(kpiType.charAt(1));//this._sCategory is 0 or 1
sap.category = this._sCategory;
}
} else {//if kpiType is not exist
this._sCategory = 0;
sap.category = this._sCategory;
}
},
/**
* Index for charts display
* @type {Number}
*/
initIndexes: function () {
//index for tile on column1
this.c1 = 0;
//index for charts on column2
this.c2 = 0;
//default to select the first dimension (index = 0)
this.selectedDim = 0;
//page size for carousel on column2
this.sPagesize = 2;
//use to control the asynchronize data loading
this.loaded = 0;
},
/**
* KPI mapping info
*/
initMappings: function () {
//initial the indexs used for quality page
this.initIndexes();
//label colors on tiles
this._tileColors = [];
//use for data-binding of tiles on column1
this._tileData = [];
//kpi names
this._kpiNames = [];
this._orgKpiNames = [];
//YAxis adjust
this._yaxis = [];
//Global build chart filter
this._sqlFilter = "";
// kpi charts on column 2
this._kpiCharts = [];
// sub-dimension charts on column 3
this._dimCharts = [];
//Defect charts
this._dimOrgValues = [];
this._selectedDims = [];
this._defectTypes = ["defect_phenomenon", "defect_causes"];
this._defectIndex = 0; //select 'Defect Phenomenon' as default
this._curDefectChart = null; //selected defect chart
this._defectType = "pie"; //the default defect chart type - 'pie'
this._defectReload = true;
},
/**
* languageSetting - set displaying language
* The function is called when initial the controller
* @return {[type]} [description]
*/
languageSetting: function () {
this._sLocale = localStorage.getItem('LANG-KEY') || '';
this.oBundle = jQuery.sap.resources({
url: "i18n/messageBundle.properties",
locale: this._sLocale
});
//set the language
if (sLocale === 'en-US') {
sap.ui.getCore().getConfiguration().setLanguage('en-US');
} else {
sap.ui.getCore().getConfiguration().setLanguage('zh-CN');
}
},
/**
* Generate tiles and charts on the page
*/
onAfterRendering: function () {
this.initialSettings();
var that = this;
//show selected start date, end date, and period(granularity of the statistical time) of the query
//in proper format on UI
this.showDateSelected();
var execToolTip = function () {
// alert('Working Now!');
that.initTooltip();
};
setInterval(execToolTip, 2000);
//when the window is resized
$(window).resize(function () {
//the chart on column2 will be reloaded based on the size of the window
that.loadColumn2Carousel();
that.adjustTileIconShown();
});
},
/**
* adjustTileIconShown description
* @return {none}
*/
adjustTileIconShown: function () {
var id = '#' + this.byId('tile-list').getId();
if ($(window).width() < 1195) {
setTimeout(function () {
$(id).find('.sapUiIcon').fadeOut();
}, 300);
} else {
setTimeout(function () {
$(id).find('.sapUiIcon').fadeIn();
}, 300);
}
},
/**
* initTooltip description
* @return {none}
*/
initTooltip: function () {
$('.v-row').hover(function (evt) {
sap.evt = evt;
var title = evt.currentTarget.querySelector('title');
var text = evt.currentTarget.querySelector('text');
var showtext = '';
var posotionX = evt.clientX;
var posotionY = evt.clientY - 30;
if (title) {
showtext +=
'<span class="tooltip" style="left:' +
posotionX + 'px;top:' + posotionY + 'px">' + title.textContent +
'</span>';
} else {
if (text) {
showtext +=
'<span class="tooltip" style="left:' +
posotionX + 'px;top:' + posotionY + 'px">' + text.textContent +
'</span>';
}
}
$('body').append(showtext);
}, function () {
$('.tooltip').remove();
});
$(window).bind('mousewheel DOMMouseScroll', function (event) {
$('.tooltip').remove();
});
},
/**
* [initialSettings description]
* @return {[type]} [description]
*/
initialSettings: function () {
$('#idViewRoot--idApp-MasterBtn').remove();
var kpiType = huawei.cmes.util.commons.Helper
.getURLParameters('kpiType');
// console.log(kpiType);
if (kpiType === '00') {
this.byId('CategorydecriptionSWT').setState(false);
} else if (kpiType === '01') {
this.byId('CategorydecriptionSWT').setState(true);
}
},
/**
* Initialize Quality Charts
*/
initPage: function () {
/*
var inforCollection = huawei.cmes.util.settings.Authorization.getLoginInfor("PAGE","HOME");
if(inforCollection === false){
var msg = "LOGIN_FAILED";
sap.ui.getCore().byId("information-msg").setText(this.oBundle.getText(msg));
this.informationMsg.open();
throw new Error("Login failed: "+ this.oBundle.getText(msg));
}
set default start/end/period on global time filter
*/
//before data comes back form backend:
//set busy for quality component
sap.ui.getCore().byId("QualityComponent").setBusy(true);
//set all charts invisible
this.getView().byId("ChartRow").setVisible(false);
//set the switch button on right upper corner disabled
sap.ui.getCore().byId('__xmlview0--CategorydecriptionSWT').setEnabled(
false);
//If succeed to get all kpi names, drawPage
this.getAllKPINames();
setInterval(function () {
HELPER.checkSessionExpiration();
}, 1000);
},
/**
* initGlobalTime - initial the query time(start&end date) and period (granularity)
* The function is called when initial the controller
* @return {none}
*/
initGlobalTime: function () {
//clear the temporary period
this._tmpPeriod = null;
//clear the temporary start date
this._tmpStartDate = null;
//clear the temporary end date
this._tmpEndDate = null;
//once the start date is initialied, don't run this function again
if (this._tileStartDate !== undefined) return;
//get current date
var curDate = new Date();
//HELPER.getLastMonth(curDate);
//get current year
var eYear = curDate.getFullYear();
//get current month
var eMonth = curDate.getMonth() + 1;
//get current date
var eDay = curDate.getDate();
//get current date
var todayDate = new Date();
//get current year
var startYear = todayDate.getFullYear();
//get current month - 1
var startMonth = todayDate.getMonth();//0-11
var thisMonth15 = startYear + '/' + (startMonth + 1) + '/15';
//14Month Ago
var startTime = new Date(new Date(thisMonth15).getTime() - 2592000000 * 13);//2592000000 * 13 ?
var firstDayOfMonth = new Date(new Date(startTime).setDate('01'));
var sMonth = firstDayOfMonth.getMonth() + 1;
var sYear = firstDayOfMonth.getFullYear();
var sDay = "01";
//两位数
eMonth = eMonth > 9 ? eMonth : "0" + eMonth;
sMonth = sMonth > 9 ? sMonth : "0" + sMonth;
eDay = eDay > 9 ? eDay : "0" + eDay;
//yyyy-mm-dd
this._globalEndDate = eYear + "-" + eMonth + "-" + eDay;
this._globalStartDate = sYear + "-" + sMonth + "-" + sDay;
this._tileStartDate = this._globalStartDate;
this._tileEndDate = this._globalEndDate;
this._globalPeriod = "MONTH";
this._globalPeriodLegend = "ActualValue";
sap.startDate = this._tileStartDate;
},
/*******************************************************************
* *****Data Binding
******************************************************************/
/**
* getAllKPINames - get KPI Names from backend, this function is called when initial the page
* The function is called when initial the Quality Page
* @return {none}
*/
getAllKPINames: function () {
var that = this;
//set the request URL
var oDataURL = huawei.cmes.util.services.Proxy
.XsodataProxy(this._kpiNameService);
var oFilter =
"/master_kpi?$filter=COMPONENT_KEY eq 'QUALITY' and KPI_TYPE eq '" +
this._sCategory + "' and ENABLE_TAG eq '1'";
//the array use to save temparory data
var info = [];
//the callback function
var dataHandler = function (oData, info) {
//since the data comes back:
//set the UI available
sap.ui.getCore().byId("QualityComponent").setBusy(false);
//display all charts
that.getView().byId("ChartRow").setVisible(true);
info = oData.d.results;
for (var i = 0; i < info.length; i++) {
//only the data with COMPONENT_ID = 1 is useful
if (info[i].COMPONENT_ID != 1) {
continue;
}
//info[i].KPI_TYPE: 0 Network, 1 Terminal
//that._kpiNames stores kpinames
if (that._kpiNames[info[i].KPI_TYPE] === undefined) {
//if no kpi names for KPI_TYPE(0 OR 1) have been saved, create corresponding array
that._kpiNames[info[i].KPI_TYPE] = [];
}
// e.g. 0: material quality, 1: process quality , 2: customer quality
var sbIndex = info[i].SUB_COMPONENT_ID.substr(
info[i].SUB_COMPONENT_ID.length - 1, 1);
sbIndex = parseInt(sbIndex) - 1;
if (sbIndex < 0) {
continue;
};
//if no kpi names for corresponding sub-component,
//e.g., Network, material quality - that._kpiNames[0][0],
//create array for it
if (that._kpiNames[info[i].KPI_TYPE][sbIndex] === undefined) {
that._kpiNames[info[i].KPI_TYPE][sbIndex] = [];
}
//info[i].KPI_TYPE - network/terminal
//sbIndex - incoming material quality, in process quality.....
//00315717 change TPY into FPY while network;change TPY into PY while terimal
var KPI_KEY = info[i].KPI_KEY;
if (KPI_KEY === 'TPY' && that._sCategory === 0) {
KPI_KEY = 'FPY';
} else if (KPI_KEY === 'TPY' && that._sCategory === 1) {
KPI_KEY = 'PY';
}
that._kpiNames[info[i].KPI_TYPE][sbIndex].push(KPI_KEY);
}
//draw page
that.drawPage();
$('.v-clippath').remove();
};
//get data form backend
this.ajaxGet(oDataURL + oFilter, info, dataHandler);
},
/**
* getTileData data binding for tiles on first column
* The function is called when load tile boxes on UI
*/
getTileData: function () {
var that = this;
//get tile vbox from ui and set empty json model for it
var tileVBox = this.getView().byId("TileVBox");
var oModel = new sap.ui.model.json.JSONModel();
tileVBox.setModel(oModel);
/* setTimeout(tileVBox.setBusy(false), 30 * 1000);*/
//compose request url
var kpiReqURL = PROXY.XsjsProxy(this._column1Service);
kpiReqURL +=
"?Component=QUALITY" +
"&Datef=" + this._tileStartDate +
"&Datet=" + this._tileEndDate +
"&KType=" + this._sCategory;
//callback function
var kpiDataHandler = function (oData, tileVBox) {
//use to save model data
var tileData = [];
//use to save sub component names
var subComps = [];
//icons for sub components
var icons = huawei.cmes.quality.setting.Config.tileIcons;
//the index indicates which sub component the kpi belongs to
var index = 0;
//the temporary tile object
var tile = {};
//use to save the current tile unit
var tileUnit = '';
for (var i = 0; i < oData.length; i++) {
//get index of component
index = subComps.indexOf(oData[i].SUB_COMPONENT_NAME);
//get hte tile unit
tileUnit = oData[i].UNIT === "PCS" ? that.oBundle.getText("PCS_Q") : oData[i].UNIT;
//if tile is not exist (index < 0), add it into the subComps array
if (index < 0) {
subComps.push(oData[i].SUB_COMPONENT_NAME);
//generate the tile object based on the data-binding need
tile = {
"SUB_COMPONENT_NAME": oData[i].SUB_COMPONENT_NAME,
"ICON": icons[subComps.length - 1],
"KPIs": [{
"KPI_NAME": that.oBundle.getText(oData[i].KPI_NAME),
"KPI_VALUE": oData[i].KPI_VALUE,
"UNIT": tileUnit
}]
};
//add the new tile object into the tileData array
tileData.push(tile);
} else {
//if tile is exist, update it
tile = tileData[index];
//add current KPI relative info into the corresponding sub component
tile.KPIs.push({
"KPI_NAME": that.oBundle.getText(oData[i].KPI_NAME),
"KPI_VALUE": oData[i].KPI_VALUE,
"UNIT": tileUnit
});
}
}
//that._sCategory - network / terminal
tileVBox.getModel().setData(tileData);
//save the tile data of current category, for example network, to improve the performance
that._tileData[that._sCategory] = tileData;
//Set the tile value color based on loaded data
that.setTileColor();
tileVBox.setBusy(false);
setTimeout(function () {
that.adjustTileIconShown();
$('.v-clippath').remove();
}, 200);
};
//if the data of the tile is not exist, request for the data
if (this._tileData[this._sCategory] === undefined) {
tileVBox.setBusy(true);
this.ajaxGet(kpiReqURL, tileVBox, kpiDataHandler);
} else {
//if the data of the tile is exist, update the tile
tileVBox.getModel().setData(this._tileData[this._sCategory]);
//set tile color based on the data from backend
this.setTileColor();
}
},
/**
* setTileColor set color for kpi values on tiles based on the data
* The function is called when bind data for tiles on column1
*/
setTileColor: function () {
var tileVBox = this.getView().byId("TileVBox");
var tileItems = tileVBox.getItems()[0].getItems();
for (var i = 0; i < tileItems.length; i++) {
//set the css class for the last tile
if (i === tileItems.length - 1) {
//the css class for last tile item is special
//the bottom border is shown for last item
tileItems[i].addStyleClass("last-tile-itme");
} else {
tileItems[i].addStyleClass("showborder-tile-item");
}
//initial the kpi and class name
var kpiName = '',className = '';
//set the defualt color code - 3: Green
var colorCode = 3;
//get the sub componnet box which contains the kpi rows
var tilePerComp = tileItems[i].getContent()[0].getItems()[1].
getItems()[1].getItems();
//loop every kpi rows for each sub component
for (var j = 0; j < tilePerComp.length; j++) {
//kpi name of current row
kpiName = tilePerComp[j].getContent()[0].getText().split(':')[0];
//if the color info cames back, set the color code
if (this._tileColors[this._sCategory][kpiName] !== undefined) {
colorCode = parseInt(this._tileColors[this._sCategory][kpiName]);
switch (colorCode) {
//set class name based on the color code
case 0:
className = "tile-kpi-value-red";
break;
case 1:
className = "tile-kpi-value-yellow";
break;
case 2:
className = "tile-kpi-value-green";
break;
}
tilePerComp[j].getContent()[1].addStyleClass(className);
}
}
}
//high light the first column of the tile
//this.c1 - the index of selected tile on column1
this.highlightOneTile(this.c1);
},
/**
* getTileColor request backend for the color of kpi values
* The function is called when load tile boxes on UI
*/
getTileColor: function () {
//get the tile vbox
var tileVBox = this.getView().byId("TileVBox");
var that = this;
var kpiName = '';
//callback function
var kpiColorDataHandler = function (oData) {
for (var i = 0; i < oData.length; i++) {
//get the kpi name
kpiName = that.oBundle.getText(oData[i].KPI_NAME);
//save the color code in corresponding position
//e.g. Network, TPY , red - that._tileColors[0][TPY] = 0
that._tileColors[that._sCategory][kpiName] = oData[i].RYG;
}
//set class for corresponding KPI value
that.tileValueFormatter(that, that._tileColors[that._sCategory]);
$('.v-clippath').remove();
};
//if no color code is fetched from backend for current category, send request
if (this._tileColors[this._sCategory] === undefined) {
this._tileColors[this._sCategory] = [];
var kpiColorReqURL = PROXY.XsjsProxy(this._column1ColorService);
kpiColorReqURL +=
"?Component=QUALITY" +
"&Datef=" + this._tileStartDate +
"&Datet=" + this._tileEndDate +
"&KType=" + this._sCategory;
//request data from backend
this.ajaxGet(kpiColorReqURL, tileVBox, kpiColorDataHandler);
}
},
/**
* setColumn2ChartModel - set model data for KPI chart on column2
* 为第二列的图集,滚动组图请求并绑定数据
* @param {[chart]} oChart - kpi chart
*/
setColumn2ChartModel: function (oChart) {
var that = this;
//如果当前KPI,在所选时间颗粒度下无意义,则赋予空值
if (!this.isValidPeriod(oChart.KPI, this._globalPeriod)) {
oChart.getModel().setData('');
//mark this chart is loaded
that.loaded++;
//check whether all charts are loaded
that.isFullLoaded();
return;
}
//set busy on current kpi chart
oChart.getKPIChart().setBusy(true);
// kpi name for current chart
var kpiName = oChart.KPI;
//generate request URL
kpiName = jQuery.sap.encodeURL(kpiName);
var oFilter = "?KPI=" + kpiName + "&KType=" + this._sCategory +
"&Prd=" + this._globalPeriod + "&Datef=" + this._globalStartDate +
"&Datet=" + this._globalEndDate;
var reqURL = PROXY.XsjsProxy(this._column2Service);
reqURL += oFilter;
//callback function
//oData - Array of data that from backend
//oChart - current kpi chart
var dataHandler = function (oData, oChart) {
//the data sample:
//oData = [{P_VALUE:99.325,C_VALUE:0,T_VALUE:99,UNIT:'%',PERIOD:'2014-01'},{P_VALUE:99.431,C_VALUE:99.387,T_VALUE:99,UNIT:'%',PERIOD:'2014-02'},{P_VALUE:99.302,C_VALUE:99.349,T_VALUE:99,UNIT:'%',PERIOD:'2014-03'},{P_VALUE:99.29,C_VALUE:99.332,T_VALUE:99,UNIT:'%',PERIOD:'2014-04'},{P_VALUE:99.259,C_VALUE:99.315,T_VALUE:99,UNIT:'%',PERIOD:'2014-05'},{P_VALUE:99.347,C_VALUE:99.321,T_VALUE:99,UNIT:'%',PERIOD:'2014-06'},{P_VALUE:99.238,C_VALUE:99.308,T_VALUE:99,UNIT:'%',PERIOD:'2014-07'},{P_VALUE:99.235,C_VALUE:99.297,T_VALUE:99,UNIT:'%',PERIOD:'2014-08'},{P_VALUE:99.187,C_VALUE:99.289,T_VALUE:99,UNIT:'%',PERIOD:'2014-09'},{P_VALUE:'',C_VALUE:99.289,T_VALUE:99,UNIT:'%',PERIOD:'2014-10'},{P_VALUE:'',C_VALUE:99.289,T_VALUE:99,UNIT:'%',PERIOD:'2014-11'},{P_VALUE:'',C_VALUE:99.289,T_VALUE:99,UNIT:'%',PERIOD:'2014-12'},{P_VALUE:'',C_VALUE:99.289,T_VALUE:99,UNIT:'%',PERIOD:'2015-01'}];
//set model data for oChart
oChart.getModel().setData(oData);
//set unit
var unit = "";
//get the fragment of the chart
var frag = oChart.getParent().getParent().getParent();
//if the unit info is back:
if (oData !== undefined && oData[0] !== undefined && oData[0].UNIT !== undefined) {
unit = oData[0].UNIT === "PCS" ? that.oBundle.getText("PCS_Q") : oData[0].UNIT;
//save unit with the chart
oChart.setUnit(unit);
//get show text of the unit
unit = that.oBundle.getText("UNIT") + ": " + unit;
//set the show text on UI
frag.getRows()[1].getCells()[0].getContent()[0].setText(unit);
}
//update model data
setTimeout(function () {
oChart.getKPIChart().getDataset().updateData();
}, 10);
//Set first legend for dimension chart
that.setDimChartLegend();
CHART_HELPER.adjustChartYAxis(oChart.getKPIChart());
// CHART_HELPER.adjustChartPeriod(that._globalPeriod,that._globalStartDate,that._globalEndDate,oChart.getKPIChart());
oChart.getKPIChart().setBusy(false);
//mark this chart as loaded
that.loaded++;
//check whether all charts are loaded
that.isFullLoaded();
$('.v-clippath').remove();
};
this.ajaxGet(reqURL, oChart, dataHandler);
},
/**
* setColumn3ChartModel - get model data for Charts in Column3
* @param {[chart]} oChart - dimension chart
*/
setColumn3ChartModel: function (oChart) {
var that = this;
//this.c1 - the index of selected sub-component on column1
//this.c2 - teh index of selected KPI chart on column2
//kpiChart - huawei.cmes.control.charts.KPIChart
var kpiChart = this._kpiCharts[this.c1][this.c2];
//get the original data model for current selected dimension
//this.selectedDim - the index of selected dimension
//kpiChart.dimModels - Array - use to save all dimensions' models to reduce the reload time
var orgDimModel = kpiChart.dimModels[this.selectedDim];
//get name of selected dimension
//kpiChart.dimNames - Array - use to save all dimension names of the KPI
var curDimNames = kpiChart.dimNames[this._sCategory];
if (curDimNames === undefined) {
//if no dimension name get from backend and saved with the KPI chart, return;
return;
}
//get the selected dimension name
var curDim = curDimNames[this.selectedDim];
//get the KPI name
var kpiName = this._kpiNames[this._sCategory][this.c1][this.c2];
//set empty model data
oChart.getModel().setData('');
//if the period(granularity of time) of the KPI is not valid
if (!this.isValidPeriod(kpiName, this._globalPeriod)) {
//set empty model data
oChart.getModel().setData('');
//mark this chart as loaded
this.loaded++;
//check whether all charts are loaded
this.isFullLoaded();
return;
}
//callback function
var dataHandler = function (oData, oChart) {
//deep clone the data to kpiChart.dimModels
kpiChart.dimModels[that.selectedDim] = that.deepClone(oData);
//Delete the empty data
var cnt=0;
var tmp = "";
for(cnt;cnt<oData.length;cnt++){
if(oData[cnt].DIMENSION !== "空" || (oData[cnt].DIMENSION === "空" && oData[cnt].KPI_VALUE !== "")){
//save the available data
tmp = oData[cnt].DIMENSION;
break;
}
}
cnt=0;
//set the DIMANSION for all "空" and "" data
if(tmp !== ""){
for(cnt;cnt<oData.length;cnt++){
if(oData[cnt].DIMENSION === "空" && oData[cnt].KPI_VALUE === ""){
oData[cnt].DIMENSION = tmp;
}
}
}
//Set Data model of dimension chart
that.setDimChartModel(oChart, oData);
//Set Data model of defect chart
that.setDefectModel(that._curDefectChart, oData);
//Set first legend for dimension chart
that.setDimChartLegend();
//Set unit for dimension chart
//that.setDimChartUnit(oChart);
/*oChart.setBusy(false);
that._curDefectChart.setBusy(false);*/
//Adjust chart x,y axis;
// CHART_HELPER.adjustChartPeriod(that._globalPeriod, that._globalStartDate,
// that._globalEndDate, oChart, "DIMENSION");
CHART_HELPER.adjustChartYAxis(oChart);
//mark the chart as loaded
that.loaded++;
//check whether all charts are loaded
that.isFullLoaded();
setTimeout(function () {
$('.v-clippath').remove();
}, 50);
};
if (this._selectedDims[this.selectedDim] === undefined) {
this._selectedDims[this.selectedDim] = [];
}
//if model is not exist, request for data
if (orgDimModel === undefined) {
//oChart - dimension chart
oChart.setBusy(true);
this._curDefectChart.setBusy(true);
var oFilter =
"?Dimension=" + curDim + "&KPI=" + kpiName + "&Filter=" + this._sqlFilter +
"&Datef=" + this._globalStartDate + "&Datet=" + this._globalEndDate +
"&Prd=" + this._globalPeriod + "&KType=" + this._sCategory;
sap.boDimension = sap.oBundle.getText(curDim);
var reqURL = PROXY.XsjsProxy(this._column3Service) + oFilter;
this.ajaxGet(reqURL, oChart, dataHandler);
} else {//if model is exist, update the model
//Set Data model of dimension chart
this.setDimChartModel(oChart, orgDimModel);
//Set unit for dimension chart
this.setDimChartUnit(oChart);
//Set Data model of defect chart
this.setDefectModel(this._curDefectChart, orgDimModel);
//Adjust chart x,y axis;
// CHART_HELPER.adjustChartPeriod(that._globalPeriod, that._globalStartDate,
// that._globalEndDate, oChart, "DIMENSION");
CHART_HELPER.adjustChartYAxis(oChart);
setTimeout(function () {
$('.v-clippath').remove();
}, 50);
}
$('.v-clippath').remove();
},
/**
* setDimChartLegend - Load chart legend value according to choose period on page 00315717herry
*/
setDimChartLegend: function () {
//var oData = oChart.getModel().oData;
if (this._globalPeriod==='YEAR'){
this._globalPeriodLegend='CurrentYearValue';
} else if (this._globalPeriod==='Quartor'){
this._globalPeriodLegend='CurrentQuartorValue';
} else if (this._globalPeriod==='WEEK'){
this._globalPeriodLegend='CurrentWeekValue';
} else if (this._globalPeriod==='DAY'){
this._globalPeriodLegend='CurrentDayValue';
} else {
this._globalPeriodLegend='ActualValue';
}
var Legendname = this.oBundle.getText(this._globalPeriodLegend);
//if (oData !== undefined ) {
$("#__xmlview0--Column2ChartVBox .v-row[class*='ID_0'] text").text(Legendname);
//}
},
/**
* [setDimChartUnit - Load chart unit on page]
* @param {sap.viz.ui5.Line} oChart - the defect chart
*/
setDimChartUnit: function (oChart) {
//get the model data of the chart
var oData = oChart.getModel().oData;
if (oData !== undefined && oData[0].UNIT !== undefined) {
//get the unit if the model data is available
var unit = oData[0].UNIT === "PCS" ? this.oBundle.getText(oData[0].UNIT + "_Q") : oData[0].UNIT;
//get the show text of the unit
unit = this.oBundle.getText("UNIT") + ": " + unit;
//get the fragment of current defect chart
var frag = oChart.getParent().getParent();
//set the show text for unit on fragment
frag.getItems()[0].setText(unit);
}
},
/**
* [setDimChartModel - Build and set data model for dimension chart]
* The function is called when draw dimension chart on column3
* @param {vizchart} oChart - dimension chart
* @param {Array} oData - model data from backend
*/
setDimChartModel: function (oChart, oData) {
//build model for dimension drop-down list;
//create Array for the orignal model data of selected dimension
//this.selectedDim - the index of selected dimension tab
//this._dimOrgValues - to save original data of dimension drop-down list
this._dimOrgValues[this.selectedDim] = [];