added new ical event description

This commit is contained in:
Elmar Kresse
2023-09-22 00:12:13 +02:00
parent 355b850ac5
commit d645fccd8b
3 changed files with 60 additions and 43 deletions

View File

@@ -9,6 +9,7 @@ import (
"log"
"strings"
"time"
"unicode"
)
func SaveEvents(seminarGroup []model.SeminarGroup, collection *models.Collection, app *pocketbase.PocketBase) ([]*models.Record, error) {
@@ -130,36 +131,6 @@ func GetRoomScheduleForDay(app *pocketbase.PocketBase, room string, date string)
return events
}
type Events []*model.Event
// EmitICal implements the interface for goics
func (e Events) EmitICal() goics.Componenter {
layout := "2006-01-02 15:04:05 -0700 MST"
c := goics.NewComponent()
c.SetType("VCALENDAR")
c.AddProperty("VERSION", "2.0")
c.AddProperty("CALSCAL", "GREGORIAN")
c.AddProperty("TZID", "Europe/Berlin")
c.AddProperty("X-WR-CALNAME", "HTWK Kalender")
c.AddProperty("X-WR-TIMEZONE", "Europe/Berlin")
c.AddProperty("X-LIC-LOCATION", "Europe/Berlin")
for _, event := range e {
s := goics.NewComponent()
s.SetType("VEVENT")
timeEnd, _ := time.Parse(layout, event.End)
timeStart, _ := time.Parse(layout, event.Start)
k, v := goics.FormatDateTime("DTEND;TZID=Europe/Berlin", timeEnd)
s.AddProperty(k, v)
k, v = goics.FormatDateTime("DTSTART;TZID=Europe/Berlin", timeStart)
s.AddProperty(k, v)
s.AddProperty("SUMMARY", event.Name)
s.AddProperty("DESCRIPTION", "Notizen: "+event.Notes+"\n Prof: "+event.Prof)
s.AddProperty("LOCATION", event.Rooms)
c.AddComponent(s)
}
return c
}
// gets all events for specific course and semester
// TODO add filter for year
func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, semester string) Events {
@@ -247,3 +218,59 @@ func GetAllModulesDistinct(app *pocketbase.PocketBase) ([]struct {
}
return eventArray, nil
}
type Events []*model.Event
// EmitICal implements the interface for goics
func (e Events) EmitICal() goics.Componenter {
layout := "2006-01-02 15:04:05 -0700 MST"
c := goics.NewComponent()
c.SetType("VCALENDAR")
c.AddProperty("VERSION", "2.0")
c.AddProperty("CALSCAL", "GREGORIAN")
c.AddProperty("TZID", "Europe/Berlin")
c.AddProperty("X-WR-CALNAME", "HTWK Kalender")
c.AddProperty("X-WR-TIMEZONE", "Europe/Berlin")
c.AddProperty("X-LIC-LOCATION", "Europe/Berlin")
for _, event := range e {
s := goics.NewComponent()
s.SetType("VEVENT")
timeEnd, _ := time.Parse(layout, event.End)
timeStart, _ := time.Parse(layout, event.Start)
k, v := goics.FormatDateTime("DTEND;TZID=Europe/Berlin", timeEnd)
s.AddProperty(k, v)
k, v = goics.FormatDateTime("DTSTART;TZID=Europe/Berlin", timeStart)
s.AddProperty(k, v)
s.AddProperty("SUMMARY", event.Name)
s.AddProperty("DESCRIPTION", generateDescription(event))
s.AddProperty("LOCATION", event.Rooms)
c.AddComponent(s)
}
return c
}
func generateDescription(event *model.Event) string {
var description string
if !CheckIfOnlyWhitespace(event.Notes) {
description += "Notizen: " + event.Notes + "\n"
}
if !CheckIfOnlyWhitespace(event.Prof) {
description += "Prof: " + event.Prof + "\n"
}
if !CheckIfOnlyWhitespace(event.Course) {
description += "Gruppe: " + event.Course + "\n"
}
return description
}
// check if course is empty or contains only whitespaces
func CheckIfOnlyWhitespace(word string) bool {
for _, letter := range word {
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
return false
}
}
return true
}

View File

@@ -4,7 +4,6 @@ import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"htwkalender/service/db"
"unicode"
)
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
@@ -22,7 +21,7 @@ func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, cou
func replaceEmptyEntryInStringArray(modules []string, replacement string) {
//replace empty string with "Sonderveranstaltungen"
for i, module := range modules {
if checkIfOnlyWhitespace(module) {
if db.CheckIfOnlyWhitespace(module) {
modules[i] = replacement
}
}
@@ -34,22 +33,12 @@ func replaceEmptyEntry(modules []struct {
}, replacement string) {
//replace empty string with "Sonderveranstaltungen"
for i, module := range modules {
if checkIfOnlyWhitespace(module.Name) {
if db.CheckIfOnlyWhitespace(module.Name) {
modules[i].Name = replacement
}
}
}
// check if course is empty or contains only whitespaces
func checkIfOnlyWhitespace(word string) bool {
for _, letter := range word {
if !unicode.IsSpace(letter) || !(letter == int32(160)) {
return false
}
}
return true
}
func GetAllModulesDistinct(app *pocketbase.PocketBase, c echo.Context) error {
modules, err := db.GetAllModulesDistinct(app)