Skip to content
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ vendor
.idea
composer.lock
yarn.lock
resources/assets/theme/sharp
/public
1,026 changes: 908 additions & 118 deletions resources/assets/dist/sharp.js

Large diffs are not rendered by default.

181 changes: 94 additions & 87 deletions resources/assets/js/_test-form.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,102 @@
export const layout = [
{
"title": "Tab1",
"columns": [
{
"size": 7,
"fields": [
[
{
"key": "A",
"size": 4,
"sizeXS": 6
},
{
"key": "B",
"sizeXS": 6
}
],
[
{
"legend": "dates",
"fields": [
[
{
"key": "date"
}
],
[
{
"key": "number"
}
export const layout = {
"tabbed":true,
"tabs":
[
{
"title": "Tab1",
"columns": [
{
"size": 7,
"fields": [
[
{
"key": "A",
"size": 4,
"sizeXS": 6
},
{
"key": "B",
"sizeXS": 6
}
],
[
{
"legend": "dates",
"fields": [
[
{
"key": "date"
}
],
[
{
"key": "number"
}
]
]
]
}
],
[
{
"key":"mdeditor",
}
}
],
[
{
"key":"mdeditor",
}
]
]
]
},
{
"size": 5,
"fields": [
[
{
"key": "mylist",
"item": [
[
{
"key": "name"
}, {
"key": "surname"
}
], [
{
"key": "age"
},
{
"size": 5,
"fields": [
[
{
"key": "mylist",
"item": [
[
{
"key": "name"
}, {
"key": "surname"
}
], [
{
"key": "age"
}
]
]
]
}
], [
{
"key": "show_autocomplete"
}, {
"key": "show_upload"
}
], [
{
"key" : "name"
}
], [
{
"key": "admin_password"
}
],[
{
"key" : "myimage"
}
],
[
{
"key" : "select"
}
}
], [
{
"key": "show_autocomplete"
}, {
"key": "show_upload"
}
], [
{
"key" : "name"
}
], [
{
"key": "admin_password"
}
],[
{
"key" : "myimage"
}
],
[
{
"key" : "select"
}
]
]
]
}
]
}
];
}
]
},
{
title:'tab2',
columns:[]
}
]
};

export const data = {
"A":"Valeur texte",
Expand Down Expand Up @@ -157,7 +165,6 @@ export const fields = {
Résultat : {{ name }} {{ surname }}
`,
inline:true,
templateProps: ['name', 'surname'],
searchKeys: ['name', 'surname'],
itemIdAttribute:'id',
conditionalDisplay: {
Expand Down
14 changes: 10 additions & 4 deletions resources/assets/js/app/controllers/TemplateController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TemplateController {
* @param templateValue
* @param templateProps
*/
static compileAndRegisterComponent(fieldKey, { templateName, templateValue, templateProps }) {
static compileAndRegisterComponent(fieldKey, { templateName, templateValue }) {

let template = new Template(fieldKey, Template.parseTemplateName(templateName));
let compName = template.compName;
Expand All @@ -20,10 +20,16 @@ class TemplateController {

let definition = TemplateDefinition[templateName];


Vue.component(compName, {
mixins:[definition||{}],
template: `<div>${templateValue}</div>`,
props: templateProps
functional:true,
render(h, ctx) {
return h({
mixins: [definition||{}],
template:`<div>${templateValue}</div>`,
props: Object.keys(ctx.props)
}, ctx.data);
}
});
}

Expand Down
78 changes: 48 additions & 30 deletions resources/assets/js/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
<template>
<div class="Form container">
<template v-if="ready">
<sharp-grid v-if="layout.length == 1" :rows="[layout[0].columns]">
<template scope="column">
<sharp-fields-layout v-if="fields" :layout="column.fields">
<template scope="fieldLayout">
<sharp-field-display :field-key="fieldLayout.key"
:context-fields="fields"
:context-data="data"
:field-layout="fieldLayout"
:update-data="updateData">
</sharp-field-display>
</template>
</sharp-fields-layout>
</template>
</sharp-grid>
<template v-if="layout.tabbed && layout.tabs.length>1">
<b-tabs pills v-model="tabIndex">
<b-tab v-for="(tab,i) in layout.tabs" :title="tab.title" :key="i">
<sharp-form-tab-content
:columns="tab.columns"
:fields="fields"
:data="data"
:update-data="updateData"
>
</sharp-form-tab-content>
</b-tab>
</b-tabs>
</template>
<template v-else>
<div v-for="tab in layout.tabs">
<sharp-form-tab-content
:columns="tab.columns"
:fields="fields"
:data="data"
:update-data="updateData"
>
</sharp-form-tab-content>
</div>
</template>
</template>
<template v-else>
Form loading...
Expand All @@ -26,23 +36,28 @@
import util from '../util';
import TemplateDefinition from '../template-definition';
import { API_PATH } from '../consts';
import testableForm from '../mixins/testable-form';

import Template from '../app/models/Template';
import TemplateController from '../app/controllers/TemplateController';

import Grid from './Grid';
import FieldsLayout from './FieldsLayout';

import * as testForm from '../_test-form';
import { NameAssociation as fieldCompNames } from './fields/index';

import FormTabContent from './FormTabContent';
import bTabs from './vendor/bootstrap-vue/components/tabs'
import bTab from './vendor/bootstrap-vue/components/tab'


export default {
name:'SharpForm',

mixins: [
testableForm
],

components: {
[Grid.name]:Grid,
[FieldsLayout.name]:FieldsLayout
[FormTabContent.name]: FormTabContent,
bTab, bTabs
},

props:{
Expand All @@ -52,9 +67,10 @@

data() {
return {
fields: null,//testForm.fields,
data: null,//testForm.data,
layout: null,//testForm.layout
fields: null,
data: null,
layout: null,
tabIndex:0,
ready:false
}
},
Expand All @@ -77,14 +93,17 @@
this.data[key] = value;
},
getForm() {
return axios.get(this.apiPath)
return new Promise((resolve,reject) =>
axios.get(this.apiPath)
.then(({data: {fields, layout, data}}) => {
this.fields = fields;
this.layout = layout;
this.data = data;

this.ready=true;
});
resolve();
})
);
},
postForm() {
return axios.post(this.apiPath)
Expand All @@ -101,19 +120,18 @@
TemplateController.compileAndRegisterComponent(fieldKey, {
templateName: fieldPropName,
templateValue: field[fieldPropName],
templateProps: field.templateProps
});
}
}
}
}
},
mounted() {
if(this.entityKey) {
created() {
if(this.entityKey != null) {
this.getForm().then(_=>this.parseTemplates());
}
else this.parseTemplates();
window.form =this;
else util.error('no entity key provided');
window.form = this;
}
}
</script>
Loading