-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Refactor hard-coded reports to objects
- Loading branch information
1 parent
5af2ccc
commit 2492a47
Showing
16 changed files
with
318 additions
and
78 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,28 @@ | ||
<?php | ||
|
||
namespace App\Domain; | ||
|
||
use JsonSerializable; | ||
use Illuminate\Support\Str; | ||
|
||
abstract class Element implements JsonSerializable | ||
{ | ||
protected $name; | ||
|
||
public function humanizedName() | ||
{ | ||
return Str::title(Str::snake(class_basename(get_class($this)), ' ')); | ||
} | ||
|
||
public function name() | ||
{ | ||
return $this->name ?: $this->humanizedName(); | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return [ | ||
'name' => $this->name(), | ||
]; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace App\Domain\Metrics; | ||
|
||
use App\Domain\Element; | ||
use Illuminate\Support\Str; | ||
use \App\Domain\Ranges\LastYear; | ||
use \App\Domain\Ranges\LastMonth; | ||
use \App\Domain\Ranges\CurrentYear; | ||
use \App\Domain\Ranges\CurrentMonth; | ||
|
||
abstract class Metric extends Element | ||
{ | ||
protected $component; | ||
protected $width = '1/2'; | ||
protected $ranges = []; | ||
protected $graphqlQuery; | ||
|
||
public function component() | ||
{ | ||
return $this->component; | ||
} | ||
|
||
public function width() | ||
{ | ||
return $this->width; | ||
} | ||
|
||
public function ranges() | ||
{ | ||
return [ | ||
new CurrentMonth, | ||
new LastMonth, | ||
new CurrentYear, | ||
new LastYear, | ||
]; | ||
} | ||
|
||
public function graphqlQuery() | ||
{ | ||
return $this->graphqlQuery ?: Str::camel(class_basename(get_class($this))); | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return array_merge(parent::jsonSerialize(), [ | ||
'component' => $this->component(), | ||
'width' => $this->width(), | ||
'ranges' => $this->ranges(), | ||
'graphql_query' => $this->graphqlQuery() | ||
]); | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace App\Domain\Metrics; | ||
|
||
abstract class PartitionMetric extends Metric | ||
{ | ||
protected $component = 'partition-metric'; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace App\Domain\Metrics; | ||
|
||
abstract class RelationPartitionMetric extends PartitionMetric | ||
{ | ||
protected $relationGraphqlQuery; | ||
protected $relationDisplayUsing; | ||
protected $relationForeignKey; | ||
|
||
public function jsonSerialize() | ||
{ | ||
return array_merge(parent::jsonSerialize(), [ | ||
'relation' => [ | ||
'graphql_query' => $this->relationGraphqlQuery, | ||
'display_using' => $this->relationDisplayUsing, | ||
'foreign_key' => $this->relationForeignKey, | ||
] | ||
]); | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace App\Domain\Metrics; | ||
|
||
abstract class ValueMetric extends Metric | ||
{ | ||
protected $component = 'value-metric'; | ||
} |
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
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
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 |
---|---|---|
@@ -1,69 +1,28 @@ | ||
<?php | ||
|
||
use \App\Domain\Ranges\CurrentMonth; | ||
use \App\Domain\Ranges\LastMonth; | ||
use \App\Domain\Ranges\CurrentYear; | ||
use \App\Domain\Ranges\LastYear; | ||
|
||
$ranges = [ | ||
new CurrentMonth, | ||
new LastMonth, | ||
new CurrentYear, | ||
new LastYear, | ||
]; | ||
use App\GraphQL\Queries\TotalIncome; | ||
use App\GraphQL\Queries\TotalExpenses; | ||
use App\GraphQL\Queries\TotalPerBrand; | ||
use App\GraphQL\Queries\IncomePerCategory; | ||
use App\GraphQL\Queries\ExpensesPerCategory; | ||
|
||
return [ | ||
'currency' => 'AED', | ||
'sms_templates' => [ | ||
'Purchase of AED {amount} with {card} at {brand},', | ||
'Payment of AED {amount} to {brand} with {card}.', | ||
'{brand} of AED {amount} has been credited ', | ||
], | ||
'currency' => 'AED', | ||
'reports' => [ | ||
[ | ||
'name' => 'Total Income', | ||
'graphql_query' => 'totalIncome', | ||
'component' => 'value-metric', | ||
'width' => '1/2', | ||
'ranges' => $ranges, | ||
], | ||
[ | ||
'name' => 'Total Expenses', | ||
'graphql_query' => 'totalExpenses', | ||
'component' => 'value-metric', | ||
'width' => '1/2', | ||
'ranges' => $ranges, | ||
], | ||
[ | ||
'name' => 'Expenses per Category', | ||
'graphql_query' => 'expensesPerCategory', | ||
'component' => 'partition-metric', | ||
'width' => '1/2', | ||
'ranges' => $ranges, | ||
], | ||
[ | ||
'name' => 'Income per Category', | ||
'graphql_query' => 'incomePerCategory', | ||
'component' => 'partition-metric', | ||
'width' => '1/2', | ||
'ranges' => $ranges, | ||
], | ||
[ | ||
'name' => 'Total per Brand', | ||
'graphql_query' => 'totalPerBrand', | ||
'component' => 'partition-metric', | ||
'width' => '1/2', | ||
'ranges' => $ranges, | ||
'relation' => [ | ||
'graphql_query' => 'allCategories', | ||
'display_using' => 'name', | ||
'foreign_key' => 'category_id', | ||
] | ||
], | ||
new TotalIncome, | ||
new TotalExpenses, | ||
new IncomePerCategory, | ||
new ExpensesPerCategory, | ||
new TotalPerBrand, | ||
|
||
// Total Income graph | ||
// Total Expenses graph | ||
// Expenses per Category graph | ||
// Transactions per Brand graph | ||
// TotalIncomeTrend | ||
// TotalExpensesTrend | ||
// ExpensesPerCategoryTrend | ||
// TotalPerBrandTrend | ||
] | ||
]; |
Oops, something went wrong.