index.coffee 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # app/pages/Admin/Clients/index.coffee
  2. document.head.insertAdjacentHTML('beforeend','<style type="text/tailwindcss">'+stylFns['app/pages/Admin/Clients/index.styl']+'</style>')
  3. CouchDB = require 'app/utils/couch'
  4. module.exports =
  5. name: 'AdminClients'
  6. render: (new Function '_ctx', '_cache', renderFns['app/pages/Admin/Clients/index.pug'])()
  7. data: ->
  8. users: []
  9. clientSearch: ''
  10. computed:
  11. filteredUsers: ->
  12. if !@clientSearch
  13. return @users
  14. search = @clientSearch.toLowerCase()
  15. return @users.filter (user) =>
  16. name = "#{user.profile?.firstName || ''} #{user.profile?.lastName || ''}".toLowerCase()
  17. email = user.email?.toLowerCase() || ''
  18. phone = user.profile?.phone?.toLowerCase() || ''
  19. name.includes(search) || email.includes(search) || phone.includes(search)
  20. mounted: ->
  21. @loadUsers()
  22. methods:
  23. # app/pages/Admin/Clients/index.coffee - обновите метод loadUsers
  24. loadUsers: ->
  25. # Используем view вместо find
  26. @$root.couchRequest('queryView', 'admin', 'users_by_created', {
  27. descending: true
  28. limit: 100
  29. })
  30. .then (result) =>
  31. @users = result.rows.map (row) -> row.value
  32. .catch (error) =>
  33. console.error 'Ошибка загрузки пользователей:', error
  34. # Fallback к обычному find
  35. @$root.couchRequest('find', {
  36. selector: { type: 'user' }
  37. sort: [{createdAt: 'desc'}]
  38. limit: 100
  39. })
  40. .then (result) =>
  41. @users = result.docs