EdTemplateCommands.js 6.84 KB
Newer Older
YazhouChen's avatar
YazhouChen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
import Vue from 'vue'
import uniqueId from 'lodash'
import {i18n} from '../main'
import AuthorityFilter from '../commands/AuthorityFilter'
import CreateAndCopySubnetDialog from '@/components/DialogComponents/SubnetDialog/CreateAndCopySubnet.vue'
import CreateAndCopyElementDiscoveryDialog from '@/components/DialogComponents/ElementDiscoveryTemplate/CreateAndCopyElementDiscoveryDialog.vue'
import CopyElementDiscoveryDialog from '@/components/DialogComponents/ElementDiscoveryTemplate/CopyElementDiscoveryDialog.vue'
import DeleteTemplateDialog from '@/components/DialogComponents/ElementDiscoveryTemplate/DeleteTemplateDialog.vue'
import UpdateTemplateDialog from '@/components/DialogComponents/ElementDiscoveryTemplate/UpdateTemplateDialog.vue'
import DeleteSubnetDialog from '@/components/DialogComponents/SubnetDialog/DeleteSubnetDialog.vue'
import UpdateSubnetDialog from '@/components/DialogComponents/SubnetDialog/UpdateSubnet.vue'
import ImportSubnetDialog from '@/components/DialogComponents/SubnetDialog/ImportSubnetDialog.vue'

Vue.component('CreateAndCopySubnetDialog', CreateAndCopySubnetDialog)
Vue.component('DeleteSubnetDialog', DeleteSubnetDialog)
Vue.component('UpdateSubnetDialog', UpdateSubnetDialog)
Vue.component('ImportSubnetDialog', ImportSubnetDialog)
Vue.component('CreateAndCopyElementDiscoveryDialog', CreateAndCopyElementDiscoveryDialog)
Vue.component('CopyElementDiscoveryDialog', CopyElementDiscoveryDialog)
Vue.component('DeleteTemplateDialog', DeleteTemplateDialog)
Vue.component('UpdateTemplateDialog', UpdateTemplateDialog)

let CommandTypes = {
  CREATE_COPY_SUBNET_CMD: {
    type: 'CreateAndCopySubnet',
    executeComponent: 'CreateAndCopySubnetDialog',
    registerComponent: CreateAndCopySubnetDialog
  },
  CREATE_COPY_ELEMENT_DISCOVERY_CMD: {
    type: 'CreateAndCopyElementDiscoveryDialog',
    executeComponent: 'CreateAndCopyElementDiscoveryDialog',
    registerComponent: CreateAndCopyElementDiscoveryDialog
  },
  COPY_ELEMENT_DISCOVERY_CMD: {
    type: 'copyElementDiscoveryDialog',
    executeComponent: 'CopyElementDiscoveryDialog',
    registerComponent: CopyElementDiscoveryDialog
  },
  DELETE_TEMPLATE_CMD: {
    type: 'DeleteTemplate',
    executeComponent: 'DeleteTemplateDialog',
    registerComponent: DeleteTemplateDialog // import对应的对话框组件
  },
  UPDATE_TEMPLATE_CMD: {
    type: 'UpdateTemplate',
    executeComponent: 'UpdateTemplateDialog',
    registerComponent: UpdateTemplateDialog // import对应的对话框组件
  },
  DELETE_SUBNET_CMD: {
    type: 'DeleteSubnet',
    executeComponent: 'DeleteSubnetDialog',
    registerComponent: DeleteSubnetDialog // import对应的对话框组件
  },
  UPDATE_SUBNET_CMD: {
    type: 'UpdateSubnet',
    executeComponent: 'UpdateSubnetDialog',
    registerComponent: UpdateSubnetDialog // import对应的对话框组件
  },
  IMPORT_SUBNET_CMD: {
    type: 'ImportSubnetToExcel',
    executeComponent: 'ImportSubnetDialog',
    registerComponent: ImportSubnetDialog // import对应的对话框组件
  }
}

class EdTemplateCommands {
  static createAndCopyEdTemplateCommand (title, templatePa, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.CREATE_COPY_ELEMENT_DISCOVERY_CMD.type),
      visible: true,
      disabled: false,
      target: templatePa,
      title: title,
      executeComponent: CommandTypes.CREATE_COPY_ELEMENT_DISCOVERY_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('EdTemplateCommands.createTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.elementDiscoveryAuthorityFilter(command)
  }
  static copyEdTemplateCommand (title, templatePa, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.COPY_ELEMENT_DISCOVERY_CMD.type),
      visible: true,
      disabled: false,
      target: templatePa,
      title: title,
      executeComponent: CommandTypes.COPY_ELEMENT_DISCOVERY_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('EdTemplateCommands.copyTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.elementDiscoveryAuthorityFilter(command)
  }

  static deleteTemplateCommand (template1, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.DELETE_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: template1,
      executeComponent: CommandTypes.DELETE_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('EdTemplateCommands.deleteTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.elementDiscoveryAuthorityFilter(command)
  }
  static updateTemplateCommand (tem, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_TEMPLATE_CMD.type),
      visible: true,
      disabled: false,
      target: tem,
      executeComponent: CommandTypes.UPDATE_TEMPLATE_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('EdTemplateCommands.modifyTemplate')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.elementDiscoveryAuthorityFilter(command)
  }
  static updateSubnetCommand (subnet, commandContext) {
    let command = {
      id: uniqueId(CommandTypes.UPDATE_SUBNET_CMD.type),
      visible: true,
      disabled: false,
      target: subnet,
      executeComponent: CommandTypes.UPDATE_SUBNET_CMD.executeComponent,
      execute: undefined,
      done: undefined,
      name: i18n.tc('SubnetCommands.modifySubnet')
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.subnetAuthorityFilter(command)
  }

  static importSubnetCommand (commandContext) {
    let command = {
      id: uniqueId(CommandTypes.IMPORT_SUBNET_CMD.type),
      visible: true,
      disabled: false,
      target: null,
      executeComponent: CommandTypes.IMPORT_SUBNET_CMD.executeComponent,
      execute: undefined,
      done: undefined
    }
    command.execute = function () {
      Vue.set(commandContext, command.id, command)
    }
    command.done = function () {
      Vue.delete(commandContext, command.id)
    }
    return AuthorityFilter.elementDiscoveryAuthorityFilter(command)
  }
}

EdTemplateCommands.CommandTypes = CommandTypes

export default EdTemplateCommands