Skip to content

Commit

Permalink
catch errors and redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Danilenko committed Feb 20, 2024
1 parent e1db231 commit a7a154c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/components/ChannelsStat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ChartDateSeries} from "@/interface/ChartDateSeries";
import {ChannelsDayStat, useChannelStore} from "@/store/channel";
import {useLocale} from "vuetify";
import {useLogStore} from "@/store/log";
import {AxiosError} from "axios";
const channelStore = useChannelStore();
const { t } = useLocale()
const channelEntities = ref<ChannelEntity[]>( []);
Expand Down Expand Up @@ -91,13 +92,16 @@ function load(){
channelEntities.value = channels;
makeChannelChart(channelChartKey.value);
loading.value = false;
})
}).catch((error: AxiosError)=>{
console.dir(error);
loading.value = false;
});
}
channelStore.init({enabled: true});
defineExpose({load})
load();
</script>

<template>
Expand Down
8 changes: 5 additions & 3 deletions src/components/DeviceStat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useDeviceStore} from "@/store/device";
import DeviceEntity from "@/model/DeviceEntity";
import dayjs from "dayjs";
import {useLocale} from "vuetify";
import {AxiosError} from "axios";
const { t } = useLocale()
const deviceStore = useDeviceStore();
Expand All @@ -25,13 +26,14 @@ function load(){
console.dir(props);
deviceStore.getDeviceStat(props.range, props.provider).then((devices: DeviceEntity[])=>{
deviceEntities.value = devices;
console.dir(devices);
loading.value = false;
}).catch((error: AxiosError)=>{
console.dir(error);
loading.value = false;
})
}
defineExpose({load})
load();
</script>

<template>
Expand Down
19 changes: 14 additions & 5 deletions src/components/Stat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,25 @@ const deviceStat = ref();
function update(){
channelStat.value.load();
deviceStat.value.load();
switch (tab.value){
case 'channel':
channelStat.value.load();
break;
case 'device':
deviceStat.value.load();
break;
}
}
</script>

<template>

<v-card>
<v-card class="ma-2">
<v-card-title>
{{$t('app.query.title')}}
</v-card-title>
<v-card-text>
<v-autocomplete v-model="provider" :label="$t('app.query.provider')" item-title="provider_name" :items="providerStore.getProviders()" :return-object="true" :clearable="true"/>

Expand All @@ -61,10 +70,10 @@ function update(){
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn @click="update" prepend-icon="mdi-refresh" color="primary">{{$t('app.query.do')}}</v-btn>
<v-btn variant="flat" @click="update" prepend-icon="mdi-refresh" color="red">{{$t('app.query.do')}}</v-btn>
</v-card-actions>
</v-card>
<v-card>
<v-card class="ma-2">
<v-tabs
v-model="tab"
bg-color="primary"
Expand Down
3 changes: 2 additions & 1 deletion src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"unique_devices": "Maximum unique devices"
},
"query": {
"title": "Report options",
"range": "Period",
"from": "From",
"to": "To",
"provider": "Only for",
"threshold": "View time threshold, min",
"do": "Do query",
"do": "Refresh",
"showMinutes": "Show duration in minutes instead formatted duration",
"showHours": "Show duration in hours instead formatted duration"
},
Expand Down
10 changes: 7 additions & 3 deletions src/store/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {defineStore} from "pinia";
import {AxiosResponse} from "axios";
import {AxiosError, AxiosResponse} from "axios";
import {Channel} from "@/dto/provider/Channel";
import channelService from "@/service/provider/ChannelService";
import ChannelEntity from "@/model/ChannelEntity";
Expand Down Expand Up @@ -86,7 +86,7 @@ export const useChannelStore = defineStore('channelStore',{
})
},
async fillStat(dateRange: Date[], provider: Provider|null = null):Promise<ChannelEntity[]>{
return new Promise<ChannelEntity[]>((resolve) => {
return new Promise<ChannelEntity[]>((resolve, reject) => {
let count:number = 0;
if(dateRange.length ==0){
resolve(this.channels);
Expand All @@ -97,14 +97,16 @@ export const useChannelStore = defineStore('channelStore',{
if(count == dateRange.length){
resolve(this.channels);
}
}).catch((error: AxiosError)=>{
reject(error);
})
}
});
},
async fillDay(value:Date, provider: Provider|null = null):Promise<number>{
this.getChannelsDayStat(value).audience = 0;

return new Promise((resolve)=>{
return new Promise((resolve,reject)=>{
accountStatService.query(
{
from: dayjs(value).format('YYYY-MM-DD'),
Expand Down Expand Up @@ -153,6 +155,8 @@ export const useChannelStore = defineStore('channelStore',{

}

}).catch((error: AxiosError)=>{
reject(error);
})
})

Expand Down
6 changes: 4 additions & 2 deletions src/store/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import DeviceEntity from "@/model/DeviceEntity";
import {defineStore} from "pinia";
import {Provider} from "@/dto/provider/Provider";
import dayjs from "dayjs";
import {AxiosResponse} from "axios";
import {AxiosError, AxiosResponse} from "axios";
import deviceStatService from "@/service/stat/DeviceStatService";
import {DeviceStatResponse} from "@/dto/stat/DeviceStatResponse";

Expand Down Expand Up @@ -36,7 +36,7 @@ export const useDeviceStore = defineStore('deviceStore', {

async getDeviceStat(dateRange: Date[], provider: Provider|null = null):Promise<DeviceEntity[]>{
this.eraseStat();
return new Promise<DeviceEntity[]>((resolve) => {
return new Promise<DeviceEntity[]>((resolve,reject) => {
let count:number = 0;
if(dateRange.length ==0){
resolve(this.devices);
Expand All @@ -61,6 +61,8 @@ export const useDeviceStore = defineStore('deviceStore', {
if(count == dateRange.length){
resolve(this.devices);
}
}).catch((error: AxiosError)=>{
reject(error);
})
}

Expand Down

0 comments on commit a7a154c

Please sign in to comment.