Skip to content

Commit

Permalink
style: fixed style using pint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Apr 17, 2024
1 parent 7a50205 commit 9b56dd3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 60 deletions.
109 changes: 54 additions & 55 deletions app/Http/Controllers/HardwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,77 @@

namespace App\Http\Controllers;

use App\Models\NethserverHardware;
use App\Models\NethsecurityHardware;
use App\Models\NethserverHardware;
use Illuminate\Http\Request;

class HardwareController extends Controller
{
public function index(Request $request, String $installation)
public function index(Request $request, string $installation)
{
// Retrieve search term from request
$searchTerm = $request->input('search_term');
// Initialize variables for storing matches and count
$matchingHardware = [];
$inputMatch = [];
$inputMatch = [];
$count = 0;

// If search term is empty, return an empty view
if($searchTerm === null || $searchTerm === '')
{
if ($searchTerm === null || $searchTerm === '') {
return view('hardware', ['matchingHardware' => collect(), 'installation' => $installation]);
}
// Perform a query to find all hardware that contain the search term
if($installation === 'NethServer'){
if(!empty($searchTerm)){
$matchingHardware = NethserverHardware::where('product_name', 'ilike', '%' . $searchTerm . '%')
->orWhere('manufacturer', 'ilike', '%' . $searchTerm . '%')
->orWhere('processor', 'ilike', '%' . $searchTerm . '%')
->orWhere('vga_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('usb_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('pci_bridge', 'ilike', '%' . $searchTerm . '%')
->orWhere('sata_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('communication_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('scsi_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('ethernet', 'ilike', '%' . $searchTerm . '%')
if ($installation === 'NethServer') {
if (! empty($searchTerm)) {
$matchingHardware = NethserverHardware::where('product_name', 'ilike', '%'.$searchTerm.'%')
->orWhere('manufacturer', 'ilike', '%'.$searchTerm.'%')
->orWhere('processor', 'ilike', '%'.$searchTerm.'%')
->orWhere('vga_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('usb_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('pci_bridge', 'ilike', '%'.$searchTerm.'%')
->orWhere('sata_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('communication_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('scsi_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('ethernet', 'ilike', '%'.$searchTerm.'%')
->get();
}
}else if($installation === 'NethSecurity'){
if(!empty($searchTerm)){
$matchingHardware = NethsecurityHardware::where('product_name', 'ilike', '%' . $searchTerm . '%')
->orWhere('manufacturer', 'ilike', '%' . $searchTerm . '%')
->orWhere('processor', 'ilike', '%' . $searchTerm . '%')
->orWhere('vga_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('usb_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('pci_bridge', 'ilike', '%' . $searchTerm . '%')
->orWhere('sata_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('communication_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('scsi_controller', 'ilike', '%' . $searchTerm . '%')
->orWhere('ethernet', 'ilike', '%' . $searchTerm . '%')
} elseif ($installation === 'NethSecurity') {
if (! empty($searchTerm)) {
$matchingHardware = NethsecurityHardware::where('product_name', 'ilike', '%'.$searchTerm.'%')
->orWhere('manufacturer', 'ilike', '%'.$searchTerm.'%')
->orWhere('processor', 'ilike', '%'.$searchTerm.'%')
->orWhere('vga_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('usb_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('pci_bridge', 'ilike', '%'.$searchTerm.'%')
->orWhere('sata_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('communication_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('scsi_controller', 'ilike', '%'.$searchTerm.'%')
->orWhere('ethernet', 'ilike', '%'.$searchTerm.'%')
->get();
}
}
// Returning an array containing only the specific hardware elements that contain the search term
foreach ($matchingHardware as $hardware) {
if(stripos($hardware->product_name, $searchTerm) !== false){
$inputMatch[] = 'Product Name: ' . $hardware->product_name;
}else if(stripos($hardware->manufacturer, $searchTerm) !== false){
$inputMatch[] = 'Manufacturer: ' . $hardware->manufacturer;
}else if(stripos($hardware->processor, $searchTerm) !== false){
$inputMatch[] = 'Processor: ' . $hardware->processor;
}else if(stripos($hardware->vga_controller, $searchTerm) !== false){
$inputMatch[] = 'Vga Controller: ' . $hardware->vga_controller;
}else if(stripos($hardware->usb_controller, $searchTerm) !== false){
$inputMatch[] = 'Usb Controller: ' . $hardware->usb_controller;
}else if(stripos($hardware->pci_bridge, $searchTerm) !== false){
$inputMatch[] = 'Pci Bridge: ' . $hardware->pci_bridge;
}else if(stripos($hardware->sata_controller, $searchTerm) !== false){
$inputMatch[] = 'Sata Controller: ' . $hardware->sata_controller;
}else if(stripos($hardware->communication_controller, $searchTerm) !== false){
$inputMatch[] = 'Communication Controller: ' . $hardware->communication_controller;
}else if(stripos($hardware->scsi_controller, $searchTerm) !== false){
$inputMatch[] = 'SCSI Controller: ' . $hardware->scsi_controller;
}else if(stripos($hardware->ethernet, $searchTerm) !== false){
$inputMatch[] = 'Ethernet: ' . $hardware->ethernet;
if (stripos($hardware->product_name, $searchTerm) !== false) {
$inputMatch[] = 'Product Name: '.$hardware->product_name;
} elseif (stripos($hardware->manufacturer, $searchTerm) !== false) {
$inputMatch[] = 'Manufacturer: '.$hardware->manufacturer;
} elseif (stripos($hardware->processor, $searchTerm) !== false) {
$inputMatch[] = 'Processor: '.$hardware->processor;
} elseif (stripos($hardware->vga_controller, $searchTerm) !== false) {
$inputMatch[] = 'Vga Controller: '.$hardware->vga_controller;
} elseif (stripos($hardware->usb_controller, $searchTerm) !== false) {
$inputMatch[] = 'Usb Controller: '.$hardware->usb_controller;
} elseif (stripos($hardware->pci_bridge, $searchTerm) !== false) {
$inputMatch[] = 'Pci Bridge: '.$hardware->pci_bridge;
} elseif (stripos($hardware->sata_controller, $searchTerm) !== false) {
$inputMatch[] = 'Sata Controller: '.$hardware->sata_controller;
} elseif (stripos($hardware->communication_controller, $searchTerm) !== false) {
$inputMatch[] = 'Communication Controller: '.$hardware->communication_controller;
} elseif (stripos($hardware->scsi_controller, $searchTerm) !== false) {
$inputMatch[] = 'SCSI Controller: '.$hardware->scsi_controller;
} elseif (stripos($hardware->ethernet, $searchTerm) !== false) {
$inputMatch[] = 'Ethernet: '.$hardware->ethernet;
}
$count++;
}
Expand All @@ -83,21 +82,21 @@ public function index(Request $request, String $installation)
$rowsCount = 0;

// Loop through inputMatch to group similar rows and count occurrences
foreach($inputMatch as $item){
list($value, $row) = explode(': ', $item, 2);
foreach ($inputMatch as $item) {
[$value, $row] = explode(': ', $item, 2);

//Check if the row already exists in the corresponding group
$rowExists = in_array($row, $groupedInputMatch[$value]['rows'] ?? []);

//If the row does not exist yet, add it
if(!$rowExists){
if(isset($groupedInputMatch[$value])){
if (! $rowExists) {
if (isset($groupedInputMatch[$value])) {
$groupedInputMatch[$value]['rows'][] = $row;
}else{
} else {
$groupedInputMatch[$value] = ['rows' => [$row]];
}
}

// Count occurrences of each row
$rowsCount = ($groupedInputMatch[$value]['occurrences'][$row] ?? 0) + 1;
$groupedInputMatch[$value]['occurrences'][$row] = $rowsCount;
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/2024_04_11_145715_nethserver_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public function up(): void
{
DB::statement("
DB::statement("
CREATE OR REPLACE VIEW nethserver_view AS
SELECT
data->'facts'->'nodes'->'1'->'product'->>'name' AS product_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function up(): void
*/
public function down(): void
{
DB::statement("DROP VIEW IF EXISTS nethsecurity_view");
DB::statement('DROP VIEW IF EXISTS nethsecurity_view');
}
};
5 changes: 2 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use App\Http\Controllers\CompatibilityController;
use App\Http\Controllers\HardwareController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SelectController;

/*
|--------------------------------------------------------------------------
Expand All @@ -24,8 +23,8 @@
->withoutMiddleware('web')
->middleware('api');

Route::get('/select', function() {
Route::get('/select', function () {
return view('select');
})->name('select-hardware');

Route::get('/hardware/{installation}', [HardwareController::class, 'index'])->name('hardware');
Route::get('/hardware/{installation}', [HardwareController::class, 'index'])->name('hardware');

0 comments on commit 9b56dd3

Please sign in to comment.