Skip to content

Commit

Permalink
v2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
gldrenthe89 committed Jan 25, 2021
1 parent 50e2aae commit 6b38368
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 86 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions resources/js/components/Button/CreateRelationCustomButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<button
@click="$emit('click')"
type="button"
class="rounded dim font-bold text-sm text-primary inline-flex items-center focus:outline-none active:outline-none focus:shadow-outline active:shadow-outline pl-1 pr-2"
>
<icon type="add" width="24" height="24" view-box="0 0 24 24" />
<span>{{ setLabel(__('Create')) }}</span>
</button>
</template>

<script>
export default {
props: {
label: {},
field: {}
},
methods: {
setLabel(defaultLabel) {
return (
this.field.createRelationButtonLabel || defaultLabel
)
},
}
}
</script>
27 changes: 27 additions & 0 deletions resources/js/components/Detail/BroadcasterBelongsToField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<panel-item :field="field">
<template slot="value">
<router-link
v-if="field.viewable && field.value"
:to="{
name: 'detail',
params: {
resourceName: field.resourceName,
resourceId: field.belongsToId,
},
}"
class="no-underline font-bold dim text-primary"
>
{{ field.value }}
</router-link>
<p v-else-if="field.value">{{ field.value }}</p>
<p v-else>&mdash;</p>
</template>
</panel-item>
</template>

<script>
export default {
props: ['resource', 'resourceName', 'resourceId', 'field'],
}
</script>
9 changes: 9 additions & 0 deletions resources/js/components/Detail/ListenerCurrencyField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<panel-item :field="field" />
</template>

<script>
export default {
props: ['resource', 'resourceName', 'resourceId', 'field'],
}
</script>
9 changes: 9 additions & 0 deletions resources/js/components/Detail/ListenerField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<panel-item :field="field" />
</template>

<script>
export default {
props: ['resource', 'resourceName', 'resourceId', 'field'],
}
</script>
9 changes: 9 additions & 0 deletions resources/js/components/Detail/ListenerHiddenField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<panel-item :field="field" />
</template>

<script>
export default {
props: ['resource', 'resourceName', 'resourceId', 'field'],
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
</option>
</select-control>

<create-relation-button
<create-relation-custom-button
v-if="canShowNewRelationModal"
@click="openRelationModal"
class="ml-1"
:dusk="`${field.attribute}-inline-create`"
:field="this.field"
/>
</div>

Expand Down Expand Up @@ -391,6 +392,13 @@ export default {
)
},
// added
isReadonlyWithCreateRelationButton() {
return (
this.field.readonlyWithCreateRelationButton || _.get(this.field, 'extraAttributes.readonlyWithCreateRelationButton')
)
},
shouldShowTrashed() {
return (
this.softDeletes &&
Expand All @@ -406,12 +414,13 @@ export default {
}).authorizedToCreate
},
// changed
canShowNewRelationModal() {
return (
this.field.showCreateRelationButton &&
!this.shownViaNewRelationModal &&
!this.isLocked &&
!this.isReadonly &&
(!this.isReadonly || this.isReadonlyWithCreateRelationButton) &&
this.authorizedToCreate
)
},
Expand Down
48 changes: 48 additions & 0 deletions resources/js/components/Form/ListenerHiddenField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<input :id="field.name" type="hidden" v-model="value" />
</template>

<script>
import { FormField } from 'laravel-nova'
export default {
mixins: [FormField],
props: ['resourceName', 'resourceId', 'field'],
created() {
Nova.$on(this.field.listensTo, this.messageReceived)
},
data: () => ({
calculating: false,
field_values: {}
}),
methods: {
/*
* Set the initial, internal value for the field.
*/
setInitialValue() {
this.value = this.field.value || ''
},
messageReceived(message) {
this.field_values[message.field_name] = message.value;
this.calculateValue()
},
calculateValue: _.debounce(function () {
this.calculating = true;
Nova.request().post(
`/gldrenthe89/nova-calculated-field/calculate/${this.resourceName}/${this.field.attribute}`,
this.field_values
).then((response) => {
this.value = response.data.value;
this.calculating = false;
}).catch(() => {
this.calculating = false;
});
}, 500),
},
}
</script>
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<!--<template>-->
<!-- <span>{{ field.value }}</span>-->
<!--</template>-->

<!--<script>-->
<!--export default {-->
<!-- props: ['resourceName', 'field'],-->
<!--}-->
<!--</script>-->

<template>
<div :class="`text-${field.textAlign}`">
<span>
Expand Down
9 changes: 9 additions & 0 deletions resources/js/components/Index/ListenerHiddenField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<span>{{ field.value }}</span>
</template>

<script>
export default {
props: ['resourceName', 'field'],
}
</script>

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions resources/js/components/listener-field/DetailField.vue

This file was deleted.

39 changes: 23 additions & 16 deletions resources/js/field.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
Nova.booting((Vue, router, store) => {
Vue.component('index-broadcaster-field', require('./components/broadcaster-field/IndexField'));
Vue.component('detail-broadcaster-field', require('./components/broadcaster-field/DetailField'));
Vue.component('form-broadcaster-field', require('./components/broadcaster-field/FormField'));
// Detail
Vue.component('detail-broadcaster-field', require('./components/Detail/BroadcasterField'));
Vue.component('detail-broadcaster-belongsto-field', require('./components/Detail/BroadcasterBelongsToField'));
Vue.component('detail-broadcaster-select-field', require('./components/Detail/BroadcasterSelectField'));
Vue.component('detail-listener-currency-field', require('./components/Detail/ListenerCurrencyField'));
Vue.component('detail-listener-field', require('./components/Detail/ListenerField'));
Vue.component('detail-listener-hidden-field', require('./components/Detail/ListenerHiddenField'));

Vue.component('index-broadcaster-select-field', require('./components/broadcaster-select-field/IndexField'));
Vue.component('detail-broadcaster-select-field', require('./components/broadcaster-select-field/DetailField'));
Vue.component('form-broadcaster-select-field', require('./components/broadcaster-select-field/FormField'));
// Form
Vue.component('form-broadcaster-field', require('./components/Form/BroadcasterField'));
Vue.component('form-broadcaster-belongsto-field', require('./components/Form/BroadcasterBelongsToField'));
Vue.component('form-broadcaster-select-field', require('./components/Form/BroadcasterSelectField'));
Vue.component('form-listener-currency-field', require('./components/Form/ListenerCurrencyField'));
Vue.component('form-listener-field', require('./components/Form/ListenerField'));
Vue.component('form-listener-hidden-field', require('./components/Form/ListenerHiddenField'));

Vue.component('index-broadcaster-belongsto-field', require('./components/broadcaster-belongsto-field/IndexField'));
Vue.component('detail-broadcaster-belongsto-field', require('./components/broadcaster-belongsto-field/DetailField'));
Vue.component('form-broadcaster-belongsto-field', require('./components/broadcaster-belongsto-field/FormField'));
// Index
Vue.component('index-broadcaster-field', require('./components/Index/BroadcasterField'));
Vue.component('index-broadcaster-belongsto-field', require('./components/Index/BroadcasterBelongsToField'));
Vue.component('index-broadcaster-select-field', require('./components/Index/BroadcasterSelectField'));
Vue.component('index-listener-currency-field', require('./components/Index/ListenerCurrencyField'));
Vue.component('index-listener-field', require('./components/Index/ListenerField'));
Vue.component('index-listener-hidden-field', require('./components/Index/ListenerHiddenField'));

Vue.component('index-listener-field', require('./components/listener-field/IndexField'));
Vue.component('detail-listener-field', require('./components/listener-field/DetailField'));
Vue.component('form-listener-field', require('./components/listener-field/FormField'));

Vue.component('index-listener-currency-field', require('./components/listener-currency-field/IndexField'));
Vue.component('detail-listener-currency-field', require('./components/listener-currency-field/DetailField'));
Vue.component('form-listener-currency-field', require('./components/listener-currency-field/FormField'));
// Button
Vue.component('create-relation-custom-button', require('./components/Button/CreateRelationCustomButton'));
})
33 changes: 30 additions & 3 deletions src/BroadcasterBelongsToField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Laravel\Nova\Element;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\ResourceRelationshipGuesser;

class BroadcasterBelongsToField extends BelongsTo
{
Expand Down Expand Up @@ -59,10 +57,39 @@ public function setType($type) : Element
* @param string|array $broadcastChannel
* @return Element
*/
public function broadcastTo($broadcastChannel) : Element
public function broadcastTo($broadcastChannel): Element
{
return $this->withMeta([
'broadcastTo' => $broadcastChannel
]);
}

/**
* Tells the client side component to show create relation button while field wil be readonly.
*
* @param bool $callback
* @return BroadcasterBelongsToField
*/
public function readonlyWithCreateRelationButton($callback = true): Element
{
$this->readonlyCallback = $callback;
$this->showCreateRelationButtonCallback = $callback;

return $this->withMeta([
'readonlyWithCreateRelationButton' => $callback
]);
}

/**
* Tells the client side component which label to use for the create relation button.
*
* @param $label
* @return BroadcasterBelongsToField
*/
public function labelForCreateRelationButton($label): Element
{
return $this->withMeta([
'createRelationButtonLabel' => $label
]);
}
}
Loading

0 comments on commit 6b38368

Please sign in to comment.