Skip to content

Commit c7db13b

Browse files
committed
first commit
0 parents  commit c7db13b

13 files changed

+230
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/dist
2+
/.idea
3+
/vendor
4+
/node_modules
5+
package-lock.json
6+
composer.phar
7+
composer.lock
8+
phpunit.xml
9+
.phpunit.result.cache
10+
.DS_Store
11+
Thumbs.db

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# nova-plus-button

composer.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "jorgv/plus-button",
3+
"description": "A Laravel Nova field.",
4+
"keywords": [
5+
"laravel",
6+
"nova"
7+
],
8+
"license": "MIT",
9+
"require": {
10+
"php": ">=7.1.0"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"Jorgv\\PlusButton\\": "src/"
15+
}
16+
},
17+
"extra": {
18+
"laravel": {
19+
"providers": [
20+
"Jorgv\\PlusButton\\FieldServiceProvider"
21+
]
22+
}
23+
},
24+
"config": {
25+
"sort-packages": true
26+
},
27+
"minimum-stability": "dev",
28+
"prefer-stable": true
29+
}

mix-manifest.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"/dist/js/field.js": "/dist/js/field.js",
3+
"/dist/css/field.css": "/dist/css/field.css"
4+
}

package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"dev": "npm run development",
5+
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
6+
"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",
7+
"watch-poll": "npm run watch -- --watch-poll",
8+
"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",
9+
"prod": "npm run production",
10+
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
11+
},
12+
"devDependencies": {
13+
"cross-env": "^5.0.0",
14+
"laravel-mix": "^1.0",
15+
"laravel-nova": "^1.0"
16+
},
17+
"dependencies": {
18+
"vue": "^2.5.0"
19+
}
20+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<panel-item :field="field" />
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: ['resource', 'resourceName', 'resourceId', 'field'],
8+
}
9+
</script>

resources/js/components/FormField.vue

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<default-field :field="field">
3+
<template slot="field">
4+
<input :id="field.name" type="text"
5+
class="w-full form-control form-input form-input-bordered"
6+
:class="errorClasses"
7+
:placeholder="field.name"
8+
v-model="value"
9+
/>
10+
11+
<p v-if="hasError" class="my-2 text-danger">
12+
{{ firstError }}
13+
</p>
14+
</template>
15+
</default-field>
16+
</template>
17+
18+
<script>
19+
import { FormField, HandlesValidationErrors } from 'laravel-nova'
20+
21+
export default {
22+
mixins: [FormField, HandlesValidationErrors],
23+
24+
props: ['resourceName', 'resourceId', 'field'],
25+
26+
methods: {
27+
/*
28+
* Set the initial, internal value for the field.
29+
*/
30+
setInitialValue() {
31+
this.value = this.field.value || ''
32+
},
33+
34+
/**
35+
* Fill the given FormData object with the field's internal value.
36+
*/
37+
fill(formData) {
38+
formData.append(this.field.attribute, this.value || '')
39+
},
40+
41+
/**
42+
* Update the field's internal value.
43+
*/
44+
handleChange(value) {
45+
this.value = value
46+
}
47+
}
48+
}
49+
</script>
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<span>
3+
<button
4+
@click="Increase"
5+
class="cursor-pointer text-70 hover:text-primary mr-3"
6+
>
7+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-labelledby="updateRequest" role="presentation" class="fill-current">
8+
<path d="M12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zm1-9h2a1 1 0 0 1 0 2h-2v2a1 1 0 0 1-2 0v-2H9a1 1 0 0 1 0-2h2V9a1 1 0 0 1 2 0v2z"/></svg>
9+
<span>{{field.value}}</span>
10+
</button>
11+
</span>
12+
</template>
13+
14+
<script>
15+
export default {
16+
props: ['resourceName', 'field'],
17+
18+
methods: {
19+
/**
20+
* Send an update request to increase value for this resource
21+
*/
22+
Increase() {
23+
this.field.value = this.field.value + this.field.increaseValue;
24+
return Nova.request().post(
25+
`/api/${this.resourceName}/increase/${this.$parent.resource.id.value}`,
26+
{
27+
count: this.field.value
28+
}
29+
)
30+
},
31+
}
32+
}
33+
</script>

resources/js/field.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Nova.booting((Vue, router) => {
2+
Vue.component('index-plus-button', require('./components/IndexField'));
3+
Vue.component('detail-plus-button', require('./components/DetailField'));
4+
Vue.component('form-plus-button', require('./components/FormField'));
5+
})

resources/sass/field.scss

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nova Tool CSS

src/FieldServiceProvider.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Jorgv\PlusButton;
4+
5+
use Laravel\Nova\Nova;
6+
use Laravel\Nova\Events\ServingNova;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class FieldServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Bootstrap any application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
Nova::serving(function (ServingNova $event) {
19+
Nova::script('plus-button', __DIR__.'/../dist/js/field.js');
20+
Nova::style('plus-button', __DIR__.'/../dist/css/field.css');
21+
});
22+
}
23+
24+
/**
25+
* Register any application services.
26+
*
27+
* @return void
28+
*/
29+
public function register()
30+
{
31+
//
32+
}
33+
}

src/PlusButton.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Jorgv\PlusButton;
4+
5+
use Laravel\Nova\Fields\Field;
6+
7+
class PlusButton extends Field
8+
{
9+
/**
10+
* The field's component.
11+
*
12+
* @var string
13+
*/
14+
public $component = 'plus-button';
15+
16+
/**
17+
* Set the increase value.
18+
*
19+
* @param array $value
20+
* @return $this
21+
*/
22+
public function increaseValue(int $value = 1)
23+
{
24+
return $this->withMeta(['increaseValue' => $value]);
25+
}
26+
}

webpack.mix.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let mix = require('laravel-mix')
2+
3+
mix.js('resources/js/field.js', 'dist/js')
4+
.sass('resources/sass/field.scss', 'dist/css')
5+
.webpackConfig({
6+
resolve: {
7+
symlinks: false
8+
}
9+
})

0 commit comments

Comments
 (0)