Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
01e21767
Commit
01e21767
authored
Jan 29, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store version updater
parent
8367742b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
21 deletions
+47
-21
index.js
index.js
+8
-0
Ajax.jsx
src/controller/Ajax.jsx
+7
-2
Ajax.jsx
src/core/Ajax.jsx
+3
-4
index.html
src/index.html
+1
-1
Store.js
src/model/Store.js
+20
-2
TestRequests.jsx
src/view/page/tmp/TestRequests.jsx
+8
-12
No files found.
index.js
View file @
01e21767
...
...
@@ -20,6 +20,12 @@ const fs = require( 'fs' );
var
cache
=
{};
const
{
execSync
}
=
require
(
'child_process'
);
let
commit
;
const
updateCommitInfo
=
function
()
{
commit
=
execSync
(
'git rev-parse HEAD'
).
toString
().
trim
();
};
updateCommitInfo
();
const
serveBundle
=
async
function
(
tpl
,
res
){
var
fileName
=
dir
(
pack
.
src
,
pack
.
entry
.
js
);
...
...
@@ -30,10 +36,12 @@ const serveBundle = async function(tpl, res){
return
res
.
end
(
err
.
message
);
}
const
cacheEntry
=
posixName
;
//+new Date()+'_'+Math.random().toString(36).substr(2)
updateCommitInfo
();
res
.
end
(
tpl
//.replace('$DATA$', JSON.stringify(data))
.
replace
(
'$BUNDLE$'
,
'<script src="'
+
cacheEntry
+
'"></script>'
)
.
replace
(
'$COMMIT$'
,
'<script>var CommitID = "'
+
commit
+
'";</script>'
)
);
transformJSX
(
jsx
+
''
,
pack
.
entry
.
js
,
function
(
err
,
result
)
{
...
...
src/controller/Ajax.jsx
View file @
01e21767
...
...
@@ -7,7 +7,9 @@ export const AsyncAuthAjax = {
return
false
;
return
await
AsyncAjax
.
get
(
url
,
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
headers
:
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
}
})
},
async
post
(
url
,
data
)
{
...
...
@@ -15,7 +17,9 @@ export const AsyncAuthAjax = {
return
false
;
return
await
AsyncAjax
.
post
(
url
,
data
,
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
headers
:
{
authorization
:
'Bearer '
+
store
.
get
(
'account.token'
)
}
})
}
};
\ No newline at end of file
src/core/Ajax.jsx
View file @
01e21767
...
...
@@ -48,9 +48,10 @@ export const Ajax = {
let
stringData
=
''
;
try
{
stringData
=
JSON
.
stringify
(
data
);
const
xhr
=
new
XMLHttpRequest
();
cfg
=
transformCfg
(
cfg
||
{});
cfg
.
url
=
url
;
const
xhr
=
new
XMLHttpRequest
();
xhrProceed
(
"POST"
,
xhr
,
cfg
,
cb
);
xhr
.
send
(
stringData
);
}
catch
(
e
)
{
...
...
@@ -65,11 +66,9 @@ export const Ajax = {
get
(
url
,
cb
,
cfg
){
try
{
const
xhr
=
new
XMLHttpRequest
();
cfg
=
transformCfg
(
cfg
||
{});
cfg
.
url
=
url
;
xhr
.
open
(
"GET"
,
url
,
true
);
xhrProceed
(
xhr
,
url
,
cb
);
const
xhr
=
new
XMLHttpRequest
();
xhrProceed
(
"GET"
,
xhr
,
cfg
,
cb
);
xhr
.
send
(
null
);
}
catch
(
e
)
{
...
...
src/index.html
View file @
01e21767
...
...
@@ -15,8 +15,8 @@
<script
src=
"core/data/store/Store.js"
></script>
$COMMIT$
<script
src=
"model/Store.js"
></script>
$BUNDLE$
</head>
<body>
...
...
src/model/Store.js
View file @
01e21767
const
store
=
new
Store
({
commit
:
window
.
CommitID
,
'navigation'
:
{
current
:
'login'
},
...
...
@@ -15,8 +16,25 @@ const store = new Store({
try
{
var
data
=
JSON
.
parse
(
localStorage
.
getItem
(
'store'
)
);
window
.
addEventListener
&&
console
.
log
(
data
)
for
(
var
k
in
data
){
store
.
set
(
k
,
data
[
k
]);
if
(
window
.
CommitID
!==
store
.
get
(
'commit'
)){
console
.
warn
(
'STORE: warn outdated:'
);
console
.
warn
(
'
\
t
\
tCurrent data: '
+
store
.
get
(
'commit'
),
store
.
_props
);
console
.
warn
(
'
\
t
\
tSaved data: '
+
window
.
CommitID
,
data
);
console
.
warn
(
'
\
tRun restoreStore() for restore saved state'
);
window
.
restoreStore
=
function
()
{
for
(
var
k
in
data
){
if
(
k
!==
'commit'
){
store
.
set
(
k
,
data
[
k
]
);
}
}
};
}
else
{
for
(
var
k
in
data
){
store
.
set
(
k
,
data
[
k
]
);
}
console
.
log
(
'STORE: loaded from localStorage'
);
}
}
catch
(
e
){}
store
.
on
(
'change'
,
function
()
{
...
...
src/view/page/tmp/TestRequests.jsx
View file @
01e21767
...
...
@@ -2,21 +2,17 @@ import Button from "/view/cmp/button/Button.jsx";
import
LabeledField
from
"../../cmp/field/LabeledField.jsx"
;
import
PhoneInput
from
"../../cmp/field/PhoneInput.jsx"
;
import
Input
from
"../../cmp/field/Input"
;
import
{
AsyncAuthAjax
}
from
"../../../controller/Ajax"
;
import
{
API
}
from
"../../../dict/Consts"
;
const
TestRequests
=
D
.
declare
(
'view.page.tmp.TestRequests'
,
()
=>
{
var
data
=
new
Store
({
phone
:
''
,
phone3
:
'7'
,
phone4
:
'8'
,
phone5
:
'79132251365'
,
phone2
:
'894'
,
});
let
response
;
return
<
div
>
<
div
>
<
h5
>
Labeled field
</
h5
>
<
LabeledField
label=
{
'Label'
}
/>
</
div
>
Курвалол
<
button
onclick=
{
async
()
=>
{
const
result
=
await
AsyncAuthAjax
.
get
(
API
.
ENDPOINTS
.
GET_USER
(
store
.
get
(
'account.userID'
)));
response
.
innerText
=
JSON
.
stringify
(
result
,
null
,
2
);
}
}
>
Get user
</
button
>
<
div
className=
'error-block'
>
{
response
=
<
div
></
div
>
}
</
div
>
</
div
>
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment