service_config_version.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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('string'),
  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. index: DS.attr('number'),
  33. isCurrent: DS.attr('boolean'),
  34. currentTooltip: function () {
  35. return Em.I18n.t('dashboard.configHistory.table.current.tooltip').format(this.get('displayName'), this.get('configGroupName'));
  36. }.property('displayName', 'configGroupName'),
  37. configGroupName: function () {
  38. return this.get('groupName') == Em.I18n.t('dashboard.configHistory.table.configGroup.default') ? (this.get('displayName') + ' ' + Em.I18n.t('common.default')) : this.get('groupName');
  39. }.property('groupName'),
  40. briefNotes: function () {
  41. return (typeof this.get('notes') === 'string') ? this.get('notes').slice(0, 100) : "";
  42. }.property('notes'),
  43. versionText: function () {
  44. return Em.I18n.t('dashboard.configHistory.table.version.versionText').format(this.get('version'));
  45. }.property('version'),
  46. makeCurrentButtonText: function() {
  47. return Em.I18n.t('dashboard.configHistory.info-bar.revert.versionButton').format(this.get('versionText'));
  48. }.property('versionText'),
  49. modifiedDate: function () {
  50. return dateUtil.dateFormat(this.get('createTime'));
  51. }.property('createTime'),
  52. shortModifiedDate: function () {
  53. return dateUtil.dateFormat(this.get('createTime'), 'MMM DD, YYYY');
  54. }.property('createTime'),
  55. /**
  56. * determine whether ServiceConfigVersion is requested from server
  57. */
  58. isRequested: DS.attr('boolean'),
  59. isRestartRequired: function () {
  60. return this.get('service.isRestartRequired') && this.get('isCurrent');
  61. }.property('service.isRestartRequired', 'isCurrent'),
  62. disabledActionMessages: function () {
  63. return {
  64. view: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.view.button.disabled') : '',
  65. compare: (this.get('isDisplayed')) ? Em.I18n.t('dashboard.configHistory.info-bar.compare.button.disabled') : '',
  66. revert: (this.get('isCurrent')) ? Em.I18n.t('dashboard.configHistory.info-bar.revert.button.disabled') : ''
  67. }
  68. }.property('isDisplayed', 'isCurrent'),
  69. disabledActionAttr: function () {
  70. return {
  71. view: (this.get('isDisplayed')) ? 'disabled' : false,
  72. compare: (this.get('isDisabled') || this.get('isDisplayed')) ? 'disabled' : false,
  73. revert: (this.get('isDisabled') || this.get('isCurrent')) ? 'disabled' : false
  74. }
  75. }.property('isDisplayed', 'isCurrent', 'isDisabled')
  76. });
  77. App.ServiceConfigVersion.FIXTURES = [];