mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-02-14 15:38:42 -06:00
Add ability to delete calendar from dashboard.
This commit is contained in:
@@ -31,6 +31,7 @@ public class CalendarUtils {
|
||||
} catch (IOException e) {
|
||||
//Fail silently.
|
||||
ExceptionHandler.sendException(null, "Failed to delete calendar", e, CalendarUtils.class);
|
||||
return false;
|
||||
}
|
||||
if (settings.useExternalCalendar()) {
|
||||
//Update settings.
|
||||
|
||||
@@ -3,11 +3,13 @@ package com.cloudcraftgaming.discal.web.handler;
|
||||
import com.cloudcraftgaming.discal.Main;
|
||||
import com.cloudcraftgaming.discal.api.calendar.CalendarAuth;
|
||||
import com.cloudcraftgaming.discal.api.database.DatabaseManager;
|
||||
import com.cloudcraftgaming.discal.api.object.GuildSettings;
|
||||
import com.cloudcraftgaming.discal.api.object.calendar.CalendarData;
|
||||
import com.cloudcraftgaming.discal.api.object.web.WebCalendar;
|
||||
import com.cloudcraftgaming.discal.api.object.web.WebChannel;
|
||||
import com.cloudcraftgaming.discal.api.object.web.WebGuild;
|
||||
import com.cloudcraftgaming.discal.api.object.web.WebRole;
|
||||
import com.cloudcraftgaming.discal.api.utils.CalendarUtils;
|
||||
import com.cloudcraftgaming.discal.api.utils.ExceptionHandler;
|
||||
import com.cloudcraftgaming.discal.api.utils.PermissionChecker;
|
||||
import com.google.api.services.calendar.model.AclRule;
|
||||
@@ -303,4 +305,23 @@ public class DashboardHandler {
|
||||
}
|
||||
return response.body();
|
||||
}
|
||||
|
||||
public static String deleteCalendar(Request request, Response response) {
|
||||
try {
|
||||
//TODO: Handle multiple calendars...
|
||||
String calId = request.queryParams("calendar-id");
|
||||
|
||||
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
|
||||
WebGuild g = (WebGuild) m.get("selected");
|
||||
CalendarData data = DatabaseManager.getManager().getMainCalendar(Long.valueOf(g.getId()));
|
||||
GuildSettings settings = DatabaseManager.getManager().getSettings(Long.valueOf(g.getId()));
|
||||
CalendarUtils.deleteCalendar(data, settings);
|
||||
|
||||
g.setCalendar(new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(g.getId())), DatabaseManager.getManager().getSettings(Long.valueOf(g.getId()))));
|
||||
response.redirect("/dashboard/guild", 301);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.sendException(null, "[WEB] Failed to delete/remove calendar!", e, DashboardHandler.class);
|
||||
}
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,9 @@ public class SparkUtils {
|
||||
path("/create", () -> {
|
||||
get("/calendar", DashboardHandler::handleCalendarCreate);
|
||||
});
|
||||
path("/delete", () -> {
|
||||
get("/calendar", DashboardHandler::deleteCalendar);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -241,6 +241,11 @@
|
||||
</label>
|
||||
<input type="submit" class="submit" value="Update">
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<a th:href="'/account/dashboard/delete/calendar?calendar-id=' + ${selected.calendar.id}">
|
||||
<button class="danger">Delete Calendar</button>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<!--Event Settings-->
|
||||
|
||||
@@ -67,6 +67,22 @@ button:hover {
|
||||
color: black;
|
||||
}
|
||||
|
||||
button.danger {
|
||||
font-size: 18px;
|
||||
background-color: #ef0813;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
border: 2px black;
|
||||
margin: 10px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
button.danger:hover {
|
||||
color: #ef0813;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
hr {
|
||||
color: #5566c2;
|
||||
background-color: #5566c2;
|
||||
|
||||
Reference in New Issue
Block a user