Skip to content

Commit

Permalink
Merge pull request #170 from bobdivinity/master
Browse files Browse the repository at this point in the history
Supports of latest version of Laravel Nova (>= 4.31)
  • Loading branch information
coroo authored Nov 21, 2023
2 parents 2da7f2c + 23a251c commit e4e1ea4
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dist/js/chart-js-integration.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/components/BarChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/DoughnutChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/PieChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/PolarAreaChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/ScatterChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4 pb-0">
<div class="h-12 flex items-center px-6 mt-4 pb-0">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/StackedChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/StripeChart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<loading-card :loading="loading" class="min-h-40">
<div class="h-6 flex items-center px-6 mt-4">
<div class="h-12 flex items-center px-6 mt-4">
<h4 class="mr-3 leading-tight text-sm font-bold">{{ checkTitle }}</h4>
<div class="flex relative ml-auto flex-shrink-0">
<default-button size="xs" class="mr-2" @click="fillData()" v-show="buttonRefresh">
Expand Down
26 changes: 15 additions & 11 deletions src/api/TotalCircleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public function handle(NovaRequest $request)
if ($request->input('model')) {
$request->merge(['model' => urldecode($request->input('model'))]);
}
$showTotal = isset($request->options) ? json_decode($request->options, true)['showTotal'] ?? true : true;
$advanceFilterSelected = isset($request->options) ? json_decode($request->options, true)['advanceFilterSelected'] ?? false : false;
$dataForLast = isset($request->options) ? json_decode($request->options, true)['latestData'] ?? 3 : 3;
$calculation = isset($request->options) ? json_decode($request->options, true)['sum'] ?? 1 : 1;

$options = is_string($request->options) ? json_decode($request->options, true) : $request->input('options', []);
$join = is_string($request->join) ? json_decode($request->join, true) : $request->input('join', []);

$showTotal = $options['showTotal'] ?? true;
$advanceFilterSelected = $options['advanceFilterSelected'] ?? false;
$dataForLast = $options['latestData'] ?? 3;
$calculation = $options['sum'] ?? 1;
$request->validate(['model' => ['bail', 'required', 'min:1', 'string']]);
$model = $request->input('model');
$modelInstance = new $model;
Expand All @@ -41,8 +45,8 @@ public function handle(NovaRequest $request)
$defaultColor = array("#ffcc5c","#91e8e1","#ff6f69","#88d8b0","#b088d8","#d8b088", "#88b0d8", "#6f69ff","#7cb5ec","#434348","#90ed7d","#8085e9","#f7a35c","#f15c80","#e4d354","#2b908f","#f45b5b","#91e8e1","#E27D60","#85DCB","#E8A87C","#C38D9E","#41B3A3","#67c4a7","#992667","#ff4040","#ff7373","#d2d2d2");
if(isset($request->series)){
foreach($request->series as $seriesKey => $serieslist){
$seriesData = json_decode($serieslist);
$filter = $seriesData->filter;
$seriesData = (object) $serieslist;
$filter = (object) $seriesData->filter;
$labelList[$seriesKey] = $seriesData->label;
if(empty($filter->value)&&isset($filter->operator)&&($filter->operator=='IS NULL' || $filter->operator=='IS NOT NULL')) {
$seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\"";
Expand All @@ -59,8 +63,8 @@ public function handle(NovaRequest $request)
}
}
}
if(isset($request->join)){
$joinInformation = json_decode($request->join, true);
if(count($join)){
$joinInformation = $join;
$query = $model::selectRaw('SUM('.$calculation.') counted'.$seriesSql)
->join($joinInformation['joinTable'], $joinInformation['joinColumnFirst'], $joinInformation['joinEqual'], $joinInformation['joinColumnSecond']);
} else {
Expand All @@ -83,8 +87,8 @@ public function handle(NovaRequest $request)
$query->where($xAxisColumn, '>=', Carbon::now()->firstOfMonth()->subMonth($dataForLast-1));
}

if(isset(json_decode($request->options, true)['queryFilter'])){
$queryFilter = json_decode($request->options, true)['queryFilter'];
if($options['queryFilter'] ?? false){
$queryFilter = $options['queryFilter'];
foreach($queryFilter as $qF){
if(isset($qF['value']) && !is_array($qF['value'])){
if(isset($qF['operator'])){
Expand Down Expand Up @@ -114,7 +118,7 @@ public function handle(NovaRequest $request)
if(isset($request->series)){
$countKey = 0;
foreach($request->series as $sKey => $sData){
$dataSeries = json_decode($sData);
$dataSeries = (object) $sData;
foreach($dataSet as $dataDetail){
$yAxis[0]['backgroundColor'][$sKey] = $dataSeries->backgroundColor ?? $defaultColor[$sKey];
$yAxis[0]['borderColor'][$sKey] = $dataSeries->borderColor ?? '#FFF';
Expand Down
46 changes: 25 additions & 21 deletions src/api/TotalRecordsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ public function handle(NovaRequest $request)
if ($request->input('model')) {
$request->merge(['model' => urldecode($request->input('model'))]);
}
$showTotal = isset($request->options) ? json_decode($request->options, true)['showTotal'] ?? true : true;
$totalLabel = isset($request->options) ? json_decode($request->options, true)['totalLabel'] ?? 'Total' : 'Total';

$options = is_string($request->options) ? json_decode($request->options, true) : $request->input('options', []);
$join = is_string($request->join) ? json_decode($request->join, true) : $request->input('join', []);

$showTotal = $options['showTotal'] ?? true;
$totalLabel = $options['totalLabel'] ?? 'Total';
$chartType = $request->type ?? 'bar';
$advanceFilterSelected = isset($request->options) ? json_decode($request->options, true)['advanceFilterSelected'] ?? false : false;
$dataForLast = isset($request->options) ? json_decode($request->options, true)['latestData'] ?? 3 : 3;
$unitOfMeasurement = isset($request->options) ? json_decode($request->options, true)['uom'] ?? 'month' : 'month';
$startWeek = isset($request->options) ? json_decode($request->options, true)['startWeek'] ?? '1' : '1';
$advanceFilterSelected = $options['advanceFilterSelected'] ?? false;
$dataForLast = $options['latestData'] ?? 3;
$unitOfMeasurement = $options['uom'] ?? 'month';
$startWeek = $options['startWeek'] ?? '1';
if(!in_array($unitOfMeasurement, ['day', 'week', 'month', 'hour'])){
throw new ThrowError('UOM not defined correctly. <br/>Check documentation: https://github.com/coroo/nova-chartjs');
}
$calculation = isset($request->options) ? json_decode($request->options, true)['sum'] ?? 1 : 1;
$calculation = $options['sum'] ?? 1;
$request->validate(['model' => ['bail', 'required', 'min:1', 'string']]);
$model = $request->input('model');
$modelInstance = new $model;
Expand All @@ -51,8 +55,8 @@ public function handle(NovaRequest $request)
$defaultColor = array("rgba($brandColor, 1)", "#ffcc5c","#91e8e1","#ff6f69","#88d8b0","#b088d8","#d8b088", "#88b0d8", "#6f69ff","#7cb5ec","#434348","#90ed7d","#8085e9","#f7a35c","#f15c80","#e4d354","#2b908f","#f45b5b","#91e8e1","#E27D60","#85DCB","#E8A87C","#C38D9E","#41B3A3","#67c4a7","#992667","#ff4040","#ff7373","#d2d2d2");
if(isset($request->series)){
foreach($request->series as $seriesKey => $serieslist){
$seriesData = json_decode($serieslist);
$filter = $seriesData->filter;
$seriesData = (object) $serieslist;
$filter = (object) $seriesData->filter;
$labelList[$seriesKey] = $seriesData->label;
if(empty($filter->value)&&isset($filter->operator)&&($filter->operator=='IS NULL' || $filter->operator=='IS NOT NULL')) {
$seriesSql .= ", SUM(CASE WHEN ".$filter->key." ".$filter->operator." then ".$calculation." else 0 end) as \"".$labelList[$seriesKey]."\"";
Expand All @@ -70,8 +74,8 @@ public function handle(NovaRequest $request)
}
}
if($unitOfMeasurement=='day'){
if(isset($request->join)){
$joinInformation = json_decode($request->join, true);
if(count($join)){
$joinInformation = $join;
$query = $model::selectRaw('DATE('.$xAxisColumn.') AS cat, DATE('.$xAxisColumn.') AS catorder, sum('.$calculation.') counted'.$seriesSql)
->join($joinInformation['joinTable'], $joinInformation['joinColumnFirst'], $joinInformation['joinEqual'], $joinInformation['joinColumnSecond']);
} else {
Expand All @@ -96,8 +100,8 @@ public function handle(NovaRequest $request)
$query->groupBy('catorder', 'cat')
->orderBy('catorder', 'asc');
} else if($unitOfMeasurement=='week'){
if(isset($request->join)){
$joinInformation = json_decode($request->join, true);
if(count($join)){
$joinInformation = $join;
if($connectionName == 'pgsql'){
$query = $model::selectRaw("to_char(DATE_TRUNC('week', ".$xAxisColumn."), 'YYYYWW') AS cat, to_char(DATE_TRUNC('week', ".$xAxisColumn."), 'YYYYWW') AS catorder, sum(".$calculation.") counted".$seriesSql)
->join($joinInformation['joinTable'], $joinInformation['joinColumnFirst'], $joinInformation['joinEqual'], $joinInformation['joinColumnSecond']);
Expand Down Expand Up @@ -131,8 +135,8 @@ public function handle(NovaRequest $request)
$query->groupBy('catorder', 'cat')
->orderBy('catorder', 'asc');
} else if($unitOfMeasurement=='hour'){
if(isset($request->join)){
$joinInformation = json_decode($request->join, true);
if(count($join)){
$joinInformation = $join;
$query = $model::selectRaw('HOUR('.$xAxisColumn.') AS cat, HOUR('.$xAxisColumn.') AS catorder, sum('.$calculation.') counted'.$seriesSql)
->join($joinInformation['joinTable'], $joinInformation['joinColumnFirst'], $joinInformation['joinEqual'], $joinInformation['joinColumnSecond']);
} else {
Expand All @@ -158,8 +162,8 @@ public function handle(NovaRequest $request)
->orderBy('catorder', 'asc');

} else {
if(isset($request->join)){
$joinInformation = json_decode($request->join, true);
if(count($join)){
$joinInformation = $join;
if($connectionName == 'pgsql'){
$query = $model::selectRaw("to_char(".$xAxisColumn.", 'Mon YYYY') AS cat, to_char(".$xAxisColumn.", 'YYYY-MM') AS catorder, sum(".$calculation.") counted".$seriesSql)
->join($joinInformation['joinTable'], $joinInformation['joinColumnFirst'], $joinInformation['joinEqual'], $joinInformation['joinColumnSecond']);
Expand Down Expand Up @@ -194,8 +198,8 @@ public function handle(NovaRequest $request)
->orderBy('catorder', 'asc');
}

if(isset(json_decode($request->options, true)['queryFilter'])){
$queryFilter = json_decode($request->options, true)['queryFilter'];
if($options['queryFilter'] ?? false){
$queryFilter = $options['queryFilter'];
foreach($queryFilter as $qF){
if(isset($qF['value']) && !is_array($qF['value'])){
if(isset($qF['operator'])){
Expand Down Expand Up @@ -233,8 +237,8 @@ public function handle(NovaRequest $request)
if(isset($request->series)){
$countKey = 0;
foreach($request->series as $sKey => $sData){
$dataSeries = json_decode($sData);
$filter = $dataSeries->filter;
$dataSeries = (object) $sData;
$filter = (object) $dataSeries->filter;
$yAxis[$sKey]['label'] = $dataSeries->label;
if(isset($dataSeries->fill)){
if($dataSeries->fill==false){
Expand Down

0 comments on commit e4e1ea4

Please sign in to comment.