service_config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.ConfigProperties = Ember.ArrayProxy.extend({
  20. content: null
  21. // content: require('data/config_properties').configProperties
  22. });
  23. App.ServiceConfig = Ember.Object.extend({
  24. serviceName: '',
  25. configCategories: [],
  26. configs: null,
  27. errorCount: function() {
  28. return this.get('configs').filterProperty('isValid', false).get('length');
  29. }.property('configs.@each.isValid')
  30. });
  31. App.ServiceConfigCategory = Ember.Object.extend({
  32. name: null,
  33. isForSlaveComponent: function () {
  34. return this.get('name') === 'DataNode' || this.get('name') === 'TaskTracker' ||
  35. this.get('name') === 'RegionServer';
  36. }.property('name')
  37. });
  38. App.ServiceConfigProperty = Ember.Object.extend({
  39. name: '',
  40. displayName: '',
  41. value: '',
  42. defaultValue: '',
  43. description: '',
  44. displayType: 'string', // string, digits, number, directories, custom
  45. unit: '',
  46. category: 'General',
  47. isRequired: true, // by default a config property is required
  48. isEditable: true, // by default a config property is editable
  49. errorMessage: '',
  50. serviceConfig: null, // points to the parent App.ServiceConfig object
  51. isValid: function() {
  52. return this.get('errorMessage') === '';
  53. }.property('errorMessage'),
  54. viewClass: function() {
  55. switch (this.get('displayType')) {
  56. case 'directories':
  57. return App.ServiceConfigTextArea;
  58. case 'custom':
  59. return App.ServiceConfigBigTextArea;
  60. case 'masterHost':
  61. return App.ServiceConfigMasterHostView;
  62. case 'slaveHosts':
  63. return App.ServiceConfigSlaveHostsView;
  64. default:
  65. return App.ServiceConfigTextField;
  66. }
  67. }.property('displayType'),
  68. validate: function() {
  69. var digitsRegex = /^\d+$/;
  70. var numberRegex = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/;
  71. var value = this.get('value');
  72. var isError = false;
  73. if (this.get('isRequired')) {
  74. if (typeof value === 'string' && value.trim().length === 0) {
  75. this.set('errorMessage', 'This is required');
  76. isError = true;
  77. console.log('required');
  78. }
  79. }
  80. if (!isError) {
  81. switch (this.get('displayType')) {
  82. case 'digits':
  83. if (!digitsRegex.test(value)) {
  84. this.set('errorMessage', 'Must contain digits only');
  85. isError = true;
  86. }
  87. break;
  88. case 'number':
  89. if (!numberRegex.test(value)) {
  90. this.set('errorMessage', 'Must be a valid number');
  91. isError = true;
  92. }
  93. break;
  94. case 'directories':
  95. break;
  96. case 'custom':
  97. break;
  98. }
  99. }
  100. if (!isError) {
  101. this.set('errorMessage', '');
  102. console.log('setting errorMessage to blank');
  103. }
  104. }.observes('value')
  105. });