PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/hq/_site/js/collection/mapping/MappingsModel.js

https://gitlab.com/zouxc/elasticsearch-cn-out-of-box
JavaScript | 50 lines | 24 code | 4 blank | 22 comment | 2 complexity | 4bdf2003a8e2ad35168999b339e8318b MD5 | raw file
  1. /*
  2. Copyright 2013 Roy Russo
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. Latest Builds: https://github.com/royrusso/elasticsearch-HQ
  13. */
  14. var MappingsModel = Backbone.Collection.extend({
  15. model:MappingSimple,
  16. url:function () {
  17. return '/_mapping';
  18. },
  19. parse:function (data) {
  20. var mappings = [];
  21. // indices are keyed by their id, so we need to get the key and add it to the value object foreach
  22. //var indices = data.indices;
  23. var indexKeys = _.keys(data);
  24. var indexValues = _.values(data);
  25. for (var i = 0; i < indexKeys.length; i++) {
  26. var indexName = indexKeys[i];
  27. var mapArr = _.keys(indexValues[i]);
  28. var mapVArr = _.values(indexValues[i]);
  29. for (var j = 0; j < mapArr.length; j++) {
  30. var simpleMapping = new MappingSimple();
  31. simpleMapping.indexId = indexName;
  32. simpleMapping.mappingName = mapArr[j];/*
  33. if (mapVArr[j] == 'mappings') { // stupid v1.0.0 change
  34. console.log(_.keys(mapVArr[j]));
  35. }*/
  36. simpleMapping.properties = mapVArr[j].properties;
  37. mappings.push(simpleMapping);
  38. }
  39. }
  40. return mappings;
  41. }
  42. });