Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Dillingham committed Apr 26, 2019
0 parents commit 834480d
Show file tree
Hide file tree
Showing 14 changed files with 830 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "dillingham/nova-list-card",
"description": "List Nova Resources",
"keywords": [
"laravel",
"nova"
],
"license": "MIT",
"require": {
"php": ">=7.1.0",
"watson/aggregate": "^1.0"
},
"autoload": {
"psr-4": {
"NovaListCard\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"NovaListCard\\CardServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Empty file added dist/css/card.css
Empty file.
1 change: 1 addition & 0 deletions dist/js/card.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"/js/card.js": "/js/card.js"
}
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.0.0",
"laravel-mix": "^1.0"
},
"dependencies": {
"vue": "^2.5.0"
}
}
237 changes: 237 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# Nova List Card
Add a variety of lists to your dashboard

### Basic Usage Example
Set the resource for the card
```php
(new NovaListCard\ListCard)
->resource(\App\Nova\Post::class)
->heading('Recent Posts')
->subtitle('email')
->timestamp()
->viewAll()
```

### Possible Scenarios
- Latest resource / Oldest resource ([example](#))
- Upcoming - latest & custom timestamp ([example](#))
- Past due - oldest & custom timestamp ([example](#))
- Top resource by relationship count ([example](#))
- Worst resource by relationship count ([example](#))
- Top resource by relationship sum ([example](#))
- Worst resource by relationship sum ([example](#))

### Available Methods

| Method | Description |
| - | - |
| resource() | declare the resource |
| heading() | add a title to card |
| subtitle() | display subtitle value |
| timestamp() | display & format timestamp |
| value() | display right side value |
| withCount() | aggregate count value |
| withSum() | aggregate sum value |
| orderBy() | set the resource order |
| limit() | set number of resources |
| viewAll() | enable view all link |
| viewAllLens() | enable lens view all |
| zebra() | add alternate row color |
| id() | unique id for card's requests |
| classes() | add css classes to card |



**Multiple Headings**

When adding a row value, add second heading
```php
->heading('Top Bloggers', '# Posts')
```

**Resource Subtitle**

Display resource subtitle beneath the title
```php
(new ListCard)
->resource(User::class)
->subtitle(),
```
Display resource proporties beneath the title
```php
(new ListCard)
->resource(User::class)
->subtitle('city'),
```

**Show View All Link**

You can link to the resource's index
```php
->resource(User::class)
->viewAll()
```
Or to a lens attached to the resource
```php
->resource(User::class)
->viewAllLens('most-popular-users')
```



**Side Values**

Display resource values on the right side
```php
(new ListCard)
->resource(User::class)
->value('city'),
```

**Aggregated Values**

Add counts of relationships:
```php
(new ListCard)
->resource(Category::class)
->withCount('posts')
->value('category_posts'),
```
Add sum of relationship column:
```php
(new ListCard)
->resource(User::class)
->withSum('orders', 'total')
->value('orders_sum'),
```
**Value formatting**

You can change the value output using [numeral.js](http://numeraljs.com/#format)

Format: 55.2k insread of 55200
```php
-value('orders_sum') // 55200
-value('orders_sum', '0.0a') // 55.2k
-value('orders_sum', '($ 0.00 a)') // $55.2k
```
Timestamp: add third parameter
```php
->value('created_at', 'mm/dd'', 'timestamp')
```

**Limit**

Set the number of items to display | default: 5:
```php
->limit(3)
```

**OrderBy**

Set the order of the resources:
```php
->orderBy('scheduled_at', 'desc')
```
Can also order by aggregated columns
```php
->orderBy('orders_sum', 'desc')
```

**Timestamps**

Defaults are created_at & moment.js format: MM/DD/YYYY:
```php
(new ListCard)->timestamp(),
(new ListCard)->timestamp('due_at'),
(new ListCard)->timestamp('completed_at', 'MM/DD'),
```
Relative timestamps: `5 days ago` | `in 5 days`
```php
(new ListCard)->timestamp('completed_at', 'relative'),
```

**Scoped Resource**

Pass an ID to the ListCard and check within [IndexQuery](https://nova.laravel.com/docs/2.0/resources/authorization.html#index-filtering):
```php
(new ListCard)->id('upcoming-tasks')
```
```php
public static function indexQuery($request, $query)
{
if($request->input('nova-list-card') == 'upcoming-tasks') {
$query->whereNull('completed_at');
}

return $query;
}
```

**CSS Classes**

Customize styles easily if you have your own theme.css
```css
.nova-list-card {}
.nova-list-card-heading {}
.nova-list-card-body {}
.nova-list-card-item {}
.nova-list-card-title {}
.nova-list-card-subtitle {}
.nova-list-card-timestamp {}
.nova-list-card-value {}
.nova-list-card-view-all {}
```
Also includes resource specific classes etc
```css
.nova-list-card.users.most-tasks
```
Also can target specific rows
```css
.nova-list-card-item-1 {
color: green;
}
.nova-list-card-item-2 {}
.nova-list-card-item-3 {}
```
If you pass an ID with `->id('upcoming-tasks)`
```css
#upcoming-tasks {}
```
You can also add classes manually
```php
->classes('font-bold text-red some-custom-class')
```
You can also add alternate row formatting
```php
->zebra()
```

# Examples

```php
(new ListCard())
->resource(Contact::class)
->heading('Recent Contacts')
->subtitle('email')
->timestamp()
->limit(3)
->viewAll(),

(new ListCard())
->resource(Contact::class)
->heading('Contacts: Most tasks', 'Tasks')
->orderBy('tasks_count', 'desc')
->subtitle('email')
->value('tasks_count')
->withCount('tasks')
->zebra()
->viewAll(),

(new ListCard())
->resource(Contact::class)
->heading('Top Opportunities', 'Estimates')
->withSum('opportunities', 'estimate')
->value('opportunities_sum', '0.0a')
->viewAllLens('top-opportunities')
->orderBy('opportunities_sum', 'desc'),
```
3 changes: 3 additions & 0 deletions resources/js/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Nova.booting((Vue, router, store) => {
Vue.component('nova-list-card', require('./components/Card'))
})
Loading

0 comments on commit 834480d

Please sign in to comment.