mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-26 07:44:56 +01:00
Add pretty format to last moditication time.
This commit is contained in:
parent
748ecf7608
commit
736d88d000
@ -12,8 +12,10 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
@XmlRootElement(name = "map")
|
@XmlRootElement(name = "map")
|
||||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||||
@ -28,6 +30,13 @@ public class RestMindmap {
|
|||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private MindMap mindmap;
|
private MindMap mindmap;
|
||||||
|
@JsonIgnore
|
||||||
|
static private SimpleDateFormat sdf;
|
||||||
|
|
||||||
|
static {
|
||||||
|
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
public RestMindmap() {
|
public RestMindmap() {
|
||||||
this(new MindMap());
|
this(new MindMap());
|
||||||
@ -38,9 +47,15 @@ public class RestMindmap {
|
|||||||
this.mindmap = mindmap;
|
this.mindmap = mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Calendar getCreationTime() {
|
public String getCreationTime() {
|
||||||
return mindmap.getCreationTime();
|
final Calendar creationTime = mindmap.getCreationTime();
|
||||||
|
String result = null;
|
||||||
|
if (creationTime != null) {
|
||||||
|
result = this.toISO8601(creationTime.getTime());
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return mindmap.getDescription();
|
return mindmap.getDescription();
|
||||||
@ -66,8 +81,9 @@ public class RestMindmap {
|
|||||||
return mindmap.getLastModifierUser();
|
return mindmap.getLastModifierUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastModificationDate() {
|
public String getLastModificationTime() {
|
||||||
return mindmap.getLastModificationDate();
|
final Calendar date = mindmap.getLastModificationTime();
|
||||||
|
return toISO8601(date.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublic() {
|
public boolean isPublic() {
|
||||||
@ -117,7 +133,7 @@ public class RestMindmap {
|
|||||||
mindmap.setProperties(properties);
|
mindmap.setProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModificationTime(Calendar lastModificationTime) {
|
public void setLastModificationTime(final String value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModifierUser(String lastModifierUser) {
|
public void setLastModifierUser(String lastModifierUser) {
|
||||||
@ -131,4 +147,12 @@ public class RestMindmap {
|
|||||||
public MindMap getDelegated() {
|
public MindMap getDelegated() {
|
||||||
return this.mindmap;
|
return this.mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String toISO8601(@Nullable Date date) {
|
||||||
|
String result = "";
|
||||||
|
if (date != null) {
|
||||||
|
result = sdf.format(date) + "Z";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,10 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
@XmlRootElement(name = "map")
|
@XmlRootElement(name = "map")
|
||||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||||
@ -27,6 +29,13 @@ public class RestMindmapInfo {
|
|||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private MindMap mindmap;
|
private MindMap mindmap;
|
||||||
|
@JsonIgnore
|
||||||
|
static private SimpleDateFormat sdf;
|
||||||
|
|
||||||
|
static {
|
||||||
|
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
public RestMindmapInfo() {
|
public RestMindmapInfo() {
|
||||||
this(new MindMap());
|
this(new MindMap());
|
||||||
@ -37,8 +46,8 @@ public class RestMindmapInfo {
|
|||||||
this.mindmap = mindmap;
|
this.mindmap = mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Calendar getCreationTime() {
|
public String getCreationTime() {
|
||||||
return mindmap.getCreationTime();
|
return this.toISO8601(mindmap.getCreationTime().getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
@ -65,8 +74,9 @@ public class RestMindmapInfo {
|
|||||||
return mindmap.getLastModifierUser();
|
return mindmap.getLastModifierUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getLastModificationDate() {
|
public String getLastModificationTime() {
|
||||||
return mindmap.getLastModificationDate();
|
final Calendar calendar = mindmap.getLastModificationTime();
|
||||||
|
return this.toISO8601(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPublic() {
|
public boolean isPublic() {
|
||||||
@ -93,14 +103,18 @@ public class RestMindmapInfo {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModificationTime(Calendar lastModificationTime) {
|
public void setLastModificationTime(String value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastModifierUser(String lastModifierUser) {
|
public void setLastModifierUser(String value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public MindMap getDelegated(){
|
public MindMap getDelegated() {
|
||||||
return this.mindmap;
|
return this.mindmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String toISO8601(@NotNull Date date) {
|
||||||
|
return sdf.format(date) + "Z";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
148
wise-webapp/src/main/webapp/js/jquery.timeago.js
Normal file
148
wise-webapp/src/main/webapp/js/jquery.timeago.js
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/**
|
||||||
|
* Timeago is a jQuery plugin that makes it easy to support automatically
|
||||||
|
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
||||||
|
*
|
||||||
|
* @name timeago
|
||||||
|
* @version 0.11.1
|
||||||
|
* @requires jQuery v1.2.3+
|
||||||
|
* @author Ryan McGeary
|
||||||
|
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||||
|
*
|
||||||
|
* For usage and examples, visit:
|
||||||
|
* http://timeago.yarp.com/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008-2011, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
|
||||||
|
*/
|
||||||
|
(function($) {
|
||||||
|
$.timeago = function(timestamp) {
|
||||||
|
if (timestamp instanceof Date) {
|
||||||
|
return inWords(timestamp);
|
||||||
|
} else if (typeof timestamp === "string") {
|
||||||
|
return inWords($.timeago.parse(timestamp));
|
||||||
|
} else {
|
||||||
|
return inWords($.timeago.datetime(timestamp));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var $t = $.timeago;
|
||||||
|
|
||||||
|
$.extend($.timeago, {
|
||||||
|
settings: {
|
||||||
|
refreshMillis: 60000,
|
||||||
|
allowFuture: false,
|
||||||
|
strings: {
|
||||||
|
prefixAgo: null,
|
||||||
|
prefixFromNow: null,
|
||||||
|
suffixAgo: "ago",
|
||||||
|
suffixFromNow: "from now",
|
||||||
|
seconds: "less than a minute",
|
||||||
|
minute: "about a minute",
|
||||||
|
minutes: "%d minutes",
|
||||||
|
hour: "about an hour",
|
||||||
|
hours: "about %d hours",
|
||||||
|
day: "a day",
|
||||||
|
days: "%d days",
|
||||||
|
month: "about a month",
|
||||||
|
months: "%d months",
|
||||||
|
year: "about a year",
|
||||||
|
years: "%d years",
|
||||||
|
wordSeparator: " ",
|
||||||
|
numbers: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
inWords: function(distanceMillis) {
|
||||||
|
var $l = this.settings.strings;
|
||||||
|
var prefix = $l.prefixAgo;
|
||||||
|
var suffix = $l.suffixAgo;
|
||||||
|
if (this.settings.allowFuture) {
|
||||||
|
if (distanceMillis < 0) {
|
||||||
|
prefix = $l.prefixFromNow;
|
||||||
|
suffix = $l.suffixFromNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var seconds = Math.abs(distanceMillis) / 1000;
|
||||||
|
var minutes = seconds / 60;
|
||||||
|
var hours = minutes / 60;
|
||||||
|
var days = hours / 24;
|
||||||
|
var years = days / 365;
|
||||||
|
|
||||||
|
function substitute(stringOrFunction, number) {
|
||||||
|
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
|
||||||
|
var value = ($l.numbers && $l.numbers[number]) || number;
|
||||||
|
return string.replace(/%d/i, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
|
||||||
|
seconds < 90 && substitute($l.minute, 1) ||
|
||||||
|
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
|
||||||
|
minutes < 90 && substitute($l.hour, 1) ||
|
||||||
|
hours < 24 && substitute($l.hours, Math.round(hours)) ||
|
||||||
|
hours < 42 && substitute($l.day, 1) ||
|
||||||
|
days < 30 && substitute($l.days, Math.round(days)) ||
|
||||||
|
days < 45 && substitute($l.month, 1) ||
|
||||||
|
days < 365 && substitute($l.months, Math.round(days / 30)) ||
|
||||||
|
years < 1.5 && substitute($l.year, 1) ||
|
||||||
|
substitute($l.years, Math.round(years));
|
||||||
|
|
||||||
|
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator;
|
||||||
|
return $.trim([prefix, words, suffix].join(separator));
|
||||||
|
},
|
||||||
|
parse: function(iso8601) {
|
||||||
|
var s = $.trim(iso8601);
|
||||||
|
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
|
||||||
|
s = s.replace(/-/,"/").replace(/-/,"/");
|
||||||
|
s = s.replace(/T/," ").replace(/Z/," UTC");
|
||||||
|
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
||||||
|
return new Date(s);
|
||||||
|
},
|
||||||
|
datetime: function(elem) {
|
||||||
|
// jQuery's `is()` doesn't play well with HTML5 in IE
|
||||||
|
var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
|
||||||
|
var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
|
||||||
|
return $t.parse(iso8601);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$.fn.timeago = function() {
|
||||||
|
var self = this;
|
||||||
|
self.each(refresh);
|
||||||
|
|
||||||
|
var $s = $t.settings;
|
||||||
|
if ($s.refreshMillis > 0) {
|
||||||
|
setInterval(function() { self.each(refresh); }, $s.refreshMillis);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
};
|
||||||
|
|
||||||
|
function refresh() {
|
||||||
|
var data = prepareData(this);
|
||||||
|
if (!isNaN(data.datetime)) {
|
||||||
|
$(this).text(inWords(data.datetime));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareData(element) {
|
||||||
|
element = $(element);
|
||||||
|
if (!element.data("timeago")) {
|
||||||
|
element.data("timeago", { datetime: $t.datetime(element) });
|
||||||
|
var text = $.trim(element.text());
|
||||||
|
if (text.length > 0) {
|
||||||
|
element.attr("title", text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return element.data("timeago");
|
||||||
|
}
|
||||||
|
|
||||||
|
function inWords(date) {
|
||||||
|
return $t.inWords(distance(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
function distance(date) {
|
||||||
|
return (new Date().getTime() - date.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix for IE6 suckage
|
||||||
|
document.createElement("abbr");
|
||||||
|
document.createElement("time");
|
||||||
|
}(jQuery));
|
@ -19,6 +19,8 @@
|
|||||||
<link href="css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet">
|
<link href="css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet">
|
||||||
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
|
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
|
||||||
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.plugins.js"></script>
|
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.plugins.js"></script>
|
||||||
|
<script type="text/javascript" language="javascript" src="js/jquery.timeago.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
@ -60,9 +62,10 @@
|
|||||||
sTitle : "Last Modified",
|
sTitle : "Last Modified",
|
||||||
bUseRendered: false,
|
bUseRendered: false,
|
||||||
sType: "numeric",
|
sType: "numeric",
|
||||||
mDataProp: "lastModificationDate",
|
mDataProp: "lastModificationTime",
|
||||||
fnRender : function(obj) {
|
fnRender : function(obj) {
|
||||||
return obj.aData.lastModificationDate + ", " + obj.aData.lastModifierUser;
|
var time = obj.aData.lastModificationTime;
|
||||||
|
return '<abbr class="timeago" title="' + time + '">' + jQuery.timeago(time) + '</abbr>' + ' ' + '<span style="color: #777;font-size: 75%;padding-left: 5px;">' + obj.aData.lastModifierUser + '</span>';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -267,8 +270,12 @@
|
|||||||
$("#buttons .moreActions").button({
|
$("#buttons .moreActions").button({
|
||||||
icons: { primary: "ui-icon-triangle-1-s" }
|
icons: { primary: "ui-icon-triangle-1-s" }
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Register time update functions ....
|
||||||
|
setTimeout(function() {
|
||||||
|
jQuery("abbr.timeago").timeago()
|
||||||
|
}, 30000);
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
Loading…
Reference in New Issue
Block a user