MINI Sh3ll
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Solar\Repositories\Panel\PanelInterface;
use App\Solar\Repositories\User\UserInterface;
use App\Solar\Repositories\RegisterAPI\RegisterAPIInterface;
use DB;
class PanelController1 extends Controller
{
/**
* @var Panel Interface
*/
private $panel;
private $user;
private $regApi;
public function __construct(PanelInterface $panel , UserInterface $user , RegisterAPIInterface $regApi) {
$this->panel = $panel;
$this->user = $user;
$this->regApi = $regApi;
}
public function index() {
$breadcrumb = breadCrumb('Panel', 'panels', '');
$search = '';
$companies_name = $this->user->getCompany();
$regApi = $this->regApi->getRegisteredAPI($search);
$graphDuration = config("register_api.graph_duration");
return view('panel.index', compact('companies_name','regApi','graphDuration','breadcrumb'));
}
/**
* Display a listing of the Panel Added in DataTable.
*
* @return \Illuminate\Http\Response
*/
public function getPanelList(Request $request) {
$returnArray = array();
$status = null;
try {
$panelList = $this->panel->getPanelList($request);
foreach ($panelList as $panel) {
$id = $panel->id;
$apiName = $panel->register_api->name;
$company = $panel->company->company_name;
$type = $panel->register_api->plot_type==1?"Graph":"Numeric";
$chartType = (($panel->register_api->plot_type==1)?ucfirst($panel->chart_type):'-');
$editButton = '';
$deleteButton = '';
// $editButton ='<a class="m-btn btn btn-secondary" href=' . route("editPanel", encrypt($panel->id)) . '>
// <i class="la la-edit"></i>
// </a>';
$deleteButton = '<a class="m-btn btn btn-secondary delete_panel" data-id=' . $id . ' href="javascript:void(0);">
<i class="la la-trash"></i>
</a>';
$action = '<div class="btn-group mr-2" role="group" aria-label="First group">
'.$editButton.' '.$deleteButton;
$action .= '</div>';
$returnArray[] = array($apiName, $company, $type, $chartType, $action);
}
} catch (Exception $ex) {
$returnArray = array();
}
return json_encode(['data' => $returnArray]);
}
/**
* Get the specified resource from storage.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function editPanel($id) {
try {
$breadcrumb = breadCrumb('Panel', 'panels', '');
$paneldetails = $this->panel->paneldetails($id);
$graphDuration = config("register_api.graph_duration");
$chartTypes = config('chart.types');
return view('panel.edit', compact('paneldetails','graphDuration','chartTypes','breadcrumb'));
} catch(Exception $ex) {
logger($exc->getMessage());
return redirect()->back()->with('error', $exc->getMessage());
}
}
/**
* Update the specified resource from storage.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function updatePanel(Request $request,$id) {
try {
dd($request->all(),$id);
$paneldetails = $this->panel->paneldetails($id);
DB::commit();
} catch(Exception $ex) {
DB::rollBack();
logger($exc->getMessage());
return redirect()->back()->with('error', $exc->getMessage());
}
}
/**
* Remove the specified Panel details from storage.
* @param int $id
* @return \Illuminate\Http\Response
*/
public function deletePanel(Request $request) {
DB::beginTransaction();
try {
$this->panel->deletePanel($request['id']);
DB::commit();
return json_encode([ 'status' => 1, 'success'=> 'Panel deleted successfully.' ]);
} catch (\Exception $exc) {
DB::rollBack();
logger($exc->getMessage());
return redirect()->back()->with('error', $exc->getMessage());
}
}
}
OHA YOOOO