mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2025-08-03 18:29:16 +02:00
added UserDefined Module Naming
This commit is contained in:
67
backend/service/ical/icalFileGeneration.go
Normal file
67
backend/service/ical/icalFileGeneration.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package ical
|
||||
|
||||
import (
|
||||
"github.com/jordic/goics"
|
||||
"htwkalender/model"
|
||||
"htwkalender/service/functions"
|
||||
"time"
|
||||
)
|
||||
|
||||
// local type for EmitICal function
|
||||
type IcalModel struct {
|
||||
Events model.Events
|
||||
Mapping []model.FeedCollection
|
||||
}
|
||||
|
||||
// EmitICal implements the interface for goics
|
||||
func (icalModel IcalModel) 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 icalModel.Events {
|
||||
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", replaceNameIfUserDefined(event.Name, icalModel.Mapping))
|
||||
s.AddProperty("DESCRIPTION", generateDescription(event))
|
||||
s.AddProperty("LOCATION", event.Rooms)
|
||||
c.AddComponent(s)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func replaceNameIfUserDefined(name string, mapping []model.FeedCollection) string {
|
||||
for _, mapEntry := range mapping {
|
||||
if mapEntry.Name == name {
|
||||
return mapEntry.UserDefinedName
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func generateDescription(event *model.Event) string {
|
||||
var description string
|
||||
|
||||
if !functions.CheckIfOnlyWhitespace(event.Notes) {
|
||||
description += "Notizen: " + event.Notes + "\n"
|
||||
}
|
||||
if !functions.CheckIfOnlyWhitespace(event.Prof) {
|
||||
description += "Prof: " + event.Prof + "\n"
|
||||
}
|
||||
if !functions.CheckIfOnlyWhitespace(event.Course) {
|
||||
description += "Gruppe: " + event.Course + "\n"
|
||||
}
|
||||
|
||||
return description
|
||||
}
|
Reference in New Issue
Block a user