Merge remote-tracking branch 'origin/main' into 21-customizable-events

This commit is contained in:
survellow
2023-11-01 20:14:56 +01:00
3 changed files with 53 additions and 11 deletions

View File

@@ -37,19 +37,20 @@ func (icalModel IcalModel) EmitICal() goics.Componenter {
s.AddProperty(k, v)
if mappingFound {
s.AddProperty("SUMMARY", replaceNameIfUserDefined(&event, mapEntry))
addPropertyIfNotEmpty(s, "SUMMARY", replaceNameIfUserDefined(&event, mapEntry))
addAlarmIfSpecified(s, event, mapEntry)
} else {
s.AddProperty("SUMMARY", event.Name)
addPropertyIfNotEmpty(s, "SUMMARY", event.Name)
}
s.AddProperty("DESCRIPTION", generateDescription(event))
s.AddProperty("LOCATION", event.Rooms)
addPropertyIfNotEmpty(s, "DESCRIPTION", generateDescription(event))
addPropertyIfNotEmpty(s, "LOCATION", event.Rooms)
c.AddComponent(s)
}
return c
}
// if reminder is specified in the configuration for this event, an alarm will be added to the event
func addAlarmIfSpecified(s *goics.Component, event model.Event, mapping model.FeedCollection) {
if mapping.Reminder {
a := goics.NewComponent()
@@ -61,6 +62,8 @@ func addAlarmIfSpecified(s *goics.Component, event model.Event, mapping model.Fe
}
}
// replaceNameIfUserDefined replaces the name of the event with the user defined name if it is not empty
// all contained template strings will be replaced with the corresponding values from the event
func replaceNameIfUserDefined(event *model.Event, mapping model.FeedCollection) string {
if !functions.OnlyWhitespace(mapping.UserDefinedName) {
return names.ReplaceTemplateSubStrings(mapping.UserDefinedName, *event)
@@ -69,6 +72,14 @@ func replaceNameIfUserDefined(event *model.Event, mapping model.FeedCollection)
return event.Name
}
// AddPropertyIfNotEmpty adds a property to the component if the value is not empty
// or contains only whitespaces
func addPropertyIfNotEmpty(component *goics.Component, key string, value string) {
if !functions.OnlyWhitespace(value) {
component.AddProperty(key, value)
}
}
func generateDescription(event model.Event) string {
var description string