Permalink
Browse files

Add linking between speakers and presentations with better JSONP hand…

…ling
  • Loading branch information...
1 parent 5ce94ee commit 2f289143f96e1e506c1a20ffac79f325fdd79499 @kborchers committed Dec 17, 2012
@@ -1,19 +1,15 @@
"use strict";
-aerogearDevnexusApp.controller( "SpeakersPresentationsCtrl", [ "$scope", "$routeParams", "$location", "dataService", function( $scope, $routeParams, $location, dataService ) {
- var viewName, offlineData, saved,
+aerogearDevnexusApp.controller( "SpeakersPresentationsCtrl", [ "$scope", "$routeParams", "dataService", "$log", function( $scope, $routeParams, dataService, $log ) {
+ var offlineSpeakers, offlinePresentations, saved, speakerDeferred, presentationDeferred,
// Offline Data expires after 1 hour
expireTime = 3600000,
today = (new Date()).getTime();
- if ( $location.$$path.indexOf( "speakers" ) >= 0 ) {
- viewName = "speaker";
- } else {
- viewName = "presentation";
- }
-
- offlineData = dataService[ viewName + "Store" ].read();
- saved = dataService[ viewName + "Saved" ].read();
+ // Get offline data
+ offlineSpeakers = dataService.speakerStore.read();
+ offlinePresentations = dataService.presentationStore.read();
+ saved = dataService.dataSaved.read();
// Set the open collapse panel
$scope.open = $routeParams.id;
@@ -22,28 +18,47 @@ aerogearDevnexusApp.controller( "SpeakersPresentationsCtrl", [ "$scope", "$route
$scope.converter = new Markdown.Converter();
// Update data
- if ( offlineData && offlineData.length && ( today - saved[ 0 ] ) < expireTime ) {
- $scope[ viewName + "s" ] = offlineData;
+ if ( offlineSpeakers && ( today - saved[ 0 ] ) < expireTime ) {
+ $scope.speakers = offlineSpeakers;
+ $scope.presentations = offlinePresentations;
} else {
- dataService[ viewName + "Pipe" ].read({
+ speakerDeferred = dataService.speakerPipe.read({
jsonp: {
callback: "jsonp",
- customCallback: "handleMatterhornData"
- },
- success: function( data ) {
- dataService[ viewName + "Store" ].save( data[ viewName + "List" ][ viewName ], { reset: true } );
- dataService[ viewName + "Saved" ].save( (new Date()).getTime(), { reset: true } );
- $scope[ viewName + "s" ] = data[ viewName + "List" ][ viewName ];
- $scope.$apply();
- },
- error: function( data ) {
- if ( offlineData && offlineData.length ) {
- $scope[ viewName + "s" ] = offlineData[ 0 ][ viewName ];
- $scope.$apply();
- } else {
- $log('error');
- }
+ customCallback: "speakerCallback"
+ }
+ });
+ presentationDeferred = dataService.presentationPipe.read({
+ jsonp: {
+ callback: "jsonp",
+ customCallback: "presentationCallback"
}
});
+
+ jQuery.when( speakerDeferred, presentationDeferred )
+ .done( function( speakerResponse, presentationResponse ) {
+ dataService.dataSaved.save( (new Date()).getTime(), { reset: true } );
+
+ // Update Speaker data
+ dataService.presentationStore.save( presentationResponse[ 0 ].presentationList.presentation, { reset: true } );
+ $scope.presentations = presentationResponse[ 0 ].presentationList.presentation;
+
+ // Update Speaker data
+ dataService.speakerStore.save( speakerResponse[ 0 ].speakerList.speaker, { reset: true } );
+ $scope.speakers = speakerResponse[ 0 ].speakerList.speaker;
+
+ $scope.$apply();
+ })
+ .fail( function( speakerResponse, presentationResponse ) {
+ $log.log(presentationResponse[ 0 ],speakerResponse[ 0 ]);
+ });
}
+
+ $scope.speakerSessions = function( speakerId ) {
+ return dataService.presentationStore.filter({
+ speaker: {
+ id: speakerId
+ }
+ });
+ };
}]);
@@ -16,33 +16,26 @@ aerogearDevnexusApp.factory( "dataService", function() {
storageType: "localStorage"
}
}).stores.speakers,
- speakerSaved: AeroGear.DataManager({
- name: "speakerSaved",
- type: "SessionLocal",
- settings: {
- storageType: "localStorage"
- }
- }).stores.speakerSaved,
presentationPipe: AeroGear.Pipeline({
- name: "sessions",
+ name: "presentations",
settings: {
baseURL: "http://devnexus.com/s/",
endpoint: "presentations.json"
}
- }).pipes.sessions,
+ }).pipes.presentations,
presentationStore: AeroGear.DataManager({
- name: "sessions",
+ name: "presentations",
type: "SessionLocal",
settings: {
storageType: "localStorage"
}
- }).stores.sessions,
- presentationSaved: AeroGear.DataManager({
- name: "sessionSaved",
+ }).stores.presentations,
+ dataSaved: AeroGear.DataManager({
+ name: "dataSaved",
type: "SessionLocal",
settings: {
storageType: "localStorage"
}
- }).stores.sessionSaved
- };
+ }).stores.dataSaved
+ }
});
@@ -4,7 +4,7 @@
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent=".accordion" href="#collapse-{{presentation.id}}">{{presentation.title}}</a>
</div>
- <div id="collapse-{{presentation.id}}" class="accordion-body collapse" ng-class="{in : open == presentation.id}">
+ <div id="collapse-{{presentation.id}}" class="accordion-body collapse" ng-class="{in : open == presentation.id}" jump-to="open, 'presentation'">
<div class="accordion-inner">
<div ng-bind-html="converter.makeHtml(presentation.description)"></div>
<div>
View
@@ -4,7 +4,7 @@
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent=".accordion" href="#collapse-{{speaker.id}}">{{speaker.firstName}} {{speaker.lastName}}</a>
</div>
- <div id="collapse-{{speaker.id}}" class="accordion-body collapse" ng-class="{in : open == speaker.id}" jump-to="open">
+ <div id="collapse-{{speaker.id}}" class="accordion-body collapse" ng-class="{in : open == speaker.id}" jump-to="open, 'speaker'">
<div class="accordion-inner">
<div class="speaker-photo">
<img src="http://devnexus.com/s/speakers/{{speaker.id}}.jpg"/>
@@ -13,6 +13,12 @@
</div>
</div>
<div ng-bind-html="converter.makeHtml(speaker.bio)"></div>
+ <ul ng-repeat="session in speakerSessions(speaker.id)">
+ <strong ng-show="$first">Presentations</strong>
+ <li>
+ <a href="#/sessions/{{session.id}}">{{session.title}}</a>
+ </li>
+ </ul>
</div>
</div>
</div>

0 comments on commit 2f28914

Please sign in to comment.