# app/pages/Admin/Routes/index.coffee document.head.insertAdjacentHTML('beforeend','') CouchDB = require 'app/utils/couch' module.exports = name: 'AdminRoutes' render: (new Function '_ctx', '_cache', renderFns['app/pages/Admin/Routes/index.pug'])() data: -> routes: [] showRouteModal: false currentRoute: { path: '' name: '' component: '' metaTitle: '' metaDescription: '' active: true } mounted: -> @loadRoutes() methods: loadRoutes: -> @$root.couchRequest('find', { selector: { type: 'route' } sort: [{path: 'asc'}] }) .then (result) => @routes = result.docs .catch (error) => console.error 'Ошибка загрузки маршрутов:', error @$root.showNotification 'Ошибка загрузки маршрутов', 'error' editRoute: (route) -> @currentRoute = { ...route } @showRouteModal = true saveRoute: -> routeData = { type: 'route' ...@currentRoute updatedAt: new Date().toISOString() } if !routeData._id routeData.createdAt = new Date().toISOString() @$root.couchRequest('put', routeData) .then (result) => if routeData._id index = @routes.findIndex (r) -> r._id == routeData._id if index != -1 @routes.splice(index, 1, { ...routeData, _id: routeData._id, _rev: result.rev }) else @routes.push({ ...routeData, _id: result.id, _rev: result.rev }) @showRouteModal = false @resetCurrentRoute() @$root.showNotification 'Маршрут успешно сохранен' # Обновляем роутер @updateRouter() .catch (error) => console.error 'Ошибка сохранения маршрута:', error @$root.showNotification 'Ошибка сохранения маршрута', 'error' deleteRoute: (routeId) -> if confirm('Вы уверены, что хотите удалить этот маршрут?') route = @routes.find (r) -> r._id == routeId @$root.couchRequest('put', { _id: routeId _rev: route._rev _deleted: true }) .then => @routes = @routes.filter (r) -> r._id != routeId @$root.showNotification 'Маршрут успешно удален' @updateRouter() .catch (error) => console.error 'Ошибка удаления маршрута:', error @$root.showNotification 'Ошибка удаления маршрута', 'error' resetCurrentRoute: -> @currentRoute = { path: '' name: '' component: '' metaTitle: '' metaDescription: '' active: true } getRouteStatusClass: (isActive) -> if isActive return 'px-2 py-1 text-xs rounded-full bg-green-100 text-green-800' else return 'px-2 py-1 text-xs rounded-full bg-red-100 text-red-800' updateRouter: -> # Здесь можно добавить логику для динамического обновления роутера console.log 'Роутер должен быть обновлен'