feat: Implement content planning and post management with a new service and calendar view. #3

Merged
xidas merged 1 commits from posts into main 2026-02-17 12:55:21 +00:00
11 changed files with 1906 additions and 2356 deletions
Showing only changes of commit ff07ca6ae0 - Show all commits

File diff suppressed because it is too large Load Diff

106
package-lock.json generated
View File

@@ -11,6 +11,7 @@
"@primeuix/themes": "^2.0.3", "@primeuix/themes": "^2.0.3",
"@primevue/themes": "^4.5.4", "@primevue/themes": "^4.5.4",
"axios": "^1.13.4", "axios": "^1.13.4",
"jszip": "^3.10.1",
"pinia": "^3.0.4", "pinia": "^3.0.4",
"primeicons": "^7.0.0", "primeicons": "^7.0.0",
"primevue": "^4.5.4", "primevue": "^4.5.4",
@@ -3896,6 +3897,12 @@
"url": "https://opencollective.com/core-js" "url": "https://opencollective.com/core-js"
} }
}, },
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
"license": "MIT"
},
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.6", "version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -4861,6 +4868,18 @@
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
}, },
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==",
"license": "MIT"
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/internal-slot": { "node_modules/internal-slot": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.1.0.tgz", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.1.0.tgz",
@@ -5474,6 +5493,18 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/jszip": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
"integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
"license": "(MIT OR GPL-3.0-or-later)",
"dependencies": {
"lie": "~3.3.0",
"pako": "~1.0.2",
"readable-stream": "~2.3.6",
"setimmediate": "^1.0.5"
}
},
"node_modules/kolorist": { "node_modules/kolorist": {
"version": "1.8.0", "version": "1.8.0",
"resolved": "https://registry.npmjs.org/kolorist/-/kolorist-1.8.0.tgz", "resolved": "https://registry.npmjs.org/kolorist/-/kolorist-1.8.0.tgz",
@@ -5491,6 +5522,15 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/lie": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
"integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
"license": "MIT",
"dependencies": {
"immediate": "~3.0.5"
}
},
"node_modules/lightningcss": { "node_modules/lightningcss": {
"version": "1.30.2", "version": "1.30.2",
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.30.2.tgz", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.30.2.tgz",
@@ -6058,6 +6098,12 @@
"dev": true, "dev": true,
"license": "BlueOak-1.0.0" "license": "BlueOak-1.0.0"
}, },
"node_modules/pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
"license": "(MIT AND Zlib)"
},
"node_modules/path-key": { "node_modules/path-key": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
@@ -6244,6 +6290,12 @@
"node": ">=12.11.0" "node": ">=12.11.0"
} }
}, },
"node_modules/process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"license": "MIT"
},
"node_modules/proxy-from-env": { "node_modules/proxy-from-env": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
@@ -6286,6 +6338,33 @@
"safe-buffer": "^5.1.0" "safe-buffer": "^5.1.0"
} }
}, },
"node_modules/readable-stream": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
"license": "MIT",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"node_modules/readable-stream/node_modules/isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
"license": "MIT"
},
"node_modules/readable-stream/node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"license": "MIT"
},
"node_modules/readdirp": { "node_modules/readdirp": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz",
@@ -6647,6 +6726,12 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==",
"license": "MIT"
},
"node_modules/shebang-command": { "node_modules/shebang-command": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
@@ -6862,6 +6947,21 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.1.0"
}
},
"node_modules/string_decoder/node_modules/safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"license": "MIT"
},
"node_modules/string-width": { "node_modules/string-width": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
@@ -7464,6 +7564,12 @@
"browserslist": ">= 4.21.0" "browserslist": ">= 4.21.0"
} }
}, },
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
"node_modules/vite": { "node_modules/vite": {
"version": "7.3.1", "version": "7.3.1",
"resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz", "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz",

View File

@@ -12,6 +12,7 @@
"@primeuix/themes": "^2.0.3", "@primeuix/themes": "^2.0.3",
"@primevue/themes": "^4.5.4", "@primevue/themes": "^4.5.4",
"axios": "^1.13.4", "axios": "^1.13.4",
"jszip": "^3.10.1",
"pinia": "^3.0.4", "pinia": "^3.0.4",
"primeicons": "^7.0.0", "primeicons": "^7.0.0",
"primevue": "^4.5.4", "primevue": "^4.5.4",

View File

@@ -70,11 +70,12 @@ const isActive = (path) => {
const navItems = computed(() => { const navItems = computed(() => {
const items = [ const items = [
{ path: '/', icon: '🏠', tooltip: 'Home' }, // { path: '/', icon: '🏠', tooltip: 'Home' },
{ path: '/projects', icon: '📂', tooltip: 'Projects' }, { path: '/projects', icon: '📂', tooltip: 'Projects' },
{ path: '/content-plan', icon: '📅', tooltip: 'Plan' },
{ path: '/ideas', icon: '💡', tooltip: 'Ideas' }, { path: '/ideas', icon: '💡', tooltip: 'Ideas' },
{ path: '/flexible', icon: '🖌️', tooltip: 'Flexible' }, { path: '/flexible', icon: '🖌️', tooltip: 'Flexible' },
{ path: '/albums', icon: '🖼️', tooltip: 'Library' }, // { path: '/albums', icon: '🖼️', tooltip: 'Library' },
{ path: '/characters', icon: '👥', tooltip: 'Characters' } { path: '/characters', icon: '👥', tooltip: 'Characters' }
] ]

View File

@@ -57,6 +57,11 @@ const router = createRouter({
name: 'flexible', name: 'flexible',
component: () => import('../views/FlexibleGenerationView.vue') component: () => import('../views/FlexibleGenerationView.vue')
}, },
{
path: '/content-plan',
name: 'content-plan',
component: () => import('../views/ContentPlanView.vue')
},
{ {
path: '/albums', path: '/albums',
name: 'albums', name: 'albums',

View File

@@ -0,0 +1,24 @@
import api from './api';
export const postService = {
getPosts: (dateFrom, dateTo) => {
const params = {};
if (dateFrom) params.date_from = dateFrom;
if (dateTo) params.date_to = dateTo;
return api.get('/posts', { params }).then(r => r.data);
},
createPost: (data) => api.post('/posts', data).then(r => r.data),
getPost: (id) => api.get(`/posts/${id}`).then(r => r.data),
updatePost: (id, data) => api.put(`/posts/${id}`, data).then(r => r.data),
deletePost: (id) => api.delete(`/posts/${id}`).then(r => r.data),
addGenerations: (postId, generationIds) =>
api.post(`/posts/${postId}/generations`, { generation_ids: generationIds }).then(r => r.data),
removeGeneration: (postId, generationId) =>
api.delete(`/posts/${postId}/generations/${generationId}`).then(r => r.data),
};

View File

@@ -32,13 +32,13 @@ export const useIdeaStore = defineStore('ideas', () => {
loading.value = true; loading.value = true;
error.value = null; error.value = null;
try { try {
await ideaService.createIdea(data); const response = await ideaService.createIdea(data);
await fetchIdeas(); // Refresh list await fetchIdeas(); // Refresh list
return true; return response.data;
} catch (err) { } catch (err) {
console.error('Error creating idea:', err); console.error('Error creating idea:', err);
error.value = err.response?.data?.detail || 'Failed to create idea'; error.value = err.response?.data?.detail || 'Failed to create idea';
return false; return null;
} finally { } finally {
loading.value = false; loading.value = false;
} }

View File

@@ -0,0 +1,955 @@
<script setup>
import { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'
import { postService } from '../services/postService'
import { aiService } from '../services/aiService'
import { useConfirm } from 'primevue/useconfirm'
import { useToast } from 'primevue/usetoast'
import Button from 'primevue/button'
import Dialog from 'primevue/dialog'
import InputText from 'primevue/inputtext'
import DatePicker from 'primevue/datepicker'
import ConfirmDialog from 'primevue/confirmdialog'
import Toast from 'primevue/toast'
import JSZip from 'jszip'
const confirm = useConfirm()
const toast = useToast()
const API_URL = import.meta.env.VITE_API_URL || ''
// --- Timezone helpers ---
// Normalize a date to noon local time before converting to ISO
// This prevents day-shift when UTC offset crosses midnight
function toLocalNoonISO(date) {
const d = new Date(date)
d.setHours(12, 0, 0, 0)
return d.toISOString()
}
// Parse date string from API — ensure it's treated as UTC
// Server may return "2026-02-16T21:00:00" without Z, which browsers
// would interpret as local time. We append Z to force UTC parsing.
function parseUTCDate(dateStr) {
if (typeof dateStr === 'string' && !dateStr.endsWith('Z') && !/[+-]\d{2}(:\d{2})?$/.test(dateStr)) {
return new Date(dateStr + 'Z')
}
return new Date(dateStr)
}
// --- Calendar state ---
const currentDate = ref(new Date()) // tracks currently viewed month
const viewMode = ref('month') // 'month' | 'week' | 'day'
const selectedDay = ref(null)
const posts = ref([])
const loading = ref(false)
// --- New/Edit post dialog ---
const showPostDialog = ref(false)
const editingPost = ref(null) // null = create, object = edit
const postForm = ref({ date: new Date(), topic: '' })
// --- Day names (Monday first) ---
const dayNames = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']
const monthNames = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь']
// --- Computeds ---
const currentMonthName = computed(() => monthNames[currentDate.value.getMonth()])
const currentYear = computed(() => currentDate.value.getFullYear())
const headerTitle = computed(() => {
if (viewMode.value === 'day' && selectedDay.value) {
const d = selectedDay.value
return `${d.getDate()} ${monthNames[d.getMonth()]} ${d.getFullYear()}`
}
if (viewMode.value === 'week' && selectedDay.value) {
const ws = getWeekStart(selectedDay.value)
const we = new Date(ws)
we.setDate(we.getDate() + 6)
const m1 = monthNames[ws.getMonth()].substring(0, 3)
const m2 = monthNames[we.getMonth()].substring(0, 3)
if (ws.getMonth() === we.getMonth()) {
return `${ws.getDate()} ${we.getDate()} ${m1} ${ws.getFullYear()}`
}
return `${ws.getDate()} ${m1} ${we.getDate()} ${m2} ${we.getFullYear()}`
}
return `${currentMonthName.value} ${currentYear.value}`
})
// Get Monday of the week containing a date
function getWeekStart(date) {
const d = new Date(date)
const day = d.getDay()
const diff = d.getDate() - day + (day === 0 ? -6 : 1) // Monday
d.setDate(diff)
d.setHours(0, 0, 0, 0)
return d
}
// Calendar grid cells for month view
const calendarDays = computed(() => {
const year = currentDate.value.getFullYear()
const month = currentDate.value.getMonth()
const firstDay = new Date(year, month, 1)
const lastDay = new Date(year, month + 1, 0)
// Day of week for first day (0=Sun, we want Mon=0)
let startDow = firstDay.getDay() - 1
if (startDow < 0) startDow = 6
const days = []
// Previous month padding
for (let i = startDow - 1; i >= 0; i--) {
const d = new Date(year, month, -i)
days.push({ date: d, isOtherMonth: true })
}
// Current month
for (let i = 1; i <= lastDay.getDate(); i++) {
const d = new Date(year, month, i)
days.push({ date: d, isOtherMonth: false })
}
// Next month padding (fill to 42 cells = 6 rows)
const remaining = 42 - days.length
for (let i = 1; i <= remaining; i++) {
const d = new Date(year, month + 1, i)
days.push({ date: d, isOtherMonth: true })
}
return days
})
// Week view days
const weekDays = computed(() => {
const start = selectedDay.value ? getWeekStart(selectedDay.value) : getWeekStart(new Date())
const days = []
for (let i = 0; i < 7; i++) {
const d = new Date(start)
d.setDate(d.getDate() + i)
days.push({ date: d, isOtherMonth: false })
}
return days
})
// Today check
const isToday = (date) => {
const today = new Date()
return date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() === today.getFullYear()
}
const isSameDay = (a, b) => {
if (!a || !b) return false
return a.getDate() === b.getDate() && a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear()
}
// Posts for a given date
const getPostsForDate = (date) => {
return posts.value.filter(p => {
const pd = parseUTCDate(p.date)
return isSameDay(pd, date)
})
}
// Day view posts
const dayPosts = computed(() => {
if (!selectedDay.value) return []
return getPostsForDate(selectedDay.value)
})
// --- API calls ---
async function fetchPosts() {
loading.value = true
try {
const year = currentDate.value.getFullYear()
const month = currentDate.value.getMonth()
// Fetch the full visible range (prev month padding + next)
const dateFrom = toLocalNoonISO(new Date(year, month - 1, 1))
const dateTo = toLocalNoonISO(new Date(year, month + 2, 0))
const result = await postService.getPosts(dateFrom, dateTo)
posts.value = Array.isArray(result) ? result : []
} catch (e) {
console.error('Failed to fetch posts', e)
posts.value = []
} finally {
loading.value = false
}
}
// --- Navigation ---
function prevPeriod() {
if (viewMode.value === 'month') {
const d = new Date(currentDate.value)
d.setMonth(d.getMonth() - 1)
currentDate.value = d
} else if (viewMode.value === 'week') {
const d = new Date(selectedDay.value || new Date())
d.setDate(d.getDate() - 7)
selectedDay.value = d
currentDate.value = new Date(d.getFullYear(), d.getMonth(), 1)
} else {
const d = new Date(selectedDay.value || new Date())
d.setDate(d.getDate() - 1)
selectedDay.value = d
currentDate.value = new Date(d.getFullYear(), d.getMonth(), 1)
}
}
function nextPeriod() {
if (viewMode.value === 'month') {
const d = new Date(currentDate.value)
d.setMonth(d.getMonth() + 1)
currentDate.value = d
} else if (viewMode.value === 'week') {
const d = new Date(selectedDay.value || new Date())
d.setDate(d.getDate() + 7)
selectedDay.value = d
currentDate.value = new Date(d.getFullYear(), d.getMonth(), 1)
} else {
const d = new Date(selectedDay.value || new Date())
d.setDate(d.getDate() + 1)
selectedDay.value = d
currentDate.value = new Date(d.getFullYear(), d.getMonth(), 1)
}
}
function goToday() {
const today = new Date()
currentDate.value = new Date(today.getFullYear(), today.getMonth(), 1)
selectedDay.value = today
}
function selectDay(dayObj) {
selectedDay.value = dayObj.date
if (viewMode.value === 'month') {
viewMode.value = 'day'
}
}
// --- Post CRUD ---
function openNewPostDialog(date) {
editingPost.value = null
postForm.value = {
date: date ? new Date(date) : new Date(),
topic: ''
}
showPostDialog.value = true
}
function openEditPostDialog(post) {
editingPost.value = post
postForm.value = {
date: parseUTCDate(post.date),
topic: post.topic
}
showPostDialog.value = true
}
async function savePost() {
if (!postForm.value.topic.trim()) {
toast.add({ severity: 'warn', summary: 'Тема обязательна', life: 2000 })
return
}
try {
if (editingPost.value) {
await postService.updatePost(editingPost.value.id, {
date: toLocalNoonISO(postForm.value.date),
topic: postForm.value.topic
})
toast.add({ severity: 'success', summary: 'Пост обновлён', life: 2000 })
} else {
await postService.createPost({
date: toLocalNoonISO(postForm.value.date),
topic: postForm.value.topic,
generation_ids: []
})
toast.add({ severity: 'success', summary: 'Пост создан', life: 2000 })
}
showPostDialog.value = false
await fetchPosts()
} catch (e) {
console.error('Save post failed', e)
toast.add({ severity: 'error', summary: 'Ошибка', detail: 'Не удалось сохранить', life: 3000 })
}
}
function deletePost(post) {
confirm.require({
message: `Удалить пост "${post.topic}"?`,
header: 'Удаление поста',
icon: 'pi pi-trash',
acceptClass: 'p-button-danger',
accept: async () => {
try {
await postService.deletePost(post.id)
toast.add({ severity: 'info', summary: 'Удалено', life: 2000 })
await fetchPosts()
} catch (e) {
console.error('Delete post failed', e)
}
}
})
}
async function removeGenerationFromPost(post, genId) {
try {
await postService.removeGeneration(post.id, genId)
// Optimistic update
const idx = post.generation_ids.indexOf(genId)
if (idx > -1) post.generation_ids.splice(idx, 1)
toast.add({ severity: 'info', summary: 'Генерация удалена из поста', life: 2000 })
} catch (e) {
console.error(e)
}
}
// --- Download Post Assets ---
const isDownloading = ref(false)
async function downloadPostAssets(post) {
const ids = post.generation_ids || []
if (ids.length === 0) return
isDownloading.value = true
try {
const user = JSON.parse(localStorage.getItem('user'))
const headers = {}
if (user && user.access_token) headers['Authorization'] = `Bearer ${user.access_token}`
else if (user && user.token) headers['Authorization'] = `${user.tokenType} ${user.token}`
const projectId = localStorage.getItem('active_project_id')
if (projectId) headers['X-Project-ID'] = projectId
// Multi-file ZIP (if > 1)
if (ids.length > 1) {
const zip = new JSZip()
// Sanitize topic for filename
const safeTopic = (post.topic || 'post').replace(/[^a-z0-9_\-а-яё ]/gi, '').trim().replace(/\s+/g, '_')
const folderName = `${safeTopic}_assets`
let successCount = 0
await Promise.all(ids.map(async (assetId) => {
try {
const url = API_URL + '/assets/' + assetId
const resp = await fetch(url, { headers })
if (!resp.ok) return
const blob = await resp.blob()
const mime = blob.type
const ext = mime.split('/')[1] || 'png'
zip.file(`${assetId}.${ext}`, blob)
successCount++
} catch (err) {
console.error('Failed to zip asset', assetId, err)
}
}))
if (successCount === 0) throw new Error('No images available for zip')
const content = await zip.generateAsync({ type: 'blob' })
const filename = `${folderName}.zip`
const a = document.createElement('a')
a.href = URL.createObjectURL(content)
a.download = filename
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
toast.add({ severity: 'success', summary: 'Архив создан', detail: `Скачано ${successCount} файлов`, life: 3000 })
} else {
// Single File
const assetId = ids[0]
const url = API_URL + '/assets/' + assetId
const resp = await fetch(url, { headers })
const blob = await resp.blob()
const file = new File([blob], assetId + '.png', { type: blob.type || 'image/png' })
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || navigator.maxTouchPoints > 1
if (isMobile && navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({ files: [file] })
} else {
const a = document.createElement('a')
a.href = URL.createObjectURL(file)
a.download = file.name
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
}
toast.add({ severity: 'success', summary: 'Скачано', detail: `Файл сохранен`, life: 2000 })
}
} catch (e) {
console.error('Download failed', e)
toast.add({ severity: 'error', summary: 'Ошибка скачивания', life: 3000 })
} finally {
isDownloading.value = false
}
}
// --- Watchers ---
watch(currentDate, fetchPosts)
onMounted(() => {
selectedDay.value = new Date()
fetchPosts()
})
// --- Generation Picker ---
const showGenPicker = ref(false)
const genPickerPost = ref(null)
const availableGenerations = ref([])
const selectedGenIds = ref(new Set())
const genLoading = ref(false)
const genLoadingMore = ref(false)
const genOffset = ref(0)
const genHasMore = ref(true)
const GEN_LIMIT = 30
function openGenPicker(post) {
genPickerPost.value = post
selectedGenIds.value = new Set()
availableGenerations.value = []
genOffset.value = 0
genHasMore.value = true
showGenPicker.value = true
loadGenerations(true)
}
async function loadGenerations(initial = false) {
if (initial) {
genLoading.value = true
genOffset.value = 0
} else {
genLoadingMore.value = true
}
try {
const response = await aiService.getGenerations(GEN_LIMIT, genOffset.value)
const list = response && response.generations ? response.generations : (Array.isArray(response) ? response : [])
if (initial) {
availableGenerations.value = list
} else {
availableGenerations.value.push(...list)
}
genOffset.value += list.length
genHasMore.value = list.length >= GEN_LIMIT
} catch (e) {
console.error('Load generations failed', e)
} finally {
genLoading.value = false
genLoadingMore.value = false
}
}
function toggleGenSelection(assetId) {
const s = new Set(selectedGenIds.value)
if (s.has(assetId)) s.delete(assetId)
else s.add(assetId)
selectedGenIds.value = s
}
async function confirmAddGenerations() {
if (!genPickerPost.value || selectedGenIds.value.size === 0) return
try {
await postService.addGenerations(genPickerPost.value.id, [...selectedGenIds.value])
toast.add({ severity: 'success', summary: `Добавлено ${selectedGenIds.value.size} изображений`, life: 2000 })
showGenPicker.value = false
await fetchPosts()
} catch (e) {
console.error('Add generations failed', e)
toast.add({ severity: 'error', summary: 'Ошибка', detail: 'Не удалось добавить', life: 3000 })
}
}
function onGenPickerScroll(e) {
const el = e.target
if (el.scrollTop + el.clientHeight >= el.scrollHeight - 100 && genHasMore.value && !genLoadingMore.value) {
loadGenerations(false)
}
}
// --- Image Preview ---
const previewVisible = ref(false)
const previewImages = ref([])
const previewIndex = ref(0)
const previewCurrent = computed(() => previewImages.value[previewIndex.value] || null)
function openPreview(assetIds, clickedId) {
previewImages.value = assetIds.map(id => API_URL + '/assets/' + id)
const idx = assetIds.indexOf(clickedId)
previewIndex.value = idx >= 0 ? idx : 0
previewVisible.value = true
}
function previewNav(dir) {
if (previewImages.value.length === 0) return
let i = previewIndex.value + dir
if (i < 0) i = previewImages.value.length - 1
if (i >= previewImages.value.length) i = 0
previewIndex.value = i
}
function onPreviewKey(e) {
if (!previewVisible.value) return
if (e.key === 'ArrowLeft') { e.preventDefault(); previewNav(-1) }
else if (e.key === 'ArrowRight') { e.preventDefault(); previewNav(1) }
else if (e.key === 'Escape') { previewVisible.value = false }
}
watch(previewVisible, (v) => {
if (v) window.addEventListener('keydown', onPreviewKey)
else window.removeEventListener('keydown', onPreviewKey)
})
onBeforeUnmount(() => {
window.removeEventListener('keydown', onPreviewKey)
})
</script>
<template>
<div class="flex flex-col h-full w-full bg-slate-900 text-slate-100 font-sans overflow-hidden">
<ConfirmDialog />
<Toast />
<!-- Header -->
<header
class="h-16 border-b border-white/5 flex items-center justify-between px-6 bg-slate-900/80 backdrop-blur z-20 shrink-0">
<div class="flex items-center gap-4">
<h1 class="text-lg font-bold text-slate-200">📅 Content plan</h1>
</div>
<div class="flex items-center gap-3">
<!-- Navigation Arrows -->
<div class="flex items-center gap-1">
<button @click="prevPeriod"
class="w-8 h-8 rounded-lg bg-slate-800 border border-white/10 flex items-center justify-center text-slate-400 hover:text-white hover:bg-slate-700 transition-all">
<i class="pi pi-chevron-left text-xs"></i>
</button>
<button @click="goToday"
class="px-3 py-1.5 rounded-lg text-xs font-medium bg-slate-800 border border-white/10 text-slate-400 hover:text-white hover:bg-slate-700 transition-all">
Сегодня
</button>
<button @click="nextPeriod"
class="w-8 h-8 rounded-lg bg-slate-800 border border-white/10 flex items-center justify-center text-slate-400 hover:text-white hover:bg-slate-700 transition-all">
<i class="pi pi-chevron-right text-xs"></i>
</button>
</div>
<!-- Period Title -->
<span class="text-sm font-semibold text-slate-200 min-w-[180px] text-center hidden md:block">{{
headerTitle }}</span>
<!-- View Toggle -->
<div class="flex bg-slate-800 rounded-lg p-1 border border-white/5">
<button @click="viewMode = 'month'"
class="px-3 py-1.5 rounded-md text-xs font-medium transition-all"
:class="viewMode === 'month' ? 'bg-violet-600 text-white shadow-lg' : 'text-slate-400 hover:text-slate-200'">
Месяц
</button>
<button @click="viewMode = 'week'; if (!selectedDay) selectedDay = new Date()"
class="px-3 py-1.5 rounded-md text-xs font-medium transition-all"
:class="viewMode === 'week' ? 'bg-violet-600 text-white shadow-lg' : 'text-slate-400 hover:text-slate-200'">
Неделя
</button>
<button @click="viewMode = 'day'; if (!selectedDay) selectedDay = new Date()"
class="px-3 py-1.5 rounded-md text-xs font-medium transition-all"
:class="viewMode === 'day' ? 'bg-violet-600 text-white shadow-lg' : 'text-slate-400 hover:text-slate-200'">
День
</button>
</div>
</div>
</header>
<!-- Mobile Period Title -->
<div class="md:hidden text-center py-2 text-sm font-semibold text-slate-200 border-b border-white/5">
{{ headerTitle }}
</div>
<!-- Content Area -->
<div class="flex-1 overflow-y-auto custom-scrollbar">
<!-- ====== MONTH VIEW ====== -->
<div v-if="viewMode === 'month'" class="h-full flex flex-col p-2 md:p-4">
<!-- Day headers -->
<div class="grid grid-cols-7 mb-1">
<div v-for="d in dayNames" :key="d"
class="text-center text-[10px] font-bold text-slate-500 uppercase tracking-wider py-2">
{{ d }}
</div>
</div>
<!-- Day cells -->
<div class="grid grid-cols-7 flex-1 gap-px bg-white/5 rounded-xl overflow-hidden">
<div v-for="(dayObj, idx) in calendarDays" :key="idx" @click="selectDay(dayObj)" :class="[
'bg-slate-900 p-1.5 min-h-[80px] md:min-h-[100px] cursor-pointer transition-all hover:bg-slate-800/80 relative group',
dayObj.isOtherMonth ? 'opacity-30' : '',
isToday(dayObj.date) ? 'ring-1 ring-violet-500/50 ring-inset' : '',
isSameDay(dayObj.date, selectedDay) ? 'bg-violet-900/20' : ''
]">
<!-- Day number -->
<div class="flex items-center justify-between mb-1">
<span :class="[
'text-xs font-bold w-6 h-6 flex items-center justify-center rounded-full',
isToday(dayObj.date) ? 'bg-violet-600 text-white' : 'text-slate-400'
]">
{{ dayObj.date.getDate() }}
</span>
<!-- Add button (show on hover) -->
<button v-if="!dayObj.isOtherMonth" @click.stop="openNewPostDialog(dayObj.date)"
class="w-5 h-5 rounded-md bg-violet-600/30 text-violet-300 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity hover:bg-violet-600/50">
<i class="pi pi-plus" style="font-size: 8px"></i>
</button>
</div>
<!-- Posts in cell -->
<div class="flex flex-col gap-0.5 overflow-hidden">
<div v-for="post in getPostsForDate(dayObj.date)" :key="post.id"
@click.stop="openEditPostDialog(post)"
class="px-1.5 py-0.5 rounded text-[10px] font-medium truncate transition-all hover:scale-[1.02] cursor-pointer"
:class="post.generation_ids?.length > 0
? 'bg-violet-600/30 text-violet-200 border border-violet-500/20'
: 'bg-slate-700/50 text-slate-300 border border-white/5'">
{{ post.topic }}
</div>
</div>
</div>
</div>
</div>
<!-- ====== WEEK VIEW ====== -->
<div v-else-if="viewMode === 'week'" class="h-full flex flex-col p-2 md:p-4">
<!-- Day headers -->
<div class="grid grid-cols-7 mb-1">
<div v-for="(dayObj, idx) in weekDays" :key="idx"
class="text-center text-[10px] font-bold uppercase tracking-wider py-2"
:class="isToday(dayObj.date) ? 'text-violet-400' : 'text-slate-500'">
{{ dayNames[idx] }} {{ dayObj.date.getDate() }}
</div>
</div>
<!-- Day columns -->
<div class="grid grid-cols-7 flex-1 gap-px bg-white/5 rounded-xl overflow-hidden">
<div v-for="(dayObj, idx) in weekDays" :key="idx"
@click="selectedDay = dayObj.date; viewMode = 'day'" :class="[
'bg-slate-900 p-2 min-h-[300px] cursor-pointer transition-all hover:bg-slate-800/80 relative group',
isToday(dayObj.date) ? 'ring-1 ring-violet-500/50 ring-inset' : '',
isSameDay(dayObj.date, selectedDay) ? 'bg-violet-900/20' : ''
]">
<!-- Add button -->
<button @click.stop="openNewPostDialog(dayObj.date)"
class="w-full mb-2 py-1 rounded-lg border border-dashed border-white/10 text-slate-500 text-xs opacity-0 group-hover:opacity-100 transition-opacity hover:border-violet-500/30 hover:text-violet-400">
<i class="pi pi-plus mr-1" style="font-size: 9px"></i> Добавить
</button>
<!-- Posts -->
<div class="flex flex-col gap-2">
<div v-for="post in getPostsForDate(dayObj.date)" :key="post.id"
class="bg-slate-800/80 rounded-lg border border-white/5 p-2 hover:border-violet-500/30 transition-all cursor-pointer"
@click.stop="openEditPostDialog(post)">
<p class="text-xs font-semibold text-slate-200 mb-1 line-clamp-2">{{ post.topic }}</p>
<!-- Generation thumbnails -->
<div v-if="post.generation_ids?.length > 0" class="flex gap-1 flex-wrap">
<img v-for="gid in post.generation_ids.slice(0, 4)" :key="gid"
:src="API_URL + '/assets/' + gid + '?thumbnail=true'"
class="w-8 h-8 rounded object-cover border border-white/10" />
<span v-if="post.generation_ids.length > 4"
class="w-8 h-8 rounded bg-slate-700 border border-white/10 flex items-center justify-center text-[10px] text-slate-400">
+{{ post.generation_ids.length - 4 }}
</span>
</div>
<!-- Actions -->
<div class="flex gap-1 mt-1.5 justify-end">
<button @click.stop="openGenPicker(post)"
class="w-5 h-5 rounded bg-violet-500/10 text-violet-400 flex items-center justify-center hover:bg-violet-500/20 transition-colors"
title="Добавить изображения">
<i class="pi pi-images" style="font-size: 9px"></i>
</button>
<button @click.stop="deletePost(post)"
class="w-5 h-5 rounded bg-red-500/10 text-red-400 flex items-center justify-center hover:bg-red-500/20 transition-colors">
<i class="pi pi-trash" style="font-size: 9px"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ====== DAY VIEW ====== -->
<div v-else class="max-w-3xl mx-auto p-4 md:p-8">
<!-- Add Post Button -->
<button @click="openNewPostDialog(selectedDay)"
class="w-full mb-6 py-3 rounded-xl border-2 border-dashed border-white/10 text-slate-400 text-sm font-medium hover:border-violet-500/40 hover:text-violet-300 hover:bg-violet-500/5 transition-all">
<i class="pi pi-plus mr-2"></i> Новый пост
</button>
<!-- No posts -->
<div v-if="dayPosts.length === 0 && !loading"
class="flex flex-col items-center justify-center py-20 text-slate-500 opacity-60">
<i class="pi pi-calendar text-5xl mb-4"></i>
<p>Нет постов на этот день</p>
</div>
<!-- Posts list -->
<div class="flex flex-col gap-4">
<div v-for="post in dayPosts" :key="post.id"
class="bg-slate-800/60 rounded-2xl border border-white/5 p-5 hover:border-violet-500/20 transition-all">
<!-- Header: topic + date -->
<div class="flex items-start justify-between mb-3">
<div class="flex-1">
<h3 class="text-base font-bold text-slate-100 mb-1">{{ post.topic }}</h3>
<p class="text-xs text-slate-500">
{{ parseUTCDate(post.date).toLocaleDateString('ru-RU', {
weekday: 'long', day: 'numeric', month: 'long'
}) }}
</p>
</div>
<button @click="deletePost(post)"
class="w-8 h-8 rounded-lg bg-slate-700/50 text-slate-400 flex items-center justify-center hover:bg-red-600/30 hover:text-red-300 transition-all"
title="Удалить">
<i class="pi pi-trash text-xs"></i>
</button>
</div>
<!-- Images section header with actions -->
<div class="flex items-center justify-between mb-2">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">
Изображения ({{ post.generation_ids?.length || 0 }})
</label>
<div class="flex gap-1">
<Button icon="pi pi-download" label="Скачать" size="small" text :loading="isDownloading"
:disabled="!post.generation_ids?.length" @click="downloadPostAssets(post)"
class="!text-slate-400 hover:!text-white !text-xs !py-1" />
<Button icon="pi pi-plus" label="Добавить" size="small" text
@click="openGenPicker(post)"
class="!text-violet-400 hover:!text-violet-300 !text-xs !py-1" />
<Button icon="pi pi-pencil" size="small" text @click="openEditPostDialog(post)"
class="!text-slate-400 hover:!text-white !text-xs !py-1" title="Редактировать" />
</div>
</div>
<!-- Generation grid -->
<div v-if="post.generation_ids?.length > 0"
class="grid grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2">
<div v-for="gid in post.generation_ids" :key="gid"
class="aspect-square relative rounded-xl overflow-hidden bg-slate-900 border border-white/5 group/img">
<img :src="API_URL + '/assets/' + gid + '?thumbnail=true'"
class="w-full h-full object-cover cursor-pointer"
@click="openPreview(post.generation_ids, gid)" />
<button @click="removeGenerationFromPost(post, gid)"
class="absolute top-1 right-1 w-5 h-5 rounded-md bg-red-600/80 text-white flex items-center justify-center opacity-0 group-hover/img:opacity-100 transition-opacity hover:bg-red-500">
<i class="pi pi-times" style="font-size: 8px"></i>
</button>
</div>
</div>
<div v-else
class="py-6 text-center text-slate-600 text-xs border border-dashed border-white/5 rounded-xl cursor-pointer hover:border-violet-500/30 hover:text-violet-400 transition-all"
@click="openGenPicker(post)">
<i class="pi pi-images mr-1"></i> Нажмите, чтобы добавить изображения
</div>
</div>
</div>
</div>
</div>
<!-- ====== NEW / EDIT POST DIALOG ====== -->
<Dialog v-model:visible="showPostDialog" :header="editingPost ? 'Редактировать пост' : 'Новый пост'" modal
:style="{ width: '600px', maxWidth: '95vw' }"
:pt="{ root: { class: '!bg-slate-800 !border-white/10' }, header: { class: '!bg-slate-800' }, content: { class: '!bg-slate-800' } }">
<div class="flex flex-col gap-4">
<!-- Date & Topic row -->
<div class="grid grid-cols-2 gap-3">
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Дата</label>
<DatePicker v-model="postForm.date" dateFormat="dd.mm.yy" showIcon class="w-full" :pt="{
root: { class: '!bg-slate-700 !border-white/10' },
pcInputText: { root: { class: '!bg-slate-700 !border-white/10 !text-white' } }
}" />
</div>
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Тема</label>
<InputText v-model="postForm.topic" placeholder="Тема поста..."
class="w-full !bg-slate-700 !border-white/10 !text-white" />
</div>
</div>
<!-- Attached Generations (edit mode only) -->
<div v-if="editingPost">
<div class="flex items-center justify-between mb-2">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">
Изображения ({{ editingPost.generation_ids?.length || 0 }})
</label>
<div class="flex gap-1">
<Button icon="pi pi-download" label="Скачать" size="small" text :loading="isDownloading"
:disabled="!editingPost.generation_ids?.length" @click="downloadPostAssets(editingPost)"
class="!text-slate-400 hover:!text-white !text-xs !py-1" />
<Button icon="pi pi-plus" label="Добавить" size="small" text
@click="openGenPicker(editingPost)"
class="!text-violet-400 hover:!text-violet-300 !text-xs !py-1" />
</div>
</div>
<!-- Generation grid -->
<div v-if="editingPost.generation_ids?.length > 0" class="grid grid-cols-4 sm:grid-cols-5 gap-2">
<div v-for="gid in editingPost.generation_ids" :key="gid"
class="aspect-square relative rounded-xl overflow-hidden bg-slate-900 border border-white/5 group/img">
<img :src="API_URL + '/assets/' + gid + '?thumbnail=true'"
class="w-full h-full object-cover cursor-pointer"
@click="openPreview(editingPost.generation_ids, gid)" />
<button @click="removeGenerationFromPost(editingPost, gid)"
class="absolute top-1 right-1 w-5 h-5 rounded-md bg-red-600/80 text-white flex items-center justify-center opacity-0 group-hover/img:opacity-100 transition-opacity hover:bg-red-500">
<i class="pi pi-times" style="font-size: 8px"></i>
</button>
</div>
</div>
<div v-else
class="py-6 text-center text-slate-600 text-xs border border-dashed border-white/5 rounded-xl cursor-pointer hover:border-violet-500/30 hover:text-violet-400 transition-all"
@click="openGenPicker(editingPost)">
<i class="pi pi-images mr-1"></i> Нажмите, чтобы добавить изображения
</div>
</div>
<div class="flex justify-end gap-2 mt-2">
<Button label="Отмена" text @click="showPostDialog = false"
class="!text-slate-400 hover:!text-white" />
<Button :label="editingPost ? 'Сохранить' : 'Создать'" @click="savePost"
class="!bg-violet-600 !border-none hover:!bg-violet-500" />
</div>
</div>
</Dialog>
<!-- ====== GENERATION PICKER DIALOG ====== -->
<Dialog v-model:visible="showGenPicker" header="Добавить изображения" modal
:style="{ width: '700px', maxWidth: '95vw' }"
:pt="{ root: { class: '!bg-slate-800 !border-white/10' }, header: { class: '!bg-slate-800' }, content: { class: '!bg-slate-800 !p-0' } }">
<!-- Selected count bar -->
<div v-if="selectedGenIds.size > 0"
class="sticky top-0 z-10 flex items-center justify-between px-4 py-2 bg-violet-600/20 border-b border-violet-500/20">
<span class="text-sm text-violet-200 font-medium">
<i class="pi pi-check-circle mr-1"></i> Выбрано: {{ selectedGenIds.size }}
</span>
<Button label="Добавить" icon="pi pi-plus" @click="confirmAddGenerations" size="small"
class="!bg-violet-600 !border-none hover:!bg-violet-500 !text-sm !py-1" />
</div>
<!-- Loading -->
<div v-if="genLoading" class="flex items-center justify-center py-20">
<i class="pi pi-spin pi-spinner text-3xl text-violet-400"></i>
</div>
<!-- Grid -->
<div v-else class="p-4 max-h-[60vh] overflow-y-auto custom-scrollbar" @scroll="onGenPickerScroll">
<div v-if="availableGenerations.length === 0"
class="flex flex-col items-center justify-center py-16 text-slate-500">
<i class="pi pi-image text-4xl mb-3"></i>
<p class="text-sm">Нет доступных генераций</p>
</div>
<div class="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2">
<template v-for="gen in availableGenerations" :key="gen.id">
<div v-for="assetId in (gen.result_list || [])" :key="assetId"
@click="toggleGenSelection(assetId)"
class="aspect-square relative rounded-xl overflow-hidden cursor-pointer transition-all group/gen border-2"
:class="selectedGenIds.has(assetId)
? 'border-violet-500 ring-2 ring-violet-500/30 scale-[0.95]'
: 'border-transparent hover:border-white/20'">
<img :src="API_URL + '/assets/' + assetId + '?thumbnail=true'"
class="w-full h-full object-cover" loading="lazy" />
<!-- Selection overlay -->
<div v-if="selectedGenIds.has(assetId)"
class="absolute inset-0 bg-violet-600/30 flex items-center justify-center">
<div
class="w-7 h-7 rounded-full bg-violet-600 flex items-center justify-center shadow-lg">
<i class="pi pi-check text-white" style="font-size: 12px"></i>
</div>
</div>
<!-- Hover overlay -->
<div v-else
class="absolute inset-0 bg-black/0 group-hover/gen:bg-black/20 transition-all flex items-center justify-center">
<div
class="w-7 h-7 rounded-full border-2 border-white/40 opacity-0 group-hover/gen:opacity-100 transition-opacity">
</div>
</div>
</div>
</template>
</div>
<!-- Load more spinner -->
<div v-if="genLoadingMore" class="flex justify-center py-4">
<i class="pi pi-spin pi-spinner text-xl text-slate-500"></i>
</div>
</div>
<!-- Footer with action -->
<div class="flex justify-end gap-2 px-4 py-3 border-t border-white/5">
<Button label="Отмена" text @click="showGenPicker = false" class="!text-slate-400 hover:!text-white" />
<Button label="Добавить" icon="pi pi-plus" :disabled="selectedGenIds.size === 0"
@click="confirmAddGenerations" class="!bg-violet-600 !border-none hover:!bg-violet-500" />
</div>
</Dialog>
<!-- ====== FULLSCREEN IMAGE PREVIEW ====== -->
<div v-if="previewVisible" class="fixed inset-0 z-[9999] bg-black/95 flex items-center justify-center"
@click.self="previewVisible = false">
<!-- Close -->
<button @click="previewVisible = false"
class="absolute top-4 right-4 w-10 h-10 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors z-10">
<i class="pi pi-times text-lg"></i>
</button>
<!-- Counter -->
<div v-if="previewImages.length > 1"
class="absolute top-4 left-1/2 -translate-x-1/2 text-white/60 text-sm bg-black/40 px-3 py-1 rounded-full">
{{ previewIndex + 1 }} / {{ previewImages.length }}
</div>
<!-- Left arrow -->
<button v-if="previewImages.length > 1" @click="previewNav(-1)"
class="absolute left-3 top-1/2 -translate-y-1/2 w-10 h-10 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors">
<i class="pi pi-chevron-left"></i>
</button>
<!-- Image -->
<img v-if="previewCurrent" :src="previewCurrent"
class="max-h-[90vh] max-w-[90vw] object-contain rounded-lg shadow-2xl" />
<!-- Right arrow -->
<button v-if="previewImages.length > 1" @click="previewNav(1)"
class="absolute right-3 top-1/2 -translate-y-1/2 w-10 h-10 rounded-full bg-white/10 text-white flex items-center justify-center hover:bg-white/20 transition-colors">
<i class="pi pi-chevron-right"></i>
</button>
</div>
</div>
</template>
<style scoped>
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.2);
}
</style>

View File

@@ -3,12 +3,14 @@ import { ref, onMounted, onBeforeUnmount, watch, computed } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { dataService } from '../services/dataService' import { dataService } from '../services/dataService'
import { aiService } from '../services/aiService' import { aiService } from '../services/aiService'
import { postService } from '../services/postService'
import Button from 'primevue/button' import Button from 'primevue/button'
import Textarea from 'primevue/textarea' import Textarea from 'primevue/textarea'
import InputText from 'primevue/inputtext' import InputText from 'primevue/inputtext'
import Dialog from 'primevue/dialog' import Dialog from 'primevue/dialog'
import Checkbox from 'primevue/checkbox' import Checkbox from 'primevue/checkbox'
import Dropdown from 'primevue/dropdown' import Dropdown from 'primevue/dropdown'
import DatePicker from 'primevue/datepicker'
import MultiSelect from 'primevue/multiselect' import MultiSelect from 'primevue/multiselect'
import ProgressSpinner from 'primevue/progressspinner' import ProgressSpinner from 'primevue/progressspinner'
import ProgressBar from 'primevue/progressbar' import ProgressBar from 'primevue/progressbar'
@@ -16,10 +18,122 @@ import Message from 'primevue/message'
import Skeleton from 'primevue/skeleton' import Skeleton from 'primevue/skeleton'
import { useAlbumStore } from '../stores/albums' import { useAlbumStore } from '../stores/albums'
import { useToast } from 'primevue/usetoast'
import Toast from 'primevue/toast'
const router = useRouter() const router = useRouter()
const API_URL = import.meta.env.VITE_API_URL const API_URL = import.meta.env.VITE_API_URL
const albumStore = useAlbumStore() const albumStore = useAlbumStore()
const toast = useToast()
// --- Multi-Select ---
const isSelectMode = ref(false)
const selectedAssetIds = ref(new Set())
const isDownloading = ref(false)
const toggleSelectMode = () => {
isSelectMode.value = !isSelectMode.value
if (!isSelectMode.value) selectedAssetIds.value = new Set()
}
const toggleImageSelection = (assetId) => {
const s = new Set(selectedAssetIds.value)
if (s.has(assetId)) s.delete(assetId)
else s.add(assetId)
selectedAssetIds.value = s
}
const selectAllImages = () => {
const s = new Set()
for (const gen of historyGenerations.value) {
if (gen.result_list) {
for (const id of gen.result_list) s.add(id)
}
}
selectedAssetIds.value = s
}
const downloadSelected = async () => {
const ids = [...selectedAssetIds.value]
if (ids.length === 0) return
isDownloading.value = true
try {
const user = JSON.parse(localStorage.getItem('user'))
const headers = {}
if (user && user.access_token) headers['Authorization'] = `Bearer ${user.access_token}`
else if (user && user.token) headers['Authorization'] = `${user.tokenType} ${user.token}`
const projectId = localStorage.getItem('active_project_id')
if (projectId) headers['X-Project-ID'] = projectId
const files = []
for (const assetId of ids) {
const url = API_URL + '/assets/' + assetId
const resp = await fetch(url, { headers })
const blob = await resp.blob()
files.push(new File([blob], assetId + '.png', { type: blob.type || 'image/png' }))
}
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || navigator.maxTouchPoints > 1
if (isMobile && navigator.canShare && navigator.canShare({ files })) {
await navigator.share({ files })
} else {
for (let i = 0; i < files.length; i++) {
const file = files[i]
const a = document.createElement('a')
a.href = URL.createObjectURL(file)
a.download = file.name
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
if (i < files.length - 1) await new Promise(r => setTimeout(r, 300))
}
}
toast.add({ severity: 'success', summary: `Скачано ${ids.length} файлов`, life: 2000 })
} catch (e) {
console.error('Download failed', e)
toast.add({ severity: 'error', summary: 'Ошибка скачивания', life: 3000 })
} finally {
isDownloading.value = false
}
}
// --- Add to Content Plan ---
const showAddToPlanDialog = ref(false)
const planPostDate = ref(new Date())
const planPostTopic = ref('')
const isSavingToPlan = ref(false)
const openAddToPlan = () => {
planPostDate.value = new Date()
planPostTopic.value = ''
showAddToPlanDialog.value = true
}
const confirmAddToPlan = async () => {
if (!planPostTopic.value.trim()) {
toast.add({ severity: 'warn', summary: 'Укажите тему', life: 2000 })
return
}
isSavingToPlan.value = true
try {
const d = new Date(planPostDate.value); d.setHours(12, 0, 0, 0)
await postService.createPost({
date: d.toISOString(),
topic: planPostTopic.value,
generation_ids: [...selectedAssetIds.value]
})
toast.add({ severity: 'success', summary: 'Добавлено в контент-план', life: 2000 })
showAddToPlanDialog.value = false
isSelectMode.value = false
selectedAssetIds.value = new Set()
} catch (e) {
console.error('Add to plan failed', e)
toast.add({ severity: 'error', summary: 'Ошибка', detail: 'Не удалось добавить', life: 3000 })
} finally {
isSavingToPlan.value = false
}
}
// --- State --- // --- State ---
const prompt = ref('') const prompt = ref('')
@@ -731,6 +845,9 @@ const confirmAddToAlbum = async () => {
</Dropdown> </Dropdown>
<Button icon="pi pi-refresh" @click="refreshHistory" rounded text <Button icon="pi pi-refresh" @click="refreshHistory" rounded text
class="!text-slate-400 hover:!bg-white/10 !w-8 !h-8 md:hidden" /> class="!text-slate-400 hover:!bg-white/10 !w-8 !h-8 md:hidden" />
<Button :icon="isSelectMode ? 'pi pi-times' : 'pi pi-check-square'" @click="toggleSelectMode"
rounded text class="!w-8 !h-8"
:class="isSelectMode ? '!text-violet-400 !bg-violet-500/20' : '!text-slate-400 hover:!bg-white/10'" />
<Button icon="pi pi-cog" @click="isSettingsVisible = true" rounded text <Button icon="pi pi-cog" @click="isSettingsVisible = true" rounded text
class="!text-slate-400 hover:!bg-white/10 !w-8 !h-8" v-if="!isSettingsVisible" /> class="!text-slate-400 hover:!bg-white/10 !w-8 !h-8" v-if="!isSettingsVisible" />
</div> </div>
@@ -748,7 +865,7 @@ const confirmAddToAlbum = async () => {
<!-- ============================================ --> <!-- ============================================ -->
<template v-if="item.isGroup"> <template v-if="item.isGroup">
<!-- Group badge --> <!-- Group badge -->
<div <div v-if="!isSelectMode"
class="absolute top-1.5 left-1.5 z-20 bg-violet-600/80 backdrop-blur-sm text-white text-[9px] font-bold px-1.5 py-0.5 rounded-md pointer-events-none"> class="absolute top-1.5 left-1.5 z-20 bg-violet-600/80 backdrop-blur-sm text-white text-[9px] font-bold px-1.5 py-0.5 rounded-md pointer-events-none">
{{ item.children.length }}x {{ item.children.length }}x
</div> </div>
@@ -807,14 +924,11 @@ const confirmAddToAlbum = async () => {
class="absolute inset-0 bg-black/60 transition-opacity duration-200 flex flex-col justify-between p-1 z-10" class="absolute inset-0 bg-black/60 transition-opacity duration-200 flex flex-col justify-between p-1 z-10"
:class="{ 'opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto': activeOverlayId !== child.id, 'opacity-100 pointer-events-auto': activeOverlayId === child.id }"> :class="{ 'opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto': activeOverlayId !== child.id, 'opacity-100 pointer-events-auto': activeOverlayId === child.id }">
<!-- Top right: edit, album, delete --> <!-- Top right: edit, delete -->
<div class="flex justify-end items-start gap-0.5"> <div class="flex justify-end items-start gap-0.5">
<Button icon="pi pi-pencil" size="small" <Button icon="pi pi-pencil" size="small"
class="!w-5 !h-5 !rounded-full !bg-white/20 !border-none !text-white !text-[8px] hover:!bg-violet-500" class="!w-5 !h-5 !rounded-full !bg-white/20 !border-none !text-white !text-[8px] hover:!bg-violet-500"
@click.stop="useResultAsAsset(child)" /> @click.stop="useResultAsAsset(child)" />
<Button icon="pi pi-folder-plus" size="small"
class="!w-5 !h-5 !rounded-full !bg-white/20 !border-none !text-white !text-[8px] hover:!bg-violet-500"
@click.stop="openAlbumPicker(child)" />
<Button icon="pi pi-trash" size="small" <Button icon="pi pi-trash" size="small"
class="!w-5 !h-5 !rounded-full !bg-red-500/20 !border-none !text-red-400 !text-[8px] hover:!bg-red-500 hover:!text-white" class="!w-5 !h-5 !rounded-full !bg-red-500/20 !border-none !text-red-400 !text-[8px] hover:!bg-red-500 hover:!text-white"
@click.stop="deleteGeneration(child)" /> @click.stop="deleteGeneration(child)" />
@@ -842,6 +956,20 @@ const confirmAddToAlbum = async () => {
</div> </div>
</div> </div>
</div> </div>
<!-- Selection overlay for group children -->
<div v-if="isSelectMode" class="absolute inset-0 z-30 pointer-events-none">
<div class="absolute top-1 left-1 z-30 flex flex-col gap-0.5 pointer-events-auto">
<template v-for="child in item.children" :key="'chk-'+child.id">
<div v-if="child.result_list && child.result_list.length > 0"
@click.stop="toggleImageSelection(child.result_list[0])"
class="w-5 h-5 rounded-md flex items-center justify-center cursor-pointer transition-all"
:class="selectedAssetIds.has(child.result_list[0]) ? 'bg-violet-600 text-white' : 'bg-black/40 border border-white/30 text-transparent'">
<i class="pi pi-check" style="font-size: 10px"></i>
</div>
</template>
</div>
</div>
</template> </template>
<!-- ============================================ --> <!-- ============================================ -->
@@ -854,7 +982,7 @@ const confirmAddToAlbum = async () => {
<img v-if="item.result_list && item.result_list.length > 0" <img v-if="item.result_list && item.result_list.length > 0"
:src="API_URL + '/assets/' + item.result_list[0] + '?thumbnail=true'" :src="API_URL + '/assets/' + item.result_list[0] + '?thumbnail=true'"
class="w-full h-full object-cover cursor-pointer" class="w-full h-full object-cover cursor-pointer"
@click.stop="openImagePreview(API_URL + '/assets/' + item.result_list[0])" /> @click.stop="isSelectMode ? toggleImageSelection(item.result_list[0]) : openImagePreview(API_URL + '/assets/' + item.result_list[0])" />
<!-- FAILED: error display --> <!-- FAILED: error display -->
<div v-else-if="item.status === 'failed'" <div v-else-if="item.status === 'failed'"
@@ -924,9 +1052,6 @@ const confirmAddToAlbum = async () => {
icon="pi pi-pencil" v-tooltip.left="'Edit (Use Result)'" icon="pi pi-pencil" v-tooltip.left="'Edit (Use Result)'"
class="!w-6 !h-6 !rounded-full !bg-white/20 !border-none !text-white text-[10px] hover:!bg-violet-500" class="!w-6 !h-6 !rounded-full !bg-white/20 !border-none !text-white text-[10px] hover:!bg-violet-500"
@click.stop="useResultAsAsset(item)" /> @click.stop="useResultAsAsset(item)" />
<Button icon="pi pi-folder-plus" v-tooltip.left="'Add to Album'"
class="!w-6 !h-6 !rounded-full !bg-white/20 !border-none !text-white text-[10px] hover:!bg-violet-500"
@click.stop="openAlbumPicker(item)" />
<Button icon="pi pi-trash" v-tooltip.left="'Delete'" <Button icon="pi pi-trash" v-tooltip.left="'Delete'"
class="!w-6 !h-6 !rounded-full !bg-red-500/20 !border-none !text-red-400 text-[10px] hover:!bg-red-500 hover:!text-white" class="!w-6 !h-6 !rounded-full !bg-red-500/20 !border-none !text-red-400 text-[10px] hover:!bg-red-500 hover:!text-white"
@click.stop="deleteGeneration(item)" /> @click.stop="deleteGeneration(item)" />
@@ -966,6 +1091,18 @@ const confirmAddToAlbum = async () => {
}}</p> }}</p>
</div> </div>
</div> </div>
<!-- Select mode checkbox overlay -->
<div v-if="isSelectMode && item.result_list && item.result_list.length > 0"
class="absolute inset-0 z-20 cursor-pointer"
@click.stop="toggleImageSelection(item.result_list[0])">
<div class="absolute top-2 left-2 w-6 h-6 rounded-lg flex items-center justify-center transition-all"
:class="selectedAssetIds.has(item.result_list[0]) ? 'bg-violet-600 text-white' : 'bg-black/40 border border-white/30 text-transparent hover:border-white/60'">
<i class="pi pi-check" style="font-size: 12px"></i>
</div>
<div v-if="selectedAssetIds.has(item.result_list[0])"
class="absolute inset-0 bg-violet-600/20 pointer-events-none"></div>
</div>
</div> </div>
</template> </template>
</div> </div>
@@ -987,7 +1124,7 @@ const confirmAddToAlbum = async () => {
</div> </div>
</div> </div>
<div v-if="isSettingsVisible" <div v-if="isSettingsVisible && !isSelectMode"
class="absolute bottom-2 left-1/2 -translate-x-1/2 w-[98%] max-w-6xl glass-panel border border-white/10 bg-slate-900/95 backdrop-blur-xl p-4 z-[60] !rounded-[2.5rem] shadow-2xl flex flex-col gap-3 max-h-[85vh] overflow-y-auto"> class="absolute bottom-2 left-1/2 -translate-x-1/2 w-[98%] max-w-6xl glass-panel border border-white/10 bg-slate-900/95 backdrop-blur-xl p-4 z-[60] !rounded-[2.5rem] shadow-2xl flex flex-col gap-3 max-h-[85vh] overflow-y-auto">
<div class="w-full flex justify-center -mt-2 mb-2 cursor-pointer" @click="isSettingsVisible = false"> <div class="w-full flex justify-center -mt-2 mb-2 cursor-pointer" @click="isSettingsVisible = false">
@@ -1282,6 +1419,53 @@ const confirmAddToAlbum = async () => {
</template> </template>
</Dialog> </Dialog>
<Toast />
<!-- Multi-select floating bar -->
<Transition name="slide-up">
<div v-if="isSelectMode && selectedAssetIds.size > 0"
class="fixed bottom-6 left-1/2 -translate-x-1/2 z-[100] bg-slate-800/95 backdrop-blur-xl border border-white/10 rounded-2xl shadow-2xl px-5 py-3 flex items-center gap-3">
<span class="text-sm text-slate-300 font-medium">
<i class="pi pi-check-circle mr-1 text-violet-400"></i>
{{ selectedAssetIds.size }} selected
</span>
<div class="w-px h-6 bg-white/10"></div>
<Button icon="pi pi-check-square" label="All" size="small" text @click="selectAllImages"
class="!text-slate-400 hover:!text-white !text-xs" />
<Button icon="pi pi-download" label="Download" size="small" :loading="isDownloading"
@click="downloadSelected" class="!bg-violet-600 !border-none hover:!bg-violet-500 !text-sm" />
<Button icon="pi pi-calendar" label="To plan" size="small" @click="openAddToPlan"
class="!bg-emerald-600 !border-none hover:!bg-emerald-500 !text-sm" />
</div>
</Transition>
<!-- Add to Plan Dialog -->
<Dialog v-model:visible="showAddToPlanDialog" header="Добавить в контент-план" modal :style="{ width: '400px' }"
:pt="{ root: { class: '!bg-slate-800 !border-white/10' }, header: { class: '!bg-slate-800' }, content: { class: '!bg-slate-800' } }">
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Дата</label>
<DatePicker v-model="planPostDate" dateFormat="dd.mm.yy" showIcon class="w-full" :pt="{
root: { class: '!bg-slate-700 !border-white/10' },
pcInputText: { root: { class: '!bg-slate-700 !border-white/10 !text-white' } }
}" />
</div>
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Тема</label>
<InputText v-model="planPostTopic" placeholder="Тема поста..."
class="w-full !bg-slate-700 !border-white/10 !text-white" />
</div>
<p class="text-xs text-slate-500"><i class="pi pi-images mr-1"></i>{{ selectedAssetIds.size }}
изображений
будет добавлено</p>
<div class="flex justify-end gap-2">
<Button label="Отмена" text @click="showAddToPlanDialog = false"
class="!text-slate-400 hover:!text-white" />
<Button label="Добавить" icon="pi pi-check" :loading="isSavingToPlan" @click="confirmAddToPlan"
class="!bg-violet-600 !border-none hover:!bg-violet-500" />
</div>
</div>
</Dialog>
</div> </div>
</template> </template>

View File

@@ -7,7 +7,9 @@ import { useConfirm } from 'primevue/useconfirm'
import { useToast } from 'primevue/usetoast' import { useToast } from 'primevue/usetoast'
import { aiService } from '../services/aiService' import { aiService } from '../services/aiService'
import { dataService } from '../services/dataService' import { dataService } from '../services/dataService'
import { postService } from '../services/postService'
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import JSZip from 'jszip'
// Components // Components
import Button from 'primevue/button' import Button from 'primevue/button'
@@ -23,6 +25,7 @@ import TabMenu from 'primevue/tabmenu'
import FileUpload from 'primevue/fileupload' import FileUpload from 'primevue/fileupload'
import ConfirmDialog from 'primevue/confirmdialog' import ConfirmDialog from 'primevue/confirmdialog'
import InputText from 'primevue/inputtext' import InputText from 'primevue/inputtext'
import DatePicker from 'primevue/datepicker'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
@@ -136,6 +139,15 @@ onMounted(async () => {
]) ])
console.log('Fetched idea:', currentIdea.value) console.log('Fetched idea:', currentIdea.value)
if (currentIdea.value) { if (currentIdea.value) {
// Check for autostart query param
if (route.query.autostart === 'true') {
// Slight delay to ensure everything is reactive and mounted
setTimeout(() => {
handleGenerate()
// Remove query param to prevent re-trigger on reload
router.replace({ query: null })
}, 500)
}
fetchGenerations(id) fetchGenerations(id)
} else { } else {
console.error('currentIdea is null after fetch') console.error('currentIdea is null after fetch')
@@ -662,21 +674,59 @@ const downloadSelected = async () => {
const projectId = localStorage.getItem('active_project_id') const projectId = localStorage.getItem('active_project_id')
if (projectId) headers['X-Project-ID'] = projectId if (projectId) headers['X-Project-ID'] = projectId
// Fetch all blobs // Multi-file ZIP (if > 1)
const files = [] if (ids.length > 1) {
for (const assetId of ids) { const zip = new JSZip()
// Sanitize idea name for filename (fallback to 'session' if no name)
const safeName = (currentIdea.value?.name || 'session').replace(/[^a-z0-9_\- ]/gi, '').trim().replace(/\s+/g, '_').toLowerCase()
const folderName = `${safeName}_assets`
let successCount = 0
// Sequential fetch to avoid overwhelming network but could be parallel
await Promise.all(ids.map(async (assetId) => {
try {
const url = API_URL + '/assets/' + assetId
const resp = await fetch(url, { headers })
if (!resp.ok) return
const blob = await resp.blob()
const mime = blob.type
const ext = mime.split('/')[1] || 'png'
zip.file(`${assetId}.${ext}`, blob)
successCount++
} catch (err) {
console.error('Failed to zip asset', assetId, err)
}
}))
if (successCount === 0) throw new Error('No images available for zip')
const content = await zip.generateAsync({ type: 'blob' })
const filename = `${folderName}.zip`
const a = document.createElement('a')
a.href = URL.createObjectURL(content)
a.download = filename
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
toast.add({ severity: 'success', summary: 'Archived', detail: `${successCount} images saved to zip`, life: 3000 })
} else {
// Single File
const assetId = ids[0]
const url = API_URL + '/assets/' + assetId const url = API_URL + '/assets/' + assetId
const resp = await fetch(url, { headers }) const resp = await fetch(url, { headers })
const blob = await resp.blob() const blob = await resp.blob()
files.push(new File([blob], assetId + '.png', { type: blob.type || 'image/png' }))
}
// Try native share (iOS share sheet) // Use share sheet only on mobile, direct download on desktop
if (navigator.canShare && navigator.canShare({ files })) { const file = new File([blob], assetId + '.png', { type: blob.type || 'image/png' })
await navigator.share({ files }) const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) || navigator.maxTouchPoints > 1
if (isMobile && navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({ files: [file] })
} else { } else {
// Fallback: browser download
for (const file of files) {
const a = document.createElement('a') const a = document.createElement('a')
a.href = URL.createObjectURL(file) a.href = URL.createObjectURL(file)
a.download = file.name a.download = file.name
@@ -685,8 +735,8 @@ const downloadSelected = async () => {
document.body.removeChild(a) document.body.removeChild(a)
URL.revokeObjectURL(a.href) URL.revokeObjectURL(a.href)
} }
toast.add({ severity: 'success', summary: 'Downloaded', detail: `Image saved`, life: 2000 })
} }
toast.add({ severity: 'success', summary: 'Downloaded', detail: `${ids.length} image(s) saved`, life: 2000 })
} catch (e) { } catch (e) {
console.error('Download failed', e) console.error('Download failed', e)
toast.add({ severity: 'error', summary: 'Error', detail: 'Download failed', life: 3000 }) toast.add({ severity: 'error', summary: 'Error', detail: 'Download failed', life: 3000 })
@@ -695,6 +745,49 @@ const downloadSelected = async () => {
} }
} }
// --- Add to Content Plan ---
const showAddToPlanDialog = ref(false)
const planPostDate = ref(new Date())
const planPostTopic = ref('')
const isSavingToPlan = ref(false)
function openAddToPlanDialog() {
planPostDate.value = new Date()
planPostTopic.value = ''
showAddToPlanDialog.value = true
}
async function confirmAddToPlan() {
if (!planPostTopic.value.trim()) {
toast.add({ severity: 'warn', summary: 'Укажите тему', life: 2000 })
return
}
isSavingToPlan.value = true
try {
// Collect unique generation ids for selected assets
const genIds = new Set()
for (const img of allGalleryImages.value) {
if (selectedAssetIds.value.has(img.assetId)) {
genIds.add(img.assetId)
}
}
await postService.createPost({
date: (() => { const d = new Date(planPostDate.value); d.setHours(12, 0, 0, 0); return d.toISOString() })(),
topic: planPostTopic.value,
generation_ids: [...genIds]
})
toast.add({ severity: 'success', summary: 'Added to content plan', life: 2000 })
showAddToPlanDialog.value = false
isSelectMode.value = false
selectedAssetIds.value = new Set()
} catch (e) {
console.error('Add to plan failed', e)
toast.add({ severity: 'error', summary: 'Error', detail: 'Failed to add to plan', life: 3000 })
} finally {
isSavingToPlan.value = false
}
}
// Exit select mode when switching to feed // Exit select mode when switching to feed
watch(viewMode, (v) => { watch(viewMode, (v) => {
if (v !== 'gallery') { if (v !== 'gallery') {
@@ -924,6 +1017,8 @@ watch(viewMode, (v) => {
<div v-if="isSelectMode && selectedAssetIds.size > 0" <div v-if="isSelectMode && selectedAssetIds.size > 0"
class="fixed bottom-6 left-1/2 -translate-x-1/2 z-[70] flex items-center gap-3 bg-slate-900/95 backdrop-blur-xl border border-white/10 rounded-full px-5 py-3 shadow-2xl"> class="fixed bottom-6 left-1/2 -translate-x-1/2 z-[70] flex items-center gap-3 bg-slate-900/95 backdrop-blur-xl border border-white/10 rounded-full px-5 py-3 shadow-2xl">
<span class="text-sm text-white font-medium">{{ selectedAssetIds.size }} selected</span> <span class="text-sm text-white font-medium">{{ selectedAssetIds.size }} selected</span>
<Button label="📅 Add to plan" icon="pi pi-calendar" @click="openAddToPlanDialog"
class="!bg-emerald-600 !border-none !rounded-full !text-sm !font-bold hover:!bg-emerald-500 !px-4 !py-2" />
<Button :label="isDownloading ? 'Downloading...' : 'Download'" icon="pi pi-download" <Button :label="isDownloading ? 'Downloading...' : 'Download'" icon="pi pi-download"
:loading="isDownloading" @click="downloadSelected" :loading="isDownloading" @click="downloadSelected"
class="!bg-violet-600 !border-none !rounded-full !text-sm !font-bold hover:!bg-violet-500 !px-4 !py-2" /> class="!bg-violet-600 !border-none !rounded-full !text-sm !font-bold hover:!bg-violet-500 !px-4 !py-2" />
@@ -934,7 +1029,7 @@ watch(viewMode, (v) => {
</div> </div>
<!-- SETTINGS PANEL (Bottom) --> <!-- SETTINGS PANEL (Bottom) -->
<div v-if="isSettingsVisible" <div v-if="isSettingsVisible && !isSelectMode"
class="absolute bottom-2 left-1/2 -translate-x-1/2 w-[98%] max-w-6xl glass-panel border border-white/10 bg-slate-900/95 backdrop-blur-xl px-4 py-3 z-[60] !rounded-[2rem] shadow-2xl flex flex-col gap-1 max-h-[60vh] overflow-y-auto"> class="absolute bottom-2 left-1/2 -translate-x-1/2 w-[98%] max-w-6xl glass-panel border border-white/10 bg-slate-900/95 backdrop-blur-xl px-4 py-3 z-[60] !rounded-[2rem] shadow-2xl flex flex-col gap-1 max-h-[60vh] overflow-y-auto">
<div class="w-full flex justify-center -mt-1 mb-1 cursor-pointer" @click="isSettingsVisible = false"> <div class="w-full flex justify-center -mt-1 mb-1 cursor-pointer" @click="isSettingsVisible = false">
@@ -1197,6 +1292,35 @@ watch(viewMode, (v) => {
</div> </div>
</Dialog> </Dialog>
<!-- Add to Content Plan Dialog -->
<Dialog v-model:visible="showAddToPlanDialog" header="Add to content plan" modal :style="{ width: '420px' }"
:pt="{ root: { class: '!bg-slate-800 !border-white/10' }, header: { class: '!bg-slate-800' }, content: { class: '!bg-slate-800' } }">
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Publication
date</label>
<DatePicker v-model="planPostDate" dateFormat="dd.mm.yy" showIcon class="w-full" :pt="{
root: { class: '!bg-slate-700 !border-white/10' },
pcInputText: { root: { class: '!bg-slate-700 !border-white/10 !text-white' } }
}" />
</div>
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Post topic</label>
<InputText v-model="planPostTopic" placeholder="Post topic..."
class="w-full !bg-slate-700 !border-white/10 !text-white" />
</div>
<p class="text-xs text-slate-500">
<i class="pi pi-images mr-1"></i> {{ selectedAssetIds.size }} images will be added
</p>
<div class="flex justify-end gap-2 mt-2">
<Button label="Отмена" text @click="showAddToPlanDialog = false"
class="!text-slate-400 hover:!text-white" />
<Button label="Добавить" :loading="isSavingToPlan" @click="confirmAddToPlan"
class="!bg-emerald-600 !border-none hover:!bg-emerald-500" />
</div>
</div>
</Dialog>
</div> </div>
</template> </template>

View File

@@ -1,14 +1,17 @@
<script setup> <script setup>
import { ref, onMounted } from 'vue' import { ref, onMounted, watch } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useIdeaStore } from '../stores/ideas' import { useIdeaStore } from '../stores/ideas'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { dataService } from '../services/dataService' // Added import
import Skeleton from 'primevue/skeleton' import Skeleton from 'primevue/skeleton'
import Dialog from 'primevue/dialog' import Dialog from 'primevue/dialog'
import InputText from 'primevue/inputtext' import InputText from 'primevue/inputtext'
import Textarea from 'primevue/textarea' import Textarea from 'primevue/textarea'
import Button from 'primevue/button' import Button from 'primevue/button'
import Image from 'primevue/image' import Image from 'primevue/image'
import Dropdown from 'primevue/dropdown'
import Checkbox from 'primevue/checkbox'
const router = useRouter() const router = useRouter()
const ideaStore = useIdeaStore() const ideaStore = useIdeaStore()
@@ -19,10 +22,103 @@ const newIdea = ref({ name: '', description: '' })
const submitting = ref(false) const submitting = ref(false)
const API_URL = import.meta.env.VITE_API_URL const API_URL = import.meta.env.VITE_API_URL
// --- Generation Settings ---
const prompt = ref('')
const selectedModel = ref('flux-schnell')
const quality = ref({ key: 'TWOK', value: '2K' })
const aspectRatio = ref({ key: 'NINESIXTEEN', value: '9:16' })
const imageCount = ref(1)
const sendToTelegram = ref(false)
const telegramId = ref('')
const useProfileImage = ref(true)
const isSubmittingGen = ref(false)
// Character & Assets
const characters = ref([])
const selectedCharacter = ref(null)
const selectedAssets = ref([])
let _savedCharacterId = null
const qualityOptions = ref([
{ key: 'ONEK', value: '1K' },
{ key: 'TWOK', value: '2K' },
{ key: 'FOURK', value: '4K' }
])
const aspectRatioOptions = ref([
{ key: "NINESIXTEEN", value: "9:16" },
{ key: "FOURTHREE", value: "4:3" },
{ key: "THREEFOUR", value: "3:4" },
{ key: "SIXTEENNINE", value: "16:9" }
])
// Restore settings
const SETTINGS_KEY = 'idea-gen-settings'
const restoreSettings = () => {
const stored = localStorage.getItem(SETTINGS_KEY)
if (!stored) return
try {
const s = JSON.parse(stored)
if (s.prompt) prompt.value = s.prompt
if (s.quality) quality.value = s.quality
if (s.aspectRatio) aspectRatio.value = s.aspectRatio
if (s.imageCount) imageCount.value = Math.min(s.imageCount, 4)
if (s.selectedModel) selectedModel.value = s.selectedModel
sendToTelegram.value = s.sendToTelegram || false
telegramId.value = s.telegramId || localStorage.getItem('telegram_id') || ''
if (s.useProfileImage !== undefined) useProfileImage.value = s.useProfileImage
_savedCharacterId = s.selectedCharacterId || null
if (s.selectedAssetIds && s.selectedAssetIds.length > 0) {
selectedAssets.value = s.selectedAssetIds.map(id => ({
id,
url: `/assets/${id}`,
name: 'Asset ' + id.substring(0, 4)
}))
}
} catch (e) {
console.error('Failed to restore settings', e)
}
}
const saveSettings = () => {
const settings = {
prompt: prompt.value,
quality: quality.value,
aspectRatio: aspectRatio.value,
imageCount: imageCount.value,
selectedModel: selectedModel.value,
sendToTelegram: sendToTelegram.value,
telegramId: telegramId.value,
useProfileImage: useProfileImage.value,
selectedCharacterId: selectedCharacter.value?.id || null,
selectedAssetIds: selectedAssets.value.map(a => a.id),
}
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings))
if (telegramId.value) localStorage.setItem('telegram_id', telegramId.value)
}
watch([prompt, quality, aspectRatio, imageCount, selectedModel, sendToTelegram, telegramId, useProfileImage, selectedCharacter, selectedAssets], saveSettings, { deep: true })
onMounted(async () => { onMounted(async () => {
await ideaStore.fetchIdeas() restoreSettings()
await Promise.all([
ideaStore.fetchIdeas(),
loadCharacters()
])
}) })
const loadCharacters = async () => {
try {
characters.value = await dataService.getCharacters()
if (_savedCharacterId && characters.value.length > 0) {
const found = characters.value.find(c => c.id === _savedCharacterId)
if (found) selectedCharacter.value = found
_savedCharacterId = null
}
} catch (e) {
console.error('Failed to load characters', e)
}
}
const goToDetail = (id) => { const goToDetail = (id) => {
router.push(`/ideas/${id}`) // Navigate to IdeaDetailView router.push(`/ideas/${id}`) // Navigate to IdeaDetailView
} }
@@ -38,10 +134,116 @@ const createIdea = async () => {
submitting.value = false submitting.value = false
} }
} }
// Auto-generation flow
const handleGenerate = async () => {
if (!prompt.value) return
isSubmittingGen.value = true
try {
// 1. Create a random name idea
const randomName = 'Session ' + new Date().toLocaleString()
const newIdea = await ideaStore.createIdea({
name: randomName,
description: 'Auto-generated from quick start'
})
// 2. Save settings (already handled by watch, but ensure latest)
saveSettings()
// 3. Navigate with autostart param
router.push({ path: `/ideas/${newIdea.id}`, query: { autostart: 'true' } })
} catch (e) {
console.error('Failed to start session', e)
} finally {
isSubmittingGen.value = false
}
}
// --- Asset Picker Logic ---
const isAssetPickerVisible = ref(false)
const assetPickerTab = ref('all') // 'all', 'uploaded', 'generated'
const modalAssets = ref([])
const isModalLoading = ref(false)
const tempSelectedAssets = ref([])
const assetPickerFileInput = ref(null)
const loadModalAssets = async () => {
isModalLoading.value = true
try {
const typeParam = assetPickerTab.value === 'all' ? undefined : assetPickerTab.value
const response = await dataService.getAssets(100, 0, typeParam)
if (response && response.assets) {
modalAssets.value = response.assets
} else {
modalAssets.value = Array.isArray(response) ? response : []
}
} catch (e) {
console.error('Failed to load modal assets', e)
modalAssets.value = []
} finally {
isModalLoading.value = false
}
}
const openAssetPicker = () => {
tempSelectedAssets.value = [...selectedAssets.value]
isAssetPickerVisible.value = true
loadModalAssets()
}
const toggleAssetSelection = (asset) => {
const index = tempSelectedAssets.value.findIndex(a => a.id === asset.id)
if (index === -1) {
tempSelectedAssets.value.push(asset)
} else {
tempSelectedAssets.value.splice(index, 1)
}
}
const confirmAssetSelection = () => {
selectedAssets.value = [...tempSelectedAssets.value]
isAssetPickerVisible.value = false
}
const removeAsset = (asset) => {
selectedAssets.value = selectedAssets.value.filter(a => a.id !== asset.id)
}
watch(assetPickerTab, () => {
if (isAssetPickerVisible.value) {
loadModalAssets()
}
})
const triggerAssetPickerUpload = () => {
assetPickerFileInput.value?.click()
}
const handleAssetPickerUpload = async (event) => {
const target = event.target
if (target.files && target.files[0]) {
const file = target.files[0]
try {
isModalLoading.value = true
await dataService.uploadAsset(file)
assetPickerTab.value = 'uploaded'
loadModalAssets()
} catch (e) {
console.error('Failed to upload asset', e)
} finally {
isModalLoading.value = false
target.value = ''
}
}
}
</script> </script>
<template> <template>
<div class="flex flex-col h-full p-8 overflow-y-auto text-slate-100 font-sans"> <div class="flex flex-col h-full font-sans relative">
<!-- Content Area (Scrollable) -->
<div class="flex-1 overflow-y-auto p-8 pb-48 custom-scrollbar">
<!-- Top Bar --> <!-- Top Bar -->
<header class="flex justify-between items-end mb-8 border-b border-white/5 pb-6"> <header class="flex justify-between items-end mb-8 border-b border-white/5 pb-6">
<div> <div>
@@ -50,16 +252,17 @@ const createIdea = async () => {
Ideas</h1> Ideas</h1>
<p class="mt-2 mb-0 text-slate-400">Your creative sessions and experiments</p> <p class="mt-2 mb-0 text-slate-400">Your creative sessions and experiments</p>
</div> </div>
<Button label="New Idea" icon="pi pi-plus" @click="showCreateDialog = true" <!-- REMOVED NEW IDEA BUTTON -->
class="!bg-violet-600 hover:!bg-violet-500 !border-none" />
</header> </header>
<!-- Loading State --> <!-- Loading State -->
<div v-if="loading && ideas.length === 0" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <div v-if="loading && ideas.length === 0" class="flex flex-col gap-4">
<div v-for="i in 6" :key="i" class="glass-panel rounded-2xl p-6 flex flex-col gap-4"> <div v-for="i in 6" :key="i" class="glass-panel rounded-2xl p-4 flex gap-4 items-center">
<Skeleton height="12rem" class="w-full rounded-xl" /> <Skeleton width="4rem" height="4rem" class="rounded-lg" />
<Skeleton width="60%" height="1.5rem" /> <div class="flex-1">
<Skeleton width="40%" height="1rem" /> <Skeleton width="40%" height="1.5rem" class="mb-2" />
<Skeleton width="60%" height="1rem" />
</div>
</div> </div>
</div> </div>
@@ -70,88 +273,252 @@ const createIdea = async () => {
<i class="pi pi-lightbulb text-4xl text-violet-400"></i> <i class="pi pi-lightbulb text-4xl text-violet-400"></i>
</div> </div>
<h3 class="text-xl font-semibold text-white mb-2">No ideas yet</h3> <h3 class="text-xl font-semibold text-white mb-2">No ideas yet</h3>
<p class="text-slate-400 mb-6 max-w-sm text-center">Start a new creative session to organize your <p class="text-slate-400 mb-6 max-w-sm text-center">Use the panel below to start a new creative session.
generations and prompts.</p> </p>
<Button label="Create your first idea" icon="pi pi-plus" @click="showCreateDialog = true" />
</div> </div>
<!-- Ideas Grid --> <!-- Ideas List (Vertical) -->
<div v-else class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <div v-else class="flex flex-col gap-3">
<div v-for="idea in ideas" :key="idea.id" <div v-for="idea in ideas" :key="idea.id"
class="glass-panel rounded-2xl p-0 flex flex-col gap-0 transition-all duration-300 cursor-pointer border border-white/5 hover:-translate-y-1 hover:bg-slate-800/80 hover:border-violet-500/30 group overflow-hidden" class="glass-panel rounded-xl p-3 flex gap-4 items-center cursor-pointer border border-white/5 hover:bg-slate-800/80 hover:border-violet-500/30 group transition-all"
@click="goToDetail(idea.id)"> @click="goToDetail(idea.id)">
<!-- Cover Image --> <!-- Thumbnail -->
<div class="aspect-video w-full bg-slate-800 relative overflow-hidden"> <div
<div v-if="idea.last_generation && idea.last_generation.status == 'done' && idea.last_generation.result_list.length > 0" class="w-full h-full"> class="w-16 h-16 rounded-lg bg-slate-800 flex-shrink-0 overflow-hidden relative border border-white/10">
<img :src="API_URL + '/assets/' + idea.last_generation.result_list[0] + '?thumbnail=true'" <img v-if="idea.last_generation && idea.last_generation.status == 'done' && idea.last_generation.result_list.length > 0"
class="w-full h-full object-cover transition-transform duration-700 group-hover:scale-105" /> :src="API_URL + '/assets/' + idea.last_generation.result_list[0] + '?thumbnail=true'"
class="w-full h-full object-cover" />
<div v-else class="w-full h-full flex items-center justify-center bg-slate-800 text-slate-600">
<i class="pi pi-image text-xl"></i>
</div> </div>
<div v-else
class="w-full h-full flex items-center justify-center bg-gradient-to-br from-slate-800 to-slate-900 group-hover:from-violet-900/20 group-hover:to-slate-900 transition-colors">
<i
class="pi pi-lightbulb text-4xl text-slate-700 group-hover:text-violet-500/50 transition-colors"></i>
</div> </div>
<!-- Overlay Gradient --> <!-- Details -->
<div <div class="flex-1 min-w-0">
class="absolute inset-0 bg-gradient-to-t from-slate-900 via-transparent to-transparent opacity-60"> <h3
class="m-0 text-lg font-bold text-slate-200 group-hover:text-violet-300 transition-colors truncate">
{{ idea.name }}</h3>
<p class="m-0 text-sm text-slate-500 truncate">{{ idea.description || 'No description' }}</p>
</div> </div>
<!-- Count Badge --> <!-- Meta -->
<div <div class="flex items-center gap-4 text-xs text-slate-500">
class="absolute top-3 right-3 bg-black/40 backdrop-blur-md text-white text-xs font-bold px-2 py-1 rounded-lg border border-white/10 flex items-center gap-1"> <div class="flex items-center gap-1 bg-slate-900/50 px-2 py-1 rounded-md">
<i class="pi pi-images text-[10px]"></i> <i class="pi pi-images text-[10px]"></i>
<span>{{ idea.generation_ids?.length || 0 }}</span> <span>{{ idea.generation_ids?.length || 0 }}</span>
</div> </div>
<i class="pi pi-chevron-right text-slate-600 group-hover:text-white transition-colors"></i>
</div> </div>
<div class="p-5"> </div>
<h3 </div>
class="m-0 mb-2 text-xl font-bold truncate text-slate-100 group-hover:text-violet-300 transition-colors"> </div>
{{ idea.name }}</h3>
<p class="m-0 text-sm text-slate-400 line-clamp-2 min-h-[2.5em] leading-relaxed">
{{ idea.description || 'No description provided.' }}
</p>
<div class="mt-4 pt-4 border-t border-white/5 flex justify-between items-center"> <!-- Create Idea Dialog (Removed) -->
<span class="text-xs text-slate-500 font-mono">ID: {{ idea.id.substring(0, 8) }}...</span>
<!-- SETTINGS PANEL (Bottom - Persistent) -->
<div <div
class="text-xs text-violet-400 font-medium opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1"> class="absolute bottom-4 left-1/2 -translate-x-1/2 w-[95%] max-w-4xl glass-panel border border-white/10 bg-slate-900/95 backdrop-blur-xl px-4 py-3 z-[60] !rounded-[2rem] shadow-2xl flex flex-col gap-1 max-h-[60vh] overflow-y-auto">
Open Session <i class="pi pi-arrow-right text-[10px]"></i>
<div class="flex flex-col lg:flex-row gap-3">
<!-- LEFT COLUMN: Prompt + Character + Assets -->
<div class="flex-1 flex flex-col gap-2">
<!-- Prompt -->
<div class="flex flex-col gap-1">
<div class="flex justify-between items-center">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Prompt</label>
<!-- Optional: Add Clear/Improve buttons here if desired, keeping simple for now to match layout -->
</div>
<Textarea v-model="prompt" rows="2" autoResize
placeholder="Describe what you want to create... (Auto-starts new session)"
class="w-full bg-slate-800 !text-sm border-white/10 text-white rounded-lg p-2 focus:border-violet-500 focus:ring-1 focus:ring-violet-500/50 transition-all resize-none shadow-inner" />
</div>
<!-- Character & Assets Row -->
<div class="flex flex-col md:flex-row gap-2">
<div class="flex-1 flex flex-col gap-1">
<label
class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Character</label>
<Dropdown v-model="selectedCharacter" :options="characters" optionLabel="name"
placeholder="Select Character" filter showClear
class="w-full !bg-slate-800 !border-white/10 !text-white !rounded-xl" :pt="{
root: { class: '!bg-slate-800' },
input: { class: '!text-white' },
trigger: { class: '!text-slate-400' },
panel: { class: '!bg-slate-800 !border-white/10' },
item: { class: '!text-slate-300 hover:!bg-white/10 hover:!text-white' }
}">
<template #value="slotProps">
<div v-if="slotProps.value" class="flex items-center gap-2">
<img v-if="slotProps.value.avatar_image"
:src="API_URL + slotProps.value.avatar_image"
class="w-6 h-6 rounded-full object-cover" />
<span>{{ slotProps.value.name }}</span>
</div>
<span v-else>{{ slotProps.placeholder }}</span>
</template>
<template #option="slotProps">
<div class="flex items-center gap-2">
<img v-if="slotProps.option.avatar_image"
:src="API_URL + slotProps.option.avatar_image"
class="w-8 h-8 rounded-full object-cover" />
<span>{{ slotProps.option.name }}</span>
</div>
</template>
</Dropdown>
<div v-if="selectedCharacter"
class="flex items-center gap-2 mt-2 px-1 animate-in fade-in slide-in-from-top-1">
<Checkbox v-model="useProfileImage" :binary="true" inputId="idea-use-profile-img"
class="!border-white/20" :pt="{
box: ({ props, state }) => ({
class: ['!bg-slate-800 !border-white/20', { '!bg-violet-600 !border-violet-600': props.modelValue }]
})
}" />
<label for="idea-use-profile-img"
class="text-xs text-slate-300 cursor-pointer select-none">Use
Character
Photo</label>
</div>
</div>
<div class="flex-1 flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Assets</label>
<div @click="openAssetPicker"
class="w-full bg-slate-800 border border-white/10 rounded-lg p-2 min-h-[38px] cursor-pointer hover:bg-slate-700/50 transition-colors flex flex-wrap gap-1.5">
<span v-if="selectedAssets.length === 0" class="text-slate-400 text-sm py-0.5">Select
Assets</span>
<div v-for="asset in selectedAssets" :key="asset.id"
class="px-2 py-1 bg-violet-600/30 border border-violet-500/30 text-violet-200 text-xs rounded-md flex items-center gap-2 animate-in fade-in zoom-in duration-200"
@click.stop>
<img v-if="asset.url" :src="API_URL + asset.url + '?thumbnail=true'"
class="w-4 h-4 rounded object-cover" />
<span class="truncate max-w-[100px]">{{ asset.name || 'Asset ' + (asset.id ?
asset.id.substring(0, 4) : '') }}</span>
<i class="pi pi-times cursor-pointer hover:text-white"
@click.stop="removeAsset(asset)"></i>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- Create Idea Dialog --> <!-- RIGHT COLUMN: Settings & Button -->
<Dialog v-model:visible="showCreateDialog" modal header="New Idea Session" :style="{ width: '500px' }" <div class="w-full lg:w-72 flex flex-col gap-2">
:breakpoints="{ '960px': '75vw', '641px': '90vw' }" <div class="grid grid-cols-2 gap-2">
:pt="{ root: { class: '!bg-slate-900 !border !border-white/10' }, header: { class: '!bg-slate-900 !border-b !border-white/5 !text-white' }, content: { class: '!bg-slate-900 !p-6' }, footer: { class: '!bg-slate-900 !border-t !border-white/5 !p-4' }, closeButton: { class: '!text-slate-400 hover:!text-white' } }"> <div class="flex flex-col gap-1">
<div class="flex flex-col gap-5"> <label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Quality</label>
<div class="flex flex-col gap-2"> <Dropdown v-model="quality" :options="qualityOptions" optionLabel="value"
<label for="name" class="font-semibold text-slate-300">Session Name</label> class="w-full !bg-slate-800 !border-white/10 !text-white !rounded-xl"
<InputText id="name" v-model="newIdea.name" :pt="{ input: { class: '!text-white' }, trigger: { class: '!text-slate-400' }, panel: { class: '!bg-slate-800 !border-white/10' }, item: { class: '!text-slate-300 hover:!bg-white/10 hover:!text-white' } }" />
class="w-full !bg-slate-800 !border-white/10 !text-white focus:!border-violet-500"
placeholder="e.g., Cyberpunk Character Study" autofocus />
</div> </div>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-1">
<label for="description" class="font-semibold text-slate-300">Description</label> <label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Ratio</label>
<Textarea id="description" v-model="newIdea.description" rows="3" <Dropdown v-model="aspectRatio" :options="aspectRatioOptions" optionLabel="value"
class="w-full !bg-slate-800 !border-white/10 !text-white focus:!border-violet-500" class="w-full !bg-slate-800 !border-white/10 !text-white !rounded-xl"
placeholder="What are you exploring in this session?" /> :pt="{ input: { class: '!text-white' }, trigger: { class: '!text-slate-400' }, panel: { class: '!bg-slate-800 !border-white/10' }, item: { class: '!text-slate-300 hover:!bg-white/10 hover:!text-white' } }" />
</div> </div>
</div> </div>
<!-- Generation Count -->
<div class="flex flex-col gap-1">
<label class="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Count</label>
<div class="flex items-center">
<div class="flex-1 flex bg-slate-800 rounded-lg border border-white/10 overflow-hidden">
<button v-for="n in 4" :key="n" @click="imageCount = n"
class="flex-1 py-1 text-xs font-bold transition-all"
:class="imageCount === n ? 'bg-violet-600 text-white' : 'text-slate-400 hover:text-white hover:bg-white/5'">
{{ n }}
</button>
</div>
</div>
</div>
<!-- Telegram (Copied from Detail View) -->
<div class="flex flex-col gap-1 bg-slate-800/50 p-2 rounded-lg border border-white/5">
<div class="flex items-center gap-2">
<Checkbox v-model="sendToTelegram" :binary="true" inputId="idea-tg-check" />
<label for="idea-tg-check" class="text-xs text-slate-300 cursor-pointer">Send to
Telegram</label>
</div>
<div v-if="sendToTelegram" class="animate-in fade-in slide-in-from-top-1">
<InputText v-model="telegramId" placeholder="Telegram ID"
class="w-full !text-xs !bg-slate-900 !border-white/10 !text-white !py-1.5" />
</div>
</div>
<div class="mt-auto">
<Button :label="isSubmittingGen ? 'Starting...' : 'Generate New Session'"
:icon="isSubmittingGen ? 'pi pi-spin pi-spinner' : 'pi pi-sparkles'"
:loading="isSubmittingGen" :disabled="isSubmittingGen || !prompt" @click="handleGenerate"
class="w-full !py-2 !text-sm !font-bold !bg-gradient-to-r from-violet-600 to-cyan-500 !border-none !rounded-lg !shadow-lg !shadow-violet-500/20 hover:!scale-[1.02] transition-all disabled:opacity-50 disabled:cursor-not-allowed" />
</div>
</div>
</div>
</div>
<Dialog v-model:visible="isAssetPickerVisible" modal header="Select Assets"
:style="{ width: '80vw', maxWidth: '900px' }"
:pt="{ root: { class: '!bg-slate-900 !border !border-white/10' }, header: { class: '!bg-slate-900 !border-b !border-white/5 !text-white' }, content: { class: '!bg-slate-900 !p-0' }, footer: { class: '!bg-slate-900 !border-t !border-white/5 !p-4' }, closeButton: { class: '!text-slate-400 hover:!text-white' } }">
<div class="flex flex-col h-[70vh]">
<!-- Tabs -->
<div class="flex border-b border-white/5 px-4 items-center">
<button v-for="tab in ['all', 'uploaded', 'generated']" :key="tab" @click="assetPickerTab = tab"
class="px-4 py-3 text-sm font-medium border-b-2 transition-colors capitalize"
:class="assetPickerTab === tab ? 'border-violet-500 text-violet-400' : 'border-transparent text-slate-400 hover:text-slate-200'">
{{ tab }}
</button>
<!-- Upload Action -->
<div class="ml-auto flex items-center">
<input type="file" ref="assetPickerFileInput" @change="handleAssetPickerUpload" class="hidden"
accept="image/*" />
<Button icon="pi pi-upload" label="Upload" @click="triggerAssetPickerUpload"
class="!text-xs !bg-violet-600/20 !text-violet-300 hover:!bg-violet-600/40 !border-none !px-3 !py-1.5 !rounded-lg" />
</div>
</div>
<!-- Grid -->
<div class="flex-1 overflow-y-auto p-4 custom-scrollbar">
<div v-if="isModalLoading" class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-4">
<Skeleton v-for="i in 10" :key="i" height="150px" class="!bg-slate-800 rounded-xl" />
</div>
<div v-else-if="modalAssets.length > 0"
class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-4">
<div v-for="asset in modalAssets" :key="asset.id" @click="toggleAssetSelection(asset)"
class="relative aspect-square rounded-xl overflow-hidden cursor-pointer border-2 transition-all group"
:class="tempSelectedAssets.some(a => a.id === asset.id) ? 'border-violet-500 ring-2 ring-violet-500/30' : 'border-transparent hover:border-white/20'">
<img :src="API_URL + asset.url + '?thumbnail=true'" class="w-full h-full object-cover" />
<div class="absolute bottom-0 left-0 right-0 p-2 bg-black/60 backdrop-blur-sm">
<p class="text-[10px] text-white truncate">{{ asset.name || 'Asset ' + (asset.id ?
asset.id.substring(0, 4) : '') }}</p>
</div>
<!-- Checkmark -->
<div v-if="tempSelectedAssets.some(a => a.id === asset.id)"
class="absolute top-2 right-2 w-6 h-6 bg-violet-500 rounded-full flex items-center justify-center shadow-lg animate-in zoom-in duration-200">
<i class="pi pi-check text-white text-xs"></i>
</div>
</div>
</div>
<div v-else class="flex flex-col items-center justify-center h-full text-slate-500">
<i class="pi pi-image text-4xl mb-2 opacity-50"></i>
<p>No assets found</p>
</div>
</div>
</div>
<template #footer> <template #footer>
<div class="flex justify-end gap-2"> <div class="flex justify-end gap-2">
<Button label="Cancel" @click="showCreateDialog = false" text <Button label="Cancel" @click="isAssetPickerVisible = false"
class="!text-slate-400 hover:!text-white" /> class="!text-slate-300 hover:!bg-white/5" text />
<Button label="Start Session" icon="pi pi-check" @click="createIdea" :loading="submitting" <Button :label="'Select (' + tempSelectedAssets.length + ')'" @click="confirmAssetSelection"
class="!bg-violet-600 hover:!bg-violet-500 !border-none" /> class="!bg-violet-600 !border-none hover:!bg-violet-500" />
</div> </div>
</template> </template>
</Dialog> </Dialog>
</div> </div>
</template> </template>
@@ -160,4 +527,21 @@ const createIdea = async () => {
background: rgba(255, 255, 255, 0.03); background: rgba(255, 255, 255, 0.03);
backdrop-filter: blur(10px); backdrop-filter: blur(10px);
} }
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.02);
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: rgba(255, 255, 255, 0.2);
}
</style> </style>