List.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-filter
  5. :list="list"
  6. :columns="columns"
  7. :single-actions="singleActions"
  8. :group-actions="groupActions"
  9. :defaultSearchKey="defaultSearchKey"
  10. :export-data-options="exportDataOptions" />
  11. </template>
  12. <script>
  13. import * as R from 'ramda'
  14. import { mapGetters } from 'vuex'
  15. import ColumnsMixin from '../mixins/columns'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. import ListMixin from '@/mixins/list'
  18. import WindowsMixin from '@/mixins/windows'
  19. import regexp from '@/utils/regexp'
  20. import { getDescriptionFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  21. export default {
  22. name: 'AgentList',
  23. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  24. props: {
  25. id: String,
  26. getParams: {
  27. type: [Function, Object],
  28. },
  29. },
  30. data () {
  31. const filterOptions = {
  32. id: {
  33. label: this.$t('table.title.id'),
  34. },
  35. name: {
  36. label: this.$t('network.text_21'),
  37. filter: true,
  38. formatter: val => {
  39. return `name.contains(${val})`
  40. },
  41. },
  42. description: getDescriptionFilter(),
  43. ip: {
  44. label: 'IP',
  45. },
  46. cluster: {
  47. label: this.$t('network.text_19'),
  48. dropdown: true,
  49. distinctField: {
  50. type: 'extra_field',
  51. key: 'cluster',
  52. },
  53. },
  54. region: {
  55. label: this.$t('dashboard.text_101'),
  56. },
  57. zone: {
  58. label: this.$t('compute.text_270'),
  59. },
  60. created_at: getCreatedAtFilter(),
  61. }
  62. const { path } = this.$route
  63. if (path.includes('/cluster')) {
  64. delete filterOptions.cluster
  65. }
  66. return {
  67. list: this.$list.createList(this, {
  68. id: this.id,
  69. resource: 'loadbalanceragents',
  70. getParams: this.getParam,
  71. filterOptions,
  72. hiddenColumns: ['metadata', 'version', 'created_at'],
  73. }),
  74. exportDataOptions: {
  75. items: [
  76. { label: 'ID', key: 'id' },
  77. { label: this.$t('network.text_21'), key: 'name' },
  78. { label: this.$t('network.text_19'), key: 'cluster' },
  79. { label: this.$t('network.text_22'), key: 'ha_state' },
  80. { label: 'IP', key: 'ip' },
  81. { label: this.$t('network.text_23'), key: 'hb_last_seen' },
  82. { label: this.$t('network.text_24'), key: 'zone' },
  83. { label: this.$t('network.version'), key: 'version' },
  84. { label: this.$t('common_715'), key: 'user_tags' },
  85. { label: this.$t('common.createdAt'), key: 'created_at' },
  86. ],
  87. },
  88. groupActions: [
  89. // {
  90. // label: this.$t('network.text_26'),
  91. // permission: 'lb_loadbalanceragents_create',
  92. // action: () => {
  93. // this.$router.push({
  94. // name: 'AgentForm',
  95. // })
  96. // },
  97. // meta: () => {
  98. // return {
  99. // buttonType: 'primary',
  100. // }
  101. // },
  102. // },
  103. {
  104. label: this.$t('table.action.set_tag'),
  105. permission: 'lb_loadbalanceragents_perform_set_user_metadata',
  106. action: () => {
  107. this.createDialog('SetTagDialog', {
  108. data: this.list.selectedItems,
  109. columns: this.columns,
  110. onManager: this.onManager,
  111. mode: 'add',
  112. params: {
  113. resources: 'loadbalanceragent',
  114. },
  115. tipName: this.$t('network.text_20'),
  116. })
  117. },
  118. meta: () => {
  119. return {
  120. validate: this.list.selectedItems.length > 0,
  121. }
  122. },
  123. },
  124. ],
  125. }
  126. },
  127. computed: {
  128. ...mapGetters(['isAdminMode']),
  129. },
  130. created () {
  131. this.initSidePageTab('agent-detail')
  132. this.list.fetchData()
  133. },
  134. methods: {
  135. getParam () {
  136. const ret = {
  137. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  138. }
  139. return ret
  140. },
  141. handleOpenSidepage (row) {
  142. this.sidePageTriggerHandle(this, 'AgentSidePage', {
  143. id: row.id,
  144. resource: 'loadbalanceragents',
  145. getParams: this.getParam,
  146. }, {
  147. list: this.list,
  148. })
  149. },
  150. defaultSearchKey (search) {
  151. if (regexp.isIPv4(search)) {
  152. return 'ip'
  153. }
  154. },
  155. },
  156. }
  157. </script>