sub_section.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. App.SubSection = DS.Model.extend({
  20. id: DS.attr('string'),
  21. /**
  22. * @type {string}
  23. */
  24. name: DS.attr('string'),
  25. /**
  26. * @type {string}
  27. */
  28. displayName: DS.attr('string'),
  29. /**
  30. * @type {boolean}
  31. */
  32. border: DS.attr('boolean', {defaultValue: false}),
  33. /**
  34. * @type {number}
  35. */
  36. rowIndex: DS.attr('number', {defaultValue: 1}),
  37. /**
  38. * @type {number}
  39. */
  40. columnIndex: DS.attr('number', {defaultValue: 1}),
  41. /**
  42. * @type {number}
  43. */
  44. rowSpan: DS.attr('number', {defaultValue: 1}),
  45. /**
  46. * @type {number}
  47. */
  48. columnSpan: DS.attr('number', {defaultValue: 1}),
  49. /**
  50. * @type {App.Section}
  51. */
  52. section: DS.belongsTo('App.Section'),
  53. /**
  54. * @type {String[]}
  55. */
  56. configProperties: DS.attr('array', {defaultValue: []}),
  57. /**
  58. * @type {App.SubSectionTab[]}
  59. */
  60. subSectionTabs: DS.hasMany('App.SubSectionTab'),
  61. dependsOn: DS.attr('array', {defaultValue: []}),
  62. /**
  63. * @type {boolean}
  64. */
  65. leftVerticalSplitter: DS.attr('boolean', {defaultValue: true}),
  66. /**
  67. * @type {App.ServiceConfigProperty[]}
  68. */
  69. configs: [],
  70. /**
  71. * @type {boolean}
  72. */
  73. hasTabs: Em.computed.bool('subSectionTabs.length'),
  74. someSubSectionTabIsVisible: Em.computed.someBy('subSectionTabs', 'isVisible', true),
  75. showTabs: Em.computed.and('hasTabs', 'someSubSectionTabIsVisible'),
  76. /**
  77. * Number of the errors in all configs
  78. * @type {number}
  79. */
  80. errorsCount: function () {
  81. var visibleTabs = this.get('subSectionTabs').filterProperty('isVisible');
  82. var subSectionTabsErrors = visibleTabs.length ? visibleTabs.mapProperty('errorsCount').reduce(Em.sum, 0) : 0;
  83. return subSectionTabsErrors + this.get('configs').filter(function(config) {
  84. return config.get('isVisible') && (!config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false));
  85. }).length;
  86. }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configs.@each.overrideErrorTrigger', 'subSectionTabs.@each.isVisible', 'subSectionTabs.@each.errorsCount'),
  87. /**
  88. * @type {boolean}
  89. */
  90. addLeftVerticalSplitter: Em.computed.and('!isFirstColumn', 'leftVerticalSplitter'),
  91. /**
  92. * @type {boolean}
  93. */
  94. addRightVerticalSplitter: Em.computed.not('isLastColumn'),
  95. /**
  96. * @type {boolean}
  97. */
  98. showTopSplitter: Em.computed.and('!isFirstRow', '!border'),
  99. /**
  100. * @type {boolean}
  101. */
  102. isFirstRow: Em.computed.equal('rowIndex', 0),
  103. /**
  104. * @type {boolean}
  105. */
  106. isMiddleRow: function () {
  107. return this.get('rowIndex') != 0 && (this.get('rowIndex') + this.get('rowSpan') < this.get('section.sectionRows'));
  108. }.property('rowIndex', 'rowSpan', 'section.sectionRows'),
  109. /**
  110. * @type {boolean}
  111. */
  112. isLastRow: function () {
  113. return this.get('rowIndex') + this.get('rowSpan') == this.get('section.sectionRows');
  114. }.property('rowIndex', 'rowSpan', 'section.sectionRows'),
  115. /**
  116. * @type {boolean}
  117. */
  118. isFirstColumn: Em.computed.equal('columnIndex', 0),
  119. /**
  120. * @type {boolean}
  121. */
  122. isMiddleColumn: function () {
  123. return this.get('columnIndex') != 0 && (this.get('columnIndex') + this.get('columnSpan') < this.get('section.sectionColumns'));
  124. }.property('columnIndex', 'columnSpan', 'section.sectionColumns'),
  125. /**
  126. * @type {boolean}
  127. */
  128. isLastColumn: function () {
  129. return this.get('columnIndex') + this.get('columnSpan') == this.get('section.sectionColumns');
  130. }.property('columnIndex', 'columnSpan', 'section.sectionColumns'),
  131. /**
  132. * If the visibility of subsection is dependent on a value of some config
  133. */
  134. isHiddenByConfig: false,
  135. /**
  136. * Determines if subsection is filtered by checking it own configs
  137. * If there is no configs, subsection can't be hidden
  138. * @type {boolean}
  139. */
  140. isHiddenByFilter: function () {
  141. var configs = this.get('configs').filter(function(c) {
  142. return !c.get('hiddenBySection') && c.get('isVisible');
  143. });
  144. return configs.length ? configs.everyProperty('isHiddenByFilter', true) : false;
  145. }.property('configs.@each.isHiddenByFilter'),
  146. /**
  147. * @type {boolean}
  148. */
  149. someConfigIsVisible: Em.computed.someBy('configs', 'isVisible', true),
  150. /**
  151. * Determines if subsection is visible
  152. * @type {boolean}
  153. */
  154. isSectionVisible: Em.computed.and('!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible')
  155. });
  156. App.SubSection.FIXTURES = [];