mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-02-14 15:38:42 -06:00
Working on calendar managing in dashboard.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
||||
package com.cloudcraftgaming.discal.api.network.discord;
|
||||
|
||||
import com.cloudcraftgaming.discal.api.enums.GoodTimezone;
|
||||
import com.cloudcraftgaming.discal.api.object.BotSettings;
|
||||
import com.cloudcraftgaming.discal.api.utils.ExceptionHandler;
|
||||
import com.cloudcraftgaming.discal.api.utils.GuildUtils;
|
||||
@@ -51,6 +52,8 @@ public class DiscordLoginHandler {
|
||||
//Get guilds...
|
||||
m.put("guilds", GuildUtils.getGuilds(userInfo.getString("id")));
|
||||
|
||||
m.put("goodTz", GoodTimezone.values());
|
||||
|
||||
DiscordAccountHandler.getHandler().addAccount(m, request.session().id());
|
||||
|
||||
//Finally redirect to the dashboard seamlessly.
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.cloudcraftgaming.discal.api.object.web;
|
||||
|
||||
import com.cloudcraftgaming.discal.api.calendar.CalendarAuth;
|
||||
import com.cloudcraftgaming.discal.api.object.GuildSettings;
|
||||
import com.cloudcraftgaming.discal.api.object.calendar.CalendarData;
|
||||
import com.cloudcraftgaming.discal.api.utils.ExceptionHandler;
|
||||
import com.cloudcraftgaming.discal.bot.internal.calendar.calendar.CalendarMessageFormatter;
|
||||
import com.google.api.services.calendar.model.Calendar;
|
||||
|
||||
/**
|
||||
* Created by Nova Fox on 1/7/18.
|
||||
* Website: www.cloudcraftgaming.com
|
||||
* For Project: DisCal-Discord-Bot
|
||||
*/
|
||||
public class WebCalendar {
|
||||
private String id;
|
||||
private String address;
|
||||
private String link;
|
||||
private String name;
|
||||
private String description;
|
||||
private String timezone;
|
||||
|
||||
private boolean external;
|
||||
|
||||
//Getters
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
public boolean isExternal() {
|
||||
return external;
|
||||
}
|
||||
|
||||
//Setters
|
||||
public void setId(String _id) {
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public void setAddress(String _address) {
|
||||
address = _address;
|
||||
}
|
||||
|
||||
public void setLink(String _link) {
|
||||
link = _link;
|
||||
}
|
||||
|
||||
public void setName(String _name) {
|
||||
name = _name;
|
||||
}
|
||||
|
||||
public void setDescription(String _desc) {
|
||||
description = _desc;
|
||||
}
|
||||
|
||||
public void setTimezone(String _tz) {
|
||||
timezone = _tz;
|
||||
}
|
||||
|
||||
public void setExternal(boolean _ext) {
|
||||
external = _ext;
|
||||
}
|
||||
|
||||
//Functions
|
||||
public WebCalendar fromCalendar(CalendarData cd, GuildSettings gs) {
|
||||
if (cd.getCalendarAddress().equalsIgnoreCase("primary")) {
|
||||
id = "primary";
|
||||
address = "primary";
|
||||
link = "N/a";
|
||||
name = "N/a";
|
||||
description = "N/a";
|
||||
timezone = "N/a";
|
||||
} else {
|
||||
id = cd.getCalendarId();
|
||||
address = cd.getCalendarAddress();
|
||||
link = CalendarMessageFormatter.getCalendarLink(id);
|
||||
external = cd.isExternal();
|
||||
try {
|
||||
if (cd.isExternal()) {
|
||||
Calendar cal = CalendarAuth.getCalendarService(gs).calendars().get(id).execute();
|
||||
name = cal.getSummary();
|
||||
description = cal.getDescription();
|
||||
timezone = cal.getTimeZone().replaceAll("/", "___");
|
||||
} else {
|
||||
Calendar cal = CalendarAuth.getCalendarService().calendars().get(id).execute();
|
||||
name = cal.getSummary();
|
||||
description = cal.getDescription();
|
||||
timezone = cal.getTimeZone().replaceAll("/", "___");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.sendException(null, "[WEB] Failed to get calendar!", e, this.getClass());
|
||||
name = "ERROR!";
|
||||
description = "ERROR";
|
||||
timezone = "ERROR";
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ public class WebGuild {
|
||||
private List<WebRole> roles = new ArrayList<>();
|
||||
private List<WebChannel> channels = new ArrayList<>();
|
||||
|
||||
private WebCalendar calendar;
|
||||
|
||||
//Getters
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -57,6 +59,10 @@ public class WebGuild {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public WebCalendar getCalendar() {
|
||||
return calendar;
|
||||
}
|
||||
|
||||
//Setters
|
||||
public void setId(String _id) {
|
||||
id = _id;
|
||||
@@ -78,6 +84,10 @@ public class WebGuild {
|
||||
botNick = _nick;
|
||||
}
|
||||
|
||||
public void setCalendar(WebCalendar _cal) {
|
||||
calendar = _cal;
|
||||
}
|
||||
|
||||
|
||||
//Functions
|
||||
public WebGuild fromGuild(IGuild g) {
|
||||
@@ -102,6 +112,8 @@ public class WebGuild {
|
||||
channels.add(new WebChannel().fromChannel(c, settings));
|
||||
}
|
||||
|
||||
calendar = new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(id)), settings);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,7 @@ public class DashboardHandler {
|
||||
g.getChannels().add(new WebChannel().fromChannel(c, g.getSettings()));
|
||||
}
|
||||
}
|
||||
//TODO: Handle calendar name/description/timezone updating.
|
||||
|
||||
//Finally redirect back to the dashboard
|
||||
response.redirect("/dashboard/guild", 301);
|
||||
@@ -191,4 +192,25 @@ public class DashboardHandler {
|
||||
}
|
||||
return response.body();
|
||||
}
|
||||
|
||||
public static String handleCalendarCreate(Request request, Response response) {
|
||||
try {
|
||||
String name = request.queryParams("cal-name");
|
||||
String desc = request.queryParams("cal-desc");
|
||||
String tz = request.queryParams("cal-timezone").replace("___", "/");
|
||||
|
||||
//TODO: Create calendar
|
||||
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
|
||||
WebGuild g = (WebGuild) m.get("selected");
|
||||
|
||||
//TODO: refresh selected guild's calendar to display properly...
|
||||
|
||||
//Finally redirect back to the dashboard
|
||||
response.redirect("/dashboard/guild", 301);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.sendException(null, "[WEB] Calendar create failed!", e, DashboardHandler.class);
|
||||
halt(500, "Internal Server Exception");
|
||||
}
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,9 @@ public class SparkUtils {
|
||||
get("/select", DashboardHandler::handleGuildSelect);
|
||||
get("/guild", DashboardHandler::handleSettingsSelect);
|
||||
get("/update", DashboardHandler::handleSettingsUpdate);
|
||||
path("/create", () -> {
|
||||
get("/calendar", DashboardHandler::handleCalendarCreate);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -172,10 +172,85 @@
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<!--TODO: Add support for multiple calendars-->
|
||||
<!--Does NOT have a calendar-->
|
||||
<div th:if="${selected.calendar.id} == primary" style="text-align: left">
|
||||
<hr>
|
||||
<h6>Create A Calendar Below!</h6>
|
||||
<form action="/account/dashboard/create/calendar" name="calendar-create">
|
||||
<label>Calendar Name/Summary
|
||||
<br>
|
||||
<input type="text" name="cal-name" value="Calendar Name">
|
||||
</label>
|
||||
<br>
|
||||
<br>
|
||||
<label>Calendar Description
|
||||
<br>
|
||||
<input type="text" name="cal-desc" value="Calendar Description">
|
||||
</label>
|
||||
<br>
|
||||
<br>
|
||||
<label>Calendar Timezone
|
||||
<br>
|
||||
<select name="cal-tz">
|
||||
<th:block th:each="tz : ${goodTz}">
|
||||
<option th:value="${tz.name}" th:text="${tz.name}"></option>
|
||||
</th:block>
|
||||
</select>
|
||||
</label>
|
||||
<br>
|
||||
<br>
|
||||
<input type="submit" class="submit" value="Create Calendar!">
|
||||
</form>
|
||||
</div>
|
||||
<!--Has MAIN calendar-->
|
||||
<div th:unless="${selected.calendar.id} == primary">
|
||||
<hr>
|
||||
<h6>Edit Your Calendar Below</h6>
|
||||
<a th:href="${selected.calendar.link}" target="_blank">
|
||||
<button>View Calendar!</button>
|
||||
</a>
|
||||
<br><br>
|
||||
<form action="/account/dashboard/update" style="text-align: left">
|
||||
<label>Calendar Name/Summary
|
||||
<br>
|
||||
<input type="text" name="cal-name" th:value="${selected.calendar.name}">
|
||||
</label>
|
||||
<input type="submit" class="submit" value="Update">
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<form action="/account/dashboard/update" style="text-align: left">
|
||||
<label>Calendar Description
|
||||
<br>
|
||||
<input type="text" name="cal-desc" th:value="${selected.calendar.description}">
|
||||
</label>
|
||||
<input type="submit" class="submit" value="Update">
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<form action="/account/dashboard/update" style="text-align: left">
|
||||
<label>Calendar Timezone
|
||||
<br>
|
||||
<select name="cal-tz">
|
||||
<th:block th:each="tz : ${goodTz}">
|
||||
<option th:value="${tz.name}" th:text="${tz.name}"
|
||||
th:selected="${tz.name} == ${selected.calendar.timezone}"></option>
|
||||
</th:block>
|
||||
</select>
|
||||
</label>
|
||||
<input type="submit" class="submit" value="Update">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!--Event Settings-->
|
||||
<div th:if="${settings} == events">
|
||||
<h6>Event Settings</h6>
|
||||
<br>
|
||||
<p>
|
||||
It's a work in progress. Soon you will be able to create/edit/manage/delete events from
|
||||
here!!
|
||||
</p>
|
||||
</div>
|
||||
<!--Announcement Settings-->
|
||||
<div th:if="${settings} == announcements">
|
||||
@@ -188,10 +263,20 @@
|
||||
onclick="useSimpleAnnouncements(this.checked)">
|
||||
</label>
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<p>
|
||||
It's a work in progress. Soon you will be able to create/edit/manage/delete
|
||||
announcements from here!!
|
||||
</p>
|
||||
</div>
|
||||
<!--RSVP Settings-->
|
||||
<div th:if="${settings} == rsvp">
|
||||
<h6>RSVP Settings</h6>
|
||||
<br>
|
||||
<p>
|
||||
It's a work in progress. Soon you will be able to control RSVPs from here!!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user