Add filtering for inactive batteries. #733

This commit is contained in:
Korina Cordero 2023-02-02 09:09:44 +00:00
parent 72fc6ee9b0
commit 6e9e56b1be
6 changed files with 66 additions and 41 deletions

View file

@ -47,6 +47,10 @@ class GenerateBatteryCompatibilityCommand extends Command
$comp_batt = []; $comp_batt = [];
foreach ($batteries as $battery) foreach ($batteries as $battery)
{ {
// check if battery is active
if (!($battery->isActive()))
continue;
// set to the first compatible battery found until a more expensive one is found // set to the first compatible battery found until a more expensive one is found
$comp_batt['id'] = $battery->getID(); $comp_batt['id'] = $battery->getID();
$comp_batt['name'] = $battery->getModel()->getName() . ' ' . $comp_batt['name'] = $battery->getModel()->getName() . ' ' .

View file

@ -825,6 +825,9 @@ class APIController extends Controller implements LoggedController
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); $batts = $vehicle->getBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{
// check if battery is active
if ($batt->isActive())
{ {
// TODO: Add warranty_tnv to battery information // TODO: Add warranty_tnv to battery information
$batt_list[] = [ $batt_list[] = [
@ -841,6 +844,7 @@ class APIController extends Controller implements LoggedController
'image_url' => $this->getBatteryImageURL($req, $batt), 'image_url' => $this->getBatteryImageURL($req, $batt),
]; ];
} }
}
// data // data
$data = [ $data = [

View file

@ -47,6 +47,9 @@ class BatteryController extends APIController
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); $batts = $vehicle->getBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{
// check if battery is active
if ($batt->isActive())
{ {
// TODO: Add warranty_tnv to battery information // TODO: Add warranty_tnv to battery information
$batt_list[] = [ $batt_list[] = [
@ -63,6 +66,7 @@ class BatteryController extends APIController
'image_url' => $this->getBatteryImageURL($req, $batt), 'image_url' => $this->getBatteryImageURL($req, $batt),
]; ];
} }
}
// data // data
$data = [ $data = [

View file

@ -496,6 +496,9 @@ class VehicleController extends Controller
// get compatible batteries from selected manufacturer // get compatible batteries from selected manufacturer
foreach ($vobj->getBatteries() as $battery) foreach ($vobj->getBatteries() as $battery)
{
// need to check if battery is active
if ($battery->isActive())
{ {
$batteries[] = [ $batteries[] = [
'id' => $battery->getID(), 'id' => $battery->getID(),
@ -509,6 +512,7 @@ class VehicleController extends Controller
]; ];
$battery_index[$battery->getID()] = 1; $battery_index[$battery->getID()] = 1;
} }
}
// add all other batteries, because they want options // add all other batteries, because they want options
foreach ($all_batts as $battery) foreach ($all_batts as $battery)

View file

@ -714,7 +714,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface
if (isset($data['error'])) if (isset($data['error']))
return $data; return $data;
$batts = $this->em->getRepository(Battery::class)->findAll(); $batts = $this->em->getRepository(Battery::class)->findBy(['flag_active' => true]);
$models = $this->em->getRepository(BatteryModel::class)->findAll(); $models = $this->em->getRepository(BatteryModel::class)->findAll();
$sizes = $this->em->getRepository(BatterySize::class)->findAll(); $sizes = $this->em->getRepository(BatterySize::class)->findAll();

View file

@ -239,7 +239,8 @@ $(function() {
manufacturer: "{{ batt.getManufacturer.getName|default('') }} ", manufacturer: "{{ batt.getManufacturer.getName|default('') }} ",
model: "{{ batt.getModel.getName|default('') }}", model: "{{ batt.getModel.getName|default('') }}",
size: "{{ batt.getSize.getName|default('') }}", size: "{{ batt.getSize.getName|default('') }}",
sell_price: "{{ batt.getSellingPrice }}" sell_price: "{{ batt.getSellingPrice }}",
flag_active: "{{ batt.isActive }}"
}; };
battRows.push(trow); battRows.push(trow);
@ -341,6 +342,14 @@ $(function() {
layout: { layout: {
scroll: true scroll: true
}, },
rows: {
beforeTemplate: function(row, data, index) {
var is_active = data.flag_active;
if (is_active == false) {
$(row).addClass('hide');
}
}
},
columns: [ columns: [
{ {
field: 'id', field: 'id',