Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. updateHistoryChanges() {
  2.             const hisrotyAllChanges = this.getHistoryChanges();
  3.  
  4.             let sortingArray = this.getChangesAddTextures().map(changeTexture => {
  5.                 return {
  6.                     texture: changeTexture,
  7.  
  8.                     groupChanges: [...(hisrotyAllChanges.filter(historyTextureChanges => {
  9.                         if (historyTextureChanges.cacheKeys && changeTexture.cacheKeys
  10.                             && historyTextureChanges.cacheKeys.find(k => changeTexture.cacheKeys.find(key => k == key))) {
  11.                             return true;
  12.                         } else if (changeTexture.mapId == _LIB.CONST.MAP_CHANGES.UPLOAD_BACKGROUND
  13.                             && !historyTextureChanges.cacheKeys) {
  14.                             return true;
  15.                         }
  16.  
  17.                         return false;
  18.                     }))].map((t, index, arr) => {
  19.                         const findedHistoryByMapId = Object.entries(_LIB.CONST.MAP_CHANGES)
  20.                             .find(change => change[1] == t.mapId);
  21.  
  22.                         return {
  23.                             id: t.timestamp,
  24.                             title: t.name || (findedHistoryByMapId ? findedHistoryByMapId[0] : 'Unknown'),
  25.                             ...(t.data && t.data.base64
  26.                                 ? { image: t.data.base64 }
  27.                                 : { icon: ["inch-filters-icon"] }),
  28.                             active: false,
  29.                             _id: t._id,
  30.                             mapId: t.mapId
  31.                         };
  32.                     }).sort((a, b) => (changeTexture.timestamp != a.id && a.id < b.id) ? -1 : 1)
  33.                 };
  34.             }).sort((a, b) => a.texture.timestamp < b.texture.timestamp ? 1 : -1);
  35.  
  36.             const activeConfig = (sortingArray.reduce((arr, item, index) => {
  37.                 arr.push({
  38.                     max: item.groupChanges.reduce((max, value, index) => {
  39.                         if ((!max.num && max.num != 0) || max.num < value.id) {
  40.                             max = { num: value.id, index };
  41.                         }
  42.  
  43.                         return max;
  44.                     }, {}),
  45.                     index: index
  46.                 });
  47.  
  48.                 return arr;
  49.             }, [])).reduce((obj, item, a, arr) => {
  50.                 console.log(arr);
  51.                 if ((!obj.num && obj.num != 0) || obj.num < item.max.num) {
  52.                     obj = {
  53.                         num: item.max.num,
  54.                         textureIndex: item.index,
  55.                         groupIndex: item.max.index
  56.                     };
  57.                 }
  58.  
  59.                 return obj;
  60.             }, {});
  61.  
  62.             if(sortingArray[activeConfig.textureIndex]) {
  63.                 sortingArray[activeConfig.textureIndex].groupChanges[activeConfig.groupIndex].active = true;
  64.             }
  65.            
  66.             this.historyChanges = sortingArray;
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement