Add saving of updated form for one step job order. #270
This commit is contained in:
parent
3a167f0b38
commit
8da95f2ed0
3 changed files with 526 additions and 686 deletions
|
|
@ -870,11 +870,12 @@ class JobOrderController extends Controller
|
|||
/**
|
||||
* @Menu(selected="jo_onestep_edit_form")
|
||||
*/
|
||||
public function oneStepEditForm($id, JobOrderHandlerInterface $jo_handler, GISManagerInterface $gis)
|
||||
public function oneStepEditForm($id, JobOrderHandlerInterface $jo_handler,
|
||||
GISManagerInterface $gis, MapTools $map_tools)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_onestep.edit', null, 'No access.');
|
||||
|
||||
$params = $jo_handler->initializeOneStepEditForm($id);
|
||||
$params = $jo_handler->initializeOneStepEditForm($id, $map_tools);
|
||||
$params['submit_url'] = $this->generateUrl('jo_onestep_edit_submit', ['id' => $id]);
|
||||
$params['return_url'] = $this->generateUrl('jo_open');
|
||||
$params['map_js_file'] = $gis->getJSJOFile();
|
||||
|
|
@ -885,7 +886,26 @@ class JobOrderController extends Controller
|
|||
return $this->render($template, $params);
|
||||
}
|
||||
|
||||
public function oneStepEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler)
|
||||
public function oneStepEditSubmit(Request $req, JobOrderHandlerInterface $jo_handler, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_onestep.edit', null, 'No access.');
|
||||
|
||||
$error_array = [];
|
||||
$error_array = $jo_handler->generateOneStepJobOrder($req, $id);
|
||||
|
||||
// check if any errors were found
|
||||
if (!empty($error_array)) {
|
||||
// return validation failure response
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1267,19 +1267,60 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
return $params;
|
||||
}
|
||||
|
||||
public function initializeOneStepEditForm($id)
|
||||
public function initializeOneStepEditForm($id, $map_tools)
|
||||
{
|
||||
$em = $this->em;
|
||||
$jo = $em->getRepository(JobOrder::class)->find($id);
|
||||
$obj = $em->getRepository(JobOrder::class)->find($id);
|
||||
|
||||
$params['obj'] = $jo;
|
||||
$params['mode'] = 'onestep_edit';
|
||||
$params['cvid'] = $jo->getCustomerVehicle()->getID();
|
||||
$params['vid'] = $jo->getCustomerVehicle()->getVehicle()->getID();
|
||||
$params['obj'] = $obj;
|
||||
$params['mode'] = 'onestep-edit';
|
||||
$params['cvid'] = $obj->getCustomerVehicle()->getID();
|
||||
$params['vid'] = $obj->getCustomerVehicle()->getVehicle()->getID();
|
||||
|
||||
$this->fillDropdownParameters($params);
|
||||
$this->fillFormTags($params);
|
||||
|
||||
// get the hubs
|
||||
// TODO: move this snippet to a function
|
||||
$hubs = $map_tools->getClosestHubs($obj->getCoordinates(), 50, date("H:i:s"));
|
||||
|
||||
$params['hubs'] = [];
|
||||
|
||||
// format duration and distance into friendly time
|
||||
foreach ($hubs as $hub) {
|
||||
// duration
|
||||
$seconds = $hub['duration'];
|
||||
|
||||
if (!empty($seconds) && $seconds > 0) {
|
||||
$hours = floor($seconds / 3600);
|
||||
$minutes = ceil(($seconds / 60) % 60);
|
||||
|
||||
$hub['duration'] = ($hours > 0 ? number_format($hours) . " hr" . ($hours > 1 ? "s" : '') . ($minutes > 0 ? ", " : '') : '') . ($minutes > 0 ? number_format($minutes) . " min" . ($minutes > 1 ? "s" : '') : '');
|
||||
} else {
|
||||
$hub['duration'] = false;
|
||||
}
|
||||
|
||||
// distance
|
||||
$meters = $hub['distance'];
|
||||
|
||||
if (!empty($meters) && $meters > 0) {
|
||||
$hub['distance'] = round($meters / 1000) . " km";
|
||||
} else {
|
||||
$hub['distance'] = false;
|
||||
}
|
||||
|
||||
// counters
|
||||
$hub['rider_count'] = count($hub['hub']->getAvailableRiders());
|
||||
$hub['jo_count'] = count($hub['hub']->getForAssignmentJobOrders());
|
||||
|
||||
// check for rejection
|
||||
$hub['flag_rejected'] = false;
|
||||
$hub_id = $hub['hub']->getID();
|
||||
|
||||
$params['hubs'][] = $hub;
|
||||
}
|
||||
|
||||
|
||||
// get template to display
|
||||
$params['template'] = $this->getTwigTemplate('jo_onestep_edit_form');
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue