service_config_version_mapper.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.serviceConfigVersionsMapper = App.QuickDataMapper.create({
  20. model: App.ServiceConfigVersion,
  21. config: {
  22. service_name: 'service_name',
  23. service_id: 'service_name',
  24. version: "service_config_version",
  25. create_time: 'createtime',
  26. group_id: 'group_id',
  27. group_name: 'group_name',
  28. hosts: 'hosts',
  29. author: 'user',
  30. notes: 'service_config_version_note',
  31. is_current: 'is_current',
  32. index: 'index'
  33. },
  34. map: function (json) {
  35. var result = [];
  36. var itemIds = {};
  37. if (json && json.items) {
  38. json.items.forEach(function (item, index) {
  39. var parsedItem = this.parseIt(item, this.get('config'));
  40. parsedItem.id = parsedItem.service_name + '_' + parsedItem.version;
  41. parsedItem.is_requested = true;
  42. itemIds[parsedItem.id] = true;
  43. parsedItem.index = index;
  44. result.push(parsedItem);
  45. }, this);
  46. this.get('model').find().forEach(function (item) {
  47. if (!itemIds[item.get('id')]) {
  48. item.set('isRequested', false);
  49. }
  50. });
  51. var itemTotal = parseInt(json.itemTotal);
  52. if (!isNaN(itemTotal)) {
  53. App.router.set('mainConfigHistoryController.filteredCount', itemTotal);
  54. }
  55. App.store.commit();
  56. App.store.loadMany(this.get('model'), result);
  57. }
  58. }
  59. });