PredixDev / predix-webapp-starter

A web application starter kit built on Polymer, Web Components, NodeJS and Predix UI Components
https://predix-webapp-starter.run.aws-usw02-pr.ice.predix.io
Other
61 stars 75 forks source link

asset-browser.html not all asset 'group' children shown #8

Closed badgertastic closed 6 years ago

badgertastic commented 7 years ago

asset-browser.html doesn't show all children.

Steps to reproduce: add additional child group(s) to groups.json:

  {
    "filter": "parent=/group/enterprise-predix",
    "parent": "/group/enterprise-predix",
    "description": "Richmond Refinery 2",
    "uri": "/group/plant-richmond-refinery-2",
    "level": "plant",
    "name": "Richmond Refinery 2"
  }

Results inconsistent depending on how many groups added.

gstroup commented 7 years ago

I ran into a similar issue and found the fix. It will be released in the next release of this repo. In the meantime, you can update the _buildAssetModel function manually. You need to add the i-- lines. Let us know if that solves your problem. Thanks.

  // build asset heirarchy from flat array
  _buildAssetModel: function(parentId, allAssets, level, selectedAssetId) {
    for (var i=0; i<allAssets.length; i++) {
      var asset = allAssets[i];
      if (!asset.parentId) {
        // if asset has no parent, it will never show on the context browser
        allAssets.splice(i, 1);
        i--; //need to move the index back after splicing.
        this._buildAssetModel(parentId, allAssets, level, selectedAssetId);
      }
      if (asset.id === selectedAssetId) {
        asset.selectedAsset = true;
      }
      if (asset.parentId === parentId) {
        asset.children = asset.children || [];
        level.push(asset);
        allAssets.splice(i, 1);
        i--; //need to move the index back after splicing.
        // console.log('allAssets remaining', allAssets.length);
        // recursive call
        this._buildAssetModel(asset.id, allAssets, asset.children, selectedAssetId);
      }
    };
  },
badgertastic commented 7 years ago

Yep -- thats fixed it. Big thanks @gstroup