Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 25, 2012
@rmarianski rmarianski rename ds -> dataStatus for clarity 4f22bb2
@rmarianski rmarianski display organizations and social links
* organizations are displayed in basic contact info
* social links get a new tab
* remove previous debugging data
a353c47
@rmarianski rmarianski sort photos on details page
linkedin < facebook < other
cd62be9
Showing with 60 additions and 108 deletions.
  1. +60 −108 search/templates/detail.html
View
168 search/templates/detail.html
@@ -427,8 +427,8 @@
$.getJSON(fetchUrl, function(data) {
- var ds = data['status'];
- if (!ds) {
+ var dataStatus = data['status'];
+ if (!dataStatus) {
return;
}
var extraDetailsContainer = $('#contact-extra-details').first();
@@ -443,14 +443,7 @@
var personDetails = $('#person-details');
personDetails.append(extraDetailsContainer);
- if (ds === 202 || ds === 500) {
- extraDetailsContainer.append(
- $('<p />').text(
- 'Supplemental data not available ... retrying in 30 seconds'));
- extraDetailsContainer.append(
- $('<p />').text('Attempted tries: ' + attempt));
- extraDetailsContainer.append(
- $('<img />', {src: '/static/spinner.gif'}));
+ if (dataStatus === 202 || dataStatus === 500) {
setTimeout(function() { fetchSupplementalData(attempt+1); }, 30000);
return;
}
@@ -461,128 +454,87 @@
function() { imageElt.css('cursor', 'default'); });
var imageIdx = 0;
var photos = data['photos'];
- var photosLength = photos.length;
+ photos.sort(function(a, b) {
+ var x = a.typeId;
+ y = b.typeId;
+ if (x === y) {
+ // can have multiple results of same type
+ // stable sort if so
+ return a.url < b.url ? -1 : a.url > b.url ? 1 : 0;
+ }
+ // linkedin < facebook < everything else
+ if (x === 'linkedin') { return -1; }
+ if (y === 'linkedin') { return 1; }
+ if (x === 'facebook') { return -1; }
+ if (y === 'facebook') { return 1; }
+ return x < y ? -1 : x > y ? 1 : 0;
+ });
function setPhoto(photo) {
- imageElt.attr('src', photo['url']);
+ imageElt.attr('src', photo['url']);
imageElt.attr('title', photo['typeName']);
}
imageElt.click(function() {
- imageIdx = (imageIdx + 1) % photosLength;
- var photo = photos[imageIdx];
- setPhoto(photo);
+ imageIdx = (imageIdx + 1) % photos.length;
+ setPhoto(photos[imageIdx]);
});
- setPhoto(data['photos'][0]);
- }
-
- var personData = [];
- function addData(title, value) {
- personData.push([title, value]);
- }
-
- var demographics = data['demographics'];
- if (demographics) {
- if (demographics['age']) {
- addData('Age', demographics['age']);
- }
- if (demographics['ageRange']) {
- addData('Age range', demographics['ageRange']);
- }
- if (demographics['gender']) {
- addData('Gender', demographics['gender']);
- }
- }
-
- var contactInfo = data['contactInfo'];
- if (contactInfo) {
- if (contactInfo['websites']) {
- var websites = [];
- $.each(contactInfo['websites'], function(i, website) {
- if (website['url']) {
- websites.push(website['url']);
- }
- });
- addData('Websites', websites);
- }
+ setPhoto(photos[0]);
}
+ var organizations = [];
if (data['organizations']) {
- var orgs = [];
$.each(data['organizations'], function(i, org) {
if (org['name']) {
- orgs.push(org['name']);
+ organizations.push(org['name']);
}
});
- addData('Organizations', orgs);
}
- var socialProfiles = data['socialProfiles'];
- if (socialProfiles) {
- $.each(socialProfiles, function(i, profile) {
+ var socialLinks = [];
+ if (data['socialProfiles']) {
+ $.each(data['socialProfiles'], function(i, profile) {
var typeName = profile['typeName'];
var url = profile['url'];
if (typeName && url) {
- addData(typeName, url);
+ socialLinks.push({typeName: typeName, url: url});
}
});
}
- var dataContainer = $('<div />', {'class': 'inner-border',
- 'style': 'max-height: inherit'});
- extraDetailsContainer.append(dataContainer);
-
- function createValueNode(value) {
- function linkOrText(x) {
- if (x.indexOf('http://') === 0 ||
- x.indexOf('https://') === 0) {
- return $('<a />', {href: x}).text(x);
- } else {
- return $('<span />').text(x);
- }
- }
-
- if (typeof value === 'string') {
- return linkOrText(value);
- } else if (typeof value === 'object') {
- var container = $('<span />');
- $.each(value, function(i, value) {
- if (i !== 0) {
- container.append(', ');
- }
- container.append(linkOrText(value));
- });
- return container;
- }
+ if (organizations.length > 0) {
+ var container = $('#content-box div').first();
+ container.append(
+ $('<p />')
+ .append($('<strong />').text('Organizations: '))
+ .append($('<span />').text(organizations.join(', '))));
+ container.css('min-height', '220px');
+ container.css('max-height', '220px');
}
- $.each(personData, function(i, datarow) {
- var title = datarow[0];
- var value = datarow[1];
- if (title && value) {
- dataContainer.append($('<p />')
- .append($('<strong />').text(title + ':'))
- .append('&nbsp;')
- .append(createValueNode(value))
- );
- }
- });
-
- if (JSON && JSON.stringify) {
- var rawDetailsLink = $('<a />', {href: '#'}).text('raw details');
- rawDetailsLink.click(function() {
- var text = JSON.stringify(data);
- $(this).replaceWith($('<p />').text(text));
- rawContainer.css({height: '400px', overflow: 'scroll'});
- return false;
+ if (socialLinks.length > 0) {
+ var tabs = $('.nav-tabs').first();
+ tabs.append(
+ $('<li />')
+ .append(
+ $('<a />', {'data-toggle': 'tab', href: '#social-links'})
+ .text('Social')));
+
+ var tabContentContainer = $('.tab-content').first();
+ var ul = $('<ul />');
+ socialLinks.sort(function(a, b) {
+ var x = a.typeName,
+ y = b.typeName;
+ return x < y ? -1 : x > y ? 1 : 0;
});
- var rawContainer = $('<div />', {id: 'raw-details'});
- rawContainer.append(rawDetailsLink);
- personDetails.append(rawContainer);
- rawContainer.css({
- 'margin-top': '1em',
- 'float': 'right',
- 'width': '500px',
- 'height': '50px'
- });
+ $.each(socialLinks, function(i, linkData) {
+ ul.append(
+ $('<li />')
+ .append(
+ $('<a />', {href: linkData.url}).text(linkData.typeName)));
+ });
+
+ tabContentContainer.append(
+ $('<div />', {id: 'social-links', 'class': 'tab-pane'})
+ .append(ul));
}
});
}

No commit comments for this range

Something went wrong with that request. Please try again.