Skip to content

Commit

Permalink
Added event tags
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed Feb 17, 2024
1 parent 3a10ef5 commit 3fea956
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions public/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ <h1>New Event</h1>
/>
<label class="tgl-btn" style="font-size: 16px" for="repeat"></label>
</div>
<label>Event Tag</label>
<input id="event-tag">
</div>
<div id="repeatform" style="display: none">
<select id="frequency">
Expand Down
7 changes: 4 additions & 3 deletions public/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const email_notification = document.getElementById('email-notification');
email_notification.textContent = `
Hi [MEMBER_NAME],
We'll be having an extra rehearsal on Monday at XXXX. We hope to see you there!
Insert email body here.
Best,
${user.name}
Expand Down Expand Up @@ -214,6 +214,7 @@ document.getElementById('submitevent').addEventListener('click', () => {
const starttimestamp = new Date(startdate + 'T' + starttime).getTime() / 1000;
const endtimestamp = new Date(enddate + 'T' + endtime).getTime() / 1000;
const isRepeating = document.getElementById('repeat').checked;
const tag = document.getElementById('event-tag').value;

if (!startdate || !starttime || !enddate || !endtime) {
Popup.alert('Please fill out all start and end times/dates.', 'var(--error)');
Expand Down Expand Up @@ -245,7 +246,7 @@ document.getElementById('submitevent').addEventListener('click', () => {
GET(
`/makeRecurringEvent?name=${name}&description=${description}&starttimestamp=${starttimestamp}&endtimestamp=${endtimestamp}&businessId=${getBusinessId()}&frequency=${frequency}&interval=${interval}&daysoftheweek=${daysoftheweek.join(
',',
)}&timezoneOffsetMS=${timezoneOffsetMS}`,
)}&timezoneOffsetMS=${timezoneOffsetMS}&tag=${tag}`,
).then(async res => {
if (res.ok) {
showSuccessDialog('new-event-success');
Expand All @@ -257,7 +258,7 @@ document.getElementById('submitevent').addEventListener('click', () => {
});
} else {
GET(
`/makeEvent?name=${name}&description=${description}&starttimestamp=${starttimestamp}&endtimestamp=${endtimestamp}&businessId=${getBusinessId()}`,
`/makeEvent?name=${name}&description=${description}&starttimestamp=${starttimestamp}&endtimestamp=${endtimestamp}&businessId=${getBusinessId()}&tag=${tag}`,
).then(async res => {
if (res.ok) {
showSuccessDialog('new-event-success');
Expand Down
12 changes: 9 additions & 3 deletions server/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ router.get('/makeEvent', async function (request, response) {
const description = request.query.description;
const starttimestamp = request.query.starttimestamp;
const endtimestamp = request.query.endtimestamp;
const tag = request.query.tag;

const eventid = await asyncRunWithID(
'INSERT INTO Events (business_id, name, description, starttimestamp, endtimestamp) VALUES (?, ?, ?, ?, ?)',
[businessId, name, description, starttimestamp, endtimestamp],
'INSERT INTO Events (business_id, name, description, starttimestamp, endtimestamp, tag) VALUES (?, ?, ?, ?, ?, ?)',
[businessId, name, description, starttimestamp, endtimestamp, tag],
);
response.send('' + eventid);
});
Expand All @@ -108,20 +109,22 @@ function createEventSequence(
frequency,
interval,
timezoneOffsetMS,
tag,
) {
let current = startDate;
while (current < endDate) {
const currentEndDate = new Date(endDate);
currentEndDate.setFullYear(current.getFullYear(), current.getMonth(), current.getDate());
asyncRunWithID(
'INSERT INTO Events (business_id, name, description, starttimestamp, endtimestamp, repeat_id) VALUES (?, ?, ?, ?, ?, ?)',
'INSERT INTO Events (business_id, name, description, starttimestamp, endtimestamp, repeat_id, tag) VALUES (?, ?, ?, ?, ?, ?, ?)',
[
businessId,
name,
description,
(current.getTime() + timezoneOffsetMS) / 1000,
(currentEndDate.getTime() + timezoneOffsetMS) / 1000,
repeatId,
tag,
],
);
if (frequency === 'daily') current.setDate(current.getDate() + interval);
Expand Down Expand Up @@ -159,6 +162,7 @@ router.get('/makeRecurringEvent', async function (request, response) {
const interval = parseInt(request.query.interval);
const daysoftheweek = request.query.daysoftheweek;
const repeatId = uuid.v4();
const tag = request.query.tag;

if (frequency === 'weekly' && daysoftheweek.length > 0) {
for (const day of daysoftheweek.split(',')) {
Expand All @@ -175,6 +179,7 @@ router.get('/makeRecurringEvent', async function (request, response) {
frequency,
interval,
timezoneOffsetMS,
tag,
);
}
} else {
Expand All @@ -188,6 +193,7 @@ router.get('/makeRecurringEvent', async function (request, response) {
frequency,
interval,
timezoneOffsetMS,
tag,
);
}

Expand Down
1 change: 1 addition & 0 deletions server/databaseSchema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS "Events" (
"starttimestamp" TEXT NOT NULL,
"endtimestamp" TEXT NOT NULL,
"repeat_id" TEXT,
"tag" TEXT,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("business_id") REFERENCES "Businesses"("id")
);
Expand Down
16 changes: 16 additions & 0 deletions server/super_admin/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,22 @@
"editview": {
"show": true
}
},
{
"name": "tag",
"verbose": "tag",
"control": {
"text": true
},
"type": "TEXT",
"allowNull": true,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
Expand Down

0 comments on commit 3fea956

Please sign in to comment.