Skip to content

Commit 04f5997

Browse files
authored
Merge pull request #204 from buggregator/issue/#139-multiple-projects-support
Issue/#139 multiple projects support
2 parents 01ab8b4 + 673d317 commit 04f5997

File tree

26 files changed

+468
-127
lines changed

26 files changed

+468
-127
lines changed

app.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<script lang="ts" setup>
66
import "./src/assets/index.css";
77
import "./src/assets/vendor";
8-
import { useSettingsStore } from "~/src/shared/stores";
8+
import { useEventsStore, useSettingsStore } from "~/src/shared/stores";
99
1010
useSettingsStore().initialize();
11+
useEventsStore().initialize();
1112
</script>

layouts/default.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<script lang="ts" setup>
2-
import { onMounted } from "vue";
2+
import { storeToRefs } from "pinia";
3+
import { watch } from "vue";
34
import { LayoutSidebar } from "~/src/widgets/ui";
45
import { useEvents } from "~/src/shared/lib/use-events";
56
import SfdumpWrap from "~/src/shared/lib/vendor/dumper";
7+
import { useEventsStore } from "~/src/shared/stores";
68
79
SfdumpWrap(window.document);
810
9-
onMounted(() => {
10-
const { events } = useEvents();
11+
const { activeProjectKey } = storeToRefs(useEventsStore());
12+
const { events } = useEvents();
1113
12-
if (!events?.items?.value?.length) {
14+
watch(
15+
() => activeProjectKey.value,
16+
() => {
1317
events.getAll();
14-
}
15-
});
18+
},
19+
{ immediate: true },
20+
);
1621
</script>
1722

1823
<template>

middleware/auth.global.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { navigateTo, defineNuxtRouteMiddleware } from "#app";
22
import { useSettings } from "~/src/shared/lib/use-settings";
3-
import {useSettingsStore} from "~/src/shared/stores";
4-
import { useProfileStore } from "~/src/shared/stores/profile"
3+
import {useSettingsStore, useProfileStore} from "~/src/shared/stores";
54

65
export default defineNuxtRouteMiddleware(async (to) => {
76
const { auth} = storeToRefs(useSettingsStore())

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"vue-eslint-parser": "^9.1.0"
6868
},
6969
"dependencies": {
70+
"@floating-ui/vue": "^1.1.2",
7071
"@highlightjs/vue-plugin": "^2.1.2",
7172
"@hpcc-js/wasm": "^2.8.0",
7273
"@pinia/nuxt": "^0.5.1",

pages/settings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useTitle } from "@vueuse/core";
33
import { storeToRefs } from "pinia";
44
import { computed } from "vue";
5-
import { useSettingsStore, THEME_MODES } from "~/src/shared/stores/settings";
5+
import { useSettingsStore, THEME_MODES } from "~/src/shared/stores";
66
import { AppHeader, BadgeNumber, IconSvg } from "~/src/shared/ui";
77
88
const settingsStore = useSettingsStore();

src/assets/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import "vendor.css";
22

33
body {
4-
@apply bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-50 p-0;
4+
@apply bg-gray-50 dark:bg-gray-800 text-gray-800 dark:text-gray-50 p-0;
55
}
66

77
body a:hover {

src/shared/lib/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './htmlEncode';
2+
export * from './textToColors';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const textToColors = (input: string): string[] => {
2+
// Utility function to convert a character to a base hue value
3+
const charToHue = (char: string): number => {
4+
const code = char.toLowerCase().charCodeAt(0);
5+
return (code - 97) * 20 % 360; // Map 'a' to 'z' to a hue value between 0 and 360
6+
};
7+
8+
// Function to generate an HSL color based on a base hue
9+
const getHslColor = (hue: number) => `hsl(${hue}, 70%, 50%)`;
10+
11+
// Extract up to three characters from the input string
12+
const chars = input.length >= 3 ? input.slice(0, 3).split('') : input.padEnd(3, input[0]).slice(0, 3).split('');
13+
14+
// Calculate the hue for each character
15+
// Generate the HSL colors list
16+
return chars.map(charToHue).map(getHslColor);
17+
}

src/shared/lib/io/use-events-requests.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {useProfileStore} from "../../stores/profile";
1+
import {storeToRefs} from "pinia";
2+
import {useEventsStore, useProfileStore} from "../../stores";
23
import type { EventId, EventType, ServerEvent } from '../../types';
34
import { REST_API_URL } from "./constants";
45

@@ -16,10 +17,13 @@ type TUseEventsRequests = () => {
1617
export const useEventsRequests: TUseEventsRequests = () => {
1718
const { token } = storeToRefs(useProfileStore())
1819

20+
const { activeProjectKey: project } = storeToRefs(useEventsStore())
21+
1922
const headers = {"X-Auth-Token": token.value }
20-
const getEventRestUrl = (param?: string): string => `${REST_API_URL}/api/event${param ? `/${param}` : 's'}`
23+
const getEventRestUrl = (param: string): string => `${REST_API_URL}/api/event/${param}${project.value ? `?project=${project.value}` : ''}`
24+
const getEventsRestUrl = (): string => `${REST_API_URL}/api/events${project.value ? `?project=${project.value}` : ''}`
2125

22-
const getAll = () => fetch(getEventRestUrl(), { headers })
26+
const getAll = () => fetch(getEventsRestUrl(), { headers })
2327
.then((response) => response.json())
2428
.then((response) => {
2529
if (response?.data) {
@@ -46,17 +50,25 @@ export const useEventsRequests: TUseEventsRequests = () => {
4650
return null;
4751
})
4852

49-
const deleteSingle = (id: EventId) => fetch(getEventRestUrl(id), {method: 'DELETE', headers})
53+
const deleteSingle = (id: EventId) => fetch(getEventRestUrl(id), {
54+
method: 'DELETE',
55+
headers,
56+
...(project.value ? { body: JSON.stringify({project: project.value }) } : null)
57+
})
5058
.catch((err) => {
5159
console.error('Fetch Error', err)
5260
})
5361

54-
const deleteAll = () => fetch(getEventRestUrl(), {method: 'DELETE', headers})
62+
const deleteAll = () => fetch(getEventsRestUrl(), {
63+
method: 'DELETE',
64+
headers,
65+
...(project.value ? { body: JSON.stringify({project: project.value}) } : null)
66+
})
5567
.catch((err) => {
5668
console.error('Fetch Error', err)
5769
})
5870

59-
const deleteList = (uuids: EventId[]) => fetch(getEventRestUrl(), {
71+
const deleteList = (uuids: EventId[]) => fetch(getEventsRestUrl(), {
6072
method: 'DELETE',
6173
headers,
6274
body: JSON.stringify({uuids})
@@ -65,10 +77,13 @@ export const useEventsRequests: TUseEventsRequests = () => {
6577
console.error('Fetch Error', err)
6678
})
6779

68-
const deleteByType = (type: EventType) => fetch(getEventRestUrl(), {
80+
const deleteByType = (type: EventType) => fetch(getEventsRestUrl(), {
6981
method: 'DELETE',
7082
headers,
71-
body: JSON.stringify({type})
83+
body: JSON.stringify({
84+
type,
85+
...(project.value ? { project: project.value } : null),
86+
})
7287
})
7388
.catch((err) => {
7489
console.error('Fetch Error', err)

src/shared/lib/io/use-smtp-requests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useProfileStore} from "../../stores/profile";
1+
import {useProfileStore} from "../../stores";
22
import type { EventId, Attachment } from "../../types";
33
import { REST_API_URL } from "./constants";
44

0 commit comments

Comments
 (0)