Commit 9197edb1 authored by Qianwen's avatar Qianwen
Browse files

add delete, adjust layout

parent e3098b4b
Pipeline #497016 passed with stages
in 3 minutes and 26 seconds
......@@ -63,13 +63,20 @@ func main() {
}
func display(msg schemas.MQTTMessage) (err error) {
time.Sleep(10 * time.Second)
time.Sleep(5 * time.Second)
fmt.Println(string(msg.Content))
return
}
func handleDefault(msg schemas.ACLMessage) (err error) {
fmt.Println(string(msg.Content))
time.Sleep(5 * time.Second)
return
}
func handlePeroid() (err error) {
fmt.Println(time.Now())
time.Sleep(5 * time.Second)
return
}
......@@ -98,6 +105,26 @@ func task(ag *agency.Agent) (err error) {
}
}
handlePerformative := map[int]func(schemas.ACLMessage) error{
0: handleDefault,
}
if id == 2 {
behPro, err := ag.NewMessageBehavior(0, handlePerformative, handleDefault)
if err == nil {
behPro.Start()
}
}
if id == 3 {
behPeroid, err := ag.NewPeriodicBehavior(10*time.Second, handlePeroid)
if err == nil {
behPeroid.Start()
}
time.Sleep(50 * time.Second)
behPeroid.Stop()
}
// sends 20 messages randomly to other agents
for i := 0; i < 20; i++ {
interval := rand.Intn(5)
......@@ -129,3 +156,51 @@ func task(ag *agency.Agent) (err error) {
return
}
func task_test(ag *agency.Agent) (err error) {
time.Sleep(10 * time.Second)
id := ag.GetAgentID()
// agent 0 subsribes the topic1
if id == 0 {
ag.MQTT.Subscribe("topic1", 1)
behMQTT, err := ag.NewMQTTTopicBehavior("topic1", display)
if err == nil {
behMQTT.Start()
}
}
// agent 1 publishes the topic1
if id == 1 {
for i := 0; i < 20; i++ {
time.Sleep(5 * time.Second)
msg := "test message" + strconv.Itoa(i)
MQTTMsg, err := ag.MQTT.NewMessage("topic1", []byte(msg))
if err == nil {
ag.MQTT.SendMessage(MQTTMsg, 1)
}
}
}
handlePerformative := map[int]func(schemas.ACLMessage) error{
0: handleDefault,
}
if id == 2 {
behPro, err := ag.NewMessageBehavior(0, handlePerformative, handleDefault)
if err == nil {
behPro.Start()
}
}
if id == 3 {
behPeroid, err := ag.NewPeriodicBehavior(10*time.Second, handlePeroid)
if err == nil {
behPeroid.Start()
}
time.Sleep(50 * time.Second)
behPeroid.Stop()
}
return
}
......@@ -118,11 +118,15 @@ func (protBehavior *aclProtocolBehavior) task() {
handle(msg)
end := time.Now()
protBehavior.ag.Logger.NewBehStats(start, end, "protocol")
protBehavior.ag.Logger.NewLog("beh", "Protocol behavior task", "start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String())
} else {
start := time.Now()
protBehavior.handleDefault(msg)
end := time.Now()
protBehavior.ag.Logger.NewBehStats(start, end, "protocol")
protBehavior.ag.Logger.NewLog("beh", "Protocol behavior task", "start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String())
}
case command := <-protBehavior.ctrl:
switch command {
......@@ -200,8 +204,8 @@ func (mqttBehavior *mqttTopicBehavior) task() {
mqttBehavior.handle(msg)
end := time.Now()
mqttBehavior.ag.Logger.NewBehStats(start, end, "mqtt")
mqttBehavior.ag.Logger.NewLog("beh", msg.String()+";start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String(), "")
mqttBehavior.ag.Logger.NewLog("beh", "mqtt topic behavior task", "start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String()+";"+msg.String())
case command := <-mqttBehavior.ctrl:
switch command {
case -1:
......@@ -283,7 +287,8 @@ func (periodBehavior *periodicBehavior) task() {
periodBehavior.handle()
end := time.Now()
periodBehavior.ag.Logger.NewBehStats(start, end, "period")
periodBehavior.ag.Logger.NewLog("beh", "peroidic behavior task", "start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String())
}
}
}
......@@ -350,6 +355,8 @@ func (custUpBehavior *customUpdateBehavior) task() {
custUpBehavior.handle(custom)
end := time.Now()
custUpBehavior.ag.Logger.NewBehStats(start, end, "custom")
custUpBehavior.ag.Logger.NewLog("beh", "custom behavior task", "start: "+start.String()+
";end: "+end.String()+";duration:"+end.Sub(start).String())
case command := <-custUpBehavior.ctrl:
switch command {
case -1:
......
<div class="maincontainer">
<div class="sidebar">
<div class="nav">
<div class="nav-item" *ngFor="let id of MASID" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<div class="nav-item" *ngFor="let id of MASID, index as i" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<a class="list-text" [routerLink]="['/ams', id]" >
<p > MAS {{ id }}</p>
<p > MAS {{ i }}</p>
</a>
</div>
</div>
......
......@@ -22,9 +22,13 @@ export class AMSComponent implements OnInit {
// get the information for the sidebar
this.masService.getMAS().subscribe((MASs: any) => {
this.MASID = []
if (MASs !== null) {
this.MASID = MASs.map( MAS => MAS.id);
console.log(this.MASID);
for (let MAS of MASs) {
if (MAS.status.code != 5) {
this.MASID.push(MAS.id)
}
}
}
});
......
......@@ -131,7 +131,7 @@
/* style of the nav tab */
.nav {
.contentcontainer .nav {
margin-left: 30px;
}
......
......@@ -2,9 +2,9 @@
<!--sidebar-->
<div class="sidebar" *ngIf="MASID.length !== 0">
<div class="nav">
<div class="nav-item" *ngFor="let id of MASID" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<div class="nav-item" *ngFor="let id of MASID, index as i" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<a class="list-text" [routerLink]="['/df', id]" >
<p > MAS {{ id }}</p>
<p > MAS {{ i }}</p>
</a>
</div>
</div>
......
......@@ -39,7 +39,13 @@ export class DFComponent implements OnInit {
// update the sidebar
this.masService.getMAS().subscribe((MASs: any) => {
this.MASID = MASs.map(MAS => MAS.id);
if (MASs !== null) {
for (let MAS of MASs) {
if (MAS.status.code != 5) {
this.MASID.push(MAS.id)
}
}
}
}, err => {
console.log(err)
});
......
......@@ -224,7 +224,7 @@
/* style of the nav tab */
.nav {
.contentcontainer .nav {
margin-left: 30px;
}
......
......@@ -2,9 +2,9 @@
<!--sidebar-->
<div class="sidebar" >
<div class="nav">
<div class="nav-item" *ngFor="let id of MASID" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<div class="nav-item" *ngFor="let id of MASID, index as i" routerLinkActive="is-active" [ngClass]="id === selectedMASID ? 'active' : ''">
<a class="list-text" [routerLink]="['/logger', id]" >
<p > MAS {{ id }}</p>
<p > MAS {{ i }}</p>
</a>
</div>
</div>
......
......@@ -124,7 +124,11 @@ export class LoggerComponent implements OnInit {
// update the sidebar
this.masService.getMAS().subscribe((MASs: any) => {
if (MASs !== null) {
this.MASID = MASs.map(MAS => MAS.id);
for (let MAS of MASs) {
if (MAS.status.code != 5) {
this.MASID.push(MAS.id)
}
}
}
}, err => {
console.log(err);
......@@ -399,6 +403,8 @@ export class LoggerComponent implements OnInit {
this.drawTimeline();
}
onChangePopoverContent(i) {
if ("data" in this.logs[i]) {
if (this.logs[i].msg === "ACL send" || this.logs[i].msg === "ACL receive") {
......@@ -406,7 +412,12 @@ export class LoggerComponent implements OnInit {
this.popoverContent[2] = this.popoverContent[2].split(".")[0];
console.log(this.logs[i].data.split("; "))
} else {
this.popoverContent = [this.logs[i].timestamp.toString().split(".")[0], this.logs[i].msg, ...this.logs[i].data.split(";")]
this.popoverContent = [this.logs[i].timestamp.toString().split(".")[0], this.logs[i].msg]
let data: string[] = this.logs[i].data.split(";");
data[0] = data[0].split(".")[0];
data[1] = data[1].split(".")[0];
this.popoverContent = [...this.popoverContent, ...data]
}
} else {
this.popoverContent = [this.logs[i].timestamp.toString().split(".")[0], ...this.logs[i].msg.split(";")];
......@@ -549,8 +560,9 @@ export class LoggerComponent implements OnInit {
const methods: string[] = ["max", "min", "count", "average"];
this.loggerService.getBehavior(this.selectedMASID.toString(), this.agentStats.toString(),
this.selectedBehType, this.searchStartTime, this.searchEndTime).subscribe( (res: any) => {
if (res !== null) {
this.statsInfo = res;
this.statsInfo = res;
if (this.statsInfo.list === null) {
this.statsInfo.list = [];
}
})
}
......
......@@ -2,9 +2,9 @@
<!--sidebar-->
<div class="sidebar">
<div class="nav">
<div class="nav-item" *ngFor="let id of MASID" routerLinkActive="is-active">
<div class="nav-item" *ngFor="let id of MASID, index as i" routerLinkActive="is-active">
<a class="list-text" [routerLink]="['/ams', id]" >
<p >MAS {{ id }}</p>
<p >MAS {{ i }}</p>
</a>
</div>
</div>
......@@ -39,57 +39,57 @@
</ng-template>
<div class="contentcontainer" >
<div *ngIf="MASID.length !== 0">
<div class="title">
<div class="title-name" >Overview</div>
<button type='button' class='btn my-btn btn-create' (click)="openLg(content)">+ New MAS</button>
</div>
<!--display the overview of agencies with tables-->
<div id="tables">
<div class="row">
<div class="col-md-4 my-row" *ngFor="let MAS of MASsDisplay | paginate: { itemsPerPage: 6, currentPage: q };">
<div class="card" (click)="onOpenMAS(MAS.id)">
<div class="card-header d-flex justify-content-between">
<h3>MAS {{MAS.id}}</h3>
<button class="btn btn-delete" (click)="onDeleteMAS(MAS.id)">
<div class="icon">
<i class="fas fa-trash"></i>
</div>
</button>
</div>
<div *ngIf="MASID.length !== 0">
<div class="title">
<div class="title-name" >Overview</div>
<button type='button' class='btn my-btn btn-create' (click)="openLg(content)">+ New MAS</button>
</div>
<!--display the overview of agencies with tables-->
<div id="tables">
<div class="row">
<div class="col-md-4 my-row" *ngFor="let MAS of MASsDisplay | paginate: { itemsPerPage: 6, currentPage: q }; index as i">
<div class="card" (click)="onOpenMAS(MAS.id)">
<div class="card-header d-flex justify-content-between">
<h3>MAS {{i}}</h3>
<button class="btn btn-delete" (click)="onDeleteMAS(MAS.id)">
<div class="icon">
<i class="fas fa-trash"></i>
</div>
</button>
</div>
<div class="card-body">
<table class="table table-striped">
<tbody>
<tr>
<th>Name</th>
<td>{{ MAS.config.name }}</td>
</tr>
<tr>
<th>Number of agents per agency </th>
<td>{{ MAS.config.agentsperagency }} </td>
</tr>
<tr>
<th> Status of df</th>
<td>{{ MAS.config.df.active }} </td>
</tr>
<tr>
<th> Status of logger </th>
<td>{{ MAS.config.logger.active }} </td>
</tr>
<tr>
<th> Status of MQTT</th>
<td> {{ MAS.config.mqtt.active }} </td>
</tr>
</tbody>
</table>
</div>
<div class="card-body">
<table class="table table-striped">
<tbody>
<tr>
<th>Name</th>
<td>{{ MAS.config.name }}</td>
</tr>
<tr>
<th>Number of agents per agency </th>
<td>{{ MAS.config.agentsperagency }} </td>
</tr>
<tr>
<th> Status of df</th>
<td>{{ MAS.config.df.active }} </td>
</tr>
<tr>
<th> Status of logger </th>
<td>{{ MAS.config.logger.active }} </td>
</tr>
<tr>
<th> Status of MQTT</th>
<td> {{ MAS.config.mqtt.active }} </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<pagination-controls class="pagination" (pageChange)="q = $event"></pagination-controls>
</div>
</div>
</div>
<pagination-controls class="pagination" (pageChange)="q = $event"></pagination-controls>
</div>
<div class="overview-empty" *ngIf="MASID.length === 0">
<div class="status">{{status}}</div>
......
......@@ -68,19 +68,24 @@ export class OverviewComponent implements OnInit {
updateMAS() {
this.masService.getMAS().subscribe((MASs: any) => {
this.MASsDisplay = [];
if (MASs !== null) {
this.MASID = MASs.map(MAS => MAS.id);
this.MASsDisplay = MASs;
for (let MAS of MASs) {
if (MAS.status.code != 5) {
this.MASsDisplay.push(MAS)
}
console.log(MAS);
}
this.MASID = this.MASsDisplay.map(MAS => MAS.id);
if (this.MASsDisplay.length === 0) {
this.status = "Currently no MASs, create one......";
}
} else {
this.status = "Currently no MASs, create one......";
this.MASsDisplay = [];
console.log(this.MASID);
}
},
err => {
this.status = "The CloneMAP platform is not connected"
}
);
}, err => {
this.status = "The CloneMAP platform is not connected";
});
}
onDeleteMAS(id: string) {
......
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