Skip to content

Commit 22b44dd

Browse files
committed
Initial commit
0 parents  commit 22b44dd

12 files changed

+973
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Element-UI CRUD
2+
3+
CRUD components for Element-UI (Vue).
4+
5+
This is intended for use with Laravel's Resource Controllers:
6+
7+
https://laravel.com/docs/5.5/controllers#resource-controllers
8+
9+
However, it may be used in other HTTP applications if the same endpoints are implemented.
10+
11+
12+
## Installation
13+
14+
Requires:
15+
16+
```
17+
npm install axios --save
18+
npm install vue --save
19+
npm install element-ui --save
20+
```
21+
22+
Install:
23+
24+
```
25+
npm install element-ui-crud --save
26+
```
27+
28+
Configuration:
29+
30+
You must set Axios as your $http library:
31+
32+
```
33+
import Axios from 'axios'
34+
Vue.prototype.$http = Axios;
35+
```
36+
37+
38+
## Components
39+
40+
Element-UI CRUD is designed to be modular so that each component can be used on its own if desired.
41+
42+
### ElCrud
43+
44+
The primary component that provides full CRUD functionality.
45+
46+
#### Example
47+
48+
```vue
49+
<template>
50+
<div>
51+
<h1>Users</h1>
52+
<hr/>
53+
54+
<el-crud endpoint="/api/users"
55+
:list="['id', 'name']"
56+
:create="['name']"
57+
:edit="['name']"
58+
:titles="{ 'id': 'ID', 'name': 'Name' }"
59+
<template slot="list" scope="scope">
60+
<el-button size="small" type="primary" v-on:click="alert(scope.row)" icon="information"></el-button>
61+
</template>
62+
</el-crud>
63+
</div>
64+
</template>
65+
66+
<script>
67+
import ElCrud from "element-ui-crud"
68+
69+
export default {
70+
components: { ElCrud },
71+
}
72+
</script>
73+
```
74+
75+
#### Over-riding/Customizing Display of Columns
76+
77+
The display of columns can be over-ridden using Vue's Template/Slot system. The general format is "component.columnName". An example is below showing how to over-ride the "id" column in the "List" component.
78+
79+
```vue
80+
<el-crud endpoint="/api/users"
81+
:list="['id', 'name']"
82+
:create="['name']"
83+
:edit="['name']"
84+
:titles="{ 'id': 'ID', 'name': 'Name' }"
85+
<template slot="list" scope="scope">
86+
<el-button size="small" type="primary" v-on:click="console.log(scope.row)" icon="information"></el-button>
87+
</template>
88+
<template slot="list.id" scope="scope">
89+
ID of user is {{ scope.row['id'] }}
90+
</template>
91+
</el-crud>
92+
```
93+
94+
If you plan on using a custom component on the Create or Edit component, you must bind the v-model as below:
95+
96+
```vue
97+
<template slot="edit.data" scope="scope">
98+
<code-editor v-model="scope.entity.data"></code-editor>
99+
</template>
100+
```
101+
102+
(Note that the component MUST support the use of v-model for this to work.)
103+
104+
#### Supported Parameters
105+
106+
- endpoint
107+
108+
The root HTTP REST endpoint of your backend that provides CRUD functionality.
109+
Note that this should implement the same endpoints as Laravel's Resource Controller.
110+
111+
- **Type:** string
112+
- **Example:** "/api/users"
113+
114+
- primary-key (optional)
115+
116+
The primary key to use on the List component.
117+
118+
- **Type:** string
119+
- **Default:** "id"
120+
121+
- list
122+
123+
Fields that should be shown on the List component.
124+
125+
- **Type:** array
126+
- **Example:** ["id", "name"]
127+
128+
- create
129+
130+
Fields that should be shown on the Create component.
131+
If not specified, create functionality will not be offered.
132+
133+
- **Type:** array
134+
- **Example:** ["name"]
135+
136+
- edit
137+
138+
Fields that should be shown on the Edit component.
139+
If not specified, edit functionality will not be offered.
140+
141+
- **Type:** array
142+
- **Example:** ["name"]
143+
144+
- show-delete
145+
146+
Whether "Delete" should be shown next to items in row.
147+
148+
- **Type:** boolean
149+
- **Default:** true
150+
151+
- show-refresh
152+
153+
Whether "Refresh" button should be shown above table.
154+
155+
- **Type:** boolean
156+
- **Default:** true
157+
158+
- titles
159+
160+
Titles to apply to List Columns and Create/Edit Forms.
161+
If not provided, the key for that column is used.
162+
163+
- **Type:** Object
164+
- **Example:** { id: 'ID', name: 'Name' }
165+
166+
- order (TODO)
167+
168+
Titles to apply to List Columns and Create/Edit Forms.
169+
If not provided, the key for that column is used.
170+
171+
- **Type:** Object
172+
- **Example:** { id: 'ID', name: 'Name' }
173+
174+
- params
175+
176+
Extra parameters that should be passed with every request.
177+
These will be passed in the query string.
178+
179+
- **Type:** Object
180+
- **Example:** { where: 'user.type == "ADMIN' }
181+
182+
- fields (TODO)
183+
184+
Extra parameters that should be passed with every request.
185+
Can be used for filtering the results server-side.
186+
187+
- **Type:** Object
188+
- **Example:** { level: 'admin' }
189+
190+
- after
191+
192+
Function to perform after Create/Edit.
193+
For example, after a edit is performed, you might wish to update a VueX store.
194+
195+
- **Type:** function
196+
- **Example:** function(entity) { this.$store.dispatch('refreshUsers'); }
197+
198+
- pagination
199+
200+
If set, Pagination will be enabled. This must be handled server-side.
201+
The "limit" and "offset" parameters will be passed in the Query String.
202+
203+
- **Type:** integer
204+
- **Default:** 0
205+
- **Example:** 50
206+
207+
- create-size
208+
209+
Size of the Create Dialog.
210+
211+
- **Type:** string
212+
- **Default:** "small"
213+
- **Example:** "large"
214+
215+
- edit-size
216+
217+
Size of the Edit Dialog.
218+
219+
- **Type:** string
220+
- **Default:** "small"
221+
- **Example:** "large"
222+
223+
- delete-size
224+
225+
Size of the Delete Dialog.
226+
227+
- **Type:** string
228+
- **Default:** "tiny"
229+
- **Example:** "small"
230+
231+
### ElList
232+
233+
Component to display the Rows in a table.
234+
235+
See [List.vue](src/List.vue) for a list of available parameters.
236+
237+
### ElEdit
238+
239+
Component to display the Edit Form.
240+
241+
See [Edit.vue](src/Edit.vue) for a list of available parameters.
242+
243+
### ElCreate
244+
245+
Component to display the Create Form.
246+
247+
See [Create.vue](src/Create.vue) for a list of available parameters.
248+
249+
## Badges
250+
251+
![](https://img.shields.io/badge/license-MIT-blue.svg)
252+
![](https://img.shields.io/badge/status-dev-yellow.svg)
253+
254+
---

index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ElCreate from './src/Create';
2+
import ElDelete from './src/Delete';
3+
import ElEdit from './src/Edit';
4+
import ElCrud from './src/ElCrud';
5+
import ElList from './src/List';
6+
import ElShow from './src/Show';
7+
8+
export default ElCrud;
9+
10+
export {
11+
ElCreate,
12+
ElDelete,
13+
ElEdit,
14+
ElList,
15+
ElShow,
16+
}

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "element-crud-ui",
3+
"version": "0.0.1",
4+
"description": "CRUD components for Element-UI V2 (Vue)",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/jimtendo/element-ui-crud.git"
12+
},
13+
"keywords": [
14+
"Element-UI",
15+
"Vue",
16+
"CRUD"
17+
],
18+
"author": "James Augustus Zuccon Phd ([email protected])",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/jimtendo/element-ui-crud/issues"
22+
},
23+
"homepage": "https://github.com/jimtendo/element-ui-crud#readme"
24+
}

0 commit comments

Comments
 (0)