service_config_version.js 3.4 KB

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