service_config_version.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var dateUtil = require('utils/date/date');
  20. App.ServiceConfigVersion = DS.Model.extend({
  21. MAX_NOTES_LENGTH: 80,
  22. serviceName: DS.attr('string'),
  23. displayName: Em.computed.formatRole('serviceName', true),
  24. groupName: DS.attr('string'),
  25. groupId: DS.attr('number'),
  26. version: DS.attr('number'),
  27. createTime: DS.attr('number'),
  28. rawCreateTime: DS.attr('number'),
  29. author: DS.attr('string'),
  30. notes: DS.attr('string'),
  31. service: DS.belongsTo('App.Service'),
  32. hosts: DS.attr('array'),
  33. index: DS.attr('number'),
  34. isCurrent: DS.attr('boolean'),
  35. isDisplayed: DS.attr('boolean'),
  36. stackVersion: DS.attr('string'),
  37. isCompatible: DS.attr('boolean'),
  38. canBeMadeCurrent: Em.computed.and('isCompatible', '!isCurrent'),
  39. isDefault: Em.computed.equal('groupName', 'default'),
  40. currentTooltip: Em.computed.i18nFormat('dashboard.configHistory.table.current.tooltip', 'displayName', 'configGroupName'),
  41. /**
  42. * @type {string}
  43. */
  44. configGroupName: function () {
  45. return this.get('isDefault') ? Em.I18n.t('common.default') : this.get('groupName');
  46. }.property('groupName','isDefault'),
  47. /**
  48. * @type {string}
  49. */
  50. authorFormatted: Em.computed.truncate('author', 20, 20),
  51. /**
  52. * @type {string}
  53. */
  54. fullNotes: function () {
  55. return (typeof this.get('notes') === 'string') ?
  56. (this.get('notes') || Em.I18n.t('dashboard.configHistory.table.notes.no')) :
  57. Em.I18n.t('dashboard.configHistory.table.notes.no');
  58. }.property('notes'),
  59. /**
  60. * @type {string}
  61. */
  62. briefNotes: Em.computed.truncate('fullNotes', 81, 81, ''),
  63. /**
  64. * @type {boolean}
  65. */
  66. moreNotesExists: Em.computed.notEqualProperties('fullNotes', 'briefNotes'),
  67. /**
  68. * @type {string}
  69. */
  70. versionText: Em.computed.i18nFormat('dashboard.configHistory.table.version.versionText', 'version'),
  71. /**
  72. * @type {string}
  73. */
  74. makeCurrentButtonText: Em.computed.i18nFormat('dashboard.configHistory.info-bar.revert.versionButton', 'versionText'),
  75. /**
  76. * @type {string}
  77. */
  78. createdDate: function () {
  79. return dateUtil.dateFormat(this.get('createTime'));
  80. }.property('createTime'),
  81. /**
  82. * @type {string}
  83. */
  84. timeSinceCreated: function () {
  85. return $.timeago(this.get('rawCreateTime'));
  86. }.property('rawCreateTime'),
  87. /**
  88. * determine whether ServiceConfigVersion is requested from server
  89. */
  90. isRequested: DS.attr('boolean'),
  91. /**
  92. * @type {boolean}
  93. */
  94. isRestartRequired: function () {
  95. if (this.get('service.isRestartRequired') && this.get('isCurrent')) {
  96. var hostNames = this.get('hosts');
  97. if (!hostNames.length) return false;
  98. for (var i = 0; i < hostNames.length; i++) {
  99. if (Object.keys(this.get('service.restartRequiredHostsAndComponents')).contains(hostNames[i])) {
  100. return true;
  101. }
  102. }
  103. }
  104. return false;
  105. }.property('service.isRestartRequired','isDefault', 'isCurrent', 'hosts', 'service.restartRequiredHostsAndComponents', 'router.mainServiceInfoConfigsController.configGroups'),
  106. /**
  107. * {{view: string, compare: string, revert: string}} disabledActionMessages
  108. */
  109. disabledActionMessages: function () {
  110. return {
  111. view: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.view.button.disabled') : '',
  112. compare: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.compare.button.disabled') : '',
  113. revert: (this.get('isCurrent')) ? Em.I18n.t('dashboard.configHistory.info-bar.revert.button.disabled') : ''
  114. }
  115. }.property('isDisplayed', 'isCurrent'),
  116. /**
  117. * {{view: (string|boolean), compare: (string|boolean), revert: (string|boolean)}} disabledActionAttr
  118. */
  119. disabledActionAttr: function () {
  120. return {
  121. view: (this.get('isDisplayed')) ? 'disabled' : false,
  122. compare: (this.get('isDisabled') || this.get('isDisplayed')) ? 'disabled' : false,
  123. revert: (this.get('isDisabled') || this.get('isCurrent')) ? 'disabled' : false
  124. }
  125. }.property('isDisplayed', 'isCurrent', 'isDisabled')
  126. });
  127. App.ServiceConfigVersion.FIXTURES = [];