This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
App.vue
159 lines (137 loc) · 5.11 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
<div id="app">
<h1 class="text-center mt-2">Vue-Form-Builder @ v2.1.0 - Development-Preview</h1>
<p class="text-center">Presented by <strong>Seth (Sandaru) Phat</strong></p>
<h4 class="text-center mb-3">What you <strong>BUILD</strong> is what you <strong>GOT</strong>.</h4>
<div class="col-md-12">
<button class="btn btn-info mr-2" @click="getData">Get JSON Form-Data (Console / Builder)</button>
<button class="btn btn-info mr-2" @click="setData">Set JSON Form-Data (Basic Configuration / Builder)</button>
<button class="btn btn-info mr-2" @click="createBlank">Create Blank Form (Builder)</button>
<button class="btn btn-info mr-2" @click="viewRenderer">
<span v-show="isRenderer">
Back to Builder
</span>
<span v-show="!isRenderer">
View Renderer Form from Basic Configuration
</span>
</button>
</div>
<hr>
<FormBuilder v-if="!isRenderer" v-model="formData"></FormBuilder>
<div class="row" v-if="isRenderer" style="padding: 20px; margin-right: 0">
<div class="col-md-12 mb-4">
<button class="btn btn-success mr-2" @click="isShowData = !isShowData">
<span v-show="isShowData">Hide Form Data</span>
<span v-show="!isShowData">Show Form Data</span>
</button>
<button class="btn btn-info mr-2" @click="setRandomData">Set Random Data</button>
<button
class="btn btn-info mr-2"
@click="setReadonly"
>
<span v-show="readOnly">Turn off ReadOnly mode</span>
<span v-show="!readOnly">Turn on ReadOnly mode</span>
</button>
</div>
<FormRenderer
v-model="formInputData"
:class="{'col-md-9': isShowData, 'col-md-12': !isShowData}"
:form-configuration="formData"
:read-only="readOnly"
/>
<div class="p-0" :class="{'col-md-3': isShowData, 'd-none': !isShowData}">
<h4>Form Input Data</h4>
<pre class="code"><code class="code" v-html="JSON.stringify(formInputData, null, 2)"></code></pre>
</div>
</div>
</div>
</template>
<script>
/**
* NOTE - This file only exists for development purpose.
*/
import FormBuilder from "@/components/FormBuilder";
import FormRenderer from "@/components/FormRenderer";
import {DEMO_FORM_DATA} from "@/demo-form-data";
export default {
components: {
FormBuilder,
FormRenderer
},
data: () => ({
formData: null,
isShowDevNote: false,
isRenderer: false,
formInputData: null,
isShowData: false,
readOnly: false,
}),
methods: {
getData() {
console.log(JSON.stringify(this.formData))
},
createBlank() {
this.formData = Object.assign({})
},
setData() {
this.formData = Object.assign({}, DEMO_FORM_DATA);
},
viewRenderer() {
if (!this.isRenderer) {
this.setData();
this.isRenderer = true;
return;
}
this.isRenderer = false;
},
setRandomData() {
const faker = require('faker');
this.$set(this, 'formInputData', {
"name": faker.name.findName(),
"brief-description": faker.company.companyName(),
"long-description": faker.lorem.paragraphs(),
"user_email": faker.internet.email(),
"is_deletable": faker.random.number({min: 0, max:1}),
"doc_props": [""+faker.random.number({min: 1, max:3})],
"doc_date": faker.date.past(),
"doc-process-range": {
startDate: faker.date.past(),
endDate: faker.date.future(),
},
"total_value": faker.finance.amount()
});
},
setReadonly() {
if (this.readOnly) {
this.readOnly = false;
return;
}
this.setRandomData();
this.readOnly = true;
},
}
}
</script>
<style scoped>
pre {
background: #333;
white-space: pre;
word-wrap: break-word;
overflow: auto;
}
pre.code {
margin: 20px 0;
border-radius: 4px;
border: 1px solid #292929;
position: relative;
}
pre.code code {
display: block;
padding: 15px 16px 14px;
border-left: 1px solid #555;
overflow-x: auto;
font-size: 13px;
line-height: 19px;
color: #ddd;
}
</style>