Compare commits

..

No commits in common. "6d566ba07744bfa1a78671db103b8038a2040be0" and "8bc6dcff27ab2d599a060798921777f9876b37bf" have entirely different histories.

17 changed files with 48 additions and 121 deletions

View file

@ -9,9 +9,6 @@ all: build
%.mjml.html: %.mjml %.mjml.html: %.mjml
npx mjml $< --config.minify > $@ npx mjml $< --config.minify > $@
.PHONY: prepare
prepare:
go mod download
.PHONY: build build-binaries build-templates .PHONY: build build-binaries build-templates
build: build-binaries build-templates ## build executable build: build-binaries build-templates ## build executable
@ -41,10 +38,8 @@ clean-templates:
clean-binaries: clean-binaries:
rm -rf ./_build/* rm -rf ./_build/*
.PHONY: test test: build
test: # build ./test.sh
go test ./...
# ./test.sh
npm: npm:
npm install npm install

View file

@ -12,7 +12,7 @@ import (
) )
const ( const (
programBinary string = "kiwimix" programBinary string = "musala"
) )
var ( var (

6
go.mod
View file

@ -6,12 +6,6 @@ require (
github.com/PuloV/ics-golang v0.0.0-20190808201353-a3394d3bcade github.com/PuloV/ics-golang v0.0.0-20190808201353-a3394d3bcade
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0 github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
) )
require ( require (

View file

@ -14,42 +14,19 @@ func NewCalendar() *Calendar {
return &Calendar{*ics.NewCalendar()} return &Calendar{*ics.NewCalendar()}
} }
// ParseCalendarFile parses an ICS file and returns a calendar // SetEvent adds an event to the calendar
func ParseCalendarFile(filePath string) (*Calendar, error) { func (cal *Calendar) SetEvent(event Event) (*Calendar, error) {
return &Calendar{*ics.NewCalendar()}, nil c, err := cal.SetEvent(event)
} return c, err
// AddEvent adds an event to the calendar
func (cal *Calendar) AddEvent(event *Event) (*Calendar, error) {
//c, err := cal.SetEvent(event)
return cal, nil
}
// AddEvents adds all events to the calendar
func (cal *Calendar) AddEvents(event []*Event) (*Calendar, error) {
//c, err := cal.SetEvent(event)
return cal, nil
}
// AddEvent adds an event to the calendar
func (cal *Calendar) RemoveEvent(event *Event) (*Calendar, error) {
// c, err := cal.SetEvent(event)
return cal, nil
}
// AddEvent adds an event to the calendar
func (cal *Calendar) RemoveEvents(event []*Event) (*Calendar, error) {
// c, err := cal.SetEvent(event)
return cal, nil
} }
// GetEvents gets all events in the calendar // GetEvents gets all events in the calendar
func (cal *Calendar) GetEvents() []*Event { func (cal *Calendar) GetEvents() []Event {
subcal := cal.Calendar subcal := cal.Calendar
subevents := subcal.GetEvents() subevents := subcal.GetEvents()
wrapped := make([]*Event, len(subevents)) wrapped := make([]Event, len(subevents))
for i, v := range subevents { for i, v := range subevents {
wrapped[i] = &Event{v} wrapped[i] = Event{v}
} }
return wrapped return wrapped
} }

View file

@ -1,13 +0,0 @@
package basetypes_test
import (
"testing"
"code.apps.glenux.net/glenux/kiwimix/pkg/basetypes"
"github.com/stretchr/testify/assert"
)
func TestCalendarFoo(t *testing.T) {
cal = basetypes.NewCalendar()
assert.Equal(t, cal, nil, "they should be equal")
}

View file

@ -6,7 +6,3 @@ import ics "github.com/PuloV/ics-golang"
type Event struct { type Event struct {
ics.Event ics.Event
} }
func (event *Event) Equals(other *Event) bool {
return false
}

View file

@ -1,9 +1 @@
package basetypes package basetypes
type Stack struct {
calendars []Calendar
}
func (stack *Stack) Push(calendar *Calendar) (*Stack, error) {
return nil, nil
}

View file

@ -13,10 +13,10 @@ type DifferenceCalendarOperation struct{}
// Ensure DifferenceCalendarOperation implements CalendarOperation // Ensure DifferenceCalendarOperation implements CalendarOperation
var _ CalendarOperation = (*DifferenceCalendarOperation)(nil) var _ CalendarOperation = (*DifferenceCalendarOperation)(nil)
func (op *DifferenceCalendarOperation) Execute(calendars ...*basetypes.Calendar) (*basetypes.Calendar, error) { func (op DifferenceCalendarOperation) Execute(calendars ...basetypes.Calendar) (basetypes.Calendar, error) {
// Check that two calendars are provided // Check that two calendars are provided
if len(calendars) != 2 { if len(calendars) != 2 {
return &basetypes.Calendar{}, errors.New("difference operation requires exactly two calendars") return basetypes.Calendar{}, errors.New("difference operation requires exactly two calendars")
} }
// Create a new calendar to store the difference // Create a new calendar to store the difference
@ -38,7 +38,7 @@ func (op *DifferenceCalendarOperation) Execute(calendars ...*basetypes.Calendar)
// If the event is unique to the first calendar, add it to the difference calendar // If the event is unique to the first calendar, add it to the difference calendar
if isUnique { if isUnique {
differenceCalendar.AddEvent(event1) differenceCalendar.SetEvent(event1)
} }
} }

View file

@ -13,9 +13,9 @@ type IntersectCalendarOperation struct{}
// Ensure IntersectCalendarOperation implements CalendarOperation // Ensure IntersectCalendarOperation implements CalendarOperation
var _ CalendarOperation = (*IntersectCalendarOperation)(nil) var _ CalendarOperation = (*IntersectCalendarOperation)(nil)
func (op *IntersectCalendarOperation) Execute(calendars ...*basetypes.Calendar) (*basetypes.Calendar, error) { func (op IntersectCalendarOperation) Execute(calendars ...basetypes.Calendar) (basetypes.Calendar, error) {
if len(calendars) != 2 { if len(calendars) != 2 {
return &basetypes.Calendar{}, errors.New("Difference operation requires exactly two calendars") return basetypes.Calendar{}, errors.New("Difference operation requires exactly two calendars")
} }
// Do your union operation here and return the new union basetypes. // Do your union operation here and return the new union basetypes.
return calendars[0], nil // Replace this with actual implementation return calendars[0], nil // Replace this with actual implementation

View file

@ -15,9 +15,9 @@ type UnionCalendarOperation struct {
var _ CalendarOperation = (*UnionCalendarOperation)(nil) var _ CalendarOperation = (*UnionCalendarOperation)(nil)
// Execute combines the events of two calendars and returns a new calendar that contains all events from both. // Execute combines the events of two calendars and returns a new calendar that contains all events from both.
func (op *UnionCalendarOperation) Execute(calendars ...*basetypes.Calendar) (*basetypes.Calendar, error) { func (op *UnionCalendarOperation) Execute(calendars ...basetypes.Calendar) (basetypes.Calendar, error) {
if len(calendars) != 2 { if len(calendars) != 2 {
return &basetypes.Calendar{}, errors.New("Union operation requires exactly two calendars") return basetypes.Calendar{}, errors.New("Union operation requires exactly two calendars")
} }
// Do your union operation here and return the new union basetypes. // Do your union operation here and return the new union basetypes.
return calendars[0], nil // Replace this with actual implementation return calendars[0], nil // Replace this with actual implementation

View file

@ -4,5 +4,5 @@ import basetypes "code.apps.glenux.net/glenux/kiwimix/pkg/basetypes"
// CalendarOperation defines the interface for operations on calendars. // CalendarOperation defines the interface for operations on calendars.
type CalendarOperation interface { type CalendarOperation interface {
Execute(calendars ...*basetypes.Calendar) (*basetypes.Calendar, error) Execute(calendars ...basetypes.Calendar) (basetypes.Calendar, error)
} }

View file

@ -15,9 +15,9 @@ type FilterCalendarOperation struct {
var _ CalendarOperation = (*FilterCalendarOperation)(nil) var _ CalendarOperation = (*FilterCalendarOperation)(nil)
// Execute filters the events of a calendar and returns a new filtered calendar. // Execute filters the events of a calendar and returns a new filtered calendar.
func (op *FilterCalendarOperation) Execute(calendars ...*basetypes.Calendar) (*basetypes.Calendar, error) { func (op *FilterCalendarOperation) Execute(calendars ...basetypes.Calendar) (basetypes.Calendar, error) {
if len(calendars) != 1 { if len(calendars) != 1 {
return &basetypes.Calendar{}, errors.New("Filter operation requires exactly one calendar") return basetypes.Calendar{}, errors.New("Filter operation requires exactly one calendar")
} }
// Do your filter operation here and return the filtered calendar. // Do your filter operation here and return the filtered calendar.
return calendars[0], nil // Replace this with actual implementation return calendars[0], nil // Replace this with actual implementation

View file

@ -1,6 +1,8 @@
package calendarops package calendarops
import ( import (
"sort"
basetypes "code.apps.glenux.net/glenux/kiwimix/pkg/basetypes" basetypes "code.apps.glenux.net/glenux/kiwimix/pkg/basetypes"
) )
@ -17,33 +19,27 @@ func NewMergeCalendarOperation() *MergeCalendarOperation {
} }
// Execute réalise l'opération de fusion. // Execute réalise l'opération de fusion.
func (op *MergeCalendarOperation) Execute(cal ...*basetypes.Calendar) (*basetypes.Calendar, error) { func (op *MergeCalendarOperation) Execute(cal ...basetypes.Calendar) (basetypes.Calendar, error) {
// Guard: exit if no calendar provided if len(cal.Events) == 0 {
if len(cal) == 0 { return cal, nil
return nil, nil
} }
mergedEvents := cal[0].GetEvents() sort.Slice(cal.Event, func(i, j int) bool {
/* return cal.Event[i].Start.Before(cal.Event[j].Start)
events := cal.GetEvents() })
sort.Slice(cal.Event, func(i, j int) bool {
return cal.Event[i].Start.Before(cal.Event[j].Start)
})
mergedEvents := []basetypes.Event{cal.Event[0]} mergedEvents := []basetypes.Event{cal.Event[0]}
for _, event := range cal.Event[1:] { for _, event := range cal.Event[1:] {
lastEvent := &mergedEvents[len(mergedEvents)-1] lastEvent := &mergedEvents[len(mergedEvents)-1]
if event.Start.Before(lastEvent.End) || event.Start.Equal(lastEvent.End) { if event.Start.Before(lastEvent.End) || event.Start.Equal(lastEvent.End) {
if event.End.After(lastEvent.End) { if event.End.After(lastEvent.End) {
lastEvent.End = event.End lastEvent.End = event.End
}
} else {
mergedEvents = append(mergedEvents, event)
} }
} else {
mergedEvents = append(mergedEvents, event)
} }
*/ }
mergedCalendar := &basetypes.Calendar{}
mergedCalendar.AddEvents(mergedEvents) return &basetypes.Calendar{Events: mergedEvents}, nil
return mergedCalendar, nil
} }

View file

@ -1,24 +1,16 @@
package stackops package stackops
import ( import "time"
"time"
basetypes "code.apps.glenux.net/glenux/kiwimix/pkg/basetypes"
)
// GeneratorLimit is a type definining // GeneratorLimit is a type definining
type GenerateConfig struct { type GenerateConfig struct {
DateBegin *time.Time DateBegin *time.Date
DateEnd *time.Time DateEnd *time.Date
TimeBegin *time.Time TimeBegin *time.Time
TimeEnd *time.Time TimeEnd *time.Time
} }
type GenerateStackOperation struct{}
var _ StackOperation = (*GenerateStackOperation)(nil)
// generate events that last all day (from X hour to Y hour) // generate events that last all day (from X hour to Y hour)
func (op *GenerateStackOperation) Execute(stack *basetypes.Stack, str string) (*basetypes.Stack, error) { func (cal *Calendar) generate() *Calendar {
return nil, nil return nil
} }

View file

@ -6,8 +6,8 @@ import (
type LoadOperation struct{} type LoadOperation struct{}
func (op *LoadOperation) Execute(stack *basetypes.Stack, filePath string) error { func (op *LoadOperation) Execute(stack *basetypes.CalendarStack, filePath string) error {
cal, err := basetypes.ParseCalendarFile(filePath) // hypothetically, ParseICSFile parses an ICS file into a Calendar object cal, err := basetypes.ParseICSFile(filePath) // hypothetically, ParseICSFile parses an ICS file into a Calendar object
if err != nil { if err != nil {
return err return err
} }

View file

@ -13,7 +13,7 @@ func NewSaveOperation(filePath string) *SaveOperation {
return saveop return saveop
} }
func (op *SaveOperation) Execute(stack *basetypes.Stack) error { func (op *SaveOperation) Execute(stack *basetypes.CalendarStack) error {
cal, err := basetypes.ParseCalendarFile(op.filePath) cal, err := basetypes.ParseCalendarFile(op.filePath)
if err != nil { if err != nil {
return err return err

View file

@ -1,7 +1,5 @@
package stackops package stackops
import basetypes "code.apps.glenux.net/glenux/kiwimix/pkg/basetypes"
type StackOperation interface { type StackOperation interface {
Execute(stack *basetypes.Stack, filePath string) (*basetypes.Stack, error) Execute(stack *CalendarStack, filePath string) error
} }