work on event editing in dashboard part 3 (recurrence)

This commit is contained in:
NovaFox161
2018-03-10 21:11:15 -06:00
parent 54f88baa05
commit ebb3e82b9b
4 changed files with 98 additions and 1 deletions

View File

@@ -111,7 +111,7 @@ public class Recurrence {
*
* @param rrule The RRules to convert from.
*/
public void fromRRule(String rrule) {
public Recurrence fromRRule(String rrule) {
rrule = rrule.replaceAll("RRULE:", "");
String[] contents = rrule.split(";");
for (String c : contents) {
@@ -138,5 +138,6 @@ public class Recurrence {
}
}
}
return this;
}
}

View File

@@ -3,7 +3,9 @@ package com.cloudcraftgaming.discal.web.endpoints.v1;
import com.cloudcraftgaming.discal.api.calendar.CalendarAuth;
import com.cloudcraftgaming.discal.api.database.DatabaseManager;
import com.cloudcraftgaming.discal.api.enums.event.EventColor;
import com.cloudcraftgaming.discal.api.enums.event.EventFrequency;
import com.cloudcraftgaming.discal.api.object.calendar.CalendarData;
import com.cloudcraftgaming.discal.api.object.event.Recurrence;
import com.cloudcraftgaming.discal.api.object.web.WebGuild;
import com.cloudcraftgaming.discal.api.utils.ExceptionHandler;
import com.cloudcraftgaming.discal.web.handler.DiscordAccountHandler;
@@ -116,6 +118,28 @@ public class EventEndpoint {
jo.put("description", e.getDescription());
jo.put("location", e.getLocation());
jo.put("color", EventColor.fromNameOrHexOrID(e.getColorId()).name());
jo.put("isParent", !(e.getId().contains("_")));
if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
jo.put("recur", true);
Recurrence r = new Recurrence().fromRRule(e.getRecurrence().get(0));
JSONObject rjo = new JSONObject();
rjo.put("frequency", r.getFrequency().name());
rjo.put("count", r.getCount());
rjo.put("interval", r.getInterval());
jo.put("recurrence", rjo);
} else {
jo.put("recur", false);
JSONObject rjo = new JSONObject();
rjo.put("frequency", EventFrequency.DAILY.name());
rjo.put("recurCount", -1);
rjo.put("interval", 1);
jo.put("recurrence", rjo);
}
eventsJson.add(jo);
}

View File

@@ -182,6 +182,9 @@
</tr>
</tbody>
</table>
<p style="text-align: center; font-size: 20px" id="local-time-display">All dates and
times should be displayed in local time. (It's a work in progress, sorry if
there are issues)</p>
</div>
<hr>
<br>

View File

@@ -208,6 +208,7 @@ function getEventsForSelectedDate() {
modalBody.className = "modal-body";
modalCon.appendChild(modalBody);
//TODO: Don't make this POST, intercept and send it in JSON!!!!!
var form = document.createElement("form");
form.method = "POST";
form.enctype = "application/x-www-form-urlencoded";
@@ -274,6 +275,7 @@ function getEventsForSelectedDate() {
form.appendChild(document.createElement("br"));
//Color
//TODO: Make this a proper dropdown
var colorLabel = document.createElement("label");
colorLabel.innerHTML = "Color";
colorLabel.appendChild(document.createElement("br"));
@@ -287,6 +289,73 @@ function getEventsForSelectedDate() {
form.appendChild(document.createElement("br"));
//Recurrence
var recurrenceLabel = document.createElement("label");
recurrenceLabel.innerHTML = "Recurrence";
recurrenceLabel.appendChild(document.createElement("br"));
form.appendChild(recurrenceLabel);
if (event.isParent) {
var enableRecurrence = document.createElement("input");
enableRecurrence.name = "enable-recurrence";
enableRecurrence.type = "checkbox";
enableRecurrence.checked = false;
recurrenceLabel.appendChild(enableRecurrence);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
//TODO: Make this a proper dropdown
//Frequency
var frequencyLabel = document.createElement("label");
frequencyLabel.innerHTML = "Recurrence - Frequency";
frequencyLabel.appendChild(document.createElement("br"));
form.appendChild(frequencyLabel);
var frequency = document.createElement("input");
frequency.name = "frequency";
frequency.type = "text";
frequency.value = event.recurrence.frequency;
frequencyLabel.appendChild(frequency);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
//Count
var countLabel = document.createElement("label");
countLabel.innerHTML = "Recurrence - Count";
countLabel.appendChild(document.createElement("br"));
form.appendChild(countLabel);
var count = document.createElement("input");
count.name = "count";
count.type = "number";
count.valueAsNumber = parseInt(event.recurrence.recurCount);
count.min = "-1";
countLabel.appendChild(count);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
//Interval
var intervalLabel = document.createElement("label");
intervalLabel.innerHTML = "Recurrence - Interval";
intervalLabel.appendChild(document.createElement("br"));
form.appendChild(intervalLabel);
var interval = document.createElement("input");
interval.name = "interval";
interval.type = "number";
interval.valueAsNumber = parseInt(event.recurrence.interval);
interval.min = "1";
intervalLabel.appendChild(interval);
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
} else {
//Cannot edit recurrence
var cannotEditRecur = document.createElement("input");
cannotEditRecur.name = "ignore-cer";
cannotEditRecur.type = "text";
cannotEditRecur.disabled = true;
cannotEditRecur.value = "Cannot edit child";
recurrenceLabel.appendChild(cannotEditRecur);
}
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
//ID for API
var hiddenId = document.createElement("input");