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
20 changes: 10 additions & 10 deletions demo/apps/apijson_demo/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ moment = 'apijson_demo.models.Moment'
[APIJSON_MODELS]
moment = {
"user_id_field" : "user_id",
"GET" : { "roles" : ["OWNER","LOGIN"] },
"HEAD" : { "roles" : ["OWNER","LOGIN"] },
"POST" : { "roles" : ["OWNER"] },
"PUT" : { "roles" : ["OWNER"] },
"DELETE" : { "roles" : ["OWNER"] },
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
"POST" : { "roles" : ["OWNER","ADMIN"] },
"PUT" : { "roles" : ["OWNER","ADMIN"] },
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
}
comment = {
"user_id_field" : "user_id",
"GET" : { "roles" : ["OWNER","LOGIN"] },
"HEAD" : { "roles" : ["OWNER","LOGIN"] },
"POST" : { "roles" : ["OWNER"] },
"PUT" : { "roles" : ["OWNER"] },
"DELETE" : { "roles" : ["OWNER"] },
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
"POST" : { "roles" : ["OWNER","ADMIN"] },
"PUT" : { "roles" : ["OWNER","ADMIN"] },
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
}

[APIJSON_REQUESTS]
Expand Down
2 changes: 2 additions & 0 deletions demo/apps/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ INSTALLED_APPS = [
'uliweb_comui',
'uliweb_apijson.apijson',
'apijson_demo',
'tables',
]

[MENUS]
MAINMENU = {
'subs':[
{'name': 'apijson', 'link':'/', 'title':u'APIJSON Demo'},
{'name': 'tables', 'link':'/tables', 'title':u'APIJSON tables'},
]
}

Expand Down
Empty file added demo/apps/tables/README.md
Empty file.
Empty file added demo/apps/tables/__init__.py
Empty file.
1 change: 1 addition & 0 deletions demo/apps/tables/static/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is used to store static files.
11 changes: 11 additions & 0 deletions demo/apps/tables/templates/Tables/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{extend "site/layout0.html"}}

{{block title}}uliweb-apijson demo{{end title}}

{{block mainmenu}}
{{<< mainmenu('tables')}}
{{end mainmenu}}

{{block sidemenu}}{{end sidemenu}}

{{block header_custom_menu}}{{end header_custom_menu}}
28 changes: 28 additions & 0 deletions demo/apps/tables/templates/Tables/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{extend "Tables/layout.html"}}

{{block content_main}}
{{use "ui.vue"}}
{{use "ui.iview"}}
{{include "vue/inc_apijson_table.html"}}
{{if role!="ADMIN":}}
<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>
{{pass #if}}
<div id="app">
<tabs v-model:value="tab_current" type="card">
<tab-pane v-for="item in tabs" :key="item" :label="item" :name="item">
<apijson-table :table_name="item"></apijson-table>
</tab-pane>
</tabs>
</div>

<script>
var vm = new Vue({
el: '#app',
delimiters: ['{', '}'],
data:{
tab_current: null,
tabs: {{=table_keys_json}}
}
})
</script>
{{end content_main}}
1 change: 1 addition & 0 deletions demo/apps/tables/templates/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory is used to store template files.
80 changes: 80 additions & 0 deletions demo/apps/tables/templates/vue/inc_apijson_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<script>
Vue.component('apijson-table', {
delimiters: ['{', '}'],
props: ["table_name"],
template: `<div>
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
<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>
</div>`,
data: function(){
return {
tcolumns:[
{title:'#',key:'id'}
],
tcolumns_init: false,
tlist:[],
query_count: 10,
current_page: 1,
total: 0,
sort_key: "id",
sort_order: "-"
}
},
methods: {
update_list: function(){
var thisp = this
var arr_params = {
"@count":thisp.query_count,
"@page":thisp.current_page-1,
"@query":2
}
arr_params[this.table_name] = {
"@order":thisp.sort_key+thisp.sort_order,
"@role":"{{=role}}"
}
var params = {
"[]":arr_params,
"total@":"/[]/total"
}
$.ajax({
type: "POST",
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
contentType: 'application/json',
data: JSON.stringify(params),
success: function (data) {
if (data.code==200) {
var arr = data["[]"]
if (!thisp.tcolumns_init) {
if (arr.length>0) {
var item = arr[0]
for (var k in item){
if (k!="id") {
thisp.tcolumns.push({title:k,key:k})
}
}
thisp.tcolumns_init = true
}
}
thisp.tlist = arr
thisp.total = data.total
}
}
})
},
table_on_sort_change: function(){

},
page_on_change: function(data) {
this.update_list()
},
page_on_page_size_change: function(data) {
this.query_count = data
this.current_page = 0
this.update_list()
}
},
mounted: function(){
this.update_list()
}
})
</script>
19 changes: 19 additions & 0 deletions demo/apps/tables/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#coding=utf-8
from uliweb import expose, functions
from json import dumps

@expose('/tables')
class Tables(object):
@expose('')
def list(self):
table_keys = settings.APIJSON_MODELS.keys()
if request.user and functions.has_role(request.user,"ADMIN"):
role = "ADMIN"
elif request.user:
role = "LOGIN"
else:
role = "UNKNOWN"
return {
"table_keys_json":dumps(table_keys),
"role":role
}
Binary file modified demo/doc/imgs/demo_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion uliweb_apijson/apijson/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _get_array(self,key):
if query_page:
#@page begin from 0
try:
query_page = int(params[n])
query_page = int(query_page)
except ValueError as e:
log.error("bad param in '%s': '%s'"%(n,params))
return json({"code":400,"msg":"@page should be an int, now '%s'"%(params[n])})
Expand Down