angularjs - how to debug an angular for loop -
i trying batch upload of multiple pdfs. each file named in specific format
02-2015 hip bs32
date / pipeline abbreviation / location abbreviation.
i running files through loop compare abbreviations list in database. assign properties object before passed api controller. pipeline , location tables setup same. issue having pipeline. problem is,
$scope.pip = $scope.pipelookup[matches[1]]; $scope.loc = $scope.locationlookup[matches[2]];
the locationlookup matching location abbreviation , placing in $scope.loc variable. pipelookup not working. of course throwing error because pipeline properties undefined. not sure if on looking something. if more information needed let me know
$scope.companies = company.query(function () { }); $scope.locations = location.query(function () { }); $scope.pipes = pipe.query(function () { }); $scope.selectcompany = function () { var id = $scope.companyid.companyid $http.get('/api/apicompany/' + id) .success(function (result) { $scope.companyname = result.companyname }); };// $scope.pipelookup = {}; $scope.locationlookup = {}; $scope.upload = function () { var files = $scope.files; if (files && files.length) { (var = 0; < files.length; i++) { var file = files[i]; $scope.pipes.map(function (pip) { $scope.pipelookup[pip['pipeab']] = pip; }); $scope.locations.map(function (loc) { $scope.locationlookup[loc['locationab']] = loc; }); var matches = file.name.match(/^\d+\d\d+\s*?(\s*)\s*(\s*?)\./i); $scope.pip = $scope.pipelookup[matches[1]]; $scope.loc = $scope.locationlookup[matches[2]]; $upload.upload({ url: '/api/apibatchpipeline', fields: { 'typeid': 1, 'companyid': $scope.companyid.companyid, 'documentdate': $scope.model.documentdate, 'pipeid': $scope.pip['pipeid'], 'pipename': $scope.pip['pipename'], 'locationid': $scope.loc['locationid'], 'locationab': $scope.loc['locationab'] }, file: file }).progress(function (evt) { var progresspercentage = parseint(100.0 * evt.loaded / evt.total); console.log('progress: ' + progresspercentage + '% ' + evt.config.file.name); }).success(function (data, status, headers, config) { console.log('file ' + config.file.name + 'uploaded. response: ' + json.stringify(data)); }).error(function (err, result) { console.log(err, result); }); } }
$scope.pipelookup json
{"anr ":{"$id":"1","pipeid":1,"pipeab":"anr ","pipename":"transcanada anr pipeline","documents":null},"cgt ":{"$id":"2","pipeid":2,"pipeab":"cgt ","pipename":"columbia gulf transmission","documents":null},"cha ":{"$id":"3","pipeid":3,"pipeab":"cha ","pipename":"enterprise channel pipeline","documents":null},"fgt ":{"$id":"4","pipeid":4,"pipeab":"fgt ","pipename":"energy transfer florida gas transmission","documents":null},"gab ":{"$id":"5","pipeid":5,"pipeab":"gab ","pipename":"enbridge garden banks pipeline","documents":null},"glo ":{"$id":"6","pipeid":6,"pipeab":"glo ","pipename":"american midstream gloria pipeline","documents":null},"gso ":{"$id":"7","pipeid":7,"pipeab":"gso ","pipename":"boardwalk gulf south pipeline","documents":null},"hio ":{"$id":"8","pipeid":8,"pipeab":"hio ","pipename":"enterprise high island offshore system","documents":null},"hip ":{"$id":"9","pipeid":9,"pipeab":"hip ","pipename":"american midstream high point pipeline","documents":null},"hpl ":{"$id":"10","pipeid":10,"pipeab":"hpl ","pipename":"energy transfer houston pipeline","documents":null},"tej ":{"$id":"11","pipeid":11,"pipeab":"tej ","pipename":"kinder morgan tejas pipeline","documents":null},"kin ":{"$id":"12","pipeid":12,"pipeab":"kin ","pipename":"kinetica partners pipeline","documents":null},"ngp ":{"$id":"13","pipeid":13,"pipeab":"ngp ","pipename":" kinder morgan natural gas pipeline","documents":null},"ser ":{"$id":"14","pipeid":14,"pipeab":"ser ","pipename":" energy transfer sea robin pipeline company ","documents":null},"snt ":{"$id":"15","pipeid":15,"pipeab":"snt ","pipename":"kinder morgan southern natural gas company","documents":null},"sry ":{"$id":"16","pipeid":16,"pipeab":"sry ","pipename":"mcpo stingray pipeline company","documents":null},"tgt ":{"$id":"17","pipeid":17,"pipeab":"tgt ","pipename":"kinder morgan tennessee gas pipeline","documents":null},"tet ":{"$id":"18","pipeid":18,"pipeab":"tet ","pipename":"spectra energy texas eastern pipeline","documents":null},"txg ":{"$id":"19","pipeid":19,"pipeab":"txg ","pipename":"boardwalk texas gas transmission","documents":null},"tsc ":{"$id":"20","pipeid":20,"pipeab":"tsc ","pipename":"williams transcontinental gas pipeline","documents":null},"trk ":{"$id":"21","pipeid":21,"pipeab":"trk ","pipename":"energy transfer trunkline gas company","documents":null},"vgs ":{"$id":"22","pipeid":22,"pipeab":"vgs ","pipename":"targa venice gathering system","documents":null}}
$scope.locationlookup json
{"vr16":{"$id":"1","locationid":1,"locationab":"vr16","locationname":"location vr16","documents":null},"mp140\t":{"$id":"2","locationid":2,"locationab":"mp140\t","locationname":"location mp140","documents":null},"bs32":{"$id":"3","locationid":3,"locationab":"bs32","locationname":"location bs32","documents":null},"mp46":{"$id":"4","locationid":4,"locationab":"mp46","locationname":"location mp46","documents":null},"df78":{"$id":"5","locationid":5,"locationab":"df78","locationname":"location df78","documents":null},"ur56":{"$id":"6","locationid":6,"locationab":"ur56","locationname":"location ur56","documents":null}}
your regex expecting dot (.) character @ end string doesn't contain dot (.) @ end hence failing.
if try regex ^\d+\d\d+\s*?(\s*)\s*(\s*?)\.
here , pass in 02-2015 hip bs32
doesn't match because regex expecting .
literal @ end.
update: here fragment of pipelookup json
"hip ": { "$id": "9", "pipeid": 9, "pipeab": "hip ", "pipename": "american midstream high point pipeline", "documents": null
}
here key "hip " notice space after hip
. why $scope.pipelookup[matches[1]]
returns nothing. remove trailing space before storing in pipelookup
object
update: on more closer look, if file.name
contains value 02-2015 hip bs32
, if want hip
value out of can use following regex
/^\d+\d\d+\s*(\s*\s*)(\s*)/i
here jsbin live demo of regex example
Comments
Post a Comment