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

WIP: pivot table #49

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion config/schematics.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@

'delete' => [
'migration' => false,
],
],

'use-pivot' => true,
];
197 changes: 173 additions & 24 deletions resources/js/components/Modal/CreateModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,113 @@
</transition-group>
</draggable>


<span v-if="pivot.isPivotModel && config('use-pivot')">
<hr
class="w-full my-4"
/>
<div class="md:flex md:items-center">
<div>
<input
v-model="pivot.source"
placeholder="Existing source model"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>

<div>
<input
v-model="pivot.target"
placeholder="Existing target model"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>
</div>
<div class="md:flex md:items-center">
<div>
<input
v-model="pivot.methods.first"
placeholder="Method"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>

<div>
<input
v-model="pivot.methods.second"
placeholder="Method"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>
</div>


<div class="md:flex md:items-center">
<div>
<input
v-model="pivot.foreignKeys.first"
placeholder="Foreign key"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>

<div>
<input
v-model="pivot.foreignKeys.second"
placeholder="Foreign key"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>
</div>
<div class="md:flex md:items-center">

<div>
<input
v-model="pivot.localKeys.first"
placeholder="References"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>

<div>
<input
v-model="pivot.localKeys.second"
placeholder="References"
class="field bg-white appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 mr-4
text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"

type="text"
>
</div>



<i style="cursor:move"
class="fas fa-arrows-alt-v text-gray-200 mx-1"/>
</div>
</span>

<div class="flex text-lg mt-3 items-end outline-none">
<div class="inline-block w-full relative bg-transparent mx-5 mb-10 pt-2 pl-5">
<span class="plus-minus">
Expand All @@ -80,6 +187,7 @@
</button>
</span>


<div class="md:flex md:items-center">
<label class="block text-gray-500 font-bold">
<input
Expand All @@ -101,7 +209,7 @@
</label>
</div>

<div class="md:flex md:items-center">
<div class="md:flex md:items-center" v-if="!pivot.isPivotModel">
<label class="block text-gray-500 font-bold">
<input
v-model="actions.hasResourceController"
Expand All @@ -112,7 +220,7 @@
</label>
</div>

<div class="md:flex md:items-center">
<div class="md:flex md:items-center" v-if="!pivot.isPivotModel">
<label class="block text-gray-500 font-bold">
<input
v-model="actions.hasFormRequest"
Expand All @@ -121,6 +229,17 @@
Form Request
</span>
</label>
</div>

<div vif="this.config('use-pivot')" class="md:flex md:items-center">
<label class="block text-gray-500 font-bold">
<input
v-model="pivot.isPivotModel"
class="mr-2 leading-tight" type="checkbox">
<span class="text-sm w-2/3">
Pivot Model
</span>
</label>
</div>
</div>
</div>
Expand Down Expand Up @@ -164,29 +283,53 @@
actions: {
hasModelMigration: this.config('create.migration'),
hasFormRequest: this.config('create.form-request'),
hasResourceController: this.config('create.resource-controller'),
hasResourceController: this.config('create.resource-controller'),
hasPivotRelations : false,
},
options: {
hasTimestamps: false,
hasTimestamps: false,
},
fields: [{
id: this.uuid(),
name: '',
type: '',
error: false
}]
}],
pivot: {
isPivotModel: false,
source : null,
target: null,
localKeys :{
first : null,
second: null,
},
foreignKeys :{
first : null,
second: null,
},
methods :{
first : null,
second: null,
}
}
}
},

created() {
EventBus.$on('new-model', () => {
this.fields = [{
id: this.uuid(),
name: '',
type: '',
error: false
}];
});
EventBus.$on('new-model', data => {
this.pivot.isPivotModel = !! data && data.isPivotModel;

if (!this.pivot.isPivotModel){
this.fields = [{
id: this.uuid(),
name: '',
type: '',
error: false
}];
} else {
this.fields = [];
}
});
},

mounted() {
Expand Down Expand Up @@ -217,7 +360,7 @@
},

removeField(field = null) {
if (this.fields.length > 1) {
if (this.fields.length > 1) {
this.fields.splice(field ? this.fields.indexOf(field) : -1, 1);
}
},
Expand All @@ -231,7 +374,7 @@
fieldErrors.forEach(field => field.error = true);

return !fieldErrors.length;
},
},

validName(name) {
return /^[A-Za-z]+$/.test(name)
Expand All @@ -248,17 +391,18 @@
.toggleClass('focus:border-red-500 border-red-500', !this.validName(name));

if (!this.validName(name) || !this.validFields()) return;

EventBus.$emit('modal-close');
EventBus.$emit('modal-close');
EventBus.$emit('loading', true);

$.post('schematics/models/create', {
$.post('schematics/models/create', {
'name': name,
'fields': this.fields,
'actions': this.actions,
'options': this.options,
'fields': this.fields.length ? this.fields : [''],
'pivot' : this.pivot,
'actions': this.actions,
'options': this.options,
}, () => {
location.reload();
location.reload();
}).fail((e) => {
console.error(e);

Expand All @@ -275,7 +419,12 @@
this.options.hasTimestamps = false;
}
}
}
},
'pivot.isPivotModel' :{
handler(newValue, oldValue){
this.actions.hasPivotRelations = newValue;
}
}
}
}
</script>
Expand Down
Loading