fix:#30 updated files in pwa

This commit is contained in:
Elmar Kresse
2024-07-24 14:13:28 +02:00
parent b7b996ffdf
commit be1300d221
17 changed files with 4280 additions and 630 deletions

View File

@@ -0,0 +1,34 @@
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
package model
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
type RoomOccupancy struct {
Name string `bson:"name"`
Occupancy primitive.Binary `bson:"occupancy"`
}
type RoomOccupancyList struct {
Start time.Time `bson:"start"`
Granularity int `bson:"granularity"`
Blocks int `bson:"blocks"`
Rooms []RoomOccupancy `bson:"rooms"`
}

View File

@@ -194,14 +194,14 @@ func AddRoutes(services serviceModel.Service) {
})
// API Endpoint to get room occupancy for a time period for all rooms, when requested as BSON
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
services.App.OnBeforeServe().Add(func(e *core.ServeEvent) error {
_, err := e.Router.AddRoute(echo.Route{
Method: http.MethodGet,
Path: "/api/schedule/rooms",
Handler: func(c echo.Context) error {
from := c.QueryParam("from")
to := c.QueryParam("to")
rooms, err := room.GetRoomOccupancyList(app, from, to, RoomOccupancyGranularity)
rooms, err := room.GetRoomOccupancyList(services.App, from, to, RoomOccupancyGranularity)
if err != nil {
slog.Error("Failed to get room occupancy: %v", "error", err)
@@ -218,7 +218,7 @@ func AddRoutes(services serviceModel.Service) {
return c.Blob(http.StatusOK, "application/bson", bson_coded)
},
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
apis.ActivityLogger(services.App),
},
})
if err != nil {

View File

@@ -14,20 +14,14 @@
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
import { defineStore } from "pinia";
import { useLocalStorage } from "@vueuse/core";
package functions
const localeStore = defineStore("localeStore", {
state: () => {
return {
locale: useLocalStorage("locale", "de"), //useLocalStorage takes in a key of 'count' and default value of 0
};
},
actions: {
setLocale(locale: string) {
this.locale = locale;
},
},
});
export default localeStore;
// function to filter an array
func Filter[T any](ss []T, test func(T) bool) (ret []T) {
for _, s := range ss {
if test(s) {
ret = append(ret, s)
}
}
return
}

View File

@@ -0,0 +1,103 @@
//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
package functions
import (
"reflect"
"strings"
"testing"
)
func Test_Filter_number(t *testing.T) {
type args struct {
ss []int
test func(int) bool
}
tests := []struct {
name string
args args
wantRet []int
}{
{
"filter even numbers",
args{
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
func(i int) bool {
return i%2 == 0
},
},
[]int{2, 4, 6, 8, 10},
},
{
"filter smaller than 5",
args{
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
func(i int) bool {
return i < 5
},
},
[]int{1, 2, 3, 4},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotRet := Filter(tt.args.ss, tt.args.test); !reflect.DeepEqual(gotRet, tt.wantRet) {
t.Errorf("filter() = %v, want %v", gotRet, tt.wantRet)
}
})
}
}
func Test_Filter_string(t *testing.T) {
type args struct {
ss []string
test func(string) bool
}
tests := []struct {
name string
args args
wantRet []string
}{
{
"filter contains a",
args{
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
func(i string) bool {
return strings.Contains(i, "a")
},
},
[]string{"a"},
},
{
"filter starts with prefix 'a'",
args{
[]string{"alpha", "beta", "a", "ab", "ac", "delta"},
func(i string) bool {
return strings.HasPrefix(i, "a")
},
},
[]string{"alpha", "a", "ab", "ac"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotRet := Filter(tt.args.ss, tt.args.test); !reflect.DeepEqual(gotRet, tt.wantRet) {
t.Errorf("filter() = %v, want %v", gotRet, tt.wantRet)
}
})
}
}

View File

@@ -18,19 +18,14 @@ package room
import (
"github.com/pocketbase/pocketbase"
"go.mongodb.org/mongo-driver/bson/primitive"
"htwkalender/data-manager/model"
"htwkalender/data-manager/service/db"
"htwkalender/data-manager/service/functions"
"htwkalender/model"
"htwkalender/service/db"
"htwkalender/service/functions"
"math"
"regexp"
"strings"
"time"
"github.com/pocketbase/pocketbase"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// maximum number of blocks is around 6 months with 15 minute granularity (180 * 24 * 4 = 17280)