-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.js
166 lines (154 loc) · 5.43 KB
/
diff.js
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
/*
GET Parameters:
showSuccess = True| Default False, Will Show Success Massages
Comparing the new object aginst the old one,
check by order
obj[x].field === obj[x].field
*/
(function($) {
function progressBar() {
w_c = jQuery("#progress_bar div").css('width');
w_c = parseInt(w_c.replace('px',''))
w_c += 15;
jQuery("#progress_bar div").css({'width':w_c+'px'});
}
var terminate = setInterval(function() {
progressBar() },1000);
var object_compare = function(output) {
if (output === 'undefined')
output = 'html'
this.config = this._initalGETParams()
this.categoryId = this.config.categoryId || 2;
this.version = this.config.version || 'IPAD';
this.obj_old = {}
this.obj_new = {}
this.fetch();
this.output = 'html';
this._warning_count = 0;
this._critical_count = 0;
}
object_compare.prototype = {
init : function() {
try {
this.compare(this.obj_old,this.obj_new)
}
catch(err) {
this.addHtmlLog(jQuery('<div class="fatal_error">'+err+'</div>'))
}
this.addStatusLog();
},
fetch : function () {
var self = this;
$.getJSON('http://local.ynet.co.il:8000/iphone/ynet/'+self.categoryId+'?version='+self.version, function(data) {
self.obj_new = data
$.getJSON('http://local.ynet.co.il:8000/iphone/json/0,,'+self.categoryId+'-'+self.version+'-NC,00.js', function(data) {
clearTimeout(terminate)
jQuery("#progress_bar").remove()
self.obj_old = data;
self.init();
});
});
},
compare : function(obj1, obj2, pre) {
if (typeof(pre) === 'undefined')
pre = '';
for (var i in obj1) {
pre_ = [pre,i].join('.')
if (typeof(obj2[i]) === 'undefined') {
this._criticalPrint(pre_+' Dosent Exists On New Object')
continue;
}
if (typeof(obj1[i]) === 'object') {
this._loging(pre_)
this.compare(obj1[i],obj2[i],pre_)
} else {
if (!this.equalType(obj1[i],obj2[i]) ||
!this.equalValue(obj1[i],obj2[i])) {
this._printError(pre_+ ' Dosent Equal: old: '+obj1[i]+' new: '+obj2[i])
} else {
console.log(this.config)
if (typeof(this.config.showSuccess) !== 'undefined' && this.config.showSuccess === "true")
this._succesful('key: '+pre_+' Equal')
}
}
}
},
equalType : function(val,val2) {
if (typeof(val) !== typeof(val2))
return false;
return true;
},
equalValue : function(val,val2) {
if (val != val2)
return false;
return true;
},
addStatusLog : function() {
this.addHtmlLog(jQuery('<div id="log_panel">'
+'<li>Critical Errors:</li>'+this._critical_count
+'<li>Warning Errors:</li>'+this._warning_count
+'</div>'));
},
_loging :function(msg) {
if (this.output == 'log')
console.log('comparing object key:'+msg)
else {
var log = document.createElement('div')
log.classList.add('loging')
log.innerHTML = msg
this.addHtmlLog(log)
}
},
_printError : function(msg) {
this._warning_count++;
if (this.output == 'log')
console.log(msg)
else {
var log = jQuery('<div class="alert alert-warning" role="alert">'+
'<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>'+
'<span class="sr-only">Error:</span> '+msg+'</div>');
this.addHtmlLog(log)
}
},
_succesful : function(msg) {
if (this.output == 'log') {
console.log('--------------')
console.log(msg)
console.log('--------------')
} else {
var log = jQuery('<div class="alert alert-success" role="alert">'+
'<span class="glyphicon glyphicon-flag" aria-hidden="true"></span>'+
'<span class="sr-only">Error:</span> '+msg+'</div>');
this.addHtmlLog(log)
}
},
_criticalPrint :function(msg) {
this._critical_count++;
if (this.output == 'log') {
console.log('--------------')
console.log(msg)
console.log('--------------')
} else {
var log = jQuery('<div class="alert alert-danger" role="alert">'+
'<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>'+
'<span class="sr-only">Error:</span> '+msg+'</div>');
this.addHtmlLog(log)
}
},
addHtmlLog : function(el) {
jQuery('#main').append(el)
},
_initalGETParams :function() {
var params = window.location.search;
var obj = {};
params = params.replace('?','');
pairs = params.split('&');
for (var i =0;i<pairs.length; i++) {
pair = pairs[i].split('=');
obj[pair[0]]=pair[1];
}
return obj;
}
};
(new object_compare());
})(jQuery);