service_config_version.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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');
  20. App.ServiceConfigVersion = DS.Model.extend({
  21. serviceName: DS.attr('string'),
  22. displayName: function() {
  23. return App.format.role(this.get('serviceName'));
  24. }.property('serviceName'),
  25. groupName: DS.attr('string'),
  26. groupId: DS.attr('number'),
  27. version: DS.attr('number'),
  28. createTime: 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. isDefault: function() {
  37. return this.get('groupName') === 'default';
  38. }.property('groupName'),
  39. currentTooltip: function () {
  40. return Em.I18n.t('dashboard.configHistory.table.current.tooltip').format(this.get('displayName'), this.get('configGroupName'));
  41. }.property('displayName', 'configGroupName'),
  42. configGroupName: function () {
  43. return this.get('isDefault') ? (this.get('displayName') + ' ' + Em.I18n.t('common.default')) : this.get('groupName');
  44. }.property('groupName','isDefault'),
  45. fullNotes: function () {
  46. return (typeof this.get('notes') === 'string') ? this.get('notes') || Em.I18n.t('dashboard.configHistory.table.notes.no') : Em.I18n.t('dashboard.configHistory.table.notes.no');
  47. }.property('notes'),
  48. briefNotes: function () {
  49. return this.get('fullNotes').slice(0, 81);
  50. }.property('fullNotes'),
  51. moreNotesExists: function () {
  52. return (typeof this.get('notes') === 'string') ? this.get('notes').length > 80 : false;
  53. }.property('notes'),
  54. versionText: function () {
  55. return Em.I18n.t('dashboard.configHistory.table.version.versionText').format(this.get('version'));
  56. }.property('version'),
  57. makeCurrentButtonText: function() {
  58. return Em.I18n.t('dashboard.configHistory.info-bar.revert.versionButton').format(this.get('versionText'));
  59. }.property('versionText'),
  60. createdDate: function () {
  61. return dateUtil.dateFormat(this.get('createTime'));
  62. }.property('createTime'),
  63. timeSinceCreated: function () {
  64. return $.timeago(this.get('createTime'));
  65. }.property('createTime'),
  66. /**
  67. * determine whether ServiceConfigVersion is requested from server
  68. */
  69. isRequested: DS.attr('boolean'),
  70. isRestartRequired: function () {
  71. if (this.get('service.isRestartRequired') && this.get('isCurrent')) {
  72. var hostNames = this.get('hosts');
  73. if (!hostNames.length) return false;
  74. for (var i = 0; i < hostNames.length; i++) {
  75. if (Object.keys(this.get('service.restartRequiredHostsAndComponents')).contains(hostNames[i])) {
  76. return true;
  77. }
  78. }
  79. }
  80. return false;
  81. }.property('service.isRestartRequired','isDefault', 'isCurrent', 'hosts', 'service.restartRequiredHostsAndComponents', 'router.mainServiceInfoConfigsController.configGroups'),
  82. disabledActionMessages: function () {
  83. return {
  84. view: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.view.button.disabled') : '',
  85. compare: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.compare.button.disabled') : '',
  86. revert: (this.get('isCurrent')) ? Em.I18n.t('dashboard.configHistory.info-bar.revert.button.disabled') : ''
  87. }
  88. }.property('isDisplayed', 'isCurrent'),
  89. disabledActionAttr: function () {
  90. return {
  91. view: (this.get('isDisplayed')) ? 'disabled' : false,
  92. compare: (this.get('isDisabled') || this.get('isDisplayed')) ? 'disabled' : false,
  93. revert: (this.get('isDisabled') || this.get('isCurrent')) ? 'disabled' : false
  94. }
  95. }.property('isDisplayed', 'isCurrent', 'isDisabled')
  96. });
  97. App.ServiceConfigVersion.FIXTURES = [];