Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 031a013

Browse files
Merge pull request #26 from zhangchunlin/master
Sync
2 parents 6747568 + f6133f8 commit 031a013

File tree

7 files changed

+199
-48
lines changed

7 files changed

+199
-48
lines changed

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ build
44
dist
55
*.egg-info
66
.idea
7-
_git
7+
_git
8+
.vscode
9+

‎uliweb_apijson/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.1.0'
1+
__version__ = '0.1.1'
22
__url__ = 'https://github.com/zhangchunlin/uliweb-apijson'
33
__author__ = 'Chunlin Zhang'
44
__email__ = 'zhangchunlin@gmail.com'

‎uliweb_apijson/apijson/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ moment = {
4545
"PUT" :{
4646
"ADD":{"@role": "OWNER"},
4747
"NECESSARY" : ["id","content"],
48+
"DISALLOW" : ["email"],
4849
},
4950
}
5051
}

‎uliweb_apijson/apijson/__init__.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,29 @@ def get_apijson_tables(role="UNKNOWN"):
2121
editable = role in roles
2222
c["editable"] = editable
2323
return apijson_tables
24+
25+
def get_apijson_table(role="UNKNOWN",name=None):
26+
from uliweb import settings
27+
28+
if not name:
29+
return {}
30+
s = settings.APIJSON_TABLES
31+
if s:
32+
apijson_tables = dict(s.iteritems())
33+
else:
34+
return {}
35+
36+
c = apijson_tables.get(name)
37+
if not c:
38+
return {}
39+
editable = c.get("editable",False)
40+
_model_name = c.get("@model_name") or n
41+
if editable=="auto":
42+
editable = False
43+
POST = settings.APIJSON_MODELS.get(_model_name,{}).get("POST")
44+
if POST:
45+
roles = POST["roles"]
46+
if roles:
47+
editable = role in roles
48+
c["editable"] = editable
49+
return c

‎uliweb_apijson/apijson/settings.ini‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ user = {
1919

2020
[FUNCTIONS]
2121
get_apijson_tables = "uliweb_apijson.apijson.get_apijson_tables"
22+
get_apijson_table = "uliweb_apijson.apijson.get_apijson_table"

‎uliweb_apijson/apijson/templates/vue/inc_apijson_table.html‎

Lines changed: 141 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<script>
22
Vue.component('apijson-table', {
33
delimiters: ['{', '}'],
4-
props: ["table_name","config","func_init","func_change_params"],
4+
props: [
5+
"table_name",
6+
"config",
7+
"custom_tcolumns_render_generator",
8+
"hook_init",
9+
"hook_ajax_params"
10+
],
511
template: `<div>
612
<div v-if="config_editable && config_add_fields!=null"><i-button type="primary" @click="add">Add</i-button> <br><br> </div>
713
<Spin size="large" fix v-if="loading"></Spin>
@@ -10,26 +16,32 @@
1016
<modal v-model="modal_add" title="Add">
1117
<i-form @submit.native.prevent :label-width="80">
1218
<form-item v-for="item in add_items" :key="item.key" :label="item.title">
13-
<i-input v-if="item.type=='input'" v-model="item.value"></i-input>
14-
<checkbox v-if="item.type=='checkbox'" v-model="item.value"></checkbox>
15-
<i-input v-if="item.type=='textarea'" v-model="item.value" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></i-input>
19+
<i-input v-if="item.component=='input'" v-model="item.value"></i-input>
20+
<checkbox v-if="item.component=='checkbox'" v-model="item.value"></checkbox>
21+
<i-input v-if="item.component=='textarea'" v-model="item.value" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></i-input>
1622
</form-item>
1723
<form-item v-if="config_editable" label="action">
18-
<i-button type="info" icon="plus" @click="real_add">Add</i-button>
24+
<i-button type="info" icon="plus" size="large" @click="real_add">Add</i-button>
1925
</form-item>
2026
</i-form>
27+
<div slot="footer">
28+
<i-button type="default" size="large" @click="modal_add=false">Cancel</i-button>
29+
</div>
2130
</modal>
2231
<modal v-model="modal_view" :title="viewedit_label">
2332
<i-form @submit.native.prevent :label-width="80">
2433
<form-item v-for="item in viewedit_items" :key="item.key" :label="item.title">
25-
<i-input v-if="item.type=='input'" v-model="item.value" :readonly="!editable(item)"></i-input>
26-
<checkbox v-if="item.type=='checkbox'" v-model="item.value" :disabled="!editable(item)"></checkbox>
27-
<i-input v-if="item.type=='textarea'" v-model="item.value" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></i-input>
34+
<i-input v-if="item.component=='input'" v-model="item.value" :readonly="!editable(item)"></i-input>
35+
<checkbox v-if="item.component=='checkbox'" v-model="item.value" :disabled="!editable(item)"></checkbox>
36+
<i-input v-if="item.component=='textarea'" v-model="item.value" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></i-input>
2837
</form-item>
2938
<form-item v-if="config_editable" label="action">
30-
<i-button type="info" icon="ios-download" @click="save">Save</i-button>
39+
<i-button type="info" icon="ios-download" size="large" @click="save">Save</i-button>
3140
</form-item>
3241
</i-form>
42+
<div slot="footer">
43+
<i-button type="default" size="large" @click="modal_view=false">Cancel</i-button>
44+
</div>
3345
</modal>
3446
<modal v-model="modal_delete" title="Confirm to delete" @on-ok="real_remove">
3547
<p>Confirm to delete #{delete_params.row&&delete_params.row.id} in table '{table_name}'?</p>
@@ -91,9 +103,24 @@
91103
}
92104
}
93105
},
106+
tcolumns_render_generator: {
107+
checkbox: function(key) {
108+
var render_func = function(h,params){
109+
var row = params.row
110+
return h('Icon',{
111+
attrs:{
112+
type: row[key]?"ios-checkmark":"ios-checkmark-outline",
113+
color: row[key]?"#2d8cf0":"#bbbec4",
114+
size: "25"
115+
},
116+
})
117+
}
118+
return render_func
119+
}
120+
},
94121
tcolumns_init: false,
95122
tlist:[],
96-
query_count: 10,
123+
query_count: thisp.config ? (thisp.config.default_page_size||10) : 10,
97124
current_page: 1,
98125
total: 0,
99126
sort_key: "id",
@@ -109,6 +136,35 @@
109136
viewedit_label: function(){return this.config_editable?'Edit':'View'}
110137
},
111138
methods: {
139+
tcolumns_custom_render(){
140+
for (var k in this.tcolumns) {
141+
var c = this.tcolumns[k]
142+
if (c.component!=null) {
143+
var g = null
144+
if (this.custom_tcolumns_render_generator!=null) {
145+
g = this.custom_tcolumns_render_generator[c.component]
146+
}
147+
if (g==null) {
148+
g = this.tcolumns_render_generator[c.component]
149+
}
150+
if (g!=null){
151+
c.render = g(c.key)
152+
}
153+
}
154+
}
155+
},
156+
ajax_hook: function(method,action,params) {
157+
if (this.hook_ajax_params!=null) {
158+
var after_hook = this.hook_ajax_params(method,action,params)
159+
if (after_hook!=null) {
160+
params = after_hook
161+
}
162+
else {
163+
console.log("warning: hook_ajax_params('"+method+"','"+action+"',params) return null, so ignore this hook")
164+
}
165+
}
166+
return params
167+
},
112168
update_list: function(){
113169
var thisp = this
114170
var arr_params = {
@@ -124,9 +180,7 @@
124180
"[]":arr_params,
125181
"total@":"/[]/total"
126182
}
127-
if (thisp.func_change_params!=null) {
128-
params = thisp.func_change_params("apijson_get",params)
129-
}
183+
params = thisp.ajax_hook("apijson_get","list",params)
130184
thisp.loading = true
131185
$.ajax({
132186
type: "POST",
@@ -141,6 +195,7 @@
141195
if (thisp.config_table_fields!=null){
142196
thisp.tcolumns = thisp.config_table_fields
143197
thisp.tcolumns.push(thisp.tcolumns_preset["action"])
198+
thisp.tcolumns_custom_render()
144199
thisp.tcolumns_init = true
145200
}
146201
else {
@@ -160,13 +215,20 @@
160215
}
161216
}
162217
thisp.tcolumns.push(thisp.tcolumns_preset["action"])
218+
thisp.tcolumns_custom_render()
163219
thisp.tcolumns_init = true
164220
}
165221
}
166222
}
167223
thisp.tlist = arr
168224
thisp.total = data.total
169225
}
226+
else {
227+
thisp.$Notice.error({
228+
title: 'error when get table '+thisp.table_name,
229+
desc: data.msg
230+
})
231+
}
170232
}
171233
})
172234
},
@@ -177,20 +239,20 @@
177239
for (var i in this.config_viewedit_fields) {
178240
var d = this.config_viewedit_fields[i]
179241
d.value = row[d.key]
180-
d.type = d.type || "input"
242+
d.component = d.component || "input"
181243
this.viewedit_items.push(d)
182244
}
183245
}
184246
else {
185-
this.viewedit_items.push({title:"id",value:row.id,"type":"input"})
186-
var type2type = {
247+
this.viewedit_items.push({title:"id",value:row.id,component:"input"})
248+
var type2comp = {
187249
"boolean":"checkbox"
188250
}
189251
for (var k in row){
190252
if (k!="id" && k[0]!="_") {
191253
var value = row[k]
192-
var type = type2type[typeof value] || "input"
193-
this.viewedit_items.push({title:k,value:value,type:type})
254+
var comp = type2comp[typeof value] || "input"
255+
this.viewedit_items.push({title:k,value:value,component:comp})
194256
}
195257
}
196258
}
@@ -226,9 +288,7 @@
226288
}
227289
}
228290
params[thisp.table_name] = record_params
229-
if (thisp.func_change_params!=null) {
230-
params = thisp.func_change_params("apijson_put",params)
231-
}
291+
params = thisp.ajax_hook("apijson_put","update",params)
232292
$.ajax({
233293
type: "POST",
234294
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.put')}}",
@@ -253,16 +313,64 @@
253313
})
254314
},
255315
real_remove: function(){
316+
if (this.config_delete_set_deleted) {
317+
this.real_remove_set_deleted()
318+
}
319+
else {
320+
this.real_remove_delete()
321+
}
322+
},
323+
real_remove_set_deleted: function(){
324+
var thisp = this
325+
var params = {
326+
"@tag": thisp.table_name
327+
}
328+
var params_table = {
329+
"id": thisp.delete_params.row.id,
330+
}
331+
params_table[this.config_deleted_field_name] = true
332+
params[thisp.table_name] = params_table
333+
334+
params = thisp.ajax_hook("apijson_put","delete",params)
335+
336+
$.ajax({
337+
type: "POST",
338+
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.put')}}",
339+
contentType: 'application/json',
340+
data: JSON.stringify(params),
341+
success: function (data) {
342+
if (data.code!=200){
343+
thisp.$Notice.error({
344+
title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name,
345+
desc: data.msg
346+
})
347+
return
348+
}
349+
var result = data[thisp.table_name]
350+
if (result.code!=200){
351+
thisp.$Notice.error({
352+
title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name,
353+
desc: result.msg
354+
})
355+
return
356+
}
357+
thisp.$Notice.success({
358+
title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name,
359+
desc: result.msg
360+
})
361+
thisp.update_list()
362+
}
363+
})
364+
},
365+
real_remove_delete: function(){
256366
var thisp = this
257367
var params = {
258368
"@tag": thisp.table_name
259369
}
260370
params[thisp.table_name] = {
261371
"id": thisp.delete_params.row.id
262372
}
263-
if (thisp.func_change_params!=null) {
264-
params = thisp.func_change_params("apijson_delete",params)
265-
}
373+
params = thisp.ajax_hook("apijson_delete","delete",params)
266374
$.ajax({
267375
type: "POST",
268376
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.delete')}}",
@@ -296,6 +404,7 @@
296404
for (var k in this.add_items){
297405
var d = this.add_items[k]
298406
d.value = null
407+
d.component = d.component || "input"
299408
}
300409
this.modal_add = true
301410
},
@@ -310,9 +419,7 @@
310419
post_params[d.key] = d.value
311420
}
312421
params[this.table_name] = post_params
313-
if (thisp.func_change_params!=null) {
314-
params = thisp.func_change_params("apijson_post",params)
315-
}
422+
params = thisp.ajax_hook("apijson_post","add",params)
316423
$.ajax({
317424
type: "POST",
318425
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.post')}}",
@@ -354,15 +461,19 @@
354461
this.config_table_fields = this.config.table_fields || null
355462
this.config_viewedit_fields = this.config.viewedit_fields || null
356463
this.config_add_fields = this.config.add_fields || null
357-
if (this.config.add_fields!=null) {
464+
if (this.config_add_fields!=null) {
358465
this.add_items = this.config_add_fields
359466
}
360467
if (this.config.default_page_size!=null) {
361468
this.query_count = this.config.default_page_size
362469
}
470+
this.config_delete_set_deleted = this.config.delete_set_deleted || false
471+
this.config_deleted_field_name = this.config.deleted_field_name || "deleted"
363472
}
364-
if (this.func_init!=null) {
365-
this.func_init(this)
473+
//if not do this, the first notice will hide behind the navigation bar in uliweb apps
474+
this.$Notice.config({top: 100,duration: 8});
475+
if (this.hook_init!=null) {
476+
this.hook_init(this)
366477
}
367478
this.update_list()
368479
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /