config_property.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.ConfigProperty = DS.Model.extend({
  20. /**
  21. * id is consist of property <code>name<code>+<code>fileName<code>+<code>configVersion.version<code>
  22. */
  23. id: DS.attr('string'),
  24. /**
  25. * config property name
  26. * @property {string}
  27. */
  28. name: DS.attr('string'),
  29. /**
  30. * config property name
  31. * @property {string}
  32. */
  33. fileName: DS.attr('string'),
  34. /**
  35. * value of property
  36. * by default is same as <code>savedValue<code>
  37. * @property {string}
  38. */
  39. value: DS.attr('string'),
  40. /**
  41. * saved value of property
  42. * @property {string}
  43. */
  44. savedValue: DS.attr('string'),
  45. /**
  46. * recommended value of property
  47. * that is returned from server
  48. * @property {string}
  49. */
  50. recommendedValue: DS.attr('string'),
  51. /**
  52. * defines if property is final
  53. * @property {boolean}
  54. */
  55. isFinal: DS.attr('boolean', {defaultValue: false}),
  56. /**
  57. * value saved on cluster
  58. */
  59. savedIsFinal: DS.attr('boolean', {defaultValue: false}),
  60. /**
  61. * value recommendedFrom Server
  62. * @property {boolean}
  63. */
  64. recommendedIsFinal: DS.attr('boolean', {defaultValue: false}),
  65. /**
  66. * link to config version
  67. * @property {App.ConfigVersion}
  68. */
  69. configVersion: DS.belongsTo('App.ConfigVersion'),
  70. /**
  71. * link to config version
  72. * from this model we can get all static info about property
  73. * @property {App.ConfigVersion}
  74. */
  75. stackConfigProperty: DS.belongsTo('App.StackConfigProperty'),
  76. /**
  77. * defines if property should be visible for user
  78. * all properties that has <code>isVisible<code> false will be present in model
  79. * and saved but will be hidden from user
  80. * @property {boolean}
  81. */
  82. isVisible: DS.attr('boolean', {defaultValue: true}),
  83. /**
  84. * defines if property value is required
  85. * in case user enter empty value error will be shown
  86. * @property {boolean}
  87. */
  88. isRequired: DS.attr('boolean', {defaultValue: true}),
  89. /**
  90. * defines if property can be edited by user
  91. * @property {boolean}
  92. */
  93. isEditable: DS.attr('boolean', {defaultValue: true}),
  94. /**
  95. * opposite to <code>isEditable<code> property
  96. * @property {boolean}
  97. */
  98. isNotEditable: Ember.computed.not('isEditable'),
  99. /**
  100. * defines if property can contain overriden values
  101. * @property {boolean}
  102. */
  103. isOverridable: DS.attr('boolean', {defaultValue: true}),
  104. /**
  105. * defines if property is used for security
  106. * @property {boolean}
  107. */
  108. isSecureConfig: DS.attr('boolean', {defaultValue: false}),
  109. /**
  110. * if false - don't save property
  111. * @property {boolean}
  112. */
  113. isRequiredByAgent: DS.attr('boolean', {defaultValue: true}),
  114. /**
  115. * if true - property is not saved
  116. * used for properties added by user
  117. * @property {boolean}
  118. */
  119. isNotSaved: DS.attr('boolean', {defaultValue: false}),
  120. /**
  121. * if true - don't show property
  122. * @property {boolean}
  123. */
  124. isHiddenByFilter: DS.attr('boolean', {defaultValue: false}),
  125. /**
  126. * properties with this flag set to false will not be saved
  127. * @property {boolean}
  128. */
  129. saveRecommended: DS.attr('boolean', {defaultValue: true}),
  130. /**
  131. * Don't show "Undo" for hosts on Installer Step7
  132. * if value is true
  133. * @property {boolean}
  134. */
  135. cantBeUndone: DS.attr('boolean', {defaultValue: false}),
  136. /**
  137. * error message; by default is empty
  138. * if value is not correct or missing for required property
  139. * this will contain error message
  140. * @property {string}
  141. */
  142. errorMessage: DS.attr('string', {defaultValue: ''}),
  143. /**
  144. * warning message; by default is empty
  145. * if value is out of recommended range
  146. * this will contain warning message
  147. * @property {string}
  148. */
  149. warnMessage: DS.attr('string', {defaultValue: ''}),
  150. /**
  151. * defines if property has errors
  152. * @type {boolean}
  153. */
  154. hasErrors: function() {
  155. return this.get('errorMessage') !== '';
  156. }.property('errorMessage'),
  157. /**
  158. * defines if property has warnings
  159. * @type {boolean}
  160. */
  161. hasWarnings: function() {
  162. return this.get('warnMessage') !== '';
  163. }.property('warnMessage'),
  164. /**
  165. * defines if property belongs to default config group
  166. * if true it's config group is default
  167. * @type {boolean}
  168. */
  169. isOriginalSCP: function() {
  170. return this.get('configVersion.isDefault');
  171. }.property('configVersion.isDefault'),
  172. /**
  173. * defines if property is added by user
  174. * @property {boolean}
  175. */
  176. isUserProperty: function() {
  177. return Em.isNone(this.get('stackConfigProperty'));
  178. }.property('stackConfigProperty'),
  179. /**
  180. * defines if this property is belongs to version
  181. * with which we make comparison
  182. * @property {boolean}
  183. */
  184. isForCompare: function() {
  185. return this.get('configVersion.isForCompare');
  186. }.property('configVersion.isForCompare'),
  187. /**
  188. * if this property can be final
  189. * @property {boolean}
  190. */
  191. supportsFinal: function () {
  192. return this.get('stackConfigProperty.supportsFinal') || this.get('isUserProperty');
  193. }.property('stackConfigProperty.supportsFinal', 'isUserProperty'),
  194. /**
  195. * Indicates when value is not the default value.
  196. * Returns false when there is no default value.
  197. * @type {boolean}
  198. */
  199. isNotDefaultValue: function () {
  200. return this.get('isEditable')
  201. && (!Em.isNone(this.get('savedValue') && this.get('value') !== this.get('savedValue'))
  202. || (this.get('supportsFinal') && !Em.isNone(this.get('savedIsFinal')) && this.get('isFinal') !== this.get('savedIsFinal')));
  203. }.property('value', 'savedValue', 'isEditable', 'isFinal', 'savedIsFinal'),
  204. /**
  205. * opposite to <code>hasErrors<code>
  206. */
  207. isValid: Ember.computed.not('hasErrors')
  208. });
  209. App.ConfigProperty.FIXTURES = [];