1

I have a large site using the Content App and we have a wide variety of Views. In both testing and development we increasingly need to know what pages a View is in use. As I said, the site is large, well past 500 pages, knowing what page a View got used on is beyond impossible.

Is there some way to in 2sxc to figure this out? A feature I am not aware of? Debugging? Insights? I am willing to do it in code in a View. I was thinking it could be solved by doing a partial...

if(IsSuperUser(Dnn.User)) {
  @RenderPage("_Debug_ListPagesUsingThisView.cshtml")
}

I am having trouble understand how or where to start. Is there a way to get to the Entity (record) of the View from within a view? Once I have that, is there a path to get to the app's module settings? where is the info actually stored that tells the App what View to use? And can I get to it?

  • DNN 9.03.02
  • 2sxc 10.9.1
  • Content App 3.03.x

ADDITIONS Continuing from the comment chain below...

I can't get any further yet, the Entity I get returned from foreach(... .Parents()) has the following fields: Template, Content, Presentation, ListContent, and ListPresentation ... but I cannot figure out how to get any data or fields out of it. Though myEntity.Content.Count (and .Template.) shows 1, any attempt to access it beyond GetType() (its a list of Dynamic Entities) returns a null. Which seems odd.

Do you know what the Entity type actually is and how to use it? The interesting thing is that the count from .Parents() returns the same number of items as in the Content-Type assigned for this View, but when I look in the (SQL) data, they are a different EntityId than the actual Content (e.g. if I trace parent EntityId 3344 I find that nearby EntityId 3343 is one of the Content-Type records this View is displaying somewhere). So thats an interesting clue. Ideas?

Jeremy Farrance
  • 740
  • 6
  • 11

2 Answers2

1

This is on our forever-wish-list :). So far we just haven't found the resources to do it. Your best place to start is to read how the data is mapped from

Using this knowledge you can assemble the data you need. I'm afraid it's going to take you at least 1/2 days work.

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • I am guessing half a day for you means a week for me. ;) But THANK YOU!! – Jeremy Farrance Jan 14 '20 at 17:35
  • So I can easily get the Entity for the View from the filename like this `var myView = AsDynamic(App.Data["2SexyContent-Template"]).Where(t => t.Path == "_Filename-Basic.cshtml").First();` – Jeremy Farrance Jan 15 '20 at 01:08
  • So that gives me the @myView.EntityGuid. So then can I use `myView.Parents()` to look for ... what? The ContentGroup that contains the GUID of myView? I've read thru and tried a few experiments, but not sure what the relationship is, what is pointing to that View/Entity and is the GUID the right thing? – Jeremy Farrance Jan 15 '20 at 01:10
  • `myView.Parents(type: "2sexyContent-ContentGroup")` doesn't throw an error, but also doesn't return anything – Jeremy Farrance Jan 15 '20 at 01:15
  • Whereas `myView.Parents()` returns 333 items which is the same number of items in the Content-Type for this View, but they are NOT that Content-Type... thats as far as I got. I probably won't continue until the weekend. Anything anyone can help with or point out from here would be massively appreciated. – Jeremy Farrance Jan 15 '20 at 01:40
  • Is this the right or easy way to get a list of the field names for an unknown Entity type? `Dictionary attribs = AsEntity(mysteryEntity).Attributes; foreach(var attr in attribs) { @attr.Key
    }` ?
    – Jeremy Farrance Jan 15 '20 at 01:43
  • getting attributes: This does look just about right. https://docs.2sxc.org/api/dot-net/ToSic.Eav.Data.IEntity.html#ToSic_Eav_Data_IEntity_Attributes – iJungleBoy Jan 16 '20 at 08:58
  • With the parents you'll need to experiment a bit, sorry. You can also get all parents() and look at the data to see what the right filter should have been, or use Parents().Where(t => ...) – iJungleBoy Jan 16 '20 at 08:59
  • See above, ADDITIONS to original question. – Jeremy Farrance Jan 20 '20 at 17:22
1

Ok, I finally created my own code - and yes, it was hard!!! Took me at least 5 hours to get everything to work - you owe me a LOT of beers ;)

I made it as part of the DNN tutorial in a miscellaneous section:

https://2sxc.org/dnn-tutorials/en/razor/2sa110/page

have fun!

here an extract of the code I needed to write - lots of LINQ


  // create a map of all blocks to DNN modules
  var block2ModuleMap = contentBlocks.GroupJoin(allMods, 
    cb => cb.EntityGuid,
    m => TryParseGuid(m.ModuleSettings[SettingsCG]),
    (cb, m) => new { 
      Block = cb, 
      Modules = m 
    }
  );

  // now map all the template-IDs to the block-module map
  var template2BlockModuleMap = block2ModuleMap.GroupBy(b2m => {
    var templates = AsList(b2m.Block.Template as object);
    return templates.Any() ? templates.First().EntityGuid : null;
  });

  var viewsWithBlocks = views.GroupJoin(template2BlockModuleMap,
    v => v.EntityGuid,
    bwm => bwm.Key,
    (v, bwm) => {
      var blockWithMod = bwm.SingleOrDefault();
      return new { 
        View = v, 
        Blocks = blockWithMod,
        ModsCount = blockWithMod != null ? blockWithMod.SelectMany(bmlist => bmlist.Modules).Count() : 0,
      };
    }
  );
iJungleBoy
  • 5,325
  • 1
  • 9
  • 21