Navigation Map

4 views
Skip to first unread message

peper

unread,
Jun 2, 2007, 7:03:35 AM6/2/07
to Gugga Flash Framework
Hi.

Is there a simple method to get whole navigation graph (tree) of all
registered sections/subsections? I have to make a navigation map and
I'd like it to be ganerated dynamically

Stefan Yotov

unread,
Jun 4, 2007, 11:58:17 AM6/4/07
to gug...@googlegroups.com
Hi Peper,

Unfortunately, there isn't an automated way to generate sitemap. You have to create one by your self.

The first idea which comes to mind is to create a SiteMap class, and register sections into the SiteMap. This way you could also apply some selection for the sections which you expect to be available for the site map.

Some pseudo interface code:
class SiteMap
{
 // singletone implentation
 public static var Instance () : SiteMap;

 public function registerSection (aParent : Section, aSection : Section, aSectionName : String) : Void;
 public function generate () : Object; // return appropriate format
}

By making it singletone, the SiteMap will be accessible from any other scope within the application.
You will need to harvest the site map recursively and it should be the most complicated aspect of the implementation, i guess.

I hope this helps,
Stefan, Gugga Team

peper

unread,
Jun 20, 2007, 4:09:40 PM6/20/07
to Gugga Flash Framework
It's a good way of course, but it needs reviewing all the code to
register sections in the sitemap :/ The site is quite big (I've got
here about 60 classes) and I'd like rather something external for the
sections controller classes. What is more, some sections (about 30%)
are loaded dynamically from DB and added later.

If there's a method to list all regitered sections for a
SectionController, I could build the sitemap tree.

I see here a gugga.util.Weaver - maybe I could put some join points on
'registerChildSection' and do the trick.

I think I will finally make all my SectionsControllers inherit from
some CommonSectionController (well, they do already:) ) and override
'registerChildSection' method to add sections to sitemap.

Thanks for Your help.

Stefan Yotov

unread,
Jun 21, 2007, 9:23:13 AM6/21/07
to gug...@googlegroups.com
Hi Peper!

Your idea to subclass the SectionsController is great!
I doubt you can avoid reviewing all the code, because you'll need human readable section labels for the sitemap, isn't that right?

Considering your letter i assume that you don't have SectionsControllers which come from database. In other words, i assume that all Sections in your application are registered before it is initialized. If my assumption is false, we shall need a different approach to the problem.

In order to answer your question, unfortunately there is no existing method to list all registered sections. I would avoid weaving the registerChildSection method, beacause weaving is native for the framework and actionscript in general. Actually the "weaving" approach involves even more code reviewing than the subclassing does (Remember that you could only weave already instantiated objects, which makes sublcassing unavoidable, again).

Well, I would do the subclassing for sure!
Our subclass implementation will need a hash table containing SectionID -> SectionName pairs. Afterwards we should create two additional methods, which expect SitemapName as an argument:

registerSiteMapSection,
registerSiteMapChildSection.

For example:
registerSiteMapSection (aSectionInstance:Section, aID:String, aSitemapName:String) : Void
{
mSitemapSectionNames[aID] = aSitemapName; // add to sitemap names
registerSection(aSectionInstance, aSectionName); // call the actual method
}

Having these implemenations in our SectionsController subclass you should review and modify parts of your code.

I would offer you a solution for the generation of the sitemap. Imagine every node of the Sections composite has a method called generateSiteMap () : String // may not be String, it is up to you.
Remebering the composite pattern definition, we should be able to use the composite entity exactly as we use a single node. Therefore, calling generateSiteMap on the ApplicationController itself should give us the desired sitemap. As far as our "generateSiteMap" implementation makes sense, of course.

Well, here is a suggestion for pseudo implementation:

(in the context of your SectionsController subclass mentioned above)
public function generateSiteMap () : String
{
var sitemap:String = "";
for(var id:String in mSitemapSectionNames)
{
if(mSitemapSectionNames[id] instanceof YourSectionsControllerSubclass)
{
sitemap .= mSitemapSectionNames[id];
sitemap .= "(" + YourSectionsControllerSubclass(mSections[id]).generateSiteMap() + ")";
}
else
{
sitemap .= mSitemapSectionNames[id];
}
}
return sitemap;
}

The real implementation should set appropriate format for the sitemap result.

This solution will fail if your SectionsControllers are lazy loaded. Having sitemap for dynamic structure could only be implemented outside of the sections controllers. In that case it would be critical to have some kind of strucure declaration (or configuration), in order to generate the sitemap.

It is great that you are pointing this issue! At this time we are in the preparation of an article for the blog, which considers dynamic application structure, and the sitemap problem is in strong relation with it.

Let me know what you think about my suggestions!

Good luck,
Stefan
Gugga Team

peper

unread,
Jun 26, 2007, 1:54:15 PM6/26/07
to Gugga Flash Framework
Hi.
I tried some solutions I got to something very similiar as You - ergo,
it look like it's a good solution :D

I need something flexible, some of my sections are 'real' sections,
but some of them are based on overriding 'openSection' method. For
example "Products.Category.5" - 5 of course is not a section but it's
i category ID. Even "Category" isn't a section. Navigation to
"Products" does, nothing.

Some sections are loaded dynamically - there's one Section MovieClip,
regitered as multiply sections, based on DB data (user can add
sections via CMS)

My idea was to keep (let's call it) local sitemap in every
SectionsController, My SectionsControllers extends my
CommonSectionController class. There are 2 steps:

1. Registering sections is joined with adding node to sitemap.

private function
registerSitemapChildSection(sectionInstanceName:String,id:String,menuItemId:String,sitemapName:String,navigationCommand:ICommand)
{
this.registerChildSection(sectionInstanceName,id,menuItemId);
this.sitemap.push(
{
name : sitemapName,
command : navigationCommand,
section : this.getComponent(sectionInstanceName)
}
);
}

As You can see, sitemap here is vector of nodes containing human
readable sitemap nodes, navigation command (used in navigable sitemap)
and reference to section - used in step two.

2. Second step is fired after initialization of all sections
controllers. It's a recursive joining those local sitemaps into a
tree.

public function getSiteMap():Array{
for(var i :Number=0;i<this.sitemap.length;i++) {
if (this.sitemap[i].section instanceof CommonSectionsController) {
this.sitemap[i].subsections =
this.sitemap[i].section.getSiteMap();
}
}

return this.sitemap;

}

It's pretty similar to your code :) The idea of composite structure is
kept, and solution is really easy.

For example :

this.registerSitemapChildSection("RecommendedSitesSection","RecommendedSites","RecommendedSites","Polecane
strony",new NavigationCommand("NotOnlyBusiness.RecommendedSites"));

On the other hand sitemap is separated from sections tree, so I can
put "something" that is not a section into a sitemap (it's client's
requirement)

this.sitemap.push(
{
name : "Some external link",
command : new OpenUrlCommand("http://google.pl","_blank"),
section : null
}
);


The solution works good, is simple for me and You and a bit advanced
programmers, but I feel it can be made simpler - of course with some
limitations.

I think the idea of totally external sitemap is good, but :

- adding sections to sitemap should be joined with regitering sections
(in initUI)
- sitemap have to be created recursive, walkinkg through graph using
the "deep first" method (I'm not sure how to call this in English)

Using external sitemap (for example Sitemap.addNode(parentNode,
childNode) ) makes it difficult to be sure that nodes are registered
in specific order.

Reply all
Reply to author
Forward
0 new messages