Improved error handling.
This commit is contained in:
parent
439b6cea8a
commit
6584090bad
2 changed files with 438 additions and 399 deletions
|
@ -551,9 +551,13 @@ class App.Utils
|
||||||
# format decimal
|
# format decimal
|
||||||
@decimal: (data, positions = 2) ->
|
@decimal: (data, positions = 2) ->
|
||||||
|
|
||||||
|
# input validation
|
||||||
|
return '' if data is undefined
|
||||||
|
return '' if data is null
|
||||||
|
|
||||||
|
if data.toString
|
||||||
data = data.toString()
|
data = data.toString()
|
||||||
|
|
||||||
# input validation
|
|
||||||
return data if data is ''
|
return data if data is ''
|
||||||
return data if data.match(/[A-z]/)
|
return data if data.match(/[A-z]/)
|
||||||
|
|
||||||
|
@ -566,17 +570,25 @@ class App.Utils
|
||||||
|
|
||||||
# add .00
|
# add .00
|
||||||
if !result || !result[2]
|
if !result || !result[2]
|
||||||
return "#{data}." + format(0, positions)
|
return "#{data}.#{format(0, positions)}"
|
||||||
length = result[2].length
|
length = result[2].length
|
||||||
diff = positions - length
|
diff = positions - length
|
||||||
|
|
||||||
# check length, add .00
|
# check length, add .00
|
||||||
return "#{result[1]}." + format(result[2], positions) if diff > 0
|
return "#{result[1]}.#{format(result[2], positions)}" if diff > 0
|
||||||
|
|
||||||
# check length, remove longer positions
|
# check length, remove longer positions
|
||||||
"#{result[1]}.#{result[2].substr(0,positions)}"
|
"#{result[1]}.#{result[2].substr(0,positions)}"
|
||||||
|
|
||||||
@formatTime: (num, digits) ->
|
@formatTime: (num, digits) ->
|
||||||
while num.toString().length < digits
|
|
||||||
|
# input validation
|
||||||
|
return '' if num is undefined
|
||||||
|
return '' if num is null
|
||||||
|
|
||||||
|
if num.toString
|
||||||
|
num = num.toString()
|
||||||
|
|
||||||
|
while num.length < digits
|
||||||
num = '0' + num
|
num = '0' + num
|
||||||
num
|
num
|
||||||
|
|
|
@ -887,7 +887,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
var diff = {}
|
var diff = {}
|
||||||
var result = App.Utils.formDiff(dataNow, dataLast)
|
var result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -900,7 +900,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -912,7 +912,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -926,7 +926,7 @@ test( "check form diff", function() {
|
||||||
owner_id: '',
|
owner_id: '',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -939,7 +939,7 @@ test( "check form diff", function() {
|
||||||
state_ids: ['1','5','6','7'],
|
state_ids: ['1','5','6','7'],
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -952,7 +952,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -967,7 +967,7 @@ test( "check form diff", function() {
|
||||||
state_ids: ['6'],
|
state_ids: ['6'],
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -980,7 +980,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -995,7 +995,7 @@ test( "check form diff", function() {
|
||||||
owner_id: ''
|
owner_id: ''
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1011,7 +1011,7 @@ test( "check form diff", function() {
|
||||||
pending_time: '2015-01-28T11:34:00Z'
|
pending_time: '2015-01-28T11:34:00Z'
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1022,7 +1022,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1037,7 +1037,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1054,7 +1054,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1065,7 +1065,7 @@ test( "check form diff", function() {
|
||||||
test: '123',
|
test: '123',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1078,7 +1078,7 @@ test( "check form diff", function() {
|
||||||
test: '123',
|
test: '123',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1094,7 +1094,7 @@ test( "check form diff", function() {
|
||||||
test: '123',
|
test: '123',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1107,7 +1107,7 @@ test( "check form diff", function() {
|
||||||
test: ['1','2','3','4']
|
test: ['1','2','3','4']
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1126,7 +1126,7 @@ test( "check form diff", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
|
@ -1144,7 +1144,7 @@ test( "check form diff", function() {
|
||||||
test: '123',
|
test: '123',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = undefined
|
dataNow = undefined
|
||||||
|
@ -1152,14 +1152,14 @@ test( "check form diff", function() {
|
||||||
|
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {}
|
dataNow = {}
|
||||||
dataLast = {"number":"10012","title":"some subject 123äöü","group_id":1,"owner_id":1,"customer_id":2,"state_id":3,"priority_id":2,"article":{"from":"Test Master Agent","to":"","cc":"","body":"dasdad","content_type":"text/html","ticket_id":12,"type_id":9,"sender_id":1,"internal":false,"form_id":"523405147"},"updated_at":"2015-01-29T09:22:23.000Z","pending_time":"2015-01-28T22:22:00.000Z","id":12}
|
dataLast = {"number":"10012","title":"some subject 123äöü","group_id":1,"owner_id":1,"customer_id":2,"state_id":3,"priority_id":2,"article":{"from":"Test Master Agent","to":"","cc":"","body":"dasdad","content_type":"text/html","ticket_id":12,"type_id":9,"sender_id":1,"internal":false,"form_id":"523405147"},"updated_at":"2015-01-29T09:22:23.000Z","pending_time":"2015-01-28T22:22:00.000Z","id":12}
|
||||||
diff = {}
|
diff = {}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
// do not compare content of data instances/objects
|
// do not compare content of data instances/objects
|
||||||
no = function test_object() {
|
no = function test_object() {
|
||||||
|
@ -1186,8 +1186,7 @@ test( "check form diff", function() {
|
||||||
number:'10013',
|
number:'10013',
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
dataNow = {
|
dataNow = {
|
||||||
number:'10013',
|
number:'10013',
|
||||||
|
@ -1203,8 +1202,7 @@ test( "check form diff", function() {
|
||||||
Article: ['2'],
|
Article: ['2'],
|
||||||
}
|
}
|
||||||
result = App.Utils.formDiff(dataNow, dataLast)
|
result = App.Utils.formDiff(dataNow, dataLast)
|
||||||
deepEqual( result, diff, 'check form diff' );
|
deepEqual(result, diff, 'check form diff')
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1246,6 +1244,21 @@ test( "check decimal format", function() {
|
||||||
verify = App.Utils.decimal(string)
|
verify = App.Utils.decimal(string)
|
||||||
equal(verify, result, string)
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = ''
|
||||||
|
result = ''
|
||||||
|
verify = App.Utils.decimal(string)
|
||||||
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = undefined
|
||||||
|
result = ''
|
||||||
|
verify = App.Utils.decimal(string)
|
||||||
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = null
|
||||||
|
result = ''
|
||||||
|
verify = App.Utils.decimal(string)
|
||||||
|
equal(verify, result, string)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// check formatTime format
|
// check formatTime format
|
||||||
|
@ -1261,6 +1274,20 @@ test( "check formatTime format", function() {
|
||||||
verify = App.Utils.formatTime(string, 2)
|
verify = App.Utils.formatTime(string, 2)
|
||||||
equal(verify, result, string)
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = ''
|
||||||
|
result = '00'
|
||||||
|
verify = App.Utils.formatTime(string, 2)
|
||||||
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = undefined
|
||||||
|
result = ''
|
||||||
|
verify = App.Utils.formatTime(string, 2)
|
||||||
|
equal(verify, result, string)
|
||||||
|
|
||||||
|
string = null
|
||||||
|
result = ''
|
||||||
|
verify = App.Utils.formatTime(string, 2)
|
||||||
|
equal(verify, result, string)
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue