Rework to use marbas and authentik instead of poketbase (#1)

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2024-05-17 23:00:52 +02:00
parent 9fb78329cc
commit 717eaa6ed8
47 changed files with 2306 additions and 1049 deletions

View File

@@ -0,0 +1,8 @@
import { MarketType } from "..";
import { AcquiredMarketType } from "./acquisition";
export type AcquiredType = Omit<AcquiredMarketType, 'type'> & {
type: MarketType,
buy: number,
sell: number
}

View File

@@ -2,7 +2,7 @@
import { LoadingSpinner, Tooltip } from '@/components';
import { formatIsk } from '@/formaters';
import { getHistory, jitaId } from '@/market';
import { getHistoryQuartils } from '@/market/scan';
import { getHistoryQuartils } from '@/market/tracking';
import { ArrowTrendingDownIcon, ArrowTrendingUpIcon } from '@heroicons/vue/24/outline';
import { computedAsync } from '@vueuse/core';
import { ref, watchEffect } from 'vue';

View File

@@ -5,8 +5,8 @@ import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/mark
import { MinusIcon, PlusIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core';
import { computed, ref } from 'vue';
import { TrackedItem } from '.';
import TrackQuantilsTooltip from './TrackQuantilsTooltip.vue';
import { AcquiredType } from './AcquiredType';
import AcquisitionQuantilsTooltip from './AcquisitionQuantilsTooltip.vue';
type Result = {
type: MarketType;
@@ -21,7 +21,7 @@ type Result = {
}
interface Props {
items?: TrackedItem[];
items?: AcquiredType[];
}
interface Emits {
@@ -36,12 +36,12 @@ defineEmits<Emits>();
const marketTaxStore = useMarketTaxStore();
const threshold = useStorage('market-track-threshold', 10);
const threshold = useStorage('market-acquisition-threshold', 10);
const filter = ref("");
const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
.filter(r => r.type.name.toLowerCase().includes(filter.value.toLowerCase()))
.map(r => {
const precentProfit = marketTaxStore.calculateProfit(r.averagePrice, r.sell);
const precentProfit = marketTaxStore.calculateProfit(r.price, r.sell);
return {
type: r.type,
@@ -49,10 +49,10 @@ const { sortedArray, headerProps } = useSort<Result>(computed(() => props.items
name: r.type.name,
buy: r.buy,
sell: r.sell,
price: r.averagePrice,
count: r.count,
price: r.price,
count: r.remaining,
precentProfit,
iskProfit: r.averagePrice * precentProfit * r.count
iskProfit: r.price * precentProfit * r.remaining
};
})), {
defaultSortKey: 'precentProfit',
@@ -100,14 +100,14 @@ const getLineColor = (result: Result) => {
<td>
<div class="flex">
<MarketTypeLabel :id="r.typeID" :name="r.name" />
<TrackQuantilsTooltip :id="r.typeID" :buy="r.buy" :sell="r.sell" />
<AcquisitionQuantilsTooltip :id="r.typeID" :buy="r.buy" :sell="r.sell" />
</div>
</td>
<td class="text-right">{{ formatIsk(r.buy) }}</td>
<td class="text-right">{{ formatIsk(r.sell) }}</td>
<td class="text-right">{{ formatIsk(r.price) }}</td>
<td class="text-right">{{ r.count }}</td>
<td class="text-right">{{ percentFormater.format(r.precentProfit) }}</td>
<td class="text-right">{{ percentFormater.format(r.precentProfit) }}</td>
<td class="text-right">{{ formatIsk(r.iskProfit) }}</td>
<td class="text-right">
<button class="btn-icon me-1" @click="$emit('buy', r.type, r.price, r.buy, r.sell)"><PlusIcon /></button>
@@ -122,4 +122,4 @@ const getLineColor = (result: Result) => {
div.end {
@apply justify-self-end ms-2;
}
</style>@/components/table
</style>

View File

@@ -3,10 +3,10 @@ import { Modal } from '@/components';
import { formatIsk } from '@/formaters';
import { MarketType, MarketTypeLabel } from '@/market';
import { ref } from 'vue';
import { useTrackedItemStore } from './track';
import { useAcquiredTypesStore } from './acquisition';
const trackedItemStore = useTrackedItemStore();
const acquiredTypesStore = useAcquiredTypesStore();
const modalOpen = ref<boolean>(false);
const type = ref<MarketType>();
@@ -38,7 +38,7 @@ const add = () => {
return;
}
trackedItemStore.addTrackedItem(id, count.value, price.value);
acquiredTypesStore.addType(id, count.value, price.value);
modalOpen.value = false;
}

View File

@@ -2,10 +2,10 @@
import { Modal } from '@/components';
import { MarketType, MarketTypeLabel } from '@/market';
import { ref } from 'vue';
import { useTrackedItemStore } from './track';
import { useAcquiredTypesStore } from './acquisition';
const trackedItemStore = useTrackedItemStore();
const acquiredTypesStore = useAcquiredTypesStore();
const modalOpen = ref<boolean>(false);
const type = ref<MarketType>();
@@ -24,7 +24,7 @@ const remove = () => {
return;
}
trackedItemStore.removeTrackedItem(id, count.value);
acquiredTypesStore.removeType(id, count.value);
modalOpen.value = false;
}

View File

@@ -0,0 +1,63 @@
import { marbasAxiosInstance } from "@/service";
import { defineStore } from "pinia";
import { computed, ref } from "vue";
export type AcquiredMarketType = {
id: number;
type: number;
quantity: number;
remaining: number;
price: number;
date: Date;
source: 'bo' | 'so' | 'prod';
user: number;
}
const endpoint = '/api/acquisitions/';
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
const acquiredTypes = ref<AcquiredMarketType[]>([]);
const types = computed(() => acquiredTypes.value);
const addType = async (type: number, quantity: number, price: number) => {
acquiredTypes.value = [...acquiredTypes.value, (await marbasAxiosInstance.post<AcquiredMarketType>(endpoint, {
type: type,
quantity: quantity,
remaining: quantity,
price: price,
date: new Date(),
source: 'bo'
})).data];
};
const removeType = async (type: number, quantity: number) => {
const found = acquiredTypes.value.find(item => item.type === type);
if (!found) {
return;
}
if (found.remaining <= 0) {
acquiredTypes.value = acquiredTypes.value.filter(i => i.type !== type);
} else {
acquiredTypes.value = acquiredTypes.value.map(i => {
if (i.type === item.type) {
return item;
} else {
return i;
}
});
}
const item = {
...found,
remaining: found.remaining - quantity
};
await marbasAxiosInstance.put(`${endpoint}${item.id}`, item);
};
marbasAxiosInstance.get<AcquiredMarketType[]>(endpoint).then(res => acquiredTypes.value = res.data.filter(item => item.remaining > 0));
return { types, addType, removeType };
});

View File

@@ -0,0 +1,7 @@
export * from './AcquiredType';
export * from './acquisition';
export { default as AcquisitionResultTable } from './AcquisitionResultTable.vue';
export { default as BuyModal } from './BuyModal.vue';
export { default as SellModal } from './SellModal.vue';

View File

@@ -4,7 +4,7 @@ import { MarketType } from "../type";
import { PriceGetter } from './MarketTypePrice';
export const evepraisalAxiosInstance = axios.create({
baseURL: '/evepraisal/',
baseURL: import.meta.env.VITE_EVEPRAISAL_URL,
headers: {
'accept': 'application/json',
"Content-Type": "application/json"

View File

@@ -4,7 +4,7 @@ import { MarketType } from "../type";
import { PriceGetter } from './MarketTypePrice';
export const fuzzworkAxiosInstance = axios.create({
baseURL: '/fuzzwork/',
baseURL: import.meta.env.VITE_FUZZWORK_URL,
headers: {
'accept': 'application/json',
"Content-Type": "application/json"

View File

@@ -1,5 +0,0 @@
export * from './HistoryQuartils';
export * from './scan';
export { default as ScanResultTable } from './ScanResultTable.vue';

View File

@@ -1,56 +0,0 @@
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, jitaId } from "@/market";
import { usePocketBase, watchCollection } from "@/pocketbase";
import { defineStore } from "pinia";
import { RecordModel } from "pocketbase";
import { computed, onMounted, ref } from "vue";
export type ScanResult = {
type: MarketType;
history: MarketOrderHistory[];
buy: number,
sell: number,
orderCount: number,
}
interface MarketScan extends RecordModel {
owner: string;
types: number[];
};
const marketScans = 'marketScans';
export const useMarketScanStore = defineStore(marketScans, () => {
const pb = usePocketBase();
const marketScan = ref<MarketScan>();
const types = computed(() => marketScan.value?.types ?? []);
const setTypes = async (types: number[]) => {
if (marketScan.value?.id) {
marketScan.value = await pb.collection(marketScans).update(marketScan.value.id, { owner: pb.authStore.model!.id, types });
} else {
marketScan.value = await pb.collection(marketScans).create({ owner: pb.authStore.model!.id, types });
}
}
const addType = async (type: number) => {
if (!types.value.includes(type)) {
await setTypes([...types.value, type]);
}
}
const removeType = async (type: number) => {
if (types.value.includes(type)) {
await setTypes(types.value.filter(t => t !== type));
}
}
watchCollection<MarketScan>(marketScans, '*', data => {
if (data.action === 'delete') {
marketScan.value = undefined;
} else if (!marketScan.value || data.record.id === marketScan.value.id) {
marketScan.value = data.record;
}
});
onMounted(async () => marketScan.value = await pb.collection(marketScans).getFirstListItem<MarketScan>('').catch(() => undefined));
return { types, setTypes, addType, removeType };
});
export const createResult = async (id: number, price: MarketTypePrice): Promise<ScanResult> => ({ history: await getHistory(jitaId, id), ...price });

View File

@@ -1,9 +0,0 @@
import { MarketType } from "@/market";
export type TrackedItem = {
type: MarketType;
count: number;
averagePrice: number;
buy: number,
sell: number
}

View File

@@ -1,7 +0,0 @@
export * from './TrackedItem';
export * from './track';
export { default as BuyModal } from './BuyModal.vue';
export { default as SellModal } from './SellModal.vue';
export { default as TrackResultTable } from './TrackResultTable.vue';

View File

@@ -1,58 +0,0 @@
import { useCollection, usePocketBase } from "@/pocketbase";
import { createSharedComposable, useLocalStorage } from '@vueuse/core';
import { defineStore } from "pinia";
import { RecordModel } from "pocketbase";
import { computed } from "vue";
export type TrackedMarketItemStorage = {
typeID: number;
count: number;
averagePrice: number;
}
interface TrackedMarketItem extends RecordModel {
owner: string;
typeID: number;
count: number;
averagePrice: number;
}
const marketTrackings = 'marketTrackings';
export const useTrackedItemsStorage = createSharedComposable(() => useLocalStorage<TrackedMarketItemStorage[]>('market-track-items', []));
export const useTrackedItemStore = defineStore(marketTrackings, () => {
const pb = usePocketBase();
const trackedItems = useCollection<TrackedMarketItem>(marketTrackings);
const items = computed(() => trackedItems);
const addTrackedItem = async (typeID: number, count: number, averagePrice: number) => {
const oldItem = trackedItems.value.find(i => i.typeID === typeID);
if (oldItem?.id) {
pb.collection(marketTrackings).update(oldItem.id, {
...oldItem,
count: count + oldItem.count,
averagePrice: ((averagePrice * count) + (oldItem.averagePrice * oldItem.count)) / (count + oldItem.count)
});
} else {
pb.collection(marketTrackings).create({ owner: pb.authStore.model!.id, typeID, count, averagePrice});
}
};
const removeTrackedItem = async (typeID: number, count: number) => {
const oldItem = trackedItems.value.find(i => i.typeID === typeID);
if (!oldItem?.id) {
return;
} else if (oldItem.count > count) {
pb.collection(marketTrackings).update(oldItem.id, {
...oldItem,
count: oldItem.count - count
});
} else {
pb.collection(marketTrackings).delete(oldItem.id);
}
};
return { items, addTrackedItem, removeTrackedItem };
});

View File

@@ -6,7 +6,7 @@ import { MarketType, MarketTypeLabel, TaxInput, useMarketTaxStore } from "@/mark
import { BookmarkSlashIcon, ShoppingCartIcon } from '@heroicons/vue/24/outline';
import { useStorage } from '@vueuse/core';
import { computed, ref } from 'vue';
import { ScanResult, getHistoryQuartils } from '.';
import { TrackingResult, getHistoryQuartils } from '.';
type Result = {
type: MarketType;
@@ -22,7 +22,7 @@ type Result = {
}
interface Props {
items?: ScanResult[];
items?: TrackingResult[];
infoOnly?: boolean;
ignoredColums?: string[];
}
@@ -45,8 +45,8 @@ defineEmits<Emits>();
const marketTaxStore = useMarketTaxStore();
const days = useStorage('market-scan-days', 365);
const threshold = useStorage('market-scan-threshold', 10);
const days = useStorage('market-tracking-days', 365);
const threshold = useStorage('market-tracking-threshold', 10);
const filter = ref("");
const onlyCheap = ref(false);
const columnsToIgnore = computed(() => {
@@ -153,4 +153,4 @@ const getLineColor = (result: Result) => {
div.end {
@apply justify-self-end ms-2;
}
</style>@/components/table
</style>

View File

@@ -0,0 +1,5 @@
export * from './HistoryQuartils';
export * from './tracking';
export { default as TrackingResultTable } from './TrackingResultTable.vue';

View File

@@ -0,0 +1,41 @@
import { MarketOrderHistory, MarketType, MarketTypePrice, getHistory, jitaId } from "@/market";
import { marbasAxiosInstance } from "@/service";
import { defineStore } from "pinia";
import { computed, ref } from "vue";
export type TrackingResult = {
type: MarketType;
history: MarketOrderHistory[];
buy: number,
sell: number,
orderCount: number,
}
type MarketTracking = {
id: number,
type: number
};
const endpoint = '/api/types_tracking/';
export const useMarketTrackingStore = defineStore('marketTracking', () => {
const trackedTypes = ref<number[]>([]);
const types = computed(() => trackedTypes.value ?? []);
const addType = async (type: number) => {
if (!trackedTypes.value.includes(type)) {
await marbasAxiosInstance.post(endpoint, { type });
}
}
const removeType = async (type: number) => {
if (trackedTypes.value.includes(type)) {
await marbasAxiosInstance.delete(`${endpoint}${type}`);
}
}
marbasAxiosInstance.get<MarketTracking[]>(endpoint).then(res => trackedTypes.value = res.data.map(item => item.type));
return { types, addType, removeType };
});
export const createResult = async (id: number, price: MarketTypePrice): Promise<TrackingResult> => ({ history: await getHistory(jitaId, id), ...price });

View File

@@ -96,7 +96,7 @@ watchEffect(async () => {
<template>
<div @click="() => isOpen = true" v-on-click-outside="() => isOpen = false">
<div class="fake-input">
<img v-if="value?.id" :src="`https://images.evetech.net/types/${value.id}/icon`" />
<img v-if="value?.id" :src="`https://images.evetech.net/types/${value.id}/icon`" alt="" />
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
</div>
<div v-if="suggestions.length > 1" class="z-10 absolute w-96">

View File

@@ -17,7 +17,7 @@ withDefaults(defineProps<Props>(), {
<template>
<div v-if="id || name">
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon`" class="inline-block w-5 h-5 me-1" />
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon`" class="inline-block w-5 h-5 me-1" alt="" />
<template v-if="name">
{{ name }}
<ClipboardButton v-if="!hideCopy" :value="name" />