Skip to content

Commit 08ec599

Browse files
committed
Thorough documentation review
1 parent 6be4713 commit 08ec599

File tree

19 files changed

+386
-203
lines changed

19 files changed

+386
-203
lines changed
Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
1-
# Bonfire - Building Admin Modules
2-
3-
- [Creating an Admin Modules](creating_an_admin_module.md)
4-
- [View Components](view_components.md)
5-
- [Filters](filters.md)
6-
- [Recycler](recycler.md)
7-
- [Resource Tabs](resource_tabs.md)
8-
- [Search](search.md)
9-
- [Widgets](widgets.md)
10-
- [Dashboard Cells](dashboard_cells.md)
1+
# Building Admin Modules
2+
3+
Any application admin panel will need more than just user management capabilities. Your app might need page, tag, product management. This section deals with extending Bonfire admin are with your own modules and integrating them into the admin panel.
4+
5+
## Creating an Admin Module
6+
7+
Learn how to create new modules of code for the admin area, centered around a single task or resource, like Users, Photos, etc. This guide covers the basics of creating a `Module.php` file, configuring module locations, and adding menu items.
8+
9+
[Read more about Creating an Admin Module](creating_an_admin_module.md)
10+
11+
## View Components
12+
13+
View Components allow you to create custom HTML elements to use within your views. This section lists the components available within the default `Admin` theme and provides examples of their usage.
14+
15+
[Read more about View Components](view_components.md)
16+
17+
## Filters
18+
19+
Filtering allows you to specify which columns can be filtered and then pass your model to a view cell that handles the display of the filters. This ensures a consistent look and functionality in the UI while providing the least amount of work when creating a UI.
20+
21+
[Read more about Filters](filters.md)
22+
23+
## Recycler
24+
25+
The Recycler provides an area where users can browse objects that have been deleted and either restore or purge them. The models for these resources must have soft deletes enabled. This section covers registering a resource, localizing column names, and modifying the Recycler query.
26+
27+
[Read more about the Recycler](recycler.md)
28+
29+
## Resource Tabs
30+
31+
Resource tabs are the tabs displayed when editing a resource, like an individual User or User Group. They make it possible to easily integrate other tabs onto a user without editing the core theme.
32+
33+
[Read more about Resource Tabs](resource_tabs.md)
34+
35+
## Search
36+
37+
Bonfire provides a flexible search system that is highlighted on all areas of the admin area. This section covers integrating your module into the search results, adding filters for the Advanced Search form, and providing search results.
38+
39+
[Read more about Search](search.md)
40+
41+
## Widgets
42+
43+
Widgets are elements that display information on the dashboard. They can be small informational cards or charts. This section covers adding new widgets, configuring them, and displaying them on the dashboard.
44+
45+
[Read more about Widgets](widgets.md)
46+
47+
## Dashboard Cells
48+
49+
Customize the dashboard with the use of view cells. This section covers specifying which cells to display, creating the cell, and displaying it on the dashboard.
50+
51+
[Read more about Dashboard Cells](dashboard_cells.md)

docs/building_sites/alerts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Bonfire uses [Tatter\Alerts](https://github.com/tattersoftware/codeigniter4-alerts) to provide support for
44
simple alerts. The usage is simple:
55

6-
```
6+
```php
77
alert('success', 'Your message goes here.');
88
```
99

@@ -15,7 +15,7 @@ and can be a single string or an array of strings to apply multiple alerts.
1515
Additionally, you can use flash messages in the session to trigger alerts.
1616
This would typically be used during a redirect:
1717

18-
```
18+
```php
1919
return redirect()->back()->with('message', 'It worked!');
2020
return redirect()->back()->with('error', 'Did not work');
2121
return redirect()->back()->with('error', ['not good', 'nope', 'cannot do it']);

docs/building_sites/assets.md

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
# Asset Management
1+
# Including Assets
22

3-
Bonfire provides a simple assets system that was created to solve two main challenges:
4-
5-
1. We should be able to serve CSS/JS assets from anywhere. While this is primarily for use by themes, it could serve many purposes.
6-
2. How to easily handle browser caching/cache-busting with updated assets.
7-
8-
And try to do this in the simplest way possible.
9-
10-
For the examples, we will link to assets for the Admin theme.
3+
As elaborated in [Assets Management](../modules/assets.md), Bonfire provides a simple assets system that was created to serve CSS/JS assets from anywhere and to easily handle browser caching/cache-busting with updated assets.
114

125
## Linking to assets
136

147
Within your views you can link to assets anywhere within your project with the `asset()` or `asset_link()` helper function.
158
`asset_link()` takes two arguments. The first is the path to the file to load. The first segment of this path must be one of the defined
16-
`$folders` in the configuration file. The rest of the path would be based on the actual file structure within that
17-
location. For the `Admin` theme, a folder has been defined called `admin`. Both the `Auth` and `App` themes have
18-
similar folders already defined.
9+
`$folders` in the configuration file `Assets.php`. The rest of the path would be based on the actual file structure within that
10+
location. For the `App` theme, a folder has been defined called `app`.
1911

20-
The second argument is the type of asset being loaded. This tells it how the resulting link should be formed.
21-
Currently, it only supports `css` and `js` files.
12+
The second argument is the type of asset being loaded. Currently, it only supports `css` and `js` files.
2213

2314
```php
24-
<?= asset_link('admin/css/admin.css', 'css') ?>
25-
<?= asset_link('admin/js/admin.js', 'js') ?>
15+
<?= asset_link('app/css/admin.css', 'css') ?>
16+
<?= asset_link('app/js/admin.js', 'js') ?>
2617
```
2718

28-
The `asset()` function is similar, except it only returns the URL. This is helpful as the function also inserts
29-
a string within the filename that helps browsers cache the file, but that will change when the file is updated
30-
so the browser knows to grab a fresh copy of the file.
19+
The `asset()` function is similar, except it only returns the URL only.
3120

3221
```html
3322
<link rel="stylesheet" href="<?= asset('admin/css/admin.css', 'css') ?>" />
@@ -36,61 +25,4 @@ so the browser knows to grab a fresh copy of the file.
3625

3726
## Configuration
3827

39-
The `Config\Assets` class has a handful of settings to customize the experience.
40-
41-
### $bustingType
42-
43-
When a link is generated it includes a string within the filename for cache-busting reasons. This would look something
44-
like: `https://localhost:8080/admin/css/admin~~213264216523.css`. The config setting, `$bustingType` defines how this
45-
string is derived. It has two possible values, either `file` or `version`.
46-
47-
The `file` setting will examine the requested file and use the file modified date/time as the basis, and convert it
48-
to a Unix timestamp. This is the easiest value to use as it is automatically updates itself based on the file. However,
49-
it does force an extra file read, and the overhead needed to get the information from the file. On many small to medium
50-
sites this is likely just fine. However, large sites, or sites that require every ounce of performance, may want to
51-
use the `version` method.
52-
53-
The `version` method requires the developer to set a new version in the configuration file whenever new code is ready
54-
to deploy to staging or production environments. See the next setting for details. To make this easier during development
55-
the current timestamp is used in testing/development environments ensuring that no caching will happen. In other
56-
environments it inserts the version number that was specified.
57-
58-
### $separator
59-
60-
The `$separator` setting allows the app to detect the part of the asset file name that was
61-
added for cache-busting purposes. It can be a single web-safe non-reserved character or
62-
a combination of such characters (characters that are allowed in a URI, but do not have
63-
a reserved purpose) that DOES NOT OCCUR in your asset file names (like `~`, `-`
64-
or `_` or any combination of ASCII letters and numbers). Separator will be inserted
65-
before the file version/timestamp, in between the file name and file extension.
66-
67-
### $versions
68-
69-
The `$versions` setting allows you to define the version number for `css` and `js` separately. This value is used
70-
as the cache-busting string when the `version` busting type is used.
71-
72-
```php
73-
public $versions = [
74-
'css' => '1.0',
75-
'js' => '1.0',
76-
];
77-
```
78-
79-
### $folders
80-
81-
This values is where you define the folders that are looked in linking to an asset. Folders for all themes and
82-
the vendor folder are setup by default.
83-
84-
```php
85-
public $folders = [
86-
'app' => ROOTPATH.'themes/app',
87-
'admin' => ROOTPATH.'themes/Admin',
88-
'auth' => ROOTPATH.'themes/Auth',
89-
'other' => ROOTPATH.'vendor',
90-
];
91-
```
92-
93-
## Route Conflict Warning
94-
95-
To make this all work, a route is specified at `/assets/(:any)` to capture the request. The assets system will not
96-
work if you override this route in your own application. I think for most sites this should not be a problem.
28+
Configuration of assets is detailed in the [Assets Management](../modules/assets.md) page of **Modules** section.

docs/building_sites/common_functions.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Common functions
22

3-
Bonfire provides a few helper functions that are always available for your use.
3+
Bonfire provides a helper function that is always available for your use.
44

55
**app_date($date)**
66

@@ -32,4 +32,3 @@ You can further include the timezone by passing `true` as the third argument.
3232
echo app_date($date, true, true);
3333
// outputs: 01/15/2021 3:35 PM CST
3434
```
35-

docs/building_sites/components.md

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
View Components (or just Components) allow you to create custom HTML elements to use within your views.
44

5-
## Self-Closing Tags
5+
## Self-Closing Tag Components
66

77
At their most basic, components serve as dynamic templates that allow you to reduce the typing in your
88
application. This can help boil longer, complex sections down to a single HTML tag. This is especially
@@ -15,7 +15,7 @@ application's, `app/Components` directory.
1515

1616
A simple avatar image might look something like this:
1717

18-
```
18+
```php
1919
// app/Components/avatar.php
2020
<img
2121
src="<?= $src ?? '' ?>"
@@ -27,15 +27,15 @@ A simple avatar image might look something like this:
2727

2828
When using the component within a view, you would insert a tag with `x-` prepended to the filename:
2929

30-
```
30+
```php
3131
<x-avatar src="<?= $user->avatarUrl() ?>" alt="<?= $user->name ?>" />
3232
```
3333

3434
Any attributes provided when you insert the component like this are made available as variables within
3535
the component view. In this case, the `$src` and `$alt` attributes are passed to the component view, resulting
3636
in the following output:
3737

38-
```
38+
```html
3939
<img
4040
src="http://example.com/avatars/foo.jpg"
4141
class="rounded-circle shadow-4"
@@ -44,15 +44,15 @@ in the following output:
4444
/>
4545
```
4646

47-
## Tags With Content
47+
## Components With Opening and Closing Tags
4848

4949
You can include the content within the opening and closing tags by inserting the reserved `$slot` variable:
5050

51-
```
51+
```html
5252
<x-green-button>Click Me!</x-green-button>
5353
```
5454

55-
```
55+
```php
5656
// app/Components/green-button.php
5757
<button class="btn btn-success">
5858
<?= $slot ?>
@@ -72,3 +72,86 @@ The data you pass will be available within the class as it's `$data` property (t
7272
A `famous-qoutes` component would have a view called `famous-quotes.php` and a controlling class called
7373
`FamousQuotesComponent.php`. The class must extend `Bonfire\View\Component`. The only requirement is that you
7474
implement a method called `render()`.
75+
76+
Below are example files of a usable `famous-quotes` component, that can be included in any of these three ways:
77+
78+
```html
79+
<x-famous-quotes />
80+
<x-famous-quotes seconds="30" />
81+
<x-famous-quotes seconds="30">Famous Quotes</x-famous-quotes>
82+
```
83+
84+
It's controlling class file `FamousQuotesComponent.php`:
85+
86+
```php
87+
namespace App\Components;
88+
89+
/**
90+
* This example controlled component allows to retrieve a random famous quote
91+
* from the ZenQuotes API and cache it for a specified number of seconds.
92+
* Number of seconds can be passed as a parameter to the component.
93+
* If you want to add a title to the component, you can pass it as a $slot variable.
94+
*/
95+
class FamousQuotesComponent extends \Bonfire\View\Component
96+
{
97+
protected $defaultNoOfSeconds = 600;
98+
protected string $famousQuotesAPINode = 'https://zenquotes.io/api/random';
99+
100+
public function render(): string
101+
{
102+
return $this->renderView($this->view, $this->getFamousQuote());
103+
}
104+
105+
public function getFamousQuote(): array
106+
{
107+
helper('cache');
108+
109+
if (isset($this->data['seconds']) && is_numeric($this->data['seconds'])) {
110+
$this->data['seconds'] = (int) round($this->data['seconds'], 0);
111+
} else {
112+
$this->data['seconds'] = $this->defaultNoOfSeconds;
113+
}
114+
115+
$cacheKey = 'famous_quote';
116+
117+
if ($cachedQuote = cache($cacheKey)) {
118+
return $cachedQuote;
119+
}
120+
121+
$response = file_get_contents($this->famousQuotesAPINode);
122+
$quoteData = json_decode($response, true);
123+
124+
if (isset($quoteData[0])) {
125+
$this->data['quote'] = [
126+
'text' => $quoteData[0]['q'],
127+
'author' => $quoteData[0]['a'],
128+
];
129+
130+
cache()->save($cacheKey, $this->data, $this->data['seconds']);
131+
} else {
132+
$this->data['quote'] = [
133+
'text' => 'Sucking at something is the first step to becoming sorta good at something.',
134+
'author' => 'Jake (from "Adventure Time")',
135+
];
136+
}
137+
138+
return $this->data;
139+
}
140+
}
141+
```
142+
143+
And it's view file `famous-quotes.php`:
144+
145+
```php
146+
<div class="card mb-3">
147+
<div class="card-header">
148+
<?= esc($slot ?? '') ?>
149+
</div>
150+
<div class="card-body mt-3">
151+
<p class="card-text text-center"><?= esc($quote['text']) ?></p>
152+
<footer class="blockquote-footer text-center"><em><?= esc($quote['author']) ?></em></footer>
153+
</div>
154+
<div class="card-footer" style="font-size:10px;">Cached for <?= esc($seconds) ?> seconds</div>
155+
</div>
156+
```
157+

0 commit comments

Comments
 (0)