forked from soIu/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.pyj
More file actions
109 lines (99 loc) · 4.1 KB
/
client.pyj
File metadata and controls
109 lines (99 loc) · 4.1 KB
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
import modules.modules
import modules.views
import orm.models as models
import orm.exceptions as exceptions
import orm.tools as tools
import react as react
from orm.pouchdb import db #Whoever criticize me about this doesn't know this is local db object not the server's
from ir.data import data, create_data
from react.components.App import App
tools.exceptions = exceptions
models.setSchema()
#tools.configuration.client = True
tools.configuration.url = "http://localhost:8069"
tools.configuration.home_view = window.localStorage.rapyd_home_view or 'res.message.chat'
configuration = v'{"home_view":window.localStorage.rapyd_home_view||"res.message.chat"}'
configuration.client = tools.configuration.client
tools.configuration = Object.assign(tools.configuration, configuration)
#if not tools.configuration.client:
def restrict_menus():
return models.env['res.users.menu'].search(['user_id', '=', models.env.user.id]).then(
def (menu_ids):
menus = [menu_id.menu for menu_id in menu_ids]
if not menus.length: return
for menu in tools.menu:
if menu not in menus: del tools.menu[menu]
)
data.push(restrict_menus)
tools.create_data = create_data
for key in tools.menu:
if tools.exist(tools.menu[key].parent):
if tools.menu[key].parent in tools.menu:
tools.menu[tools.menu[key].parent].childs.push(tools.menu[key])
tools.menu[tools.menu[key].parent].childs.sort(
def (a, b):
return a.sequence - b.sequence
)
del tools.menu[key]
@async
def init_client():
try:
console.log('Initialize Client')
await [tools.create_data()]
window.renderApp(App)
if tools.client.Native.Platform.OS != 'web': return console.log('Im out')
if tools.configuration.long_name or tools.configuration.app_name: document.querySelector('title').innerHTML = tools.configuration.long_name or tools.configuration.app_name
if tools.configuration.custom_navbar:
style = document.createElement('style')
style.innerHTML = '.navbar, .toolbar, .statusbar {background-color: ' + tools.configuration.custom_navbar + '!important}'
document.querySelector('head').append(style)
if document.querySelector('div.navbar'):
color_element = document.createElement('meta')
color_element.name = 'theme-color';
color_element.content = '#' + getComputedStyle(document.querySelector('.navbar'), None).backgroundColor.replace('rgb(', '').replace(')', '').split(', ').map(
def (color):
return parseInt(color).toString(16)
).map(
def (hex):
return ('0' + hex) if hex.length == 1 else hex
).join('')
document.querySelector('head').appendChild(color_element)
#tools.client.api.globals.registerManifest()
except Exception as error:
raise error
@async
def check_session():
session = None
try:
session = await [window.session_db.get('session')]
except Exception as error:
console.log(error)
await [window.session_db.changes({'since': 0, 'limit': 1})]
session = await [window.session_db.get('session')]
models.env.user = models.env['res.users'].browse()
models.env.user.id = session.id
models.env.user.login = session.login
models.env.user.password = session.password
url = ''
if tools.client.Native.Platform.OS == 'web':
href = window.location.origin + window.location.pathname
url = href.substring(0, href.lastIndexOf('/')) + '/'
storage_url = await [tools.client.Native.AsyncStorage.getItem('rapyd_server_url')]
console.log(storage_url)
if storage_url: url = storage_url
tools.configuration.url = url
return init_client()
def start_client():
check_session().catch(console.error)
tools.init_client = start_client
try:
export_object.models = models
export_object.tools = tools
export_object.local_db = db
window.tools = tools
window.models = models
except Exception as error:
console.error(error)
window.models = models
window.tools = tools
window.local_db = db