| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # app/pages/Admin/Routes/index.coffee
- document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss">'+stylFns['app/pages/Admin/Routes/index.styl']+'</style>')
- 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 'Роутер должен быть обновлен'
|