Skip to content

Commit

Permalink
feat: remove dexie from calendar system and fix date end of month issue
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Dec 22, 2024
1 parent 8f4fa7a commit ca64a7e
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 219 deletions.
11 changes: 6 additions & 5 deletions app/components/wiki/PagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
import type { NavItem } from '@nuxt/content';
import type { PageShort } from '~~/gen/ts/resources/wiki/page';
const props = defineProps<{
pages: PageShort[];
}>();
const { t } = useI18n();
function mapNavItemToNavItem(page: PageShort): NavItem {
const fullPath = `/wiki/${page.job}/${page.id}/${page.slug ?? ''}`;
return {
_id: page.id,
title: page.title !== '' ? page.title : `${page?.jobLabel ? page?.jobLabel + ': ' : ''}${t('common.wiki')}`,
_path: `/wiki/${page.job}/${page.id}/${page.slug ?? ''}`,
_path: fullPath,
children: page.children.map((p) => mapNavItemToNavItem(p)),
icon: page.deletedAt !== undefined ? 'i-mdi-trash-can' : undefined,
};
}
const props = defineProps<{
pages: PageShort[];
}>();
const navItems = computed(() => props.pages.map((p) => mapNavItemToNavItem(p)) ?? []);
</script>

Expand Down
109 changes: 0 additions & 109 deletions app/composables/useDexieLiveQuery.ts

This file was deleted.

4 changes: 3 additions & 1 deletion app/pages/calendar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const {
);
watchDebounced(currentDate.value, async () => refresh(), { debounce: 100, maxWait: 1000 });
watchDebounced(activeCalendarIds, async () => refresh());
function formatStartEndTime(entry: CalendarEntry): string {
const start = toDate(entry.startTime);
Expand Down Expand Up @@ -634,10 +635,11 @@ const isOpen = ref(false);
</ClientOnly>
</UFormGroup>

<UTooltip :text="$t('common.refresh')">
<UTooltip :text="$t('common.refresh')" class="inline-flex w-full">
<UButton
icon="i-mdi-refresh"
variant="outline"
class="w-full"
:disabled="loading || loadingState"
:loading="loading || loadingState"
@click="refresh()"
Expand Down
22 changes: 0 additions & 22 deletions app/store/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { format } from 'date-fns';
import Dexie, { type Table } from 'dexie';
import 'dexie-observable';
import 'dexie-syncable';
import { defineStore } from 'pinia';
import type { Calendar, CalendarEntry } from '~~/gen/ts/resources/calendar/calendar';
import { RsvpResponses } from '~~/gen/ts/resources/calendar/calendar';
Expand Down Expand Up @@ -70,9 +67,6 @@ export const useCalendarStore = defineStore('calendar', {

const now = new Date();
response.entries.forEach((entry) => {
calendarDB.entries.add(entry);
calendarDB.entries.delete(entry);

const startTime = toDate(entry.startTime);
const time = startTime.getTime() - now.getTime();

Expand Down Expand Up @@ -367,22 +361,6 @@ export const useCalendarStore = defineStore('calendar', {
},
});

class CalendarDexie extends Dexie {
calendars!: Table<Calendar>;
entries!: Table<CalendarEntry>;

constructor() {
super('calendar');
this.version(1).stores({
calendars: 'id',
entries: 'id, calendarId',
rsvps: 'entry_id, user_id',
});
}
}

export const calendarDB = new CalendarDexie();

if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useCalendarStore, import.meta.hot));
}
11 changes: 9 additions & 2 deletions gen/go/proto/services/calendar/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/fivenet-app/fivenet/query/fivenet/table"
jet "github.com/go-jet/jet/v2/mysql"
"github.com/go-jet/jet/v2/qrm"
"github.com/jinzhu/now"
)

func (s *Server) ListCalendarEntries(ctx context.Context, req *ListCalendarEntriesRequest) (*ListCalendarEntriesResponse, error) {
Expand Down Expand Up @@ -68,8 +69,12 @@ func (s *Server) ListCalendarEntries(ctx context.Context, req *ListCalendarEntri
condition = condition.AND(tCalendar.UpdatedAt.GT_EQ(jet.TimestampT(req.After.AsTime())))
}

condition = condition.AND(tCalendarEntry.StartTime.GT_EQ(jet.DateTime(int(req.Year), time.Month(req.Month), 1, 0, 0, 0))).
AND(tCalendarEntry.StartTime.LT(jet.DateTime(int(req.Year), time.Month(req.Month+1), 1, 0, 0, 0)))
baseDate := now.New(time.Date(int(req.Year), time.Month(req.Month), 1, 0, 0, 0, 0, time.Local))
startDate := baseDate.BeginningOfMonth()
endDate := baseDate.EndOfMonth()

condition = condition.AND(tCalendarEntry.StartTime.GT_EQ(jet.DateTimeT(startDate))).
AND(tCalendarEntry.StartTime.LT(jet.DateTimeT(endDate)))

resp := &ListCalendarEntriesResponse{}

Expand Down Expand Up @@ -132,9 +137,11 @@ func (s *Server) GetUpcomingEntries(ctx context.Context, req *GetUpcomingEntries
tCalendarEntry.CreatorID.EQ(jet.Int32(userInfo.UserId)),
),
tCalendarEntry.StartTime.LT_EQ(
// Now plus X seconds
jet.CURRENT_TIMESTAMP().ADD(jet.INTERVALd(time.Duration(req.Seconds)*time.Second)),
),
tCalendarEntry.StartTime.GT_EQ(
// Now minus 1 minute
jet.CURRENT_TIMESTAMP().SUB(jet.INTERVALd(1*time.Minute)),
),
)
Expand Down
21 changes: 13 additions & 8 deletions gen/go/proto/services/centrum/centrummanager/housekeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,9 @@ func (s *Housekeeper) checkUnitUsers(ctx context.Context) error {
continue
}

unitId, _ := s.GetUserUnitID(ctx, userId)
unitId, found := s.GetUserUnitID(ctx, userId)
// If user is in that unit and still on duty, nothing to do, otherwise remove the user from the unit
if unit.Id == unitId && s.tracker.IsUserOnDuty(userId) {
if found && unit.Id == unitId && s.tracker.IsUserOnDuty(userId) {
foundUserIds = append(foundUserIds, userId)
continue
}
Expand All @@ -770,23 +770,28 @@ func (s *Housekeeper) checkUnitUsers(ctx context.Context) error {
}
}

userUnitIds, err := s.State.ListUserIdsFromUserIdUnitIds(ctx)
userUnitIds, err := s.State.ListUserUnitMappings(ctx)
if err != nil {
return err
}

errs := multierr.Combine()
for _, userId := range userUnitIds {
// Check if user id with unit mapping is in one of the units
if !slices.Contains(foundUserIds, userId) {
s.logger.Warn("found invalid user id unit mapping", zap.Int32("user_id", userId))
for _, userUnit := range userUnitIds {
// Check if user id is part of an unit
if slices.Contains(foundUserIds, userUnit.UserId) {
continue
}

s.logger.Warn("found user id with unit mapping that isn't in any unit", zap.Int32("user_id", userUnit.UserId), zap.Int32s("users_in_units", foundUserIds), zap.Any("mapping", userUnit))

// TODO this isn't working as intended at the moment
/*
// Unset unit id for user when user is not in any unit
if err := s.UnsetUnitIDForUser(ctx, userId); err != nil {
errs = multierr.Append(errs, err)
continue
}
}
*/
}

return errs
Expand Down
1 change: 0 additions & 1 deletion gen/go/proto/services/centrum/centrummanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func (s *Manager) loadData(ctx context.Context) error {
return nil
ctx, span := s.tracer.Start(ctx, "centrum-loaddata")
defer span.End()

Expand Down
16 changes: 5 additions & 11 deletions gen/go/proto/services/centrum/centrumstate/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package centrumstate

import (
"context"
"strconv"

"github.com/fivenet-app/fivenet/gen/go/proto/resources/centrum"
"github.com/fivenet-app/fivenet/gen/go/proto/resources/timestamp"
Expand Down Expand Up @@ -36,20 +35,15 @@ func (s *State) UnsetUnitIDForUser(ctx context.Context, userId int32) error {
return s.userIDToUnitID.Delete(ctx, userIdKey(userId))
}

func (s *State) ListUserIdsFromUserIdUnitIds(ctx context.Context) ([]int32, error) {
keys, err := s.userIDToUnitID.Keys(ctx, "")
func (s *State) ListUserUnitMappings(ctx context.Context) (map[int32]*centrum.UserUnitMapping, error) {
mappings, err := s.userIDToUnitID.List()
if err != nil {
return nil, err
}

ids := make([]int32, len(keys))
for idx := range keys {
id, err := strconv.Atoi(keys[idx])
if err != nil {
continue
}

ids[idx] = int32(id)
ids := map[int32]*centrum.UserUnitMapping{}
for _, m := range mappings {
ids[m.UserId] = m
}

return ids, nil
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.2.0
github.com/h2non/filetype v1.1.3
github.com/improbable-eng/grpc-web v0.15.0
github.com/jinzhu/now v1.1.5
github.com/json-iterator/go v1.1.12
github.com/microcosm-cc/bluemonday v1.0.27
github.com/minio/minio-go/v7 v7.0.82
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
"browser-headers": "0.4.1",
"consola": "3.3.0",
"date-fns": "4.1.0",
"dexie": "4.0.10",
"dexie-observable": "4.0.1-beta.13",
"dexie-syncable": "4.0.1-beta.13",
"emoji-blast": "0.10.2",
"google-protobuf": "3.21.4",
"grpc-web": "1.5.0",
Expand Down Expand Up @@ -97,9 +94,9 @@
"@types/splitpanes": "2.2.6",
"@types/uuid": "10.0.0",
"@types/zxcvbn": "4.4.5",
"@vueuse/core": "12.0.0",
"@vueuse/nuxt": "12.0.0",
"@vueuse/router": "12.0.0",
"@vueuse/core": "12.1.0",
"@vueuse/nuxt": "12.1.0",
"@vueuse/router": "12.1.0",
"autoprefixer": "10.4.20",
"cssnano": "7.0.6",
"eslint": "9.17.0",
Expand Down
Loading

0 comments on commit ca64a7e

Please sign in to comment.