-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathreport.js
More file actions
1506 lines (1417 loc) · 41.1 KB
/
Copy pathreport.js
File metadata and controls
1506 lines (1417 loc) · 41.1 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
/*
* report.js -- WME Validator report support
* Copyright (C) 2013-2018 Andriy Berestovskyy
*
* This file is part of WME Validator: https://github.com/WMEValidator/
*
* WME Validator is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WME Validator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WME Validator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Show generated report
*/
/** @suppress {strictMissingProperties} */
function F_SHOWREPORT(reportFormat) {
// shortcuts
/** @const */
var _now = new Date();
/** @const */
var _nowISO = _now.toISOString().slice(0, 10);
/** @const */
var _repU = _REP.$users;
/** @const */
var _repC = _REP.$cities;
/** @const */
var _repCC = _REP.$cityCounters;
/** @const */
var _repRC = _REP.$reportCounters;
/** @const */
var _repS = _REP.$streets;
/** @const */
var isBeta = -1 !== window.location.href.indexOf("beta");
// false if at least one filter or search set
var noFilters = true;
// final report data
var FR = '';
var FRheader = '';
var FRfooter = '';
// window object
var newWin = null;
///////////////////////////////////////////////////////////////////////
// Format strings
// h1
var Bh1, Eh1;
// h2
var Bh2, Eh2;
// small
var Bsmall, Esmall;
// big
var Bbig, Ebig;
// link
var Ba, Ca, Ea;
// link target Validator
var BaV;
// color
var Bcolor, Ccolor, Ecolor;
// bold
var Bb, Eb;
// p
var Bp, Ep;
// br
var Br;
// ol
var Bol, Eol;
// ul
var Bul, Eul;
// li
var Bli, Eli;
// code
var Bcode, Ecode;
// —
var Mdash, Nbsp;
// current format
var curFormat;
///////////////////////////////////////////////////////////////////////
// Support functions
function setFormat(fmt) {
curFormat = fmt;
switch (fmt) {
case RF_HTML:
Bh1 = '\n<h1>', Eh1 = '</h1>\n<hr>\n';
Bh2 = '\n\n<h2>', Eh2 = '</h2>\n';
Bsmall = '<small>', Esmall = '</small>';
Bbig = '<big>', Ebig = '</big>';
Ba = '<a target="_blank" href="', Ca = '">', Ea = '</a>';
BaV = '<a target="Validator" href="';
Bcolor = '<span style="color:', Ccolor = '">', Ecolor = '</span>';
Bb = '<b>', Eb = '</b>';
Bp = '<p>', Ep = '</p>';
Br = '<br>\n';
Bul = '\n<ul>\n', Eul = '\n</ul>\n';
Bcode = '\n<div style="text-align:left" dir="ltr" class="code" onclick="selectAll(this)">', Ecode = '</div>\n';
Bol = '\n<ol>\n', Eol = '\n</ol>\n';
Bli = '\n<li>', Eli = '</li>\n';
Mdash = ' — ';
Nbsp = ' ';
break;
case RF_BB:
Bh1 = '\n[size=200]', Eh1 = '[/size]\n';
Bh2 = '\n[size=150]', Eh2 = '[/size]\n';
Bsmall = '[size=85]', Esmall = '[/size]';
Bbig = '[size=120]', Ebig = '[/size]';
Ba = '[url=', Ca = ']', Ea = '[/url]';
BaV = Ba;
Bcolor = '[color=', Ccolor = ']', Ecolor = '[/color]';
Bb = '[b]', Eb = '[/b]';
Bp = '\n', Ep = '\n';
Br = '\n';
Bul = '\n[list]', Eul = '[/list]\n';
Bcode = '\n[code]', Ecode = '\n[/code]';
Bol = '\n[list=1]', Eol = '[/list]\n';
Bli = '\n[*]', Eli = '[/*]\n';
Mdash = ' - ';
Nbsp = ' ';
break;
}
return '';
}
// returns report source
function getReportSource() {
var m = 0;
var n = "";
for (var cid in _repCC) {
if (_repCC.hasOwnProperty(cid) && m < _repCC[cid] && _repC[cid]) {
m = _repCC[cid];
n = _repC[cid];
}
}
return n;
}
// returns top permalink
function getTopPermalink() {
var center, zoom;
if (_RT.$startCenter) {
center = _RT.$startCenter;
zoom = _RT.$startZoom;
}
else {
center = wmeSDK.Map.getMapCenter();
zoom = wmeSDK.Map.getZoomLevel();
}
//var c = center.clone().transform(nW.Config.map.projection.local, nW.Config.map.projection.remote);
return window.location.origin
+ window.location.pathname
+ '?zoomLevel=' + zoom
+ '&lat=' + Math.round(center.lat * 1e5) / 1e5
+ '&lon=' + Math.round(center.lon * 1e5) / 1e5
+ '&env=' + wmeSDK.Settings.getRegionCode()
;
}
// returns HTML header
function getHTMLHeader(strTitle) {
var dir = _I18n.getDir();
var dirLeft = trLeft(dir);
var dirRight = trRight(dir);
return '<html dir="' + dir + '"><head><style>'
+ '\na{background-color:white}'
+ '\na:visited{background-color:' + GL_VISITEDBGCOLOR
+ ' !important;color:' + GL_VISITEDCOLOR + ' !important}'
+ '\n.note a{background-color:' + GL_NOTEBGCOLOR
+ ';color:' + GL_NOTECOLOR + '}'
+ '\n.warning a{background-color:' + GL_WARNINGBGCOLOR
+ ';color:' + GL_WARNINGCOLOR + '}'
+ '\n.error a{background-color:' + GL_ERRORBGCOLOR
+ ';color:' + GL_ERRORCOLOR + '}'
+ '\n.custom1 a{background-color:' + GL_CUSTOM1BGCOLOR
+ ';color:' + GL_CUSTOM1COLOR + '}'
+ '\n.custom2 a{background-color:' + GL_CUSTOM2BGCOLOR
+ ';color:' + GL_CUSTOM2COLOR + '}'
+ '\ndiv.note{background-color:' + GL_NOTEBGCOLOR + ';padding:1em;margin-top:0.5em}'
+ '\ndiv.warning{background-color:' + GL_WARNINGBGCOLOR + ';padding:1em;margin-top:0.5em}'
+ '\ndiv.error{background-color:' + GL_ERRORBGCOLOR + ';padding:1em;margin-top:0.5em}'
+ '\nh2+ul>li{margin-bottom:1em}'
+ '\nul{margin-top:0}'
+ '\nh1,h2{margin-bottom:4px;font-family:Georgia,Times,"Times New Roman",serif}'
+ '\nbody{margin:2em;font-family:"Lucida Grande","Lucida Sans Unicode","DejaVu Sans",Lucida,Arial,Helvetica,sans-serif}'
+ '\ndiv#contents{display:inline-block;margin:1em 0;padding:1em;background-color:#f9f9f9;border:1px solid #aaa}'
+ '\ndiv#contents li{margin-bottom:0.1em}'
+ '\ndiv.code::before{content: "CODE: SELECT ALL";display:block;border-bottom:1px solid #ccc;font:bold 1em "Lucida Grande","Trebuchet MS",Verdana,Helvetica,Arial,sans-serif;color:#105289;margin-bottom:5px;}'
+ '\ndiv.code{margin-top:0.5em;display:block;width:650px;overflow:auto;padding:0.5em;border:1px solid #ccc;background-color:#f4fff4;white-space:pre;font:0.9em Monaco,"Andale Mono","Courier New",Courier,mono;line-height:1.3em;color:#2E8B57;cursor:pointer}'
+ '\n</style>'
+ '\n<script>'
+ '\nfunction selectAll(e){'
+ 'if(window.getSelection){'
+ 'var s = window.getSelection();'
+ 'var r = document.createRange();'
+ 'r.selectNodeContents(e);'
+ 's.removeAllRanges();'
+ 's.addRange(r);'
+ '}}'
+ '\n</script>'
+ '\n<title>' + strTitle + " " + _nowISO + '</title>'
+ '\n<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>'
// + '\n<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">'
+ '\n</head><body>'
;
}
// returns natural list
function getNaturalList(arr) {
if (1 === arr.length)
return arr[0];
var ret = '';
arr.forEach(function (e, i) {
if (arr.length - 1 === i)
ret += ' ' + trS("report.and") + ' ';
else if (0 !== i)
ret += ', ';
ret += e;
});
return ret;
}
// returns document header
function getHeader(strTitle) {
var ret = Bh1 + strTitle + Eh1;
if (RF_LIST !== reportFormat
&& RF_CREATEPACK !== reportFormat) {
ret += Bsmall + trS("report.generated.by")
+ ' ' + _RT.$curUserName + ' '
+ trS("report.generated.on")
+ ' '
+ _nowISO + Esmall + Br
+ Br + Bb
+ trS("report.source")
+ ' ' + Eb + Ba + getTopPermalink() + Ca
+ checkNoCity(getReportSource())
+ Ea + Br
;
var filters = [];
if (_UI.pMain.pFilter.oExcludeDuplicates.CHECKED)
filters.push(trS("report.filter.duplicate"));
if (!_UI.pMain.pFilter.oEnablePlaces.CHECKED)
filters.push(trS("report.filter.places"));
if (_UI.pMain.pFilter.oExcludeStreets.CHECKED)
filters.push(trS("report.filter.streets"));
if (_UI.pMain.pFilter.oExcludeOther.CHECKED)
filters.push(trS("report.filter.other"));
if (_UI.pMain.pFilter.oExcludeNonEditables.CHECKED)
filters.push(trS("report.filter.noneditable"));
if (_UI.pMain.pFilter.oExcludeNotes.CHECKED)
filters.push(trS("report.filter.notes"));
if (filters.length) {
noFilters = false;
ret += Bb + trS("report.filter.title")
+ ' ' + Eb + getNaturalList(filters)
+ ' '
+ trS("report.filter.excluded")
+ Br;
}
filters = [];
if (!_UI.pMain.pSearch.oIncludeYourEdits.NODISPLAY
&& _UI.pMain.pSearch.oIncludeYourEdits.CHECKED)
filters.push(trS("report.search.updated.by")
+ ' ' + _RT.$curUserName);
if (!_UI.pMain.pSearch.oIncludeUpdatedBy.NODISPLAY
&& _UI.pMain.pSearch.oIncludeUpdatedBy.VALUE)
filters.push(trS("report.search.updated.by")
+ ' ' + _UI.pMain.pSearch.oIncludeUpdatedBy.VALUE);
if (_UI.pMain.pSearch.oIncludeUpdatedSince.VALUE)
filters.push(trS("report.search.updated.since")
+ ' ' + _UI.pMain.pSearch.oIncludeUpdatedSince.VALUE);
if (_UI.pMain.pSearch.oIncludeCityName.VALUE)
filters.push(trS("report.search.city")
+ ' ' + _UI.pMain.pSearch.oIncludeCityName.VALUE);
if (_UI.pMain.pSearch.oIncludeChecks.VALUE)
filters.push(trS("report.search.reported")
+ ' ' + _UI.pMain.pSearch.oIncludeChecks.VALUE);
if (filters.length) {
noFilters = false;
ret += Bb + trS("report.search.title")
+ Eb + ' ' + trS("report.search.only")
+ ' ' + getNaturalList(filters)
+ ' ' + trS("report.search.included") + Br;
}
if (isBeta)
ret += Br + Bb + trS("report.beta.warning") + Eb + Br
+ trS("report.beta.text")
+ Br + Bb + trS("report.beta.share") + Eb + Br
;
}
return ret;
}
// returns document sub header
function getSubHeader(strTitle) {
return Bh2 + strTitle + Eh2;
}
// returns text representation of access list
function getTextACL(acl) {
if (acl)
return acl.split(',').join(', ');
else
return '*';
}
// returns check properties
function getCheckProperties(checkID, ccode, showSeverity, showCountry) {
var check = _RT.$checks[checkID];
var ret = "";
if (showSeverity && check.SEVERITY && RS_MAX > check.SEVERITY)
ret += Bb
+ trS("report.list.severity") + ' ' + Eb + getTextSeverity(check.SEVERITY)
+ (check.REPORTONLY ?
" (" + trS("report.list.reportOnly") + ")" : "")
+ Br;
if (1 < check.FORLEVEL)
ret += Bb + trS("report.list.forEditors")
+ ' ' + Eb + check.FORLEVEL + ' '
+ trS("report.list.andUp") + Br;
if (showCountry)
ret += Bb + trS("report.list.forCountries")
+ ' ' + Eb + getTextACL(check.FORCOUNTRY) + Br;
if (check.FORCITY)
ret += Bb + trS("report.list.forCities")
+ ' ' + Eb + getTextACL(check.FORCITY) + Br;
var options;
if (check.OPTIONS && (options = getCheckOptions(checkID, ccode))) {
var defParams = ccode === _I18n.$defLng;
var arrParams = [];
for (var optionName in options) {
// skip options with dots and numbers
if (!/^[a-z]+$/i.test(optionName))
continue;
var optionTitle = options[optionName + '.title'];
if (defParams && !optionTitle)
continue;
arrParams.push({
$name: optionName,
$title: optionTitle,
$value: options[optionName]
});
}
if (arrParams.length) {
ret += Bb;
var country = _I18n.getCapitalizedCountry(ccode) || ccode;
if (defParams)
ret += trS("report.list.params");
else
ret += trSO("report.list.params.set", { "country": country });
ret += Eb + Bcode + '"' + checkID + '.params": {\n';
for (var i = 0; i < arrParams.length; i++) {
var param = arrParams[i];
if (defParams)
ret += ' // ' + param.$title + '\n';
ret += ' "' + param.$name + '": '
+ JSON.stringify(param.$value) + ',' + '\n';
}
ret += "}," + Ecode;
}
}
return ret;
}
function addTextLabels(pack, label, defSet, oldPack) {
var defData = (defSet[label] || '')
.replace(new RegExp('^W:'), PFX_WIKI)
.replace(new RegExp('^P:'), PFX_SEARCH)
.replace(new RegExp('^F:'), PFX_FORUM)
.replace(new RegExp('^D:'), PFX_DISCUSS)
;
var origData = (oldPack[label] || '');
if (origData) {
var oldData = origData
.replace(new RegExp('^' + GL_TODOMARKER), '')
.replace(new RegExp('^W:'), PFX_WIKI)
.replace(new RegExp('^P:'), PFX_SEARCH)
.replace(new RegExp('^F:'), PFX_FORUM)
.replace(new RegExp('^D:'), PFX_DISCUSS)
;
// preserve old data
var oldDataEN = (oldPack[label + '.en'] || '')
.replace(new RegExp('^W:'), PFX_WIKI)
.replace(new RegExp('^P:'), PFX_SEARCH)
.replace(new RegExp('^F:'), PFX_FORUM)
.replace(new RegExp('^D:'), PFX_DISCUSS)
;
if (oldDataEN) {
if (oldDataEN === defData) {
// no changes
pack[label + '.en'] = defData;
pack[label] = origData;
}
else {
// new default string
pack[label + '.en'] = defData;
pack[label] = GL_TODOMARKER + oldData;
}
}
else {
// no english data
// we assume no changes
pack[label + '.en'] = defData;
pack[label] = origData;
}
}
else {
// no old data
// mark line for translation
pack[label + '.en'] = defData;
pack[label] = GL_TODOMARKER + defData;
}
}
// returns new pack header
function getPackHeader(country, lng) {
return '// ==UserScript==' + Br
+ '// @name WME Validator Localization for ' + country + Br
+ '// @version ' + WV_VERSION + Br
+ '// @description This script localizes WME Validator for ' + country
+ '. You also need main package (WME Validator) installed.' + Br
+ '// @match https://beta.waze.com/*editor*' + Br
+ '// @match https://www.waze.com/*editor*' + Br
+ '// @exclude https://www.waze.com/*user/*editor/*' + Br
+ '// @grant none' + Br
+ '// @run-at document-start' + Br
+ '// ==/UserScript==' + Br
+ '//' + Br
+ '/*' + Br
+ (lng ?
' Please translate all the lines marked with "' + GL_TODOMARKER + '"' + Br
+ ' Please DO NOT change ".en" properties. To override english text use "titleEN",' + Br
+ ' "problemEN" and "solutionEN" properties (see an example below).' + Br
+ Br
: '')
+ ' See Settings->About->Available checks for complete list of checks and their params.' + Br
+ Br
+ ' Examples:' + Br
+ Br
+ ' Enable #170 "Lowercase street name" but allow lowercase "exit" and "to":' + Br
+ ' "170.enabled": true,' + Br
+ ' "170.params": {' + Br
+ ' "regexp": "/^((exit|to) )?[a-z]/",' + Br
+ ' "},' + Br
+ Br
+ ' Enable #130 "Custom check" to find a dot in street names, but allow dots at Ramps:' + Br
+ ' "130.enabled": true,' + Br
+ ' "130.params": {' + Br
+ ' "titleEN": "Street name with a dot",' + Br
+ ' "problemEN": "There is a dot in the street name (excluding Ramps)",' + Br
+ ' "solutionEN": "Expand the abbreviation or remove the dot",' + Br
+ ' "template": "${type}:${street}",' + Br
+ ' "regexp": "D/^[^4][0-9]?:.*\\\\./",' + Br
+ ' },' + Br
+ ' *Note: use D at the beginning of RegExp to enable debugging on JS console.' + Br
+ ' *Note: do not forget to escape backslashes in strings, i.e. use "\\\\" instead of "\\".' + Br
+ '*/' + Br
;
}
// returns new pack
function getPack(country, ccode, lng) {
var ucountry = country.toUpperCase();
var _country = country.split(' ').join('_');
var oldPack = _I18n.$translations[ccode] || {};
var ret = ''
+ Br
+ 'window.WME_Validator_' + _country + ' = '
;
var newCountries = [];
for (let k in _I18n.$country2code) {
if (ccode === _I18n.$country2code[k]
&& ucountry !== k)
newCountries.push(_I18n.capitalize(k));
}
// add current country to the top of the list
newCountries.unshift(country);
// add current user to authors
var newAuthor = oldPack[".author"] || _RT.$topUser.$userName;
if (-1 === newAuthor.indexOf(_RT.$topUser.$userName))
newAuthor += " and " + _RT.$topUser.$userName;
var newLink = oldPack[".link"] || GL_TODOMARKER;
var pack = {
".country": (1 === newCountries.length ?
newCountries[0]
: newCountries),
".codeISO": ccode,
".author": newAuthor,
".updated": _nowISO,
".link": newLink,
};
if (ccode in _I18n.$code2code)
pack[".fallbackCode"] = _I18n.$code2code[ccode];
if (lng) {
if (ccode in _I18n.$code2dir)
pack[".dir"] = _I18n.$code2dir[ccode];
let newLngs = [];
for (let k in _I18n.$lng2code) {
if (ccode === _I18n.$lng2code[k]
&& k !== lng)
newLngs.push(k);
}
// add current lng to the top of the list
newLngs.unshift(lng);
pack[".lng"] = (1 === newLngs.length ?
newLngs[0]
: newLngs);
}
// compare and add UI strings
if (lng) {
for (let label in _I18n.$defSet) {
// skip meta labels and checks
if (/^\./.test(label)
|| /^[0-9]/.test(label))
continue;
// get data
addTextLabels(pack, label, _I18n.$defSet, oldPack);
}
}
// compare and add checks
let allLabels = _RT.$otherLabels.concat(_RT.$textLabels);
let arrDepCodes = _I18n.getDependantCodes(ccode);
for (let i = 1; i < MAX_CHECKS; i++) {
// skip mirror checks
if ((CK_MIRRORFIRST + 100) <= i
&& (CK_MIRRORLAST + 100) >= i)
continue;
// check is enabled?
let label = i + '.enabled';
let checkEnabled = false;
if (_I18n.$defSet[label] || oldPack[label])
checkEnabled = true;
if (!checkEnabled) {
// check dependant countries
for (var depC = 0; depC < arrDepCodes.length; depC++) {
var depCode = arrDepCodes[depC];
if (_I18n.$translations[depCode]
&& _I18n.$translations[depCode][label])
checkEnabled = true;
}
}
// check if check is no longer exist
if (checkEnabled && !((i + '.title') in _I18n.$defSet)) {
pack[i + '.note'] = GL_TODOMARKER + "The check #" + i + " is no longer exist. See the forum thread for more details.";
continue;
}
for (let j = 0; j < allLabels.length; j++) {
let labelSfx = allLabels[j];
label = i + '.' + labelSfx;
let defData = _I18n.$defSet[label];
let oldData = oldPack[label];
if (classCodeDefined(defData) || classCodeDefined(oldData)) {
if (-1 !== _RT.$textLabels.indexOf(labelSfx)) {
// text label
if (lng && checkEnabled)
addTextLabels(pack, label, _I18n.$defSet, oldPack);
}
else {
// copy and clear compiled params
if ("params" === labelSfx) {
if (!classCodeDefined(oldData))
continue;
defData = deepCopy(defData || {});
oldData = deepCopy(oldData);
for (let k = CO_MIN; k <= CO_MAX; k++) {
delete defData[k];
delete oldData[k];
}
for (let k in defData) {
if (!defData.hasOwnProperty(k)) continue;
if (/\.title$/.test(k))
delete defData[k];
}
}
// non-text label
if (!deepCompare(defData, oldData))
pack[label] = oldData;
}
}
}
}
ret += JSON.stringify(pack, null, ' ') + ';\n';
return ret;
}
// returns list of checks
function getListOfChecks(countryID, country) {
let ucountry = country.toUpperCase();
let ccode = "";
if (countryID)
ccode = _I18n.getCountryCode(ucountry);
let ret = trS("report.list.see") + ' ' + Bb
+ trS("report.list.checks") + Eb + Br + Br;
let fallbacks = '';
if (ccode)
for (let i in _I18n.$country2code) {
if (!_I18n.$country2code.hasOwnProperty(i)) continue;
if (i === ucountry)
continue;
let acode = _I18n.$country2code[i];
if (ccode && acode !== ccode)
continue;
fallbacks += _I18n.capitalize(i)
+ ' \u2192 '
+ country + Br;
}
for (let i in _I18n.$code2code) {
if (!_I18n.$code2code.hasOwnProperty(i)) continue;
let countryFrom = _I18n.getCapitalizedCountry(i);
let countryTo = _I18n.getCapitalizedCountry(_I18n.$code2code[i]);
if (ccode && i !== ccode && _I18n.$code2code[i] !== ccode)
continue;
if (country && countryFrom !== country && countryTo !== country)
continue;
fallbacks += countryFrom + ' (' + i + ') \u2192 '
+ countryTo
+ ' (' + _I18n.$code2code[i] + ')' + Br;
}
if (fallbacks)
ret += Bb + trS("report.list.fallback") + Eb + Br
+ fallbacks;
var sortedIDs = getSortedCheckIDs();
if (ccode) {
// country
var enabledIDs = [];
var disabledIDs = [];
// check if enabled for country
sortedIDs.forEach(function (cid) {
var c = _RT.$checks[cid];
if (!c) return;
// do not show global access
if (RS_MAX === c.SEVERITY) return;
var en = true;
var forCountry = c.FORCOUNTRY;
if (forCountry) {
if (!_WV.checkAccessFor(forCountry, function (e) {
if (e in _I18n.$code2country)
return _I18n.$code2country[e] === ucountry;
error("Please report: fc=" + e);
return false;
}))
en = false;
}
if (en)
enabledIDs.push(cid);
else
disabledIDs.push(cid);
});
ret += Bh2 + trSO("report.list.enabled", { "n": enabledIDs.length })
+ ' ' + country + ":" + Eh2 + Bul;
enabledIDs.forEach(function (cid) {
ret += Bli + getCheckDescription(cid, countryID, Bb, Eb + Br)
+ Bsmall;
ret += getCheckProperties(cid, ccode, false, false);
ret += Esmall + Eli;
});
ret += Eul;
ret += Bh2 + trSO("report.list.disabled", { "n": disabledIDs.length })
+ ' ' + country + ":" + Eh2 + Bul;
disabledIDs.forEach(function (cid) {
ret += Bli + getCheckDescription(cid, 0, Bb, Eb + Br) + Bsmall;
ret += getCheckProperties(cid, _I18n.$defLng, false, true);
ret += Esmall + Eli;
});
ret += Eul;
}
else {
// no country
ret += Bh2 + trSO("report.list.total", { "n": sortedIDs.length }) + ':'
+ Eh2 + Bul;
sortedIDs.forEach(function (cid) {
var c = _RT.$checks[cid];
if (!c) return;
// do not show global access
if (RS_MAX === c.SEVERITY) return;
ret += Bli + getCheckDescription(cid, 0, Bb, Eb + Br) + Bsmall;
ret += getCheckProperties(cid, _I18n.$defLng, false, true);
ret += Esmall + Eli;
});
ret += Eul;
}
return ret;
}
// returns HTML footer
function getHTMLFooter() {
return '\n<hr>'
+ '\n<center dir="ltr"><small>WME Validator v' + WV_VERSION + '<br>© 2013-2018 Andriy Berestovskyy</small></center>'
+ '\n</body></html>'
;
}
// returns text area header
function getTAHeader(h) {
var ret =
'\n<p>'
+ (RF_CREATEPACK === reportFormat ?
trS("msg.textarea.pack")
: trS("msg.textarea"))
+ ':</p>'
+ '\n<p><textarea style="resize:vertical;width:100%;height:' + h + '">';
setFormat(RF_BB);
return ret;
}
// returns text area footer
function getTAFooter() {
setFormat(RF_HTML);
return '\n</textarea></p>';
}
// returns size warning
function getSizeWarning(size) {
return 5e4 < size ?
'\n<p style="color:#e00">'
+ trSO("report.size.warning", { "n": size })
+ '</p>'
: '';
}
// opens new browser window
function openWindow(data) {
let nw = window.open("", "_blank");
nw.document.write(data);
// UW.open("data:text/html;charset=UTF-8," + encodeURIComponent(data),
// "_blank");
}
// opens new browser window for final report
/** @param {string=} title */
function openWindowFR(title) {
var encFR = "data:text/html;charset=UTF-8,";
if (newWin) {
// insert save button
if (reportFormat === RF_HTML) {
title = title.split(" ").join("_");
newWin.document.write(FRheader);
var saveRep = FRheader;
saveRep += FR;
saveRep += FRfooter;
saveRep = encodeURIComponent(saveRep);
var saveLink = '<br><a download="';
saveLink += title;
saveLink += '_';
saveLink += _nowISO;
saveLink += '.html" href="data:text/html;charset=UTF-8,';
saveLink += saveRep;
saveRep = '';
saveLink += '"><button>';
saveLink += trS("report.save");
saveLink += '</button></a><br>';
newWin.document.write(saveLink);
newWin.document.write(FR);
newWin.document.write(saveLink);
newWin.document.write(FRfooter);
}
else
newWin.document.write(FR);
}
else {
encFR += encodeURIComponent(FRheader);
FRheader = '';
encFR += encodeURIComponent(FR);
FR = '';
encFR += encodeURIComponent(FRfooter);
FRfooter = '';
window.open(encFR, "_blank");
}
}
// filter helpers
var seenObjects = {};
var lastCheckID = -1;
var lastCityID = -1;
var lastStreetID = -1;
var counterNotes = 0;
var counterWarnings = 0;
var counterErrors = 0;
var counterCustoms1 = 0;
var counterCustoms2 = 0;
// reset filter
function resetFilter() {
seenObjects = {};
lastCheckID = -1;
lastCityID = -1;
lastStreetID = -1;
counterNotes = 0;
counterWarnings = 0;
counterErrors = 0;
counterCustoms1 = 0;
counterCustoms2 = 0;
}
// returns TOC
function getTOC() {
resetFilter();
FR += '\n<br><div id="contents">';
FR += '\n<big><b>';
FR += trS("report.contents");
FR += '</b></big>';
FR += '\n<ol>';
traverseReport(function (obj) {
if (checkFilter(0, obj.$objectCopy, seenObjects)
&& getFilteredSeverity(obj.$check.SEVERITY, obj.$checkID, false)) {
if (obj.$checkID !== lastCheckID) {
lastCheckID = obj.$checkID;
var check = obj.$check;
var strCountry = _REP.$countries[obj.$objectCopy.$countryID];
var ccode = "";
if (strCountry)
ccode = _I18n.getCountryCode(strCountry.toUpperCase());
else {
// try top country
ccode = _RT.$cachedTopCCode;
}
var options = trO(check.OPTIONS, ccode)
FR += '\n<li class="';
FR += getTextSeverity(obj.$check.SEVERITY);
FR += '"><a href="#a';
FR += lastCheckID;
FR += '">';
FR += exSOS(check.TITLE, options, "titleEN");
FR += '</a></li>';
}
// TODO:
// bug: TOC item shows duplicate objects
// solution: filter, then create the toc and report
// alt solution: remove dublicate checks!
// return RT_NEXTCHECK;
}
});
FR += '\n<li><a href="#a">';
FR += trS("report.summary");
FR += '</a></li>';
FR += '\n</ol>\n</div>';
}
// get sorted check IDs
function getSortedCheckIDs() {
return _RT.$sortedCheckIDs ? _RT.$sortedCheckIDs
: _RT.$sortedCheckIDs =
Object.keys(_RT.$checks)
.sort(cmpCheckIDs);
}
// _REP->$cityIDs->streetIDs->$objectIDs->$reportIDs
// traverse report and call a handler
function traverseReport(handler) {
let mapCenter = wmeSDK.Map.getMapCenter();
// get sorted cities
function getSortedCities() {
var ret = _REP.$sortedCityIDs;
if (!ret || ret.length != _REP.$unsortedCityIDs.length)
return _REP.$sortedCityIDs =
[].concat(_REP.$unsortedCityIDs).sort(function (a, b) {
return _repC[a].localeCompare(_repC[b]);
});
return ret;
}
// get sorted streets
function getSortedStreets(repC) {
var ret = repC.$sortedStreetIDs;
if (!ret || ret.length != repC.$unsortedStreetIDs.length)
return repC.$sortedStreetIDs
= [].concat(repC.$unsortedStreetIDs).sort(function (a, b) {
return _repS[a].localeCompare(_repS[b]);
});
return ret;
}
// get hypot
function getHypot(c1, c2) {
// return Math.round(Math.sqrt(c1*c1 + c2*c2)*10);
return Math.sqrt(c1 * c1 + c2 * c2);
}
// get sorted objects
function getSortedObjects(repS) {
var ret = repS.$sortedObjectIDs;
var repSeg = repS.$objectIDs;
if (!ret || ret.length != repS.$unsortedObjectIDs.length)
return repS.$sortedSegmentIDs
= [].concat(repS.$unsortedObjectIDs).sort(function (a, b) {
var segA = repSeg[a], segB = repSeg[b];
if (segA.$typeRank !== segB.$typeRank)
return segB.$typeRank - segA.$typeRank;
// if ranks are the same - sort by the distance
/** @const */
var distAB = getHypot(segA.$center.lat - segB.$center.lat,
segA.$center.lon - segB.$center.lon);
// the objects are close
if (0.002 > distAB) return 0;
/** @const */
var distA = getHypot(mapCenter.lat - segA.$center.lat,
mapCenter.lon - segA.$center.lon);
/** @const */
var distB = getHypot(mapCenter.lat - segB.$center.lat,
mapCenter.lon - segB.$center.lon);
return distA - distB;
});
return ret;
}
///////////////////////////////////////////////////////////////////
// For all sorted checks
var checkIDs = getSortedCheckIDs();
nextCheck: for (var i = 1; i < checkIDs.length; i++) {
var checkID = checkIDs[i];
var check = _RT.$checks[checkID];
if (!check) continue;
// filter minor issues
if (_UI.pMain.pFilter.oExcludeNotes.CHECKED
&& RS_NOTE === check.SEVERITY
)
continue;
// for all cities
var sortedCities = getSortedCities();
for (var sorcid = 0; sorcid < sortedCities.length; sorcid++) {
var cid = sortedCities[sorcid];
var repC = _REP.$cityIDs[cid];
// for all streets
var sortedStreets = getSortedStreets(repC);
for (var sorsid = 0; sorsid < sortedStreets.length; sorsid++) {
var sid = sortedStreets[sorsid];
var repS = repC.$streetIDs[sid];
// for all object copies
if (repS.$unsortedObjectIDs){
var sortedObjects = getSortedObjects(repS);
for (var sorscid = 0; sorscid < sortedObjects.length; sorscid++) {
var scid = sortedObjects[sorscid];
var sc = repS.$objectIDs[scid];
if (checkID in sc.$reportIDs) {
var obj = {
$checkID: checkID,
$check: check,
$param: sc.$reportIDs[checkID],
$cityParam: repC.$params[checkID],
$streetParam: repS.$params[checkID],
$objectCopy: sc
};
switch (handler(obj)) {
case RT_STOP:
return;
case RT_NEXTCHECK:
continue nextCheck;
};
} // checkID in reportIDs
}
} // for all objects
} // for all streets
} // for all cities
} // for all checks
}
// closes report street
function closeReportStreet() {
if (0 <= lastStreetID || 0 <= lastCityID) {
lastStreetID = -1;
FR += Eli;
}
}
// closes report city
function closeReportCity() {
if (0 <= lastCityID) {
lastCityID = -1;
closeReportStreet();
FR += Eul;
}