list_updated.js 815 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. import Agent from '../Agent'
  7. module.exports = (app, new_list, hosts = null) => {
  8. let state = {list: new_list}
  9. return Promise.resolve()
  10. .then(() => {
  11. let current = app.state.current
  12. if (current && current.is_sys) {
  13. return Agent.pact('getSysHosts')
  14. .then(sys_hosts => {
  15. state.sys_hosts = sys_hosts
  16. state.current = sys_hosts
  17. })
  18. } else if (hosts) {
  19. state.current = hosts
  20. } else if (current) {
  21. let c = new_list.find(i => i.id === current.id)
  22. if (c) {
  23. state.current = c
  24. }
  25. }
  26. })
  27. .then(() => {
  28. app.setState(state, () => {
  29. if (hosts) {
  30. Agent.emit('select', hosts.id)
  31. }
  32. })
  33. })
  34. }