157 lines
6.6 KiB
JavaScript
157 lines
6.6 KiB
JavaScript
/*
|
|
Logic Solution
|
|
WeeeCarbonFootprint
|
|
Template Directive
|
|
displayOption example:
|
|
{
|
|
show: true/false,
|
|
onOk(selected,selectedType): callback function , selected : the parameter that user selected
|
|
, selectedType : the category that parameter belongs
|
|
}
|
|
*/
|
|
|
|
angular.module('View.Directive')
|
|
.directive('quality', function (CONSTANTS) {
|
|
var arr = window.location.href.split("/");
|
|
if (arr[3].indexOf('app') == 0)
|
|
baseUrl = '';
|
|
else
|
|
baseUrl = '/' + arr[3];
|
|
return {
|
|
restrict: 'E',
|
|
scope: {
|
|
displayOption: '=displayOption',
|
|
},
|
|
transclude: true,
|
|
controller: function ($scope, $element, $timeout, $http) {
|
|
function DQRni2DQRi(DQRni) {
|
|
var ret;
|
|
switch (DQRni) {
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
ret = 1;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
ret = 2;
|
|
break;
|
|
case 6:
|
|
case 8:
|
|
case 9:
|
|
ret = 3;
|
|
break;
|
|
case 10:
|
|
case 12:
|
|
case 16:
|
|
ret = 4;
|
|
break;
|
|
case 15:
|
|
case 20:
|
|
case 25:
|
|
ret = 5;
|
|
break;
|
|
default:
|
|
ret = 0;
|
|
break;
|
|
}
|
|
//console.log('DQRni2DQRi', DQRni, ret);
|
|
return ret;
|
|
}
|
|
function DQR(Re, Co, Ti, Ge, Te) {
|
|
if (isNaN(Re) || isNaN(Co) || isNaN(Ti) || isNaN(Ge)
|
|
|| isNaN(Te))
|
|
return NaN;
|
|
var Xw = 0;
|
|
if (Re > Xw)
|
|
Xw = Re;
|
|
if (Co > Xw)
|
|
Xw = Co;
|
|
if (Ti > Xw)
|
|
Xw = Ti;
|
|
if (Ge > Xw)
|
|
Xw = Ge;
|
|
if (Te > Xw)
|
|
Xw = Te;
|
|
var ret;
|
|
ret = (Re + Co + Ti + Ge + Te + Xw * 5.0) / 10;
|
|
return ret;
|
|
}
|
|
$scope.calculate = function () {
|
|
if ($scope.displayOption != undefined) {
|
|
//console.log('calculate');
|
|
$scope.displayOption.data.DQRniRe =
|
|
$scope.displayOption.data.DQRaiRe
|
|
* $scope.displayOption.data.DQReiRe;
|
|
$scope.displayOption.data.DQRniCo =
|
|
$scope.displayOption.data.DQRaiCo
|
|
* $scope.displayOption.data.DQReiCo;
|
|
$scope.displayOption.data.DQRniTi =
|
|
$scope.displayOption.data.DQRaiTi
|
|
* $scope.displayOption.data.DQReiTi;
|
|
$scope.displayOption.data.DQRniGe =
|
|
$scope.displayOption.data.DQRaiGe
|
|
* $scope.displayOption.data.DQReiGe;
|
|
$scope.displayOption.data.DQRniTe =
|
|
$scope.displayOption.data.DQRaiTe
|
|
* $scope.displayOption.data.DQReiTe;
|
|
|
|
$scope.displayOption.data.DQRiRe =
|
|
DQRni2DQRi($scope.displayOption.data.DQRniRe);
|
|
$scope.displayOption.data.DQRiCo =
|
|
DQRni2DQRi($scope.displayOption.data.DQRniCo);
|
|
$scope.displayOption.data.DQRiTi =
|
|
DQRni2DQRi($scope.displayOption.data.DQRniTi);
|
|
$scope.displayOption.data.DQRiGe =
|
|
DQRni2DQRi($scope.displayOption.data.DQRniGe);
|
|
$scope.displayOption.data.DQRiTe =
|
|
DQRni2DQRi($scope.displayOption.data.DQRniTe);
|
|
|
|
$scope.displayOption.data.DQR = DQR(
|
|
$scope.displayOption.data.DQRiRe,
|
|
$scope.displayOption.data.DQRiCo,
|
|
$scope.displayOption.data.DQRiTi,
|
|
$scope.displayOption.data.DQRiGe,
|
|
$scope.displayOption.data.DQRiTe
|
|
);
|
|
|
|
$scope.displayOption.data.DQRw =
|
|
$scope.displayOption.data.DQR
|
|
* $scope.displayOption.data.Fi;
|
|
}
|
|
};
|
|
$scope.onOkFn = function () {
|
|
$http.post(baseUrl+'/api/DataQualityLevel/Save/', $scope.displayOption.data
|
|
).success(function (data) {
|
|
//console.log(data);
|
|
}).error(function (data, status) {
|
|
//console.log(data, status);
|
|
});
|
|
$scope.displayOption.show = false;
|
|
};
|
|
$scope.onCancelFn = function () {
|
|
$scope.displayOption.show = false;
|
|
};
|
|
},
|
|
link: function (scope, element, attrs) {
|
|
// using $watch to find modal opening event
|
|
scope.$watch('displayOption', function (newValue, oldValue) {
|
|
if (scope.displayOption && (scope.displayOption.show == true)) {
|
|
// add class 'modal-open' to <body> if a modal is opening
|
|
angular.element('body').addClass('modal-open');
|
|
//alert('show');
|
|
}
|
|
else if (scope.displayOption && (scope.displayOption.show == false)) {
|
|
// remove class 'modal-open' from <body> if a modal is colsing
|
|
angular.element('body').removeClass('modal-open');
|
|
//alert('hide');
|
|
}
|
|
// Reset form status by $setPristine
|
|
if (scope.passedForm) {
|
|
scope.passedForm.$setPristine();
|
|
}
|
|
}, true)
|
|
},
|
|
templateUrl: CONSTANTS.TB + 'quality'
|
|
};
|
|
}); |