Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ffbf9b

Browse files
committed
add tables demo
1 parent bf6c2fd commit 1ffbf9b

File tree

12 files changed

+153
-11
lines changed

12 files changed

+153
-11
lines changed

demo/apps/apijson_demo/settings.ini

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ moment = 'apijson_demo.models.Moment'
66
[APIJSON_MODELS]
77
moment = {
88
"user_id_field" : "user_id",
9-
"GET" : { "roles" : ["OWNER","LOGIN"] },
10-
"HEAD" : { "roles" : ["OWNER","LOGIN"] },
11-
"POST" : { "roles" : ["OWNER"] },
12-
"PUT" : { "roles" : ["OWNER"] },
13-
"DELETE" : { "roles" : ["OWNER"] },
9+
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
10+
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
11+
"POST" : { "roles" : ["OWNER","ADMIN"] },
12+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
13+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
1414
}
1515
comment = {
1616
"user_id_field" : "user_id",
17-
"GET" : { "roles" : ["OWNER","LOGIN"] },
18-
"HEAD" : { "roles" : ["OWNER","LOGIN"] },
19-
"POST" : { "roles" : ["OWNER"] },
20-
"PUT" : { "roles" : ["OWNER"] },
21-
"DELETE" : { "roles" : ["OWNER"] },
17+
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
18+
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
19+
"POST" : { "roles" : ["OWNER","ADMIN"] },
20+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
21+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
2222
}
2323

2424
[APIJSON_REQUESTS]

demo/apps/settings.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ INSTALLED_APPS = [
1919
'uliweb_comui',
2020
'uliweb_apijson.apijson',
2121
'apijson_demo',
22+
'tables',
2223
]
2324

2425
[MENUS]
2526
MAINMENU = {
2627
'subs':[
2728
{'name': 'apijson', 'link':'/', 'title':u'APIJSON Demo'},
29+
{'name': 'tables', 'link':'/tables', 'title':u'APIJSON tables'},
2830
]
2931
}
3032

demo/apps/tables/README.md

Whitespace-only changes.

demo/apps/tables/__init__.py

Whitespace-only changes.

demo/apps/tables/static/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store static files.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{extend "site/layout0.html"}}
2+
3+
{{block title}}uliweb-apijson demo{{end title}}
4+
5+
{{block mainmenu}}
6+
{{<< mainmenu('tables')}}
7+
{{end mainmenu}}
8+
9+
{{block sidemenu}}{{end sidemenu}}
10+
11+
{{block header_custom_menu}}{{end header_custom_menu}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{extend "Tables/layout.html"}}
2+
3+
{{block content_main}}
4+
{{use "ui.vue"}}
5+
{{use "ui.iview"}}
6+
{{include "vue/inc_apijson_table.html"}}
7+
{{if role!="ADMIN":}}
8+
<div class="alert alert-warning" role="alert">You should <a class="btn btn-primary btn-sm" href="{{=url_for('uliweb_apps.login.views.login')}}" role="button">login</a> with user <strong>admin</strong> to view all the tables</div>
9+
{{pass #if}}
10+
<div id="app">
11+
<tabs v-model:value="tab_current" type="card">
12+
<tab-pane v-for="item in tabs" :key="item" :label="item" :name="item">
13+
<apijson-table :table_name="item"></apijson-table>
14+
</tab-pane>
15+
</tabs>
16+
</div>
17+
18+
<script>
19+
var vm = new Vue({
20+
el: '#app',
21+
delimiters: ['{', '}'],
22+
data:{
23+
tab_current: null,
24+
tabs: {{=table_keys_json}}
25+
}
26+
})
27+
</script>
28+
{{end content_main}}

demo/apps/tables/templates/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store template files.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<script>
2+
Vue.component('apijson-table', {
3+
delimiters: ['{', '}'],
4+
props: ["table_name"],
5+
template: `<div>
6+
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
7+
<page :total="total" :page-size="query_count" :current.sync="current_page" :page-size-opts="[10, 20, 50, 100]" show-sizer @on-change="page_on_change" @on-page-size-change="page_on_page_size_change"></page>
8+
</div>`,
9+
data: function(){
10+
return {
11+
tcolumns:[
12+
{title:'#',key:'id'}
13+
],
14+
tcolumns_init: false,
15+
tlist:[],
16+
query_count: 10,
17+
current_page: 1,
18+
total: 0,
19+
sort_key: "id",
20+
sort_order: "-"
21+
}
22+
},
23+
methods: {
24+
update_list: function(){
25+
var thisp = this
26+
var arr_params = {
27+
"@count":thisp.query_count,
28+
"@page":thisp.current_page-1,
29+
"@query":2
30+
}
31+
arr_params[this.table_name] = {
32+
"@order":thisp.sort_key+thisp.sort_order,
33+
"@role":"{{=role}}"
34+
}
35+
var params = {
36+
"[]":arr_params,
37+
"total@":"/[]/total"
38+
}
39+
$.ajax({
40+
type: "POST",
41+
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
42+
contentType: 'application/json',
43+
data: JSON.stringify(params),
44+
success: function (data) {
45+
if (data.code==200) {
46+
var arr = data["[]"]
47+
if (!thisp.tcolumns_init) {
48+
if (arr.length>0) {
49+
var item = arr[0]
50+
for (var k in item){
51+
if (k!="id") {
52+
thisp.tcolumns.push({title:k,key:k})
53+
}
54+
}
55+
thisp.tcolumns_init = true
56+
}
57+
}
58+
thisp.tlist = arr
59+
thisp.total = data.total
60+
}
61+
}
62+
})
63+
},
64+
table_on_sort_change: function(){
65+
66+
},
67+
page_on_change: function(data) {
68+
this.update_list()
69+
},
70+
page_on_page_size_change: function(data) {
71+
this.query_count = data
72+
this.current_page = 0
73+
this.update_list()
74+
}
75+
},
76+
mounted: function(){
77+
this.update_list()
78+
}
79+
})
80+
</script>

demo/apps/tables/views.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#coding=utf-8
2+
from uliweb import expose, functions
3+
from json import dumps
4+
5+
@expose('/tables')
6+
class Tables(object):
7+
@expose('')
8+
def list(self):
9+
table_keys = settings.APIJSON_MODELS.keys()
10+
if request.user and functions.has_role(request.user,"ADMIN"):
11+
role = "ADMIN"
12+
elif request.user:
13+
role = "LOGIN"
14+
else:
15+
role = "UNKNOWN"
16+
return {
17+
"table_keys_json":dumps(table_keys),
18+
"role":role
19+
}

demo/doc/imgs/demo_screenshot.png

-14.5 KB
Loading

uliweb_apijson/apijson/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _get_array(self,key):
123123
if query_page:
124124
#@page begin from 0
125125
try:
126-
query_page = int(params[n])
126+
query_page = int(query_page)
127127
except ValueError as e:
128128
log.error("bad param in '%s': '%s'"%(n,params))
129129
return json({"code":400,"msg":"@page should be an int, now '%s'"%(params[n])})

0 commit comments

Comments
 (0)