combo_search_box.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.MainHostComboSearchBoxView = Em.View.extend({
  20. templateName: require('templates/main/host/combo_search_box'),
  21. didInsertElement: function () {
  22. window.visualSearch = VS.init({
  23. container: $('#combo_search_box'),
  24. query: '',
  25. showFacets: true,
  26. unquotable: [
  27. 'text'
  28. ],
  29. callbacks: {
  30. search: function (query, searchCollection) {
  31. var $query = $('#search_query');
  32. var count = searchCollection.size();
  33. $query.stop().animate({opacity: 1}, {duration: 300, queue: false});
  34. $query.html('<span class="raquo">&raquo;</span> You searched for: ' +
  35. '<b>' + (query || '<i>nothing</i>') + '</b>. ' +
  36. '(' + count + ' facet' + (count == 1 ? '' : 's') + ')');
  37. clearTimeout(window.queryHideDelay);
  38. window.queryHideDelay = setTimeout(function () {
  39. $query.animate({
  40. opacity: 0
  41. }, {
  42. duration: 1000,
  43. queue: false
  44. });
  45. }, 2000);
  46. },
  47. facetMatches: function (callback) {
  48. console.log('called');
  49. callback([
  50. {label: 'name', category: 'Host'},
  51. {label: 'ip', category: 'Host'},
  52. {label: 'version', category: 'Host'},
  53. {label: 'health', category: 'Host'},
  54. {label: 'service', category: 'Service'},
  55. {label: 'component', category: 'Service'},
  56. {label: 'state', category: 'Service'}
  57. ]);
  58. },
  59. valueMatches: function (facet, searchTerm, callback) {
  60. switch (facet) {
  61. case 'name':
  62. callback([
  63. {value: 'c6401.ambari.apache.org', label: 'c6401.ambari.apache.org'},
  64. {value: 'c6402.ambari.apache.org', label: 'c6402.ambari.apache.org'},
  65. {value: 'c6403.ambari.apache.org', label: 'c6403.ambari.apache.org'}
  66. ]);
  67. break;
  68. case 'ip':
  69. callback(['192.168.64.101', '192.168.64.102', '192.168.64.103']);
  70. break;
  71. case 'rack':
  72. callback(['/default-rack', '/default-rack-1', '/default-rack-2']);
  73. break;
  74. case 'version':
  75. callback([
  76. 'HDP-2.0.0.0-1587',
  77. 'HDP-2.1.2.2-1576',
  78. 'HDP-2.2.4.0-2252',
  79. 'HDP-2.3.4.0-3485'
  80. ]);
  81. break;
  82. case 'health':
  83. callback([
  84. 'Healthy',
  85. 'Master Down',
  86. 'Slave Down',
  87. 'Lost Heartbeat',
  88. 'Alerts',
  89. 'Restart',
  90. 'Maintainance Mode'
  91. ]);
  92. break;
  93. case 'service':
  94. callback([
  95. 'HDFS',
  96. 'YARN',
  97. 'HIVE',
  98. 'HBASE',
  99. 'Storm',
  100. 'Oozie',
  101. 'Falcon',
  102. 'Pig',
  103. 'Spark',
  104. 'Zookeeper',
  105. 'AMS',
  106. 'Ranger'
  107. ]);
  108. break;
  109. case 'component':
  110. callback([
  111. 'NameNode',
  112. 'SNameNode',
  113. 'ZooKeeper Server',
  114. 'DataNode',
  115. 'HDFS Client',
  116. 'Zookeeper Client'
  117. ], {preserveOrder: true});
  118. break;
  119. case 'state':
  120. callback([
  121. 'Started',
  122. 'Stopped',
  123. 'Install Failed',
  124. 'Decommissioning',
  125. 'Decommissioned'
  126. ], {preserveOrder: true});
  127. break;
  128. }
  129. }
  130. }
  131. });
  132. }
  133. });