mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-02 17:59:16 +02:00
added new ical event description
This commit is contained in:
@@ -21,5 +21,6 @@ type Event struct {
|
|||||||
Rooms string `db:"Rooms"`
|
Rooms string `db:"Rooms"`
|
||||||
Notes string `db:"Notes"`
|
Notes string `db:"Notes"`
|
||||||
BookedAt string `db:"BookedAt"`
|
BookedAt string `db:"BookedAt"`
|
||||||
|
Course string `db:"course"`
|
||||||
Semester string `db:"semester"`
|
Semester string `db:"semester"`
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SaveEvents(seminarGroup []model.SeminarGroup, collection *models.Collection, app *pocketbase.PocketBase) ([]*models.Record, error) {
|
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
|
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
|
// gets all events for specific course and semester
|
||||||
// TODO add filter for year
|
// TODO add filter for year
|
||||||
func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, semester string) Events {
|
func GetPlanForCourseAndSemester(app *pocketbase.PocketBase, course string, semester string) Events {
|
||||||
@@ -247,3 +218,59 @@ func GetAllModulesDistinct(app *pocketbase.PocketBase) ([]struct {
|
|||||||
}
|
}
|
||||||
return eventArray, nil
|
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
|
||||||
|
}
|
||||||
|
@@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/labstack/echo/v5"
|
"github.com/labstack/echo/v5"
|
||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
"htwkalender/service/db"
|
"htwkalender/service/db"
|
||||||
"unicode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetModulesForCourseDistinct(app *pocketbase.PocketBase, c echo.Context, course string, semester string) error {
|
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) {
|
func replaceEmptyEntryInStringArray(modules []string, replacement string) {
|
||||||
//replace empty string with "Sonderveranstaltungen"
|
//replace empty string with "Sonderveranstaltungen"
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
if checkIfOnlyWhitespace(module) {
|
if db.CheckIfOnlyWhitespace(module) {
|
||||||
modules[i] = replacement
|
modules[i] = replacement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,22 +33,12 @@ func replaceEmptyEntry(modules []struct {
|
|||||||
}, replacement string) {
|
}, replacement string) {
|
||||||
//replace empty string with "Sonderveranstaltungen"
|
//replace empty string with "Sonderveranstaltungen"
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
if checkIfOnlyWhitespace(module.Name) {
|
if db.CheckIfOnlyWhitespace(module.Name) {
|
||||||
modules[i].Name = replacement
|
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 {
|
func GetAllModulesDistinct(app *pocketbase.PocketBase, c echo.Context) error {
|
||||||
modules, err := db.GetAllModulesDistinct(app)
|
modules, err := db.GetAllModulesDistinct(app)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user