Merge pull request #243 from 1day2die/Fix_HomeView_CreditsLeft
Credits-Left box from View to Controller
This commit is contained in:
commit
fbfbbda8f3
2 changed files with 95 additions and 31 deletions
|
@ -1,30 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UsefulLink;
|
||||
use App\Models\Configuration;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
const TIME_LEFT_BG_SUCCESS = "bg-success";
|
||||
const TIME_LEFT_BG_WARNING = "bg-warning";
|
||||
const TIME_LEFT_BG_DANGER = "bg-danger";
|
||||
const TIME_LEFT_OUT_OF_CREDITS_TEXT = "You ran out of Credits";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the Background Color for the Days-Left-Box in HomeView
|
||||
*
|
||||
* @param float $days
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimeLeftBoxBackground(float $days)
|
||||
{
|
||||
switch ($days)
|
||||
{
|
||||
case ($days >= 15):
|
||||
return $this::TIME_LEFT_BG_SUCCESS;
|
||||
break;
|
||||
|
||||
case ($days >= 8 && $days <= 14):
|
||||
return $this::TIME_LEFT_BG_WARNING;
|
||||
break;
|
||||
|
||||
case ($days <= 7):
|
||||
return $this::TIME_LEFT_BG_DANGER;
|
||||
break;
|
||||
|
||||
default:
|
||||
return $this::TIME_LEFT_BG_WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the Text for the Days-Left-Box in HomeView
|
||||
*
|
||||
* @param float $days
|
||||
* @param float $hours
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimeLeftBoxText(float $days, float $hours)
|
||||
{
|
||||
if ($days < 1)
|
||||
{
|
||||
if ($hours < 1)
|
||||
{
|
||||
return $this::TIME_LEFT_OUT_OF_CREDITS_TEXT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return strval($hours);
|
||||
}
|
||||
}
|
||||
return strval(number_format($days, 0));
|
||||
}
|
||||
|
||||
/** Show the application dashboard. */
|
||||
public function index(Request $request)
|
||||
{
|
||||
$usage = 0;
|
||||
$usage = Auth::user()->creditUsage();
|
||||
$credits = Auth::user()->Credits();
|
||||
$bg = "";
|
||||
$boxText = "";
|
||||
$unit = "";
|
||||
|
||||
/** Build our Time-Left-Box */
|
||||
if ($credits > 0.01 and $usage > 0)
|
||||
{
|
||||
$days = number_format(($credits * 30) / $usage, 2, '.', '');
|
||||
$hours = number_format($credits / ($usage / 30 / 24) , 2, '.', '');
|
||||
|
||||
$bg = $this->getTimeLeftBoxBackground($days);
|
||||
$boxText = $this->getTimeLeftBoxText($days, $hours);
|
||||
$unit = $days < 1 ? 'hours' : 'days';
|
||||
|
||||
foreach (Auth::user()->servers as $server){
|
||||
$usage += $server->product->price;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// RETURN ALL VALUES
|
||||
return view('home')->with([
|
||||
'useage' => $usage,
|
||||
'useful_links' => UsefulLink::all()->sortBy('id')
|
||||
'credits' => $credits,
|
||||
'useful_links' => UsefulLink::all()->sortBy('id'),
|
||||
'bg' => $bg,
|
||||
'boxText' => $boxText,
|
||||
'unit' => $unit
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -67,40 +67,26 @@
|
|||
</div>
|
||||
|
||||
<!-- /.col -->
|
||||
@if(Auth::user()->Credits() > 0.01 and $useage > 0)
|
||||
<div class="col-12 col-sm-6 col-md-3">
|
||||
<div class="info-box mb-3">
|
||||
@if(number_format((Auth::user()->Credits()*30)/$useage,0,'.','') >= 15)
|
||||
<span class="info-box-icon bg-success elevation-1">
|
||||
@elseif (number_format((Auth::user()->Credits()*30)/$useage,0,'.','') >= 8 && number_format((Auth::user()->Credits()*30)/$useage,0,'.','') <= 14)
|
||||
<span class="info-box-icon bg-warning elevation-1">
|
||||
@elseif (number_format((Auth::user()->Credits()*30)/$useage,0,'.','') <= 7)
|
||||
<span class="info-box-icon bg-danger elevation-1">
|
||||
@endif
|
||||
<i class="fas fa-hourglass-half"></i></span>
|
||||
|
||||
<div class="info-box-content">
|
||||
<span class="info-box-text">Out of {{CREDITS_DISPLAY_NAME}} in </span>
|
||||
@if(number_format((Auth::user()->Credits()*30)/$useage,2,'.','') < "1")
|
||||
@if(number_format(Auth::user()->Credits()/($useage/30/24),2,'.','') < "1")
|
||||
<span class="info-box-number">You ran out of Credits </span>
|
||||
@else
|
||||
<span class="info-box-number">{{number_format(Auth::user()->Credits()/($useage/30/24),0,'.','')}} <sup> hours</sup></span>
|
||||
@endif
|
||||
@else
|
||||
<span class="info-box-number">{{number_format((Auth::user()->Credits()*30)/$useage,0,'.','')}} <sup> days</sup></span>
|
||||
@endif
|
||||
@if($credits > 0.01 and $useage > 0)
|
||||
<div class="col-12 col-sm-6 col-md-3">
|
||||
<div class="info-box mb-3">
|
||||
<span class="info-box-icon {{$bg}} elevation-1">
|
||||
<i class="fas fa-hourglass-half"></i></span>
|
||||
<div class="info-box-content">
|
||||
<span class="info-box-text">Out of {{CREDITS_DISPLAY_NAME}} in </span>
|
||||
<span class="info-box-number">{{$boxText}}<sup>{{$unit}}</sup></span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.info-box-content -->
|
||||
</div>
|
||||
<!-- /.info-box -->
|
||||
@endif
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card card-default">
|
||||
|
|
Loading…
Add table
Reference in a new issue