service_config_version_mapper.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: "serviceconfigversion",
  25. create_time: 'createtime',
  26. group_id: 'group_id',
  27. group_name: 'group_name',
  28. author: 'user',
  29. notes: 'service_config_version_note',
  30. is_current: 'is_current',
  31. index: 'index'
  32. },
  33. map: function (json) {
  34. var result = [];
  35. var itemIds = {};
  36. var currentConfigVersions = App.cache['currentConfigVersions'];
  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_current = !!currentConfigVersions[parsedItem.id];
  42. parsedItem.is_requested = true;
  43. itemIds[parsedItem.id] = true;
  44. parsedItem.index = index;
  45. result.push(parsedItem);
  46. }, this);
  47. this.get('model').find().forEach(function (item) {
  48. if (!itemIds[item.get('id')]) {
  49. item.set('isRequested', false);
  50. }
  51. });
  52. var itemTotal = parseInt(json.itemTotal);
  53. if (!isNaN(itemTotal)) {
  54. App.router.set('mainConfigHistoryController.filteredCount', itemTotal);
  55. }
  56. App.store.loadMany(this.get('model'), result);
  57. }
  58. }
  59. });