Commit 5a8f5e11 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

frontend appearance

parent 34c046da
Pipeline #303259 passed with stages
in 2 minutes and 43 seconds
......@@ -184,6 +184,14 @@ func GetAgentAddress(masID int, agentID int) (address schemas.Address, httpStatu
return
}
// DeleteAgent deletes an agent
func DeleteAgent(masID int, agentID int) (httpStatus int, err error) {
httpStatus, err = httpretry.Delete(httpClient, "http://"+Host+":"+strconv.Itoa(Port)+
"/api/clonemap/mas/"+strconv.Itoa(masID)+"/agents/"+strconv.Itoa(agentID), nil,
time.Second*2, 2)
return
}
// GetAgencies requests agency information
func GetAgencies(masID int) (agencies schemas.Agencies, httpStatus int, err error) {
var body []byte
......
/*
Copyright 2020 Institute for Automation of Complex Power Systems,
E.ON Energy Research Center, RWTH Aachen University
This project is licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
Apache License, Version 2.0:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package frontend
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
// handleMAS is the handler for requests to path /api/ams/mas
func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
// return short info of all MAS
var mass []schemas.MASInfoShort
mass, _, cmapErr = amsclient.GetMASsShort()
if cmapErr == nil {
httpErr = httpreply.Resource(w, mass, cmapErr)
} else {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
}
} else if r.Method == "POST" {
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas")
}
return
}
// handlemasID is the handler for requests to path /api/ams/mas/{mas-id}
func (fe *Frontend) handlemasID(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "GET" {
// return long information about specified MAS
var masInfo schemas.MASInfo
masInfo, _, cmapErr = amsclient.GetMAS(masID)
httpErr = httpreply.Resource(w, masInfo, cmapErr)
} else if r.Method == "DELETE" {
// delete specified MAS
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas/{mas-id}")
}
return
}
// handleAgent is the handler for requests to path /api/clonemap/mas/{mas-id}/agents
func (fe *Frontend) handleAgent(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "POST" {
// create new agent in MAS
var body []byte
body, cmapErr = ioutil.ReadAll(r.Body)
if cmapErr == nil {
var groupSpecs []schemas.ImageGroupSpec
cmapErr = json.Unmarshal(body, &groupSpecs)
if cmapErr == nil {
_, cmapErr = amsclient.PostAgents(masID, groupSpecs)
httpErr = httpreply.Created(w, cmapErr, "text/plain", []byte("Ressource Created"))
} else {
httpErr = httpreply.JSONUnmarshalError(w)
}
} else {
httpErr = httpreply.InvalidBodyError(w)
}
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas/{mas-id}/agents")
}
return
}
// handleAgentID is the handler for requests to path /api/ams/mas/{mas-id}/agents/{agent-id}
func (fe *Frontend) handleAgentID(masID int, agentID int, w http.ResponseWriter,
r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
// return long information of specified agent
var agentInfo schemas.AgentInfo
agentInfo, _, cmapErr = amsclient.GetAgent(masID, agentID)
httpErr = httpreply.Resource(w, agentInfo, cmapErr)
} else if r.Method == "DELETE" {
// delete specified agent
_, cmapErr = amsclient.DeleteAgent(masID, agentID)
httpErr = httpreply.Deleted(w, cmapErr)
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas/{mas-id}/agents/" +
"{agent-id}")
}
return
}
......@@ -50,9 +50,7 @@ import (
"strconv"
"strings"
amsclient "git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/ams/client"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
)
// handleAPI is the global handler for requests to path /api
......@@ -104,50 +102,30 @@ func (fe *Frontend) handleAMS(w http.ResponseWriter, r *http.Request,
resvalid = true
cmapErr, httpErr = fe.handlemasID(masID, w, r)
}
default:
cmapErr = errors.New("Resource not found")
}
return
}
// handleMAS is the handler for requests to path /api/ams/mas
func (fe *Frontend) handleMAS(w http.ResponseWriter, r *http.Request) (cmapErr, httpErr error) {
if r.Method == "GET" {
// return short info of all MAS
var mass []schemas.MASInfoShort
mass, _, cmapErr = amsclient.GetMASsShort()
if cmapErr == nil {
httpErr = httpreply.Resource(w, mass, cmapErr)
} else {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
case 6:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
cmapErr, httpErr = fe.handleAgent(masID, w, r)
resvalid = true
}
}
} else if r.Method == "POST" {
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas")
}
return
}
// handlemasID is the handler for requests to path /api/ams/mas/{mas-id}
func (fe *Frontend) handlemasID(masID int, w http.ResponseWriter, r *http.Request) (cmapErr,
httpErr error) {
if r.Method == "GET" {
// return long information about specified MAS
var masInfo schemas.MASInfo
masInfo, _, cmapErr = amsclient.GetMAS(masID)
if cmapErr == nil {
httpErr = httpreply.Resource(w, masInfo, cmapErr)
} else {
httpErr = httpreply.CMAPError(w, cmapErr.Error())
case 7:
var masID int
masID, cmapErr = strconv.Atoi(respath[4])
if respath[2] == "clonemap" && respath[3] == "mas" && cmapErr == nil {
if respath[5] == "agents" {
var agentID int
agentID, cmapErr = strconv.Atoi(respath[6])
if cmapErr == nil {
cmapErr, httpErr = fe.handleAgentID(masID, agentID, w, r)
resvalid = true
}
}
}
} else if r.Method == "DELETE" {
// delete specified MAS
} else {
httpErr = httpreply.MethodNotAllowed(w)
cmapErr = errors.New("Error: Method not allowed on path /api/ams/mas/{mas-id}")
default:
cmapErr = errors.New("Resource not found")
}
return
}
......
......@@ -12,13 +12,13 @@ body {
height: 100%;
position: fixed;
overflow-y: scroll;
top: 0;
top: 1;
left: 0;
background: rgb(220,220,220);
background: rgb(230,230,230);
}
.sidebar p {
padding: 1em 0em 0em 1em;
padding: 2em 0em 0em 1em;
}
.sidebar ul {
......@@ -33,11 +33,15 @@ body {
text-decoration: none;
display: block;
padding: 1em 0em 1em 1em;
background: rgb(210,210,210);
background: rgb(222,222,222);
}
.sidebarcur {
background: rgb(215,215,215);
}
.sidebar ul li a:hover {
background-color: rgb(170,170,170);
background-color: rgb(200,200,200);
}
.contentcontainer {
......@@ -50,8 +54,10 @@ body {
/* display: block; */
position: fixed;
top: 0;
width: calc(100% - 5cm);
background-color: rgb(255,255,255);
left: 0;
width: 100%;
background-color: rgb(75,0,130);
color: rgb(255,255,255);
}
.contentmenu {
......@@ -63,6 +69,7 @@ body {
.modules {
display: none;
color: rgb(255,255,255);
}
.contenttitle {
......@@ -85,4 +92,18 @@ body {
hr {
margin: 0em 1em;
}
table {
width: 100%;
}
th, td {
text-align: left;
padding: 0em 2em;
font-weight: normal;
}
.tablehead {
padding: 1em 5em;
}
\ No newline at end of file
......@@ -32,7 +32,6 @@
<a href="#" class="modules">Logger</a>
<a href="#" class="modules">DF</a>
</div>
<hr>
</div>
<h2 class="contenttitle">Titel</h2>
<div class="content" id="textblock">
......
......@@ -24,8 +24,8 @@ function sideplatform(){
function sidemas(){
$(".modules").show();
$("#headertitle").text(this.id);
masID = this.id.split("sidemas")
$("#headertitle").text("MAS"+masID[1]);
contentAMS(parseInt(masID[1]))
}
......@@ -68,24 +68,29 @@ function clearContent() {
function contentMasInfo(masInfo) {
clearContent();
$(".content").append("<table id=\"masinfotable\"></table>");
$("#masinfotable").append("<tr><th>ID:</th><th>"+masInfo.id.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th>Config</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Name:</th><th>"+masInfo.config.name+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Agents per agency:</th><th>"+masInfo.config.agentsperagency.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>DF:</th><th>"+masInfo.config.df.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>Logging:</th><th>"+masInfo.config.logging.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th>MQTT:</th><th>"+masInfo.config.mqtt.toString()+"</th></tr>");
$("#masinfotable").append("<tr><th>Containers</th></tr>");
$(".content").append("<table id=\"masinfoid\"></table>");
$("#masinfoid").append("<tr><th>ID:</th><th>"+masInfo.id.toString()+"</th></tr>");
$(".content").append("<hr>");
$(".content").append("<table id=\"masinfoconfig\"></table>");
$("#masinfoconfig").append("<tr><th>Config</th></tr>");
$("#masinfoconfig").append("<tr><th></th><th>Name:</th><th>"+masInfo.config.name+"</th></tr>");
$("#masinfoconfig").append("<tr><th></th><th>Agents per agency:</th><th>"+masInfo.config.agentsperagency.toString()+"</th></tr>");
$("#masinfoconfig").append("<tr><th></th><th>DF:</th><th>"+masInfo.config.df.toString()+"</th></tr>");
$("#masinfoconfig").append("<tr><th></th><th>Logging:</th><th>"+masInfo.config.logging.toString()+"</th></tr>");
$("#masinfoconfig").append("<tr><th></th><th>MQTT:</th><th>"+masInfo.config.mqtt.toString()+"</th></tr>");
$(".content").append("<hr>");
$(".content").append("<table id=\"masinfocontainer\"></table>");
$("#masinfocontainer").append("<tr><th>Containers</th></tr>");
for (let i of masInfo.groups.instances) {
$("#masinfotable").append("<tr><th></th><th>"+i.id.toString()+":</th><th>"+i.config.image+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Agencies:</th><th>"+i.agencies.counter.toString()+"</th></tr>");
$("#masinfocontainer").append("<tr><th></th><th>"+i.id.toString()+":</th><th>"+i.config.image+"</th></tr>");
$("#masinfocontainer").append("<tr><th></th><th></th><th>Agencies:</th><th>"+i.agencies.counter.toString()+"</th></tr>");
}
$("#masinfotable").append("<tr><th>Agents</th></tr>");
$(".content").append("<hr>");
$(".content").append("<table id=\"masinfoagents\"></table>");
$("#masinfoagents").append("<tr><th>Agents</th></tr>");
for (let i of masInfo.agents.instances) {
$("#masinfotable").append("<tr><th></th><th>"+i.id.toString()+":</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Name:</th><th>"+i.spec.name+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Type:</th><th>"+i.spec.type+"</th></tr>");
$("#masinfotable").append("<tr><th></th><th></th><th>Address:</th><th>"+i.address.agency+"</th></tr>");
$("#masinfoagents").append("<tr><th></th><th>"+i.id.toString()+":</th><th>Name:</th><th>"+i.spec.name+"</th></tr>");
$("#masinfoagents").append("<tr><th></th><th></th><th>Type:</th><th>"+i.spec.type+"</th></tr>");
$("#masinfoagents").append("<tr><th></th><th></th><th>Address:</th><th>"+i.address.agency+"</th></tr>");
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment