summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-09-10 17:45:18 +0200
committerJonathan Bauer2015-09-10 17:45:18 +0200
commit8a775f1d03ceb36383ef620c8116199cf6e2da28 (patch)
tree0561fc2e8f9187509fa5f5474bae47641bda4301
parent[client] workaround for wrongly assigned error message when uploading new ima... (diff)
downloadtutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.tar.gz
tutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.tar.xz
tutor-module-8a775f1d03ceb36383ef620c8116199cf6e2da28.zip
[client] added "Expiring" column to versionTable and introduced FormatHelper.daysTil(<long_timestamp_in_millis>)
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java38
2 files changed, 43 insertions, 3 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java
index 9c940af8..f69d3c47 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageVersionTable.java
@@ -8,19 +8,22 @@ import org.openslx.dozmod.util.FormatHelper;
public class ImageVersionTable extends ListTable<ImageVersionDetails> {
public static final ListTableColumn COL_CREATED = new ListTableColumn("Erstellungszeitpunkt", Long.class);
+ public static final ListTableColumn COL_EXPIRING = new ListTableColumn("Ablaufszeitpunkt", Long.class);
public static final ListTableColumn COL_UPLOADER = new ListTableColumn("Ersteller");
public static final ListTableColumn COL_VALID = new ListTableColumn("Verwendbar", Boolean.class);
public static final ListTableColumn COL_SIZE = new ListTableColumn("Größe", Long.class);
public static final ListTableColumn COL_ID = new ListTableColumn("Interne ID");
public ImageVersionTable() {
- super(COL_CREATED, COL_UPLOADER, COL_VALID, COL_SIZE, COL_ID);
+ super(COL_CREATED, COL_EXPIRING, COL_UPLOADER, COL_VALID, COL_SIZE, COL_ID);
}
@Override
protected Object getValueAtInternal(ImageVersionDetails row, ListTableColumn column) {
if (column == COL_CREATED)
return row.getCreateTime();
+ if (column == COL_EXPIRING)
+ return row.getExpireTime();
if (column == COL_UPLOADER)
return row.getUploaderId();
if (column == COL_VALID)
@@ -38,11 +41,12 @@ public class ImageVersionTable extends ListTable<ImageVersionDetails> {
return value;
if (column == COL_CREATED)
return FormatHelper.longDate((long) value);
+ if (column == COL_EXPIRING)
+ return FormatHelper.daysTil((long) value);
if (column == COL_UPLOADER)
return FormatHelper.userName(UserCache.find((String) value));
if (column == COL_SIZE)
return FormatHelper.bytes((long) value, false);
throw new IndexOutOfBoundsException();
}
-
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
index 26c7071a..5594be6a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
@@ -1,7 +1,14 @@
package org.openslx.dozmod.util;
+import java.util.Calendar;
+
+import org.joda.time.DateTime;
+import org.joda.time.Days;
+import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.PeriodFormat;
+import org.joda.time.format.PeriodFormatter;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.UserInfo;
@@ -112,5 +119,34 @@ public class FormatHelper {
return ret + String.format("%02d:%02d", seconds / 3600, (seconds % 3600) / 60);
}
}
-
+ /**
+ * Returns the number of days left til the given end timestamp
+ *
+ * @param timestamp to calculate the days until
+ * @return user-ready String containing the amount of days left if <14 days and > 24h,
+ * the number of hours left if <24. If end is already passed, then just
+ * the same as longDate
+ */
+ public static String daysTil(final long timestamp) {
+ Period period = new Period(DateTime.now().getMillis(), timestamp * 1000);
+ if (period.getYears() > 0 || period.getMonths() > 0 || period.getWeeks() > 2) {
+ return longDate(timestamp);
+ } else {
+ // under 2 weeks, get the days and add the week if any
+ int daysLeft = period.getDays();
+ if (period.getWeeks() == 1)
+ daysLeft += 7;
+ if (daysLeft <= 14 && daysLeft >= 1) {
+ return new String(daysLeft + " Tag(e)");
+ } else if (daysLeft == 0) {
+ int hoursLeft = period.getHours();
+ if (hoursLeft != 0) {
+ return new String(hoursLeft + " Stunde(n)");
+ } else {
+ return new String(period.getMinutes() + " Minute(n)");
+ }
+ }
+ }
+ return "-"; // Error
+ }
}