published
updated
  • Nov 8, 2008 8:15:00PM UTC
source uri
author
Handler
acre handler
plural name
  • Templates
Test
path
  • /en/bob_dylan
  • /en/bob_dylan?domain=/user/jdouglas/view
  • /en/bob_dylan?domain=/user/jdouglas/view&sort=domain
  • /en/the_departed?domain=/user/jdouglas/view&sort=domain
  • /guid/9202a8c04000641f8000000003caf4ac?domain=/user/jdouglas/view&sort=domain
  • /en/the_departed
  • /en/david_bowie

summary

var id = acre.environ.path_info; /* * domain = domain where types define tabs ...

content

var id = acre.environ.path_info; /* * domain = domain where types define tabs * empty = show empty properties * sort = prop | val */ var settings = acre.environ.params; if (id == '/') id='/en/bob_dylan' // set default topic if there wasn't one passed in the URL settings // Get "primary types" // // If the topic being rendered contains a primary type, // that type's domain tab should be shown first // and that tab should be named after the type, not the domain var primaryTypesRaw = getPrimaryTypes(); var primaryTypes = primaryTypesRaw["/user/robert/topic_view/primary_type_holder/primary_type"]; var primaryType = null; var primaryDomain = null; // Get types from special domain that defines tabs // This domain path is defined as an argument in the invoking URL // // The types in this domain each represent a type, and // the properties in these types define which properties // are displayed in each tab. // These properties delegate from properties in commons types var viewTabMap = getDomainTabOrder(); var tabIndex = 0; var tabBodyIndex = 0; var tabOrder = []; var tabs = {}; var commonProperties = {}; // Get topic data and process properties var util = acre.require("worker"); var o = util.getHotshot(id, settings); for (d in o.domains){ var domain = o.domains[d]; // Skip data in user domains (for now) if(domain.id.match(/^\/user/)) { continue; }; // Identify if any of the topic's types are a "primary type" // Put the matching type as the first in the domain so the properties appear at the top of the tab if (!primaryType) { for (t in domain.types) { for (ind in primaryTypes) { if (domain.types[t].id == primaryTypes[ind].id) { // Set the matching primary type and domain for later processing primaryType = domain.types[t]; primaryDomain = domain.id; // Move the matching type first in the domain var typeHold = domain.types[t]; domain.types.splice(t,1); domain.types.unshift(typeHold); continue; } } } } for (t in domain.types) { var typeEntry = domain.types[t]; if (typeEntry.id == "/common/topic") { processCommonTopicType(typeEntry); } else { processOtherType(typeEntry, domain); } } } // If there is a primary type in topic, set it as the first tab if (primaryDomain) { for (tab in tabOrder) { if (tabOrder[tab] == primaryDomain) { tabOrder.splice(tab,1); tabOrder.unshift(primaryDomain); tabs[primaryDomain].name = primaryType.name; } } } // Set tabs ordering by number of properties if (settings.sort && settings.sort == 'prop') { tabOrder.sort(function(a,b) { return tabs[b].propertyEntries.length - tabs[a].propertyEntries.length; }); // or set tabs ordering by number of property values } else if (settings.sort && settings.sort == 'val') { tabOrder.sort(function(a,b) { return tabs[b].dataCount - tabs[a].dataCount; }); // or set property ordering by special type ordering domain } else if (settings.sort && settings.domain && settings.sort == 'domain') { tabOrder.sort(function(a,b) { var aIndex = viewTabMap[a] != null ? viewTabMap[a] : tabs[a].order * 1000; var bIndex = viewTabMap[b] != null ? viewTabMap[b] : tabs[a].order * 1000; return aIndex - bIndex; }); } // Get primary types function getPrimaryTypes() { return (acre.freebase.MqlRead({ "id" : "/guid/9202a8c04000641f8000000008f65cd9", "/user/robert/topic_view/primary_type_holder/primary_type" : [ { "id" : null, "name" : null, "type" : "/type/type", "domain" : { "id":null, "name":null } } ] }).result); } // Process properties on /common/topic function processCommonTopicType(typeEntry) { for (p in typeEntry.properties) { var propertyEntry = typeEntry.properties[p]; var dataEntries = propertyEntry.data; if (dataEntries.length == 0) { continue; } commonProperties[propertyEntry.id] = dataEntries; } }; // Process properties on...
Created by jdouglas Aug 7, 2008
Last edited by jdouglas Nov 8, 2008
View topic history »

Comments

There is no discussion about this document.

Start the Discussion »