Refactor TelegramManager and improve frontend article display
- Simplified inline keyboard button creation in TelegramManager for better readability. - Adjusted the structure of the keyboard arrays to ensure proper formatting. - Enhanced Articles.vue by cleaning up the layout and ensuring consistent spacing and alignment. - Improved the handling of article display properties for better user experience.
This commit is contained in:
@@ -117,8 +117,8 @@ class TelegramManager:
|
|||||||
|
|
||||||
# Crear botones inline para el primer mensaje del grupo
|
# Crear botones inline para el primer mensaje del grupo
|
||||||
if is_favorite:
|
if is_favorite:
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("✅ En favoritos", callback_data=f"already_fav_{article.get_platform()}_{article.get_id()}"),
|
InlineKeyboardButton("✅ En favoritos", callback_data=f"already_fav_{article.get_platform()}_{article.get_id()}"),
|
||||||
InlineKeyboardButton("🗑️ Quitar", callback_data=f"unfav_{article.get_platform()}_{article.get_id()}")
|
InlineKeyboardButton("🗑️ Quitar", callback_data=f"unfav_{article.get_platform()}_{article.get_id()}")
|
||||||
],
|
],
|
||||||
@@ -130,9 +130,9 @@ class TelegramManager:
|
|||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("⭐ Añadir a favoritos", callback_data=f"fav_{article.get_platform()}_{article.get_id()}_{search_name}"),
|
InlineKeyboardButton("⭐ Añadir a favoritos", callback_data=f"fav_{article.get_platform()}_{article.get_id()}_{search_name}"),
|
||||||
InlineKeyboardButton("Ir al anuncio", url=f"{article.get_url()}")
|
InlineKeyboardButton("Ir al anuncio", url=f"{article.get_url()}")
|
||||||
]
|
|
||||||
]
|
]
|
||||||
|
]
|
||||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||||
|
|
||||||
# Enviar un mensaje adicional con los botones (reply al primer mensaje del grupo)
|
# Enviar un mensaje adicional con los botones (reply al primer mensaje del grupo)
|
||||||
@@ -231,12 +231,12 @@ class TelegramManager:
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
new_keyboard = [
|
new_keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("✅ En favoritos", callback_data=f"already_fav_{platform}_{article_id}"),
|
InlineKeyboardButton("✅ En favoritos", callback_data=f"already_fav_{platform}_{article_id}"),
|
||||||
InlineKeyboardButton("🗑️ Quitar", callback_data=f"unfav_{platform}_{article_id}")
|
InlineKeyboardButton("🗑️ Quitar", callback_data=f"unfav_{platform}_{article_id}")
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
await query.edit_message_reply_markup(
|
await query.edit_message_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(new_keyboard)
|
reply_markup=InlineKeyboardMarkup(new_keyboard)
|
||||||
)
|
)
|
||||||
@@ -326,11 +326,11 @@ class TelegramManager:
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[
|
[
|
||||||
InlineKeyboardButton("⭐ Añadir a favoritos", callback_data=f"fav_{platform}_{article_id}_Unknown")
|
InlineKeyboardButton("⭐ Añadir a favoritos", callback_data=f"fav_{platform}_{article_id}_Unknown")
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
await query.edit_message_reply_markup(
|
await query.edit_message_reply_markup(
|
||||||
reply_markup=InlineKeyboardMarkup(keyboard)
|
reply_markup=InlineKeyboardMarkup(keyboard)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
<div class="flex justify-between items-center mb-4">
|
<div class="flex justify-between items-center mb-4">
|
||||||
<h1 class="text-3xl font-bold text-gray-900">Artículos Notificados</h1>
|
<h1 class="text-3xl font-bold text-gray-900">Artículos Notificados</h1>
|
||||||
<div class="flex items-center space-x-4">
|
<div class="flex items-center space-x-4">
|
||||||
<select
|
<select
|
||||||
v-model="selectedPlatform"
|
v-model="selectedPlatform"
|
||||||
@change="loadArticles"
|
@change="loadArticles"
|
||||||
class="input"
|
class="input"
|
||||||
style="width: auto;"
|
style="width: auto;"
|
||||||
>
|
>
|
||||||
<option value="">Todas las plataformas</option>
|
<option value="">Todas las plataformas</option>
|
||||||
<option value="wallapop">Wallapop</option>
|
<option value="wallapop">Wallapop</option>
|
||||||
<option value="vinted">Vinted</option>
|
<option value="vinted">Vinted</option>
|
||||||
</select>
|
</select>
|
||||||
<button @click="loadArticles" class="btn btn-primary">
|
<button @click="loadArticles" class="btn btn-primary">
|
||||||
Actualizar
|
Actualizar
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -83,21 +83,21 @@
|
|||||||
<div class="flex-1 min-w-0">
|
<div class="flex-1 min-w-0">
|
||||||
<div class="flex items-start justify-between mb-2">
|
<div class="flex items-start justify-between mb-2">
|
||||||
<div class="flex-1 min-w-0">
|
<div class="flex-1 min-w-0">
|
||||||
<div class="flex items-center space-x-2 mb-2">
|
<div class="flex items-center space-x-2 mb-2">
|
||||||
<span
|
<span
|
||||||
class="px-2 py-1 text-xs font-semibold rounded flex-shrink-0"
|
class="px-2 py-1 text-xs font-semibold rounded flex-shrink-0"
|
||||||
:class="
|
:class="
|
||||||
article.platform === 'wallapop'
|
article.platform === 'wallapop'
|
||||||
? 'bg-blue-100 text-blue-800'
|
? 'bg-blue-100 text-blue-800'
|
||||||
: 'bg-green-100 text-green-800'
|
: 'bg-green-100 text-green-800'
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
{{ article.platform?.toUpperCase() || 'N/A' }}
|
{{ article.platform?.toUpperCase() || 'N/A' }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-sm text-gray-500 whitespace-nowrap">
|
<span class="text-sm text-gray-500 whitespace-nowrap">
|
||||||
{{ formatDate(article.notifiedAt) }}
|
{{ formatDate(article.notifiedAt) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 class="text-lg font-semibold text-gray-900 mb-1 truncate" :title="article.title">
|
<h3 class="text-lg font-semibold text-gray-900 mb-1 truncate" :title="article.title">
|
||||||
{{ article.title || 'Sin título' }}
|
{{ article.title || 'Sin título' }}
|
||||||
@@ -211,7 +211,7 @@ async function loadArticles(reset = true, silent = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -235,7 +235,7 @@ async function loadArticles(reset = true, silent = false) {
|
|||||||
console.error('Error cargando artículos:', error);
|
console.error('Error cargando artículos:', error);
|
||||||
} finally {
|
} finally {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -524,10 +524,12 @@ function closeGeneralModal() {
|
|||||||
|
|
||||||
async function saveWorker() {
|
async function saveWorker() {
|
||||||
try {
|
try {
|
||||||
const updatedWorkers = { ...workers.value };
|
const updatedWorkers = {
|
||||||
if (!updatedWorkers.items) {
|
...workers.value,
|
||||||
updatedWorkers.items = [];
|
items: [...(workers.value.items || [])],
|
||||||
}
|
disabled: [...(workers.value.disabled || [])],
|
||||||
|
general: workers.value.general || {}
|
||||||
|
};
|
||||||
|
|
||||||
const workerData = {
|
const workerData = {
|
||||||
name: workerForm.value.name,
|
name: workerForm.value.name,
|
||||||
@@ -567,10 +569,14 @@ async function saveWorker() {
|
|||||||
|
|
||||||
async function saveGeneralConfig() {
|
async function saveGeneralConfig() {
|
||||||
try {
|
try {
|
||||||
const updatedWorkers = { ...workers.value };
|
const updatedWorkers = {
|
||||||
updatedWorkers.general = {
|
...workers.value,
|
||||||
...(textToArray(generalForm.value.title_exclude_text).length > 0 && { title_exclude: textToArray(generalForm.value.title_exclude_text) }),
|
items: workers.value.items || [],
|
||||||
...(textToArray(generalForm.value.description_exclude_text).length > 0 && { description_exclude: textToArray(generalForm.value.description_exclude_text) }),
|
disabled: workers.value.disabled || [],
|
||||||
|
general: {
|
||||||
|
...(textToArray(generalForm.value.title_exclude_text).length > 0 && { title_exclude: textToArray(generalForm.value.title_exclude_text) }),
|
||||||
|
...(textToArray(generalForm.value.description_exclude_text).length > 0 && { description_exclude: textToArray(generalForm.value.description_exclude_text) }),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await api.updateWorkers(updatedWorkers);
|
await api.updateWorkers(updatedWorkers);
|
||||||
@@ -588,14 +594,17 @@ async function disableWorker(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedWorkers = { ...workers.value };
|
const updatedWorkers = {
|
||||||
if (!updatedWorkers.disabled) {
|
...workers.value,
|
||||||
updatedWorkers.disabled = [];
|
items: workers.value.items || [],
|
||||||
}
|
disabled: [...(workers.value.disabled || [])]
|
||||||
|
};
|
||||||
|
|
||||||
if (!updatedWorkers.disabled.includes(name)) {
|
if (!updatedWorkers.disabled.includes(name)) {
|
||||||
updatedWorkers.disabled.push(name);
|
updatedWorkers.disabled.push(name);
|
||||||
}
|
}
|
||||||
await api.updateWshowGeneralModalorkers(updatedWorkers);
|
|
||||||
|
await api.updateWorkers(updatedWorkers);
|
||||||
await loadWorkers();
|
await loadWorkers();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error desactivando worker:', error);
|
console.error('Error desactivando worker:', error);
|
||||||
@@ -605,10 +614,12 @@ async function disableWorker(name) {
|
|||||||
|
|
||||||
async function enableWorker(name) {
|
async function enableWorker(name) {
|
||||||
try {
|
try {
|
||||||
const updatedWorkers = { ...workers.value };
|
const updatedWorkers = {
|
||||||
if (updatedWorkers.disabled) {
|
...workers.value,
|
||||||
updatedWorkers.disabled = updatedWorkers.disabled.filter(n => n !== name);
|
items: workers.value.items || [],
|
||||||
}
|
disabled: [...(workers.value.disabled || [])].filter(n => n !== name)
|
||||||
|
};
|
||||||
|
|
||||||
await api.updateWorkers(updatedWorkers);
|
await api.updateWorkers(updatedWorkers);
|
||||||
await loadWorkers();
|
await loadWorkers();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -623,11 +634,13 @@ async function deleteWorker(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedWorkers = { ...workers.value };
|
const updatedWorkers = {
|
||||||
updatedWorkers.items = updatedWorkers.items.filter(w => w.name !== name);
|
...workers.value,
|
||||||
if (updatedWorkers.disabled) {
|
items: (workers.value.items || []).filter(w => w.name !== name),
|
||||||
updatedWorkers.disabled = updatedWorkers.disabled.filter(n => n !== name);
|
disabled: (workers.value.disabled || []).filter(n => n !== name),
|
||||||
}
|
general: workers.value.general || {}
|
||||||
|
};
|
||||||
|
|
||||||
await api.updateWorkers(updatedWorkers);
|
await api.updateWorkers(updatedWorkers);
|
||||||
await loadWorkers();
|
await loadWorkers();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user