upgrade_entity.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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: function () {
  40. return this.get('status') !== 'PENDING';
  41. }.property('status'),
  42. /**
  43. * status of tasks/items/groups which should be grayed out and disabled
  44. * @type {Array}
  45. */
  46. nonActiveStates: ['PENDING', 'ABORTED'],
  47. /**
  48. * @type {boolean}
  49. */
  50. isRunning: function () {
  51. return ['IN_PROGRESS'].contains(this.get('status'));
  52. }.property('status'),
  53. /**
  54. * @type {number}
  55. */
  56. progress: function () {
  57. return Math.floor(this.get('progress_percent'));
  58. }.property('progress_percent'),
  59. /**
  60. * indicate whether entity has active link
  61. * @type {boolean}
  62. */
  63. isActive: function () {
  64. return !this.get('nonActiveStates').contains(this.get('status'));
  65. }.property('status'),
  66. /**
  67. * indicate whether upgrade group should be expanded
  68. * @type {boolean}
  69. */
  70. isExpandableGroup: function () {
  71. return this.get('type') === 'GROUP' && (this.get('isActive') || this.get('hasExpandableItems'));
  72. }.property('isActive', 'hasExpandableItems'),
  73. upgradeGroupStatus: function () {
  74. if (this.get('type') === 'GROUP') {
  75. return !this.get('isActive') && this.get('hasExpandableItems') ? 'SUBITEM_FAILED' : this.get('status');
  76. }
  77. }.property('isExpandableGroup')
  78. });