2015-08-05 06:03:02 -07:00
|
|
|
angular.module('biomed')
|
2015-12-16 09:12:35 -08:00
|
|
|
.controller("TestRunAddCtrl", testRunAddController)
|
|
|
|
.controller("TestRunViewCtrl", testRunViewController)
|
2015-08-05 06:03:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
function testRunAddController($scope, Devices, CheckLists, TestRuns, $location, $filter, $routeParams) {
|
|
|
|
var search = $location.search();
|
|
|
|
|
|
|
|
console.log(search);
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
$scope.device = Devices.get({id: search.deviceId}, function () {
|
2015-08-05 06:03:02 -07:00
|
|
|
console.log($scope.device);
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
$scope.checkList = CheckLists.get({id: $scope.device.deviceType.checkList}, function () {
|
2015-08-05 06:03:02 -07:00
|
|
|
$scope.loading = false;
|
|
|
|
|
|
|
|
$scope.model = {
|
|
|
|
device: $scope.device._id,
|
|
|
|
date: new Date(),
|
|
|
|
fields: []
|
|
|
|
};
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
_.each($scope.checkList.fields, function (field) {
|
2015-08-05 06:03:02 -07:00
|
|
|
|
|
|
|
if (field.type == 'boolean') {
|
|
|
|
field.value = 'false'
|
|
|
|
}
|
|
|
|
|
|
|
|
field.result = false;
|
|
|
|
$scope.model.fields.push(field);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
$scope.$watch('model', function () {
|
2015-08-05 06:03:02 -07:00
|
|
|
$scope.model.result = true;
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
_.each($scope.model.fields, function (field) {
|
2015-08-05 06:03:02 -07:00
|
|
|
if (field.type == 'boolean') {
|
|
|
|
field.result = (field.value == 'true');
|
|
|
|
} else if (field.type == 'range') {
|
|
|
|
field.result = field.value >= field.min && field.value <= field.max;
|
2015-08-23 22:40:30 -07:00
|
|
|
} else if (field.type == 'text') {
|
|
|
|
field.result = true;
|
2015-08-05 06:03:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.model.result &= field.result;
|
|
|
|
})
|
|
|
|
}, true);
|
|
|
|
|
2015-12-16 09:12:35 -08:00
|
|
|
$scope.save = function () {
|
|
|
|
TestRuns.create($scope.model, function (result) {
|
2015-08-05 06:03:02 -07:00
|
|
|
$location.path("/testRuns/" + result._id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRunViewController($scope, Devices, CheckLists, TestRuns, $location, $filter, $routeParams) {
|
|
|
|
$scope.model = TestRuns.get($routeParams);
|
2015-08-23 22:40:30 -07:00
|
|
|
}
|