Split alert messages into title and msg, title should be unique

This commit is contained in:
Ziver Koc 2017-01-30 17:31:06 +01:00
parent df9b41a843
commit 9fa687081a
3 changed files with 22 additions and 8 deletions

View file

@ -5,7 +5,8 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-minus-sign" aria-hidden="true"></span>
<strong>{{.getMessage()}}</strong> <strong>{{.getTitle()}}</strong> &nbsp;
{{#.getMessage()}}{{.getMessage()}}{{/.getMessage()}}
</div> </div>
{{/.isError()}} {{/.isError()}}
{{#.isWarning()}} {{#.isWarning()}}
@ -14,7 +15,8 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>
<strong>{{.getMessage()}}</strong> <strong>{{.getTitle()}}</strong> &nbsp;
{{#.getMessage()}}{{.getMessage()}}{{/.getMessage()}}
</div> </div>
{{/.isWarning()}} {{/.isWarning()}}
{{#.isSuccess()}} {{#.isSuccess()}}
@ -23,7 +25,8 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<span class="glyphicon glyphicon-ok-circle" aria-hidden="true"></span> <span class="glyphicon glyphicon-ok-circle" aria-hidden="true"></span>
<strong>{{.getMessage()}}</strong> <strong>{{.getTitle()}}</strong> &nbsp;
{{#.getMessage()}}{{.getMessage()}}{{/.getMessage()}}
</div> </div>
{{/.isSuccess()}} {{/.isSuccess()}}
{{#.isInfo()}} {{#.isInfo()}}
@ -32,7 +35,8 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
<strong>{{.getMessage()}}</strong> <strong>{{.getTitle()}}</strong> &nbsp;
{{#.getMessage()}}{{.getMessage()}}{{/.getMessage()}}
</div> </div>
{{/.isInfo()}} {{/.isInfo()}}
{{/alerts}} {{/alerts}}

View file

@ -108,8 +108,9 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
maxRawTimestampInDB + (dataInterval * 3) < System.currentTimeMillis()) { maxRawTimestampInDB + (dataInterval * 3) < System.currentTimeMillis()) {
logger.fine("Sensor \"" + sensorId + "\" has stopped sending data"); logger.fine("Sensor \"" + sensorId + "\" has stopped sending data");
HalAlertManager.getInstance().addAlert(new HalAlert(AlertLevel.WARNING, HalAlertManager.getInstance().addAlert(new HalAlert(AlertLevel.WARNING,
"Sensor \"" + sensor.getName() + "\" has stopped responding " + "Sensor \"" + sensor.getName() + "\" has stopped responding",
"since <span class=\"timestamp\">"+maxRawTimestampInDB+"</span>", AlertTTL.DISMISSED)); "since <span class=\"timestamp\">"+maxRawTimestampInDB+"</span>",
AlertTTL.DISMISSED));
} }
} }

View file

@ -110,12 +110,18 @@ public class HalAlertManager implements HttpPage {
private int id; private int id;
private AlertLevel level; private AlertLevel level;
private String title;
private String msg; private String msg;
private int ttl; private int ttl;
public HalAlert(AlertLevel level, String msg, AlertTTL ttl) {
public HalAlert(AlertLevel level, String title, AlertTTL ttl) {
this(level, title, null, ttl);
}
public HalAlert(AlertLevel level, String title, String msg, AlertTTL ttl) {
this.id = nextId++; this.id = nextId++;
this.level = level; this.level = level;
this.title = title;
this.msg = msg; this.msg = msg;
setTTL(ttl); setTTL(ttl);
} }
@ -131,6 +137,9 @@ public class HalAlertManager implements HttpPage {
public boolean isWarning(){ return level == AlertLevel.WARNING; } public boolean isWarning(){ return level == AlertLevel.WARNING; }
public boolean isSuccess(){ return level == AlertLevel.SUCCESS; } public boolean isSuccess(){ return level == AlertLevel.SUCCESS; }
public boolean isInfo(){ return level == AlertLevel.INFO; } public boolean isInfo(){ return level == AlertLevel.INFO; }
public String getTitle() {
return title;
}
public String getMessage() { public String getMessage() {
return msg; return msg;
} }
@ -149,7 +158,7 @@ public class HalAlertManager implements HttpPage {
public boolean equals(Object obj){ public boolean equals(Object obj){
if (obj instanceof HalAlert) if (obj instanceof HalAlert)
return level == ((HalAlert) obj).level && return level == ((HalAlert) obj).level &&
msg.equals(((HalAlert) obj).msg); title.equals(((HalAlert) obj).title);
return false; return false;
} }
} }