Compare commits

...

8 Commits

Author SHA1 Message Date
e81fdc24bb fix is logged in check 2025-05-10 09:33:43 +02:00
778de8ca14 update an fix login 2025-05-10 09:30:16 +02:00
00c37c0a37 update an cleanup 2025-03-08 14:38:05 +01:00
a56580ce27 refresh acquisitions 2024-06-18 12:02:56 +02:00
11f886cd71 Add total if name is missing 2024-06-04 16:18:52 +02:00
ac07236936 total in acquisition table 2024-06-04 14:39:48 +02:00
9aa37b355e tracking progress bar 2024-06-02 16:51:06 +02:00
12ad7d36ff cleanup acquisitions 2024-06-02 15:50:17 +02:00
14 changed files with 1265 additions and 1165 deletions

2278
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,7 @@
"@vueuse/integrations": "^10.2.1",
"axios": "^1.4.0",
"axios-rate-limit": "^1.3.1",
"gemory": "file:",
"loglevel": "^1.8.1",
"loglevel-plugin-prefix": "^0.8.4",
"oidc-client-ts": "^3.0.1",
@@ -30,9 +31,9 @@
"postcss": "^8.4.27",
"tailwindcss": "^3.3.3",
"typescript": "^5.0.2",
"vite": "^5.2.11",
"vite": "^6.3.5",
"vite-plugin-runtime-env": "^0.1.1",
"vitest": "^1.6.0",
"vitest": "^3.1.3",
"vue-tsc": "^2.0.18"
}
}

View File

@@ -17,7 +17,7 @@ export const useAuthStore = defineStore('auth', () => {
});
const user = ref<User>();
const isLoggedIn = computed(() => !!user.value);
const isLoggedIn = computed(() => user.value?.expired === false);
const accessToken = computed(() => user.value?.access_token);
const username = computed(() => user.value?.profile.name ?? "");
const userId = computed(() => user.value?.profile.sub ?? "");

View File

@@ -0,0 +1,19 @@
<script setup lang="ts">
import { computed } from 'vue';
interface Props {
value: number;
total: number;
}
const props = defineProps<Props>();
const percentage = computed(() => (props.value / props.total) * 100);
</script>
<template>
<div class="w-full bg-gray-600 rounded-full h-2.5">
<div class="bg-emerald-600 h-2.5 rounded-full" :style="{ width: percentage + '%'}" />
</div>
</template>

View File

@@ -2,6 +2,7 @@ export { default as ClipboardButton } from './ClipboardButton.vue';
export { default as Dropdown } from './Dropdown.vue';
export { default as LoadingSpinner } from './LoadingSpinner.vue';
export { default as Modal } from './Modal.vue';
export { default as ProgressBar } from './ProgressBar.vue';
export { default as SliderCheckbox } from './SliderCheckbox.vue';
export { default as Tooltip } from './tooltip/Tooltip.vue';

View File

@@ -6,7 +6,8 @@ interface Props {
list?: any[];
itemHeight: number;
headerHeight?: number;
bottom?: string;
footerHeight?: number;
bottom?: string; // FIXME: use css variable
}
@@ -35,11 +36,16 @@ const computedHeaderHeight = computed(() => {
return h + 'px';
})
const computedFooterHeight = computed(() => {
const h = props.footerHeight ?? 0;
return h + 'px';
})
const computedWrapperProps = computed(() => ({
...wrapperProps.value,
style: {
...wrapperProps.value.style,
height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + 1px)`
height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + ${computedFooterHeight.value} + 1px)`
}
}))
const itemHeightStyle = computed(() => {
@@ -72,6 +78,10 @@ div.table-container {
@apply sticky z-10;
top: -1px;
}
>tfoot {
@apply bg-slate-600 sticky z-10;
bottom: -1px;
}
>*>tr, >*>tr>td {
height: v-bind(itemHeightStyle);
}
@@ -79,6 +89,7 @@ div.table-container {
}
&::-webkit-scrollbar-track {
margin-top: v-bind(computedHeaderHeight);
margin-bottom: v-bind(computedFooterHeight);
}
}
</style>

View File

@@ -10,13 +10,13 @@ export const marbasAxiosInstance = axios.create({
},
})
marbasAxiosInstance.interceptors.request.use(r => {
const authStore = useAuthStore();
const authStore = useAuthStore();
marbasAxiosInstance.interceptors.request.use(async r => {
if (!authStore.isLoggedIn) {
throw new Error("Not logged in");
await authStore.redirect();
}
const accessToken = authStore.accessToken;
if (accessToken) {
@@ -29,6 +29,12 @@ marbasAxiosInstance.interceptors.request.use(r => {
})
logResource(marbasAxiosInstance)
marbasAxiosInstance.interceptors.response.use(async r => {
if (r.status === 401) {
await authStore.redirect();
return marbasAxiosInstance.request(r.config);
}
let next: string = r.data?.next;
let results = r.data?.results;

View File

@@ -120,12 +120,39 @@ const { sortedArray, headerProps, showColumn } = useSort<Result>(computed(() =>
})
const getLineColor = (result: Result) => {
if (result.precentProfit >= (threshold.value / 100)) {
return 'line-green';
return 'line-green';
} else if (result.precentProfit < 0) {
return 'line-red';
}
return '';
}
const total = computed(() => {
if (sortedArray.value.length <= 1) {
return null;
}
const first = sortedArray.value[0];
if (!first) {
return null;
}
const sameItem = sortedArray.value.every(r => r.type.id === first.type.id);
const quantity = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.quantity, 0) : 0;
const totalRemaining = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.remaining, 0) : 0;
const price = sortedArray.value.reduce((acc, r) => acc + r.price * r.remaining, 0) / totalRemaining;
const precentProfit = marketTaxStore.calculateProfit(price, first.sell);
const iskProfit = sortedArray.value.reduce((acc, r) => acc + r.iskProfit, 0);
return {
sameItem,
price,
remaining: totalRemaining,
quantity,
precentProfit,
iskProfit
};
});
</script>
<template>
@@ -142,7 +169,7 @@ const getLineColor = (result: Result) => {
</div>
</div>
</div>
<VirtualScrollTable :list="sortedArray" :itemHeight="33" bottom="1rem">
<VirtualScrollTable :list="sortedArray" :itemHeight="33" :footerHeight="!!total ? 33 : 0" bottom="1rem">
<template #default="{ list }">
<thead>
<tr>
@@ -178,6 +205,37 @@ const getLineColor = (result: Result) => {
</td>
</tr>
</tbody>
<tfoot v-if="!!total">
<tr>
<td v-if="showColumn('name')">Total</td>
<td v-if="showColumn('buy')">
<template v-if="!showColumn('name')">Total</template>
</td>
<td v-if="showColumn('sell')">
<template v-if="!showColumn('name') && !showColumn('buy')">Total</template>
</td>
<td v-if="showColumn('date')">
<template v-if="!showColumn('name') && !showColumn('buy') && !showColumn('sell')">Total</template>
</td>
<td v-if="showColumn('price')" class="text-right">
<template v-if="total.sameItem">
{{ formatIsk(total.price) }}
</template>
</td>
<td v-if="showColumn('remaining')" class="text-right">
<template v-if="total.sameItem">
{{ total.remaining }}/{{ total.quantity }}
</template>
</td>
<td v-if="showColumn('precentProfit')" class="text-right">
<template v-if="total.sameItem">
{{ percentFormater.format(total.precentProfit) }}
</template>
</td>
<td v-if="showColumn('iskProfit')" class="text-right">{{ formatIsk(total.iskProfit) }}</td>
<td v-if="showColumn('buttons')" />
</tr>
</tfoot>
</template>
<template #empty>
<div class="text-center mt-4">

View File

@@ -13,14 +13,13 @@ export type MarbasAcquiredType = MarbasObject & {
price: number;
date: Date;
source: AcquiredTypeSource;
user: number;
}
type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & {
date: string;
}
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'user' | 'date'>;
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'date'>;
const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({
...raw,
@@ -68,7 +67,9 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
};
marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
const refresh = () => marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
return { acquiredTypes: types, addAcquiredType, removeAcquiredType };
refresh();
return { acquiredTypes: types, addAcquiredType, removeAcquiredType, refresh };
});

View File

@@ -23,8 +23,8 @@ const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalM
return date;
});
export const getHistory = async (tyeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => {
export const getHistory = async (typeId: number, regionId?: number): Promise<EsiMarketOrderHistory[]> => {
const rId = regionId ?? jitaId;
return historyCache.computeIfAbsent(rId, tyeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: tyeId } })).data);
return historyCache.computeIfAbsent(rId, typeId, async () => (await esiAxiosInstance.get(`/markets/${rId}/history/`, { params: { type_id: typeId } })).data);
}

View File

@@ -1,3 +1 @@
export const jitaId = 10000002;

View File

@@ -6,11 +6,12 @@ import { ref, watch } from 'vue';
const buyModal = ref<typeof BuyModal>();
const sellModal = ref<typeof SellModal>();
const apraisalStore = useApraisalStore();
const acquiredTypesStore = useAcquiredTypesStore();
const items = ref<AcquiredType[]>([]);
const refresh = async () => await acquiredTypesStore.refresh();
watch(() => acquiredTypesStore.acquiredTypes, async itms => {
if (itms.length === 0) {
return;
@@ -34,6 +35,9 @@ watch(() => acquiredTypesStore.acquiredTypes, async itms => {
<template>
<div class="mt-4">
<div class="flex">
<button class="ms-auto" @click="refresh">Refresh</button>
</div>
<template v-if="items.length > 0">
<AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" />
<BuyModal ref="buyModal" />

View File

@@ -1,4 +1,5 @@
<script setup lang="ts">
import { Modal, ProgressBar } from "@/components";
import { MarketType, MarketTypeInput, MarketTypePrice, getHistory, getMarketTypes, useApraisalStore } from "@/market";
import { BuyModal } from '@/market/acquisition';
import { TrackingResult, TrackingResultTable, createResult, useMarketTrackingStore } from '@/market/tracking';
@@ -56,10 +57,6 @@ watch(() => marketTrackingStore.types, async t => {
const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad));
items.value = [
...items.value
];
typesToLoad.forEach(async i => items.value.push(await createResult(i, prices.find(p => p.type.id === i) as MarketTypePrice)));
}, { immediate: true });
</script>
@@ -76,5 +73,10 @@ watch(() => marketTrackingStore.types, async t => {
<hr />
<TrackingResultTable :items="items" @buy="(type, buy, sell) => buyModal?.open(type, { 'Buy': buy, 'Sell': sell })" @remove="removeItem" />
<BuyModal ref="buyModal" />
<Modal :open="items.length > 0 && items.length < marketTrackingStore.types.length">
<div class="ms-auto me-auto mb-2 w-96">
<ProgressBar :value="items.length" :total="marketTrackingStore.types.length" />
</div>
</Modal>
</template>
</template>

View File

@@ -49,6 +49,9 @@
@apply bg-emerald-500 hover:bg-emerald-600;
}
}
tfoot>tr>td {
@apply font-semibold;
}
::-webkit-scrollbar {