1app.controller("labels_index_controller", function( 2 $scope, 3 $location, 4 $modal, 5 labels, 6 LabelsPathTo, 7 receipts, 8 preparations 9) { 10 11 var initialize = function() { 12 $scope.labels = labels 13 $scope.preparations = preparations 14 $scope.receipts = receipts 15 $scope.ingredients = [] 16 $scope.fillIngredients() 17 } 18 19 $scope.fillIngredients = function(){ 20 for (i = 0; i < $scope.preparations.length; i++) { 21 $scope.ingredients.push($scope.preparations[i]) 22 } 23 24 for (i = 0; i < $scope.receipts.length; i++) { 25 $scope.ingredients.push($scope.receipts[i]) 26 } 27 return $scope.ingredients 28 } 29 30 $scope.newLabelModal = function() { 31 var modalInstance = $modal.open({ 32 templateUrl: "views/labels/label_modal.html", 33 controller: "label_modal_controller", 34 resolve: { 35 ingredients: function() { 36 return $scope.ingredients 37 } 38 } 39 }) 40 } 41 42 $scope.goToLabelDetails = function(label) { 43 $location.url("/labels/" + label.id + "/details") 44 } 45 46 $scope.deleteLabel = function(label_id) { 47 if (confirm("Deseja mesmo deletar esse rótulo?")) { 48 LabelsPathTo.remove( 49 { 50 id: label_id 51 }, 52 function success(result) { 53 $scope.labels = $.grep($scope.labels, function(e) { 54 return e.id != label_id 55 }) 56 } 57 ) 58 } 59 } 60 61 initialize() 62}) 63 64app.controller("label_modal_controller", function( 65 $scope, 66 $location, 67 $modal, 68 LabelsPathTo, 69 $timeout, 70 $modalInstance, 71 $rootScope, 72 ingredients, 73 ReceiptsPathTo, 74 PreparationsPathTo 75) { 76 var initialize = function() { 77 $scope.ingredients = ingredients 78 } 79 80 $scope.selectIngredient = function(resource){ 81 if(resource.class_name == 'preparation'){ 82 PreparationsPathTo.get({ 83 id: resource.id 84 }, 85 function(result){ 86 $scope.resource = result 87 }) 88 } 89 else if(resource.class_name == 'receipt'){ 90 ReceiptsPathTo.get({ 91 id: resource.id 92 }, 93 function(result){ 94 $scope.resource = result 95 }) 96 } 97 } 98 99 $scope.createNewLabel = function() { 100 if($scope.resource.class_name == 'preparation'){ 101 var ingredients_desc = [] 102 if($scope.resource.prep_input_composition) { 103 $scope.resource.prep_input_composition.sort(function(a, b) { 104 return b.quantity - a.quantity 105 }) 106 for (var i = 0; i < $scope.resource.prep_input_composition.length; i++) { 107 if ( 108 ingredients_desc.indexOf( 109 " " + $scope.resource.prep_input_composition[i].name 110 ) == -1 111 ) { 112 ingredients_desc.push(" " + $scope.resource.prep_input_composition[i].name) 113 } 114 } 115 $scope.label = { 116 label_name: $scope.resource.name, 117 preparation_id: $scope.resource.id, 118 ingredients_desc: ingredients_desc.toString(), 119 account_id: $rootScope.current_user.account_id, 120 multiplier: 1, 121 portion: $scope.resource.total_grammage 122 } 123 } 124 } 125 else if($scope.resource.class_name == 'receipt'){ 126 var ingredients_desc = [] 127 $scope.resource.receipt_input_composition.sort(function(a, b) { 128 return b.quantity - a.quantity 129 }) 130 for (var i = 0; i < $scope.resource.receipt_input_composition.length; i++) { 131 if ( 132 ingredients_desc.indexOf( 133 " " + $scope.resource.receipt_input_composition[i].name 134 ) == -1 135 ) { 136 ingredients_desc.push(" " + $scope.resource.receipt_input_composition[i].name) 137 } 138 } 139 $scope.label = { 140 label_name: $scope.resource.name, 141 receipt_id: $scope.resource.id, 142 ingredients_desc: ingredients_desc.toString(), 143 account_id: $rootScope.current_user.account_id, 144 multiplier: 1, 145 portion: $scope.resource.total_grammage 146 } 147 } 148 if(!$scope.resource.label_id){ 149 LabelsPathTo.save( 150 { 151 label: $scope.label 152 }, 153 function sucess(label) { 154 $modalInstance.close() 155 Intercom("trackEvent", "Rotulo_Criou")
156 $location.url("/labels/" + label.id + "/details") 157 } 158 ) 159 } 160 else { 161 $modalInstance.close() 162 $location.url("/labels/" + $scope.resource.label_id + "/details") 163 } 164 } 165 166 $scope.closeModal = function(){ 167 $modalInstance.close() 168 } 169 170 initialize() 171}) 172 173app.controller("label_details_controller", function( 174 $scope, 175 $location, 176 $timeout, 177 label, 178 LabelsPathTo, 179 auth 180) { 181 var initialize = function() { 182 $scope.label = label 183 $scope.roundRules() 184 $scope.noValueWarning() 185 $scope.showLabel = false 186 if (!$scope.label.receipt_unit_name) { 187 $scope.label.receipt_unit_name = 'g' 188 } 189 } 190 191 $scope.setReceiptUnit = function(receipt_unit){ 192 $scope.label.receipt_unit_name = receipt_unit 193 } 194 195 $scope.labelExcel = function() { 196 if($scope.label.label_values.energy_kcal > 0){ 197 var current_auth = auth.get() 198 199 var exportUrl = 200 $scope.endpoint + 201 "labels/" + 202 $scope.label.id + 203 "/label_csv" + 204 ".csv?user_email=" + 205 current_auth.user.email + 206 "&user_token=" + 207 current_auth.user.authentication_token + 208 "&csv=1" 209 window.location = exportUrl 210 211 Intercom("trackEvent", "Rotulo_Baixou") 212 } 213 } 214 215 $scope.noValueWarning = function(){ 216 if(($scope.label.label_values.energy_kcal <= 4 && $scope.label.label_values.energy_kcal > 0) || ($scope.label.label_values.carbohydrate <= 0.5 && $scope.label.label_values.carbohydrate > 0) || ($scope.label.label_values.total_sugars <= 0.5 && $scope.label.label_values.total_sugars > 0) || ($scope.label.label_values.added_sugars <= 0.1 && $scope.label.label_values.added_sugars > 0) || ($scope.label.label_values.minerals_sodium <= 5 && $scope.label.label_values.minerals_sodium > 0)) { 217 $scope.showNoValueWarning = true 218 } 219 } 220 221 $scope.updateIngredientsDesc = function() { 222 if ( 223 confirm( 224 "Ao remontar a lista de itens, você recebe possÃveis novos itens que foram adicionados a receita à venda ou receita após esse rótulo ter sido criado. Atualizar a lista de itens do rótulo fará com que você perca qualquer alteração na lista antiga, deseja continuar?" 225 ) 226 ) { 227 var ingredients_desc = [] 228 if($scope.label.parent == 'preparation'){ 229 var list = $scope.label.label_ingredient.preparation_input_composition 230 var sortedList = list.sort((a, b) => (a.quantity < b.quantity) ? 1 : -1) 231 for ( 232 var i = 0; 233 i < sortedList.length; 234 i++ 235 ) { 236 if ( 237 ingredients_desc.indexOf( 238 " " + 239 sortedList[i].name 240 ) == -1 241 ) { 242 ingredients_desc.push( 243 " " + 244 sortedList[i].name 245 ) 246 } 247 } 248 } 249 else if ($scope.label.parent == 'receipt'){ 250 var list = $scope.label.label_ingredient.receipt_input_composition 251 var sortedList = list.sort((a, b) => (a.quantity < b.quantity) ? 1 : -1) 252 for ( 253 var i = 0; 254 i < sortedList.length; 255 i++ 256 ) { 257 if ( 258 ingredients_desc.indexOf( 259 " " + 260 sortedList[i].name 261 ) == -1 262 ) { 263 ingredients_desc.push( 264 " " + 265 sortedList[i].name 266 ) 267 } 268 } 269 } 270 $scope.label.ingredients_desc = ingredients_desc 271 .toString() 272 .replace(/\"/g, "") 273 } 274 $scope.updateLabel() 275 } 276 277 $scope.needsToUpdateLabel = function() { 278 $scope.needsToSaveChanges = true 279 } 280 281 $scope.roundRules = function(){ 282 $scope.needsToSaveChanges = true 283 $scope.showApproximate = false 284 //check if integer 285 if($scope.label.portion_by_package > 2 && $scope.label.portion_by_package % 1 !== 0){ 286 $scope.label_round_portion = Math.round($scope.label.portion_by_package) 287 $scope.showApproximate = true 288 } 289 } 290 291 $scope.getMultiplier = function() { 292 $scope.label.multiplier = $scope.label.portion / 100 293 $scope.needsToUpdateLabel() 294 } 295
296 $scope.exportToPDF = function() { 297 var current_auth = auth.get() 298 299 window.location = 300 $scope.endpoint + 301 "labels/" + 302 $scope.label.id + 303 "/print" + 304 ".pdf?user_email=" + 305 current_auth.user.email + 306 "&user_token=" + 307 current_auth.user.authentication_token 308 Intercom("trackEvent", "Rotulo_Baixou") 309 } 310 311 $scope.updateLabel = function(printAfter) { 312 $scope.needsToSaveChanges = false 313 LabelsPathTo.update( 314 { 315 id: $scope.label.id, 316 label: $scope.label 317 }, 318 function success() { 319 if(!printAfter){ 320 Toastify({ 321 text: "Rótulo atualizado com sucesso!", 322 duration: 2000, 323 newWindow: true, 324 gravity: "top", // `top` or `bottom` 325 position: "right", // `left`, `center` or `right` 326 stopOnFocus: true, // Prevents dismissing of toast on hover 327 offset: { 328 y: 65 329 }, 330 style: { 331 background: "#E4531A", 332 borderRadius: "4px", 333 opacity: "0.8" 334 }, 335 onClick: function(){} // Callback after click 336 }).showToast() 337 } else { 338 Toastify({ 339 text: "Aguarde enquanto exportamos seu rótulo!", 340 duration: 5500, 341 newWindow: true, 342 gravity: "top", // `top` or `bottom` 343 position: "right", // `left`, `center` or `right` 344 stopOnFocus: true, // Prevents dismissing of toast on hover 345 offset: { 346 y: 65 347 }, 348 style: { 349 background: "#E4531A", 350 borderRadius: "4px", 351 opacity: "0.8" 352 }, 353 onClick: function(){} // Callback after click 354 }).showToast() 355 } 356 if(printAfter == 'pdf'){ 357 $scope.exportToPDF() 358 } 359 if(printAfter == 'csv'){ 360 $scope.labelExcel() 361 } 362 } 363 ) 364 } 365 366 $scope.updateExtraFields = function(field_name) { 367 $scope.needsToSaveChanges = true 368 if($scope.label.extra_fields && $scope.label.extra_fields.indexOf(field_name) != -1) { 369 var stringToReplace = field_name + "," 370 $scope.label.extra_fields = $scope.label.extra_fields.replace(stringToReplace, "") 371 } else { 372 $scope.label.extra_fields = $scope.label.extra_fields + field_name + "," 373 } 374 console.log("pós", $scope.label.extra_fields) 375 } 376 377 $scope.breakdownExtraFields = function() { 378 $scope.extra_label_values = $scope.label.extra_label_values.split(",") 379 } 380 381 initialize() 382})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.