Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Cloud
MAS
clonemap
Commits
4dd09045
Commit
4dd09045
authored
Oct 11, 2020
by
Stefan Dähling
Browse files
add upload mas to frontend
parent
fe86c211
Pipeline
#341478
passed with stages
in 59 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pkg/frontend/ams.go
View file @
4dd09045
...
@@ -113,7 +113,19 @@ func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr,
...
@@ -113,7 +113,19 @@ func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr
=
httpreply
.
CMAPError
(
w
,
cmapErr
.
Error
())
httpErr
=
httpreply
.
CMAPError
(
w
,
cmapErr
.
Error
())
}
}
}
else
if
r
.
Method
==
"POST"
{
}
else
if
r
.
Method
==
"POST"
{
var
body
[]
byte
body
,
cmapErr
=
ioutil
.
ReadAll
(
r
.
Body
)
if
cmapErr
==
nil
{
var
masSpec
schemas
.
MASSpec
cmapErr
=
json
.
Unmarshal
(
body
,
&
masSpec
)
if
cmapErr
==
nil
{
_
,
httpErr
=
amsclient
.
PostMAS
(
masSpec
)
}
else
{
httpErr
=
httpreply
.
JSONUnmarshalError
(
w
)
}
}
else
{
httpErr
=
httpreply
.
InvalidBodyError
(
w
)
}
}
else
{
}
else
{
httpErr
=
httpreply
.
MethodNotAllowed
(
w
)
httpErr
=
httpreply
.
MethodNotAllowed
(
w
)
cmapErr
=
errors
.
New
(
"Error: Method not allowed on path /api/ams/mas"
)
cmapErr
=
errors
.
New
(
"Error: Method not allowed on path /api/ams/mas"
)
...
...
pkg/frontend/handler.go
View file @
4dd09045
...
@@ -70,6 +70,9 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
...
@@ -70,6 +70,9 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
resvalid
,
cmapErr
,
httpErr
=
fe
.
handleDF
(
w
,
r
,
respath
)
resvalid
,
cmapErr
,
httpErr
=
fe
.
handleDF
(
w
,
r
,
respath
)
case
"logger"
:
case
"logger"
:
resvalid
,
cmapErr
,
httpErr
=
fe
.
handleLogging
(
w
,
r
,
respath
)
resvalid
,
cmapErr
,
httpErr
=
fe
.
handleLogging
(
w
,
r
,
respath
)
case
"overview"
:
resvalid
=
true
cmapErr
,
httpErr
=
fe
.
handleOverview
(
w
,
r
)
default
:
default
:
cmapErr
=
errors
.
New
(
"Resource not found"
)
cmapErr
=
errors
.
New
(
"Resource not found"
)
}
}
...
@@ -87,6 +90,17 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
...
@@ -87,6 +90,17 @@ func (fe *Frontend) handleAPI(w http.ResponseWriter, r *http.Request) {
}
}
}
}
// handleOverview is the handler for requests to path /api/overview
func
(
fe
*
Frontend
)
handleOverview
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
cmapErr
,
httpErr
error
)
{
if
r
.
Method
==
"GET"
{
cmapErr
,
httpErr
=
fe
.
handleMAS
(
w
,
r
)
}
else
{
httpErr
=
httpreply
.
MethodNotAllowed
(
w
)
cmapErr
=
errors
.
New
(
"Error: Method not allowed on path /api/overview"
)
}
return
}
// listen opens a http server listening and serving request
// listen opens a http server listening and serving request
func
(
fe
*
Frontend
)
listen
()
(
err
error
)
{
func
(
fe
*
Frontend
)
listen
()
(
err
error
)
{
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
...
...
web/css/main.css
View file @
4dd09045
...
@@ -87,6 +87,15 @@ body {
...
@@ -87,6 +87,15 @@ body {
margin
:
1em
0em
5em
0em
;
margin
:
1em
0em
5em
0em
;
}
}
.contentbox
{
margin
:
0em
0em
5em
0em
;
}
textarea
{
width
:
100%
;
height
:
20em
;
}
.footer
{
.footer
{
display
:
none
;
display
:
none
;
position
:
fixed
;
position
:
fixed
;
...
@@ -98,7 +107,7 @@ body {
...
@@ -98,7 +107,7 @@ body {
}
}
hr
{
hr
{
margin
:
0em
1em
;
margin
:
0em
1em
1em
1em
;
}
}
table
{
table
{
...
...
web/js/main.js
View file @
4dd09045
...
@@ -42,12 +42,21 @@ function updateSidebar(){
...
@@ -42,12 +42,21 @@ function updateSidebar(){
function
contentOverview
(
mass
)
{
function
contentOverview
(
mass
)
{
$
(
"
.contenttitle
"
).
replaceWith
(
"
<h2 class=
\"
contenttitle
\"
>Overview</h2>
"
);
$
(
"
.contenttitle
"
).
replaceWith
(
"
<h2 class=
\"
contenttitle
\"
>Overview</h2>
"
);
clearContent
();
clearContent
();
$
(
"
.content
"
).
append
(
"
<table id=
\"
mass
\"
></table>
"
);
$
(
"
.content
"
).
append
(
"
<div class=
\"
contentbox
\"
id=
\"
startbox
\"
></div>
"
)
$
(
"
#mass
"
).
append
(
"
<tr><th>MASs:</th><th>
"
+
mass
.
length
.
toString
()
+
"
</th></tr>
"
);
$
(
"
#startbox
"
).
append
(
"
<table id=
\"
startmas
\"
></table>
"
);
$
(
"
.content
"
).
append
(
"
<hr>
"
);
$
(
"
#startmas
"
).
append
(
"
<tr><th><h3>Start new MAS:</h3></th></tr>
"
)
$
(
"
#startbox
"
).
append
(
"
<hr>
"
);
$
(
"
#startbox
"
).
append
(
"
<tr><th><input type=
\"
file
\"
id=
\"
inputMAS
\"
value=
\"
Import
\"
accept=
\"
.json
\"
/></th><th><button id=
\"
uploadMAS
\"
>Upload</button></th></tr>
"
)
$
(
"
#inputMAS
"
).
change
(
inputMAS
);
$
(
"
#uploadMAS
"
).
click
(
uploadMAS
);
$
(
"
#startbox
"
).
append
(
"
<tr><th><textarea id=
\"
newMAS
\"
></textarea></th></tr>
"
)
$
(
"
.content
"
).
append
(
"
<div class=
\"
contentbox
\"
id=
\"
massbox
\"
></div>
"
)
$
(
"
#massbox
"
).
append
(
"
<table id=
\"
mass
\"
></table>
"
);
$
(
"
#mass
"
).
append
(
"
<tr><th><h3>MASs:</h3></th><th>
"
+
mass
.
length
.
toString
()
+
"
</th></tr>
"
);
$
(
"
#massbox
"
).
append
(
"
<hr>
"
);
for
(
let
i
of
mass
)
{
for
(
let
i
of
mass
)
{
let
masID
=
"
MAS
"
+
i
.
id
.
toString
()
let
masID
=
"
MAS
"
+
i
.
id
.
toString
()
$
(
"
.content
"
).
append
(
"
<table id=
\"
"
+
masID
+
"
\"
></table>
"
);
$
(
"
#massbox
"
).
append
(
"
<table id=
\"
"
+
masID
+
"
\"
></table>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th>
"
+
masID
+
"
</th></tr>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th>
"
+
masID
+
"
</th></tr>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th></th><th>Name:</th><th>
"
+
i
.
config
.
name
+
"
</th></tr>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th></th><th>Name:</th><th>
"
+
i
.
config
.
name
+
"
</th></tr>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th></th><th>Agents per agency:</th><th>
"
+
i
.
config
.
agentsperagency
.
toString
()
+
"
</th></tr>
"
);
$
(
"
#
"
+
masID
).
append
(
"
<tr><th></th><th>Agents per agency:</th><th>
"
+
i
.
config
.
agentsperagency
.
toString
()
+
"
</th></tr>
"
);
...
@@ -58,15 +67,32 @@ function contentOverview(mass) {
...
@@ -58,15 +67,32 @@ function contentOverview(mass) {
}
}
}
}
// callback for inputMAS input button
function
inputMAS
()
{
let
files
=
this
.
files
;
if
(
files
.
length
<=
0
)
{
return
false
;
}
let
fr
=
new
FileReader
();
fr
.
onload
=
function
(
e
)
{
var
result
=
JSON
.
parse
(
e
.
target
.
result
);
var
formatted
=
JSON
.
stringify
(
result
,
null
,
2
);
$
(
"
#newMAS
"
).
val
(
formatted
);
}
fr
.
readAsText
(
files
.
item
(
0
));
}
// callback for uploadMAS button
function
uploadMAS
()
{
let
masconfig
=
$
(
"
#newMAS
"
).
val
();
request
.
post
(
"
/api/ams/mas
"
,
masconfig
)
sideoverview
()
}
// request info about mas and call function to show content
// request info about mas and call function to show content
function
contentAMS
(
masID
){
function
contentAMS
(
masID
){
// fetch('/api/ams/mas/'+masID.toString())
// .then(response => response.json())
// .then(masInfo => {
// $(".contenttitle").replaceWith("<h2 class=\"contenttitle\">MAS"+masID.toString()+"</h2>");
// contentMasInfo(masInfo);
// console.log(masInfo);
// })
request
.
get
(
'
/api/ams/mas/
'
+
masID
.
toString
(),
showAMSContent
)
request
.
get
(
'
/api/ams/mas/
'
+
masID
.
toString
(),
showAMSContent
)
}
}
...
...
web/js/request.js
View file @
4dd09045
...
@@ -4,4 +4,19 @@ function get(url, callback) {
...
@@ -4,4 +4,19 @@ function get(url, callback) {
.
then
(
json
=>
{
callback
(
json
)})
.
then
(
json
=>
{
callback
(
json
)})
}
}
export
{
get
};
function
post
(
url
,
data
)
{
\ No newline at end of file
fetch
(
url
,
{
method
:
'
post
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
data
})
.
then
(
(
text
)
=>
{
// log response text
console
.
log
(
text
);
})
.
catch
((
error
)
=>
{
console
.
log
(
"
Error:
"
,
error
)
})
}
export
{
get
,
post
};
\ No newline at end of file
Write
Preview
Supports
Markdown
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