LabelDictionary.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. class LabelDictionary {
  16. // The word will be uppercased
  17. static acronyms = ['id', 'api', 'url', 'vm', 'os', 'dhcp', 'sql', 'oci']
  18. // The word will be replaced
  19. static abbreviations = {
  20. migr: 'Migration',
  21. auth: 'Authentication',
  22. fip: 'Floating IP',
  23. }
  24. static dictionary = {
  25. auth_url: 'Auth URL',
  26. migr_image: 'Migration Image Name or Id',
  27. migr_network: 'Migration Network Name or ID',
  28. migr_worker_boot_from_volume: 'Boot Migration Workers from Volume',
  29. volumes_are_zeroed: 'Volumes on destination are created zeroed',
  30. keep_mac: 'Keep MAC address',
  31. reuse_ports: 'Reuse Existing Ports',
  32. replace_mac: 'Replace MAC Address',
  33. migr_worker_use_config_drive: 'Migration Worker use ConfigDrive',
  34. migr_worker_use_fip: 'Migration Worker use FIP',
  35. aws: 'Amazon',
  36. openstack: 'OpenStack',
  37. opc: 'Oracle Cloud',
  38. vmware_vsphere: 'VMware',
  39. migr_subnet_id: 'Migration Subnet ID',
  40. separate_vm: 'Separate Migration/VM?',
  41. windows_migr_image: { label: 'Windows Migration Image', description: 'The Windows Migration Image information found on the Azure page' },
  42. linux_migr_image: { label: 'Linux Migration Image', description: 'The Linux Migration Image information found on the Azure page' },
  43. duplicate_to_project: { label: 'Project', description: 'Duplicate endpoint to selected project' },
  44. // AzureStack suffixes
  45. azure_datalake_analytics_catalog_and_job_endpoint: 'Azure Datalake Analytics Catalog And Job Endpoint Suffix',
  46. azure_datalake_store_file_system_endpoint: 'Azure Datalake Store File System Endpoint Suffix',
  47. keyvault_dns: 'Keyvault DNS Suffix',
  48. sql_server_hostname: 'SQL Server Hostname Suffix',
  49. storage_endpoint: 'Storage Endpoint Suffix',
  50. preserve_nic_ips: 'Preserve NIC IPs',
  51. }
  52. // Fields which have enums for which dictionary labels should be used.
  53. // If a field has enums and is not in this array, their values will be used as labels
  54. static enumFields = ['port_reuse_policy']
  55. static get(fieldName: ?string): string {
  56. let labelInfo = fieldName ? this.dictionary[fieldName] : null
  57. if (labelInfo) {
  58. if (typeof labelInfo === 'string') {
  59. return labelInfo
  60. }
  61. if (labelInfo.label) {
  62. return labelInfo.label
  63. }
  64. }
  65. let words = fieldName ? fieldName.split('_') : []
  66. words = words.map(word => {
  67. let acronym = this.acronyms.find(a => a === word)
  68. let newWord = acronym ? acronym.toUpperCase() : (this.abbreviations[word] || word)
  69. return newWord.charAt(0).toUpperCase() + newWord.substr(1)
  70. })
  71. return words.join(' ')
  72. }
  73. static getDescription(fieldName: string): string {
  74. let labelInfo = this.dictionary[fieldName]
  75. if (labelInfo && typeof labelInfo === 'object') {
  76. return labelInfo.description || ''
  77. }
  78. return ''
  79. }
  80. }
  81. export default LabelDictionary