This commit is contained in:
Kseninia Mikhaylova 2024-07-19 10:08:34 +03:00
parent 8e35d2ecb5
commit 29f1391288
5 changed files with 51 additions and 14 deletions

View File

@ -69,7 +69,7 @@ class TgBot:
text = await TgBot.app.bot.get_file(item.text)
TgBotUpdater.return_values[item.text] = text.file_path
except Exception as e:
TgBotUpdater.return_values[item.text] = 'error'
TgBotUpdater.return_values[item.text] = None
async def set_handlers(self):
TgBot.app.add_handler(
@ -187,7 +187,7 @@ class TgBot:
f"Step {current_step} from user {user.full_name} in {update.message}"
)
if not current_step and update.message.text == "/inv":
if update.effective_message.text == "/inv":
context.chat_data["step"] = "name"
await update.effective_message.reply_markdown_v2(
(
@ -311,7 +311,6 @@ class TgBot:
await element.asave()
empty_fields = await tmc_element.field.filter(text=None).acount()
logger.info(empty_fields)
if empty_fields > 0:
context.chat_data["step"] = "add_tmc"
await self.inv(update, context)

View File

@ -30,7 +30,7 @@ const columns = [
<h1>Проведенные инвентаризации</h1>
</div>
<div class="col-span-12">
<UTable :rows="items" :columns="columns">
<UTable :rows="items" :columns="columns" :ui="{ td: { base: 'whitespace-normal max-w-sm' } }">
<template #date-data="{ row }">
Создано: {{ new Date(row.created_at).toLocaleString('ru-RU') }}<br />
Обновлено: {{ new Date(row.updated_at).toLocaleString('ru-RU') }}
@ -54,8 +54,4 @@ const columns = [
table {
max-width: 100%;
}
li {
white-space: normal;
}
</style>

44
front/store/authors.ts Normal file
View File

@ -0,0 +1,44 @@
interface imagesList {
[key: string]: {
status: 'idle' | 'pending' | 'success' | 'error',
result?: string
}
}
export const useImagesStore = defineStore('images', {
state: () => ({ list: {} as imagesList }),
actions: {
getImage(name: string) {
if (!this.list[name]) {
this.list[name] = {
status: 'idle',
// result: 'https://media.istockphoto.com/id/1490517357/photo/scientists-are-researching-and-analyzing-harmful-contaminants-in-the-laboratory.webp?s=170667a&w=0&k=20&c=Fh4t-P_b-a1QxwyBUzUa0AuLp8FLNyLy4hl4HUm82Ao='
}
}
if (
!Object.entries(this.list).filter(el => el[1].status == 'pending').length &&
Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
this.loadImages()
}
return this.list[name]
},
async loadOneImage(name: string) {
const file_url_data = await apiCall<string[]>(`tgbot/items/get_image/${name}/`)
if (file_url_data.length > 0 && file_url_data[0] !== null) {
this.list[name].status = 'success'
this.list[name].result = file_url_data[0]
} else {
this.list[name].status = 'error'
}
if (Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
this.loadImages()
}
},
loadImages() {
const elements = Object.entries(this.list).filter(el => el[1].status == 'idle')
elements.slice(0, 2).map(el => {
this.list[el[0]].status = 'pending'
this.loadOneImage(el[0])
})
}
},
})

View File

@ -14,9 +14,7 @@ export const useImagesStore = defineStore('images', {
// result: 'https://media.istockphoto.com/id/1490517357/photo/scientists-are-researching-and-analyzing-harmful-contaminants-in-the-laboratory.webp?s=170667a&w=0&k=20&c=Fh4t-P_b-a1QxwyBUzUa0AuLp8FLNyLy4hl4HUm82Ao='
}
}
if (
!Object.entries(this.list).filter(el => el[1].status == 'pending').length &&
Object.entries(this.list).filter(el => el[1].status == 'idle').length) {
if (!Object.values(this.list).filter(el => el.status == 'pending').length) {
this.loadImages()
}
return this.list[name]
@ -24,7 +22,7 @@ export const useImagesStore = defineStore('images', {
async loadOneImage(name: string) {
const file_url_data = await apiCall<string[]>(`tgbot/items/get_image/${name}/`)
if (file_url_data.length > 0 && file_url_data[0] !== 'error') {
if (file_url_data.length > 0 && file_url_data[0] !== null) {
this.list[name].status = 'success'
this.list[name].result = file_url_data[0]
} else {