forked from Silvanite/novatoolpermissions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Silvanite#72 from SGS-Optimisation/feature/69-pm-r…
…ule-metrics added rule activity stat
- Loading branch information
Showing
18 changed files
with
558 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
|
||
namespace App\Features; | ||
|
||
|
||
abstract class BaseFeature | ||
{ | ||
abstract public function handle(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
|
||
namespace App\Features\Stats; | ||
|
||
|
||
use App\Features\BaseFeature; | ||
use App\Models\ClientAccount; | ||
use App\Models\Rule; | ||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Query\Expression; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Str; | ||
use Laravel\Nova\Metrics\Trend; | ||
use Laravel\Nova\Metrics\TrendDateExpressionFactory; | ||
|
||
class RuleCreationPerClientAccount extends Trend | ||
{ | ||
public $dataset = []; | ||
|
||
/** | ||
* RuleCreationPerClientAccount constructor. | ||
* @param int $range | ||
* @param string $count | ||
*/ | ||
public function __construct( | ||
public ?string $count = self::BY_WEEKS, | ||
public ?int $range = 24, | ||
public ?string $column = 'created_at' | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
|
||
public function handle() | ||
{ | ||
foreach (ClientAccount::withCount('rules')->get() as $client_account) { | ||
$this->dataset[$client_account->name] = [ | ||
'client_id' => $client_account->id, | ||
'rules_count' => $client_account->rules_count, | ||
'created_at' => $client_account->created_at->format('Y-m-d H:i:s'), | ||
'trend' => $this->processClientAccount($client_account)->trend, | ||
]; | ||
} | ||
|
||
return $this->dataset; | ||
} | ||
|
||
public function processClientAccount($client_account) | ||
{ | ||
$query = Rule::forClient($client_account); | ||
|
||
$request = new Request(); | ||
$request->merge(['range' => $this->range, 'twelveHourTime' => false, 'timezone' => 'UTC']); | ||
|
||
return $this->{'countBy'.Str::title(Str::plural($this->count))}($request, $query, $this->column); | ||
} | ||
|
||
public function ranges() | ||
{ | ||
return [ | ||
5 => __('5 Weeks'), | ||
10 => __('10 Weeks'), | ||
15 => __('15 Weeks'), | ||
24 => __('24 Weeks'), | ||
]; | ||
} | ||
|
||
public function name() | ||
{ | ||
return 'Client Account Rules Per Week'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Stats; | ||
|
||
use App\Features\Stats\RuleCreationPerClientAccount; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\ClientAccount; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
use Laravel\Jetstream\Jetstream; | ||
|
||
class StatsController extends Controller | ||
{ | ||
public function index(Request $request) | ||
{ | ||
$count = $request->get('count', 'week'); | ||
$range = $request->get('range', 24); | ||
$column = $request->get('column', 'created_at'); | ||
|
||
|
||
return Jetstream::inertia()->render($request, 'Stats/ClientAccountStats', [ | ||
'stats' => (new RuleCreationPerClientAccount($count, $range, $column))->handle(), | ||
'count' => Str::title($count), | ||
'range' => $range, | ||
'column' => $column, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Nova\Dashboards; | ||
|
||
use App\Models\ClientAccount; | ||
use App\Nova\Metrics\RulesPerWeek; | ||
use Laravel\Nova\Dashboard; | ||
|
||
class ClientDashboard extends Dashboard | ||
{ | ||
public ClientAccount $client_account; | ||
|
||
/** | ||
* ClientDashboard constructor. | ||
* @param ClientAccount $client_account | ||
*/ | ||
public function __construct(ClientAccount $client_account) | ||
{ | ||
$this->client_account = $client_account; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Get the cards for the dashboard. | ||
* | ||
* @return array | ||
*/ | ||
public function cards() | ||
{ | ||
return [ | ||
new RulesPerWeek($this->client_account), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the URI key for the dashboard. | ||
* | ||
* @return string | ||
*/ | ||
public static function uriKey() | ||
{ | ||
return 'client-dashboard'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.