import java.text.SimpleDateFormat;
import java.util.Date;
-import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.Core.SoneStatus;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.util.json.JsonObject;
/**
*/
public class GetSoneStatusPage extends JsonPage {
- /** The Sone core. */
- private final Core core;
-
/**
* Creates a new AJAX sone status handler.
*
- * @param core
- * The Sone core
+ * @param webInterface
+ * The Sone web interface
*/
- public GetSoneStatusPage(Core core) {
- super("ajax/getSoneStatus.ajax");
- this.core = core;
+ public GetSoneStatusPage(WebInterface webInterface) {
+ super("ajax/getSoneStatus.ajax", webInterface);
}
+ //
+ // JSONPAGE METHODS
+ //
+
/**
* {@inheritDoc}
*/
@Override
protected JsonObject createJsonObject(Request request) {
String soneId = request.getHttpRequest().getParam("sone");
- Sone sone = core.getSone(soneId);
- SoneStatus soneStatus = core.getSoneStatus(sone);
- return new JsonObject().put("status", soneStatus.name()).put("modified", sone.getModificationCounter() > 0).put("lastUpdated", new SimpleDateFormat("MMM d, yyyy, HH:mm:ss").format(new Date(sone.getTime())));
+ Sone sone = webInterface.core().getSone(soneId);
+ SoneStatus soneStatus = webInterface.core().getSoneStatus(sone);
+ return new JsonObject().put("status", soneStatus.name()).put("name", SoneAccessor.getNiceName(sone)).put("modified", sone.getModificationCounter() > 0).put("lastUpdated", new SimpleDateFormat("MMM d, yyyy, HH:mm:ss").format(new Date(sone.getTime()))).put("age", (System.currentTimeMillis() - sone.getTime()) / 1000);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean needsFormPassword() {
+ return false;
}
}