-
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #9 from ryanmitchell/v2
Merge V2 into master
- Loading branch information
Showing
27 changed files
with
2,223 additions
and
24 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
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,8 +1,81 @@ | ||
## Reports | ||
|
||
Adds a report view to the sales menu allowing high level stats on a date range. | ||
Add reporting and data interrogation to your TastyIgniter install. | ||
|
||
### Installation | ||
|
||
1. Add to extensions/thoughtco/reports inside Tasty Igniter install. | ||
2. Enable extension in Systems -> Extensions | ||
|
||
## Usage | ||
|
||
After installation a new Reports menu will be added to the admin sidebar, giving links to the Reports Dashboard and Query Builder. | ||
|
||
### Dashboard | ||
|
||
The Dashboard is a widget based view giving some high level overviews of reports in a configurable date range. Widgets can be changed, moved, and deleted in a similar way to the main admin dashboard. | ||
|
||
### Query Builder | ||
The query builder allows you to generate and save custom queries that create an exportable, searchable table of data. Once set up this queries can be accessed at will with data auto-updated. | ||
|
||
## Extending | ||
|
||
This extension has been designed to allow extending of the Querybuilder queries and fields. | ||
|
||
### Adding rule options | ||
|
||
Through your extension add rules by listening for the core `admin.form.extendFieldsBefore` event. For example: | ||
|
||
```php | ||
Event::listen('admin.form.extendFieldsBefore', function (Form $form) { | ||
|
||
if ($form->model instanceof \Thoughtco\Reports\Models\QueryBuilder) { | ||
|
||
$form->fields['builderjson']['filters']['\Admin\Models\Customers_model']['filters'][] = [ | ||
'id' => 'customers.loyaltypoints', | ||
'label' => 'Loyalty Points', | ||
'type' => 'integer', | ||
'operators' => [ | ||
'equal', 'not_equal', | ||
'less', 'less_or_equal', | ||
'greater', 'greater_or_equal', | ||
], | ||
]; | ||
|
||
} | ||
|
||
}); | ||
``` | ||
|
||
### Extending where fields | ||
|
||
Through your extension add rules by listening for the core `thoughtco.reports.fieldToQuery` event, and apply logic on the basis of the $field and $controller . For example: | ||
|
||
```php | ||
Event::listen('thoughtco.reports.fieldToQuery', function ($controller, $query, $field, $operator, $value, $condition) { | ||
|
||
if (!in_array(get_class($query->getModel()), ['Admin\Models\Customers_model'])) | ||
return; | ||
|
||
if ($field == 'customers.loyaltypoints') { | ||
$query->where('loyalty_points', $operator, $value); | ||
} | ||
|
||
}); | ||
``` | ||
|
||
### Extending overall query | ||
|
||
Through your extension add rules by listening for the core `extendQuery` event, and apply logic on the basis of the $query, $modelName and $controller . For example: | ||
|
||
```php | ||
Event::listen('thoughtco.reports.extendQuery', function($controller, $query, $modelName) { | ||
|
||
// we only care about certain models by default - this allows others to extend | ||
if (!in_array($modelName, ['\Admin\Models\Orders_model', '\Admin\Models\Customers_model'])) | ||
return; | ||
|
||
$query->selectRaw('*, CONCAT(first_name, " ", last_name) as customer_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,21 @@ | ||
|
||
+function ($) { | ||
"use strict" | ||
|
||
var $modelEl = $('#form-field-querybuilder-builderjson-type'); | ||
var $initialValue = $modelEl.val(); | ||
|
||
var checkContexts = function() { | ||
var $context = $modelEl.val(); | ||
$('.repeater-items select option') | ||
.each(function($idx, $el) { | ||
let $val = JSON.parse($el.value); | ||
if (!$val.contexts.includes($context)) | ||
$el.disabled = true; | ||
}); | ||
}; | ||
|
||
$modelEl.on('change', checkContexts); | ||
$(window).on('repeaterItemAdded', checkContexts); | ||
|
||
}(window.jQuery) |
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,8 @@ | ||
{ | ||
"name": "thoughtco/reports", | ||
"type": "tastyigniter-extension", | ||
"keywords": ["tastyigniter", "reports"], | ||
"require": { | ||
"league/csv": "^9.0" | ||
} | ||
} |
Oops, something went wrong.