/* This is data directive , fetch specific lca detail through lca cache service with LCAID */ var app = angular.module('View.Directive') app.directive('lcaDetail', function () {// return { controller: function ($scope, $routeParams, LCADetailCacheService) { $scope.Allocation = -1; $scope.Ratio = 0.00; if ($routeParams.LCAID) LCADetailCacheService.getLCADetailAsync($routeParams.LCAID).then(function (result) { $scope.lcaDetail = result; $scope.lcaDetail.hasPCR = result.PCRID != null; $scope.lcaDetail.isProductLCA = isProductLCA(result.LCAType); $scope.productLCA = result.productLCA; $scope.product = result.product if ($scope.lcaDetail.isProductLCA) { $scope.Allocation = $scope.productLCA["ProductAllocation" + $routeParams.DetailType]; if ($scope.Allocation != undefined) { /* if ($scope.Allocation == 0) $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.product.Weight, $scope.lcaDetail.FabProductionWeight); else if ($scope.Allocation == 1) $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.product.AreaSize, $scope.lcaDetail.FabProductionArea); else if ($scope.Allocation == 2) $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, 1, $scope.lcaDetail.FabProductionPcs); else if ($scope.Allocation == 3) $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.lcaDetail.ProductProductionEconomic, $scope.lcaDetail.FabProductionEconomic); else if ($scope.Allocation == 4) $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.lcaDetail.ProductProductionHour, $scope.lcaDetail.FabProductionHour); */ if ($scope.Allocation == 0) //重量分配 //$scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.product.Weight, $scope.lcaDetail.FabProductionWeight); $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs * $scope.product.Weight / $scope.lcaDetail.FabProductionWeight, 1, $scope.lcaDetail.ProductProductionPcs); else if ($scope.Allocation == 1) //面積分配 //$scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.product.AreaSize, $scope.lcaDetail.FabProductionArea); $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs * $scope.product.AreaSize / $scope.lcaDetail.FabProductionArea, 1, $scope.lcaDetail.ProductProductionPcs); else if ($scope.Allocation == 2) //產量分配 //$scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, 1, $scope.lcaDetail.FabProductionPcs); $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, 1, $scope.lcaDetail.FabProductionPcs); else if ($scope.Allocation == 3) //經濟分配 //$scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.lcaDetail.ProductProductionEconomic, $scope.lcaDetail.FabProductionEconomic); $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs * $scope.lcaDetail.ProductProductionEconomic / $scope.lcaDetail.FabProductionEconomic, 1, $scope.lcaDetail.ProductProductionPcs); else if ($scope.Allocation == 4) //工時分配 //$scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs, $scope.lcaDetail.ProductProductionHour, $scope.lcaDetail.FabProductionHour); $scope.Ratio = $scope.calculate($scope.lcaDetail.ProductProductionPcs * $scope.lcaDetail.ProductProductionHour / $scope.lcaDetail.FabProductionHour, 1, $scope.lcaDetail.ProductProductionPcs); else if ($scope.Allocation == 99) $scope.Ratio = 1; } } }) $scope.modifyCacheAllocation = function () { var cache = LCADetailCacheService.getCache('LCADetail'); if (cache.get($routeParams.LCAID)) { var data = cache.get($routeParams.LCAID) data.productLCA["ProductAllocation" + $routeParams.DetailType] = $scope.Allocation; cache.put($routeParams.LCAID, data); } } $scope.calculate = function (a, b, c) { // 計算 a * b / c,若結果為nan回傳 0 var ret = a * b / c if (isNaN(ret)) return 0 if (ret == Infinity) return 0 //return Number(Math.round(ret + 'e' + 4) + 'e-' + 4) return ret } } }; }) app.filter('calculateF', function () { var filter = function (a, b, c) { // 計算 a * b / c,若結果為nan回傳 0 var ret = a * b / c if (isNaN(ret)) return 0 if (ret == Infinity) return 0 return Number(Math.round(ret + 'e' + 4) + 'e-' + 4) }; return filter; }); app.filter('getFileName', function () { var filter = function (str) { if (str == undefined) return ''; var arr = str.split('/'); var len = arr[arr.length - 1].split('_', 1)[0].length; return arr[arr.length - 1].substring(len); }; return filter; });