upgrade_entity.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /**
  19. * @type {Ember.Object}
  20. * @class
  21. */
  22. App.upgradeEntity = Em.Object.extend({
  23. /**
  24. * type of entity "GROUP", "ITEM", "TASK"
  25. * @type {string}
  26. */
  27. type: null,
  28. /**
  29. * @type {boolean}
  30. */
  31. isExpanded: false,
  32. /**
  33. * @type {boolean}
  34. */
  35. hasExpandableItems: false,
  36. /**
  37. * @type {boolean}
  38. */
  39. isVisible: Em.computed.notEqual('status', 'PENDING'),
  40. /**
  41. * status of tasks/items/groups which should be grayed out and disabled
  42. * @type {Array}
  43. */
  44. nonActiveStates: ['PENDING', 'ABORTED'],
  45. /**
  46. * @type {boolean}
  47. */
  48. isRunning: Em.computed.existsIn('status', ['IN_PROGRESS']),
  49. /**
  50. * @type {number}
  51. */
  52. progress: function () {
  53. return Math.floor(this.get('progress_percent'));
  54. }.property('progress_percent'),
  55. /**
  56. * indicate whether entity has active link
  57. * @type {boolean}
  58. */
  59. isActive: function () {
  60. return !this.get('nonActiveStates').contains(this.get('status'));
  61. }.property('status'),
  62. /**
  63. * indicate whether upgrade group should be expanded
  64. * @type {boolean}
  65. */
  66. isExpandableGroup: function () {
  67. return this.get('type') === 'GROUP' && (this.get('isActive') || this.get('hasExpandableItems'));
  68. }.property('isActive', 'hasExpandableItems'),
  69. upgradeItemStatus: Em.computed.firstNotBlank('display_status', 'status'),
  70. /**
  71. * @type {string}
  72. */
  73. upgradeGroupStatus: function () {
  74. if (App.get('upgradeSuspended') && this.get('status') === 'ABORTED') {
  75. return 'SUSPENDED';
  76. }
  77. if (this.get('type') === 'GROUP' && !this.get('isActive') && this.get('hasExpandableItems')) {
  78. return 'SUBITEM_FAILED';
  79. }
  80. return this.get('display_status') || this.get('status');
  81. }.property('isExpandableGroup', 'display_status', 'status', 'App.upgradeSuspended')
  82. });