Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buttons between blocks #233

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@
:resource-id="resourceId"
:resource="resource"
:errors="errors"
:total-count="order.length"
:layouts="layouts"
:limit-counter="limitCounter"
@move-up="moveUp(group.key)"
@move-down="moveDown(group.key)"
@remove="remove(group.key)"
/>
</div>

<component
:layouts="layouts"
:is="field.menu.component"
:field="field"
:limit-counter="limitCounter"
:errors="errors"
:resource-name="resourceName"
:resource-id="resourceId"
:resource="resource"
@addGroup="addGroup($event)"
/>
<div>
<component
:layouts="layouts"
:is="field.menu.component"
:field="field"
:limit-counter="limitCounter"
:errors="errors"
:resource-name="resourceName"
:resource-id="resourceId"
:resource="resource"
:addAtPosition="false"
:index="order.length"
/>
</div>

</template>
</component>
Expand All @@ -48,6 +54,7 @@
import FullWidthField from './FullWidthField';
import { FormField, HandlesValidationErrors } from 'laravel-nova';
import Group from '../group';
import { eventBus } from '../eventbus';

export default {
mixins: [FormField, HandlesValidationErrors],
Expand Down Expand Up @@ -163,6 +170,7 @@ export default {
for (var i = 0; i < this.value.length; i++) {
this.addGroup(
this.getLayout(this.value[i].layout),
i,
this.value[i].attributes,
this.value[i].key,
this.field.collapsed
Expand All @@ -179,9 +187,9 @@ export default {
},

/**
* Append the given layout to flexible content's list
* Add the given layout to flexible content's list at given position
*/
addGroup(layout, attributes, key, collapsed) {
addGroup(layout, position, attributes, key, collapsed) {
if(!layout) return;

collapsed = collapsed || false;
Expand Down Expand Up @@ -226,6 +234,11 @@ export default {
this.order.splice(index, 1);
this.$delete(this.groups, key);
}
},
mounted() {
eventBus.$on('add-group-'+this.field.attribute, (layout, position) => {
this.addGroup(layout, position);
});
}
}
</script>
165 changes: 100 additions & 65 deletions resources/js/components/FormGroup.vue
Original file line number Diff line number Diff line change
@@ -1,86 +1,121 @@
<template>
<div class="relative flex bg-white mb-4 pb-1" :id="group.key">
<div class="z-10 bg-white border-t border-l border-b border-60 h-auto pin-l pin-t rounded-l self-start w-8">
<button
dusk="expand-group"
type="button"
class="group-control btn border-r border-40 w-8 h-8 block"
:title="__('Expand')"
@click.prevent="expand"
v-if="collapsed">
<icon class="align-top" type="plus-square" width="16" height="16" view-box="0 0 24 24" />
</button>
<div v-if="!collapsed">
<div>
<div v-if="index == 0">
<component
:layouts="layouts"
:is="field.menu.component"
:field="field"
:limit-counter="limitCounter"
:errors="errors"
:resource-name="resourceName"
:resource-id="resourceId"
:resource="resource"
:addAtPosition="true"
:index="index"
/>
</div>

<div class="relative flex bg-white mb-4 pb-1" :id="group.key">
<div class="z-10 bg-white border-t border-l border-b border-60 h-auto pin-l pin-t rounded-l self-start w-8">
<button
dusk="collapse-group"
dusk="expand-group"
type="button"
class="group-control btn border-r border-40 w-8 h-8 block"
:title="__('Collapse')"
@click.prevent="collapse">
<icon class="align-top" type="minus-square" width="16" height="16" view-box="0 0 24 24" />
:title="__('Expand')"
@click.prevent="expand"
v-if="collapsed">
<icon class="align-top" type="plus-square" width="16" height="16" view-box="0 0 24 24" />
</button>
<div v-if="!readonly">
<div v-if="!collapsed">
<button
dusk="move-up-group"
dusk="collapse-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Move up')"
@click.prevent="moveUp">
<icon type="arrow-up" view-box="0 0 8 4.8" width="10" height="10" />
class="group-control btn border-r border-40 w-8 h-8 block"
:title="__('Collapse')"
@click.prevent="collapse">
<icon class="align-top" type="minus-square" width="16" height="16" view-box="0 0 24 24" />
</button>
<button
dusk="move-down-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Move down')"
@click.prevent="moveDown">
<icon type="arrow-down" view-box="0 0 8 4.8" width="10" height="10" />
</button>
<button
dusk="delete-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Delete')"
@click.prevent="confirmRemove">
<icon type="delete" view-box="0 0 20 20" width="16" height="16" />
</button>
<portal to="modals">
<delete-flexible-content-group-modal
v-if="removeMessage"
@confirm="remove"
@close="removeMessage=false"
:message="field.confirmRemoveMessage"
:yes="field.confirmRemoveYes"
:no="field.confirmRemoveNo"
/>
</portal>
<div v-if="!readonly">
<button
dusk="move-up-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Move up')"
@click.prevent="moveUp">
<icon type="arrow-up" view-box="0 0 8 4.8" width="10" height="10" />
</button>
<button
dusk="move-down-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Move down')"
@click.prevent="moveDown">
<icon type="arrow-down" view-box="0 0 8 4.8" width="10" height="10" />
</button>
<button
dusk="delete-group"
type="button"
class="group-control btn border-t border-r border-40 w-8 h-8 block"
:title="__('Delete')"
@click.prevent="confirmRemove">
<icon type="delete" view-box="0 0 20 20" width="16" height="16" />
</button>
<portal to="modals">
<delete-flexible-content-group-modal
v-if="removeMessage"
@confirm="remove"
@close="removeMessage=false"
:message="field.confirmRemoveMessage"
:yes="field.confirmRemoveYes"
:no="field.confirmRemoveNo"
/>
</portal>
</div>
</div>
</div>
</div>
<div class="-mb-1 flex flex-col min-h-full w-full">
<div :class="titleStyle" v-if="group.title">
<div class="leading-normal py-1 px-8"
:class="{'border-b border-40': !collapsed}">
<p class="text-80">
<span class="mr-4 font-semibold">#{{ index + 1 }}</span>
{{ group.title }}
</p>
<div class="-mb-1 flex flex-col min-h-full w-full">
<div :class="titleStyle" v-if="group.title">
<div class="leading-normal py-1 px-8"
:class="{'border-b border-40': !collapsed}">
<p class="text-80">
<span class="mr-4 font-semibold">#{{ index + 1 }}</span>
{{ group.title }}
</p>
</div>
</div>
<div :class="containerStyle">
<component
v-for="(item, index) in group.fields"
:key="index"
:is="'form-' + item.component"
:resource-name="resourceName"
:resource-id="resourceId"
:resource="resource"
:field="item"
:errors="errors"
:show-help-text="item.helpText != null"
:class="{ 'remove-bottom-border': index == group.fields.length - 1 }"
/>
</div>
</div>
<div :class="containerStyle">
</div>

<div
v-if="field.withMultipleButtons && (totalCount > 0 && index < totalCount - 1)">
<component
v-for="(item, index) in group.fields"
:key="index"
:is="'form-' + item.component"
:layouts="layouts"
:is="field.menu.component"
:limit-counter="limitCounter"
:resource-name="resourceName"
:resource-id="resourceId"
:resource="resource"
:field="item"
:field="field"
:errors="errors"
:show-help-text="item.helpText != null"
:show-help-text="field.helpText != null"
:class="{ 'remove-bottom-border': index == group.fields.length - 1 }"
:addAtPosition="true"
:index="index + 1"
/>
</div>
</div>
</div>
</template>
Expand All @@ -91,7 +126,7 @@ import { BehavesAsPanel } from 'laravel-nova';
export default {
mixins: [BehavesAsPanel],

props: ['errors', 'group', 'index', 'field'],
props: ['errors', 'group', 'index', 'field', 'layouts', 'limitsCounter', 'totalCount'],

data() {
return {
Expand Down
39 changes: 33 additions & 6 deletions resources/js/components/OriginalDropMenu.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<template>
<div class="z-20 relative" v-if="layouts">
<div
class="z-20 relative"
:class="{
'add-at-position-button-container': addAtPosition
}"
v-if="layouts"
>
<div class="relative" v-if="layouts.length > 1">
<div v-if="isLayoutsDropdownOpen"
class="absolute rounded-lg shadow-lg max-w-full mb-3 pin-b max-h-search overflow-y-auto border border-40"
class="absolute rounded-lg shadow-lg max-w-full mb-3 pin-b max-h-search overflow-y-auto border border-40"
>
<div>
<ul class="list-reset">
<li v-for="layout in layouts" class="border-b border-40">
<li v-for="layout in layouts" :key="layout.name" class="border-b border-40">
<a
:dusk="'add-' + layout.name"
@click="addGroup(layout)"
Expand All @@ -23,6 +29,9 @@
type="button"
tabindex="0"
class="btn btn-default btn-primary inline-flex items-center relative"
:class="{
'btn-xs': addAtPosition
}"
@click="toggleLayoutsDropdownOrAddDefault"
v-if="this.limitCounter > 0"
>
Expand All @@ -32,9 +41,10 @@
</template>

<script>
import { eventBus } from '../eventbus';

export default {
props: ['layouts', 'field', 'resourceName', 'resourceId', 'resource', 'errors', 'limitCounter'],
props: ['layouts', 'field', 'resourceName', 'resourceId', 'resource', 'errors', 'limitCounter', 'addAtPosition', 'index'],

data() {
return {
Expand All @@ -56,15 +66,32 @@
},

/**
* Append the given layout to flexible content's list
* Add the given layout to flexible content's list at button's position
*/
addGroup(layout) {
if (!layout) return;

this.$emit('addGroup', layout);
eventBus.$emit('add-group-'+this.field.attribute, layout, this.index);

this.isLayoutsDropdownOpen = false;
},
}
}
</script>

<style scoped>
.add-at-position-button-container {
padding-bottom: 5px;
padding-top: 5px;
margin-top: -16px;
opacity: 0;
overflow: visible;
transition: opacity 0.6s;
}
.add-at-position-button-container:hover {
opacity: 1;
}
.add-at-position-button-container button {
margin: 0 auto;
}
</style>
14 changes: 10 additions & 4 deletions resources/js/components/SearchMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
</div>
<div v-if="layouts.length > 1">
<div style="min-width: 300px;">
<div class="flexible-search-menu-multiselect">
<div
class="flexible-search-menu-multiselect"
:class="{
'mb-4': addAtPosition
}"
>
<multiselect
v-model="selectedLayout" :options="layouts"
:custom-label="renderLayoutName"
Expand All @@ -34,11 +39,12 @@
<script>

import Multiselect from 'vue-multiselect'
import { eventBus } from '../eventbus';

export default {
components: {Multiselect},

props: ['layouts', 'field', 'resourceName', 'resourceId', 'resource', 'errors', 'limitCounter'],
props: ['layouts', 'field', 'resourceName', 'resourceId', 'resource', 'errors', 'limitCounter', 'addAtPosition', 'index'],

data() {
return {
Expand Down Expand Up @@ -77,12 +83,12 @@
},

/**
* Append the given layout to flexible content's list
* Add the given layout to flexible content's list at button's position
*/
addGroup(layout) {
if (!layout) return;

this.$emit('addGroup', layout);
eventBus.$emit('add-group-'+this.field.attribute, layout, this.index);

this.isLayoutsDropdownOpen = false;
this.selectedLayout = null;
Expand Down
Loading