117 lines
3.8 KiB
JavaScript
117 lines
3.8 KiB
JavaScript
poconsole.controller('wellTestCtrl', function($scope, json, Page, $log){
|
|
Page.setTitle('Well Test');
|
|
Page.setPage('welltest');
|
|
var getWellTests = function(){
|
|
$scope.newTest = {
|
|
shot_datetime:null,
|
|
pump_intake_pressure:null,
|
|
fluid_gradient:null,
|
|
friction:null,
|
|
taken_by:null
|
|
};
|
|
|
|
var getWellTests = json.getWellTests();
|
|
getWellTests.then(function(data){
|
|
var wtObj = {};
|
|
for (var v in data){
|
|
if (wtObj.hasOwnProperty(data[v].date)){
|
|
wtObj[data[v].date][data[v].name] = data[v].val;
|
|
} else {
|
|
wtObj[data[v].date] = {date: data[v].date};
|
|
wtObj[data[v].date][data[v].name] = data[v].val;
|
|
}
|
|
}
|
|
console.log(wtObj);
|
|
$scope.wellTests = wtObj;
|
|
});
|
|
};
|
|
|
|
$scope.message = null;
|
|
$scope.newTest = {
|
|
shot_datetime:null,
|
|
pump_intake_pressure:null,
|
|
fluid_gradient:null,
|
|
friction:null,
|
|
taken_by:null
|
|
};
|
|
|
|
|
|
$scope.addWellTest = function(){
|
|
if(!$scope.newTest.shot_datetime){
|
|
$scope.message = "No Date/Time provided.";
|
|
} else if(!$scope.newTest.pump_intake_pressure){
|
|
$scope.message = "No Pump Intake Pressure provided.";
|
|
} else if(!$scope.newTest.taken_by){
|
|
$scope.message = "No Taken By provided.";
|
|
} else {
|
|
$scope.message = json.pushFluidShot($scope.newTest.shot_datetime, $scope.newTest.pump_intake_pressure, $scope.newTest.fluid_gradient, $scope.newTest.friction, $scope.newTest.taken_by);
|
|
getWellTests();
|
|
}
|
|
|
|
};
|
|
|
|
$scope.deleteWellTest = function(id){
|
|
json.deleteWellTest(id);
|
|
getWellTests();
|
|
if ($scope.ShowDeletedTests){
|
|
getDeletedWellTests();
|
|
}
|
|
};
|
|
|
|
$scope.undeleteFluidShot = function(id){
|
|
json.undeleteFluidShot(id);
|
|
getFluidShots();
|
|
if ($scope.showDeletedFluidShots){
|
|
getDeletedFluidShots();
|
|
}
|
|
|
|
};
|
|
|
|
$scope.toggleDeleted = function(){
|
|
if ($scope.showDeletedFluidShots){
|
|
$scope.showDeletedFluidShots = false;
|
|
} else {
|
|
$scope.showDeletedFluidShots = true;
|
|
getDeletedFluidShots();
|
|
}
|
|
};
|
|
|
|
var getDeletedFluidShots = function(){
|
|
$scope.showDeletedFluidShots = true;
|
|
var getDeletedFluidShots = json.getDeletedFluidShots();
|
|
getDeletedFluidShots.then(function(data){
|
|
$scope.deletedFluidShots = data.fluid_shots;
|
|
});
|
|
};
|
|
|
|
$scope.startEditFluidShot = function(id){
|
|
$scope.message = null;
|
|
var editShotTarget = $scope.fluidShots.filter(function(x){
|
|
return (x.id == id);
|
|
})[0];
|
|
|
|
$scope.editShot = {
|
|
id:editShotTarget.id,
|
|
shot_datetime:editShotTarget.shot_datetime,
|
|
pump_intake_pressure:editShotTarget.pump_intake_pressure,
|
|
fluid_gradient:editShotTarget.fluid_gradient,
|
|
friction:editShotTarget.friction,
|
|
taken_by:editShotTarget.taken_by
|
|
};
|
|
};
|
|
|
|
$scope.submitEditedShot = function(){
|
|
if(!$scope.editShot.shot_datetime){
|
|
$scope.message = "No Date/Time provided.";
|
|
} else if(!$scope.editShot.pump_intake_pressure){
|
|
$scope.message = "No Pump Intake Pressure provided.";
|
|
} else if(!$scope.editShot.taken_by){
|
|
$scope.message = "No Taken By provided.";
|
|
} else {
|
|
$scope.message = json.updateFluidShot($scope.editShot.id, $scope.editShot.shot_datetime, $scope.editShot.pump_intake_pressure, $scope.editShot.fluid_gradient, $scope.editShot.friction, $scope.editShot.taken_by);
|
|
getFluidShots();
|
|
}
|
|
};
|
|
getWellTests();
|
|
});
|