<div class="navbar navbar-inverse">
<div class="navbar-inner">
<ul class="nav">
- <li><a {{action showArtists href=true}}>Artists</a></li>
+ <li><a {{action showMediaItems href=true}}>Items</a></li>
</ul>
</div>
</div>
{{outlet library}}
</script>
- <script type="text/x-handlebars" data-template-name="artists">
+ <script type="text/x-handlebars" data-template-name="mediaItems">
+ <ul class="item-list striped">
+ {{#each item in controller}}
+ <li>{{item.title}}</li>
+ {{/each}}
+ </ul>
</script>
<!-- the UI framework -->
<script src="javascripts/app/store.js"></script>
<!-- models -->
- <script src="javascripts/app/models/artistModel.js"></script>
+ <script src="javascripts/app/models/mediaItemModel.js"></script>
<!-- controllers -->
<script src="javascripts/app/controllers/applicationController.js">
</script>
- <script src="javascripts/app/controllers/artistsController.js"></script>
+ <script src="javascripts/app/controllers/mediaItemsController.js"></script>
<!-- views -->
- <script src="javascripts/app/views/artistsView.js"></script>
+ <script src="javascripts/app/views/mediaItemsView.js"></script>
</body>
</html>
win.Hoofbeats = win.Ember.Application.create({
VERSION: '0.1',
rootElement: '#application',
- initialized: false,
- init: function() {
- var self = this;
-
- if (self.initialized) {
- return;
- }
-
- if (win.HoofbeatsLibrary) {
- self.library = new win.HoofbeatsLibrary();
- self.initialized = true;
- } else {
- setTimeout(function() {
- self.init();
- }, 100);
- }
- }
+ library: null,
});
}(window));
+++ /dev/null
-(function(app, Ember, _) {
- var ArtistsController = Ember.ArrayController.extend({
- content: [],
- });
-
- app.ArtistsController = ArtistsController;
- app.artistsController = ArtistsController.create();
-})(window.Hoofbeats, window.Ember);
--- /dev/null
+(function(app, Ember, _) {
+ var MediaItemsController = Ember.ArrayController.extend({
+ content: [],
+ });
+
+ app.MediaItemsController = MediaItemsController;
+ app.mediaItemsController = MediaItemsController.create();
+})(window.Hoofbeats, window.Ember);
+++ /dev/null
-(function(app, Ember) {
- var Artist = Ember.Object.extend({
- id: null,
- firstName: null,
- lastName: null,
- bandName: null,
-
- name: function() {
- var ret = "";
- if (this.get('firstName') && this.get('lastName')) {
- ret = "%@, %@".fmt(this.get('lastName', this.get('firstName')));
- if(this.get('bandName')) {
- ret += " (%@)".fmt(this.get('bandName'));
- }
- } else {
- ret = this.get('bandName');
- }
-
- return ret;
- }.property('firstName', 'lastName', 'bandName'),
-
- isBandOnly: function() {
- if (this.get('firstName') === null &&
- this.get('lastName') === null &&
- this.get('bandName') !== null) {
- return true;
- }
- return false;
- }.property('firstName', 'lastName', 'bandName')
- });
-
-
- Artist.reopenClass({
- find: function() {
- return app.Store.getArtists();
- }
- });
-
- app.Artist = Artist;
-})(window.Hoofbeats, window.Ember);
--- /dev/null
+(function(app, Ember) {
+ var MediaItem = Ember.Object.extend({
+ id: null,
+ title: null
+ });
+
+
+ MediaItem.reopenClass({
+ findAll: function() {
+ var items = [];
+
+ console.log("MediaItem.findAll: entered.");
+ app.Store.getMediaItems().done(function(data) {
+ data.forEach(function(item) {
+ console.log("MediaItem.findAll: pushing object.");
+ items.pushObject(app.MediaItem.create(item));
+ });
+ });
+
+ return items;
+ }
+ });
+
+ app.MediaItem = MediaItem;
+})(window.Hoofbeats, window.Ember);
/* vi: set et sw=4 ts=4 si: */
-(function(app, Ember) {
+(function(win, app, Ember) {
var Router = Ember.Router.extend({
location: 'none',
- showArtists: Ember.Route.transitionTo('artists'),
+ showMediaItems: Ember.Route.transitionTo('mediaItems'),
+
+ initLibrary: function() {
+ var self = this;
+
+ if (app.library !== null) {
+ return;
+ }
+
+ if (win.HoofbeatsLibrary) {
+ app.library = new win.HoofbeatsLibrary();
+ } else {
+ setTimeout(function() {
+ self.initLibrary();
+ }, 100);
+ }
+
+ },
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
- redirectsTo: 'artists'
+ redirectsTo: 'mediaItems'
}),
- artists: Ember.Route.extend({
- route: '/artists',
+ mediaItems: Ember.Route.extend({
+ route: '/mediaItems',
connectOutlets: function(router) {
var controller = router.get('applicationController');
+ router.initLibrary();
controller.connectOutlet(
- 'library', 'artists', app.Artist.find());
+ 'library', 'mediaItems', app.MediaItem.findAll());
}
})
})
});
app.Router = Router;
-}(window.Hoofbeats, window.Ember));
+}(window, window.Hoofbeats, window.Ember));
/* vi: set et sw=4 ts=4 si: */
-(function(app) {
+(function(app, $) {
var Store = function() {
this.reset();
this.scan();
return;
}
+ console.log("Store.scan: entered.");
if (app.library) {
app.library.scan().then(function() {
self.scanCompleted = true;
+ console.log(
+ "Store.scan: completed. " +
+ app.library.size +
+ " items in the library.");
});
} else {
setTimeout(function() {
}
},
- getArtists: function() {
- var artists = [];
- return artists;
+ getMediaItems: function(deferred) {
+ var self = this,
+ d = deferred || new $.Deferred();
+
+ console.log("Store.getMediaItems: entered.");
+ if (self.scanCompleted) {
+ console.log("Store.getMediaItems: scan is completed, resolving promise.");
+ deferred.resolve(app.library.items);
+ } else {
+ // If the scan is not completed, we must be still scanning.
+ console.log("Store.getMediaItems: scan still pending. Trying again later.");
+ setTimeout(function() {
+ return self.getMediaItems(d);
+ }, 100);
+ }
+
+ return d.promise();
}
};
app.Store = new Store();
-})(window.Hoofbeats);
+})(window.Hoofbeats, window.jQuery);
+++ /dev/null
-/* vi: set et sw=4 ts=4 si: */
-(function(app, Ember) {
- var ArtistsView = Ember.View.extend({
- templateName: 'artists',
- tagName: 'ul',
- classNames: ['artists']
- });
-
- app.ArtistsView = ArtistsView;
-})(window.Hoofbeats, window.Ember);
--- /dev/null
+/* vi: set et sw=4 ts=4 si: */
+(function(app, Ember) {
+ var MediaItemsView = Ember.View.extend({
+ templateName: 'mediaItems',
+ tagName: 'ul',
+ classNames: ['mediaItems']
+ });
+
+ app.MediaItemsView = MediaItemsView;
+})(window.Hoofbeats, window.Ember);
this.fetchCount = 100;
this.fetchOffset = 0;
+ this.oneTime = false;
this.mediaItems = [];
this.initialize = function() {
"UNION", [this.audioTypeFilter, this.videoTypeFilter]);
};
- this.scan = function() {
+ this.scan = function(count) {
this.deferred = new $.Deferred();
this.initialize()
this.mediaItems = [];
this.fetchOffset = 0;
+ if (count !== undefined) {
+ this.fetchCount = count;
+ this.oneTime = true;
+ }
+
tizen.content.find(
this.findCB.bind(this),
this.errorCB.bind(this),
};
this.errorCB = function(error) {
- console.log("Error: " + error.name);
+ console.log("HoofbeatsLibrary.errorCB: " + error.name);
this.deferred.reject();
throw new Error(error.name);
};
items.forEach(function(item, index, items) {
self.mediaItems.push(item);
win.MusicBrainz.getArtist(item.artists[0]).done(function(data) {
- console.log(data);
+ console.log(
+ "HoofbeatsLibrary.findCB: " +
+ "item resolved on MusicBrainz: " +
+ data.name);
});
});
- if (items.length == this.fetchCount) {
+ if (items.length == this.fetchCount && !this.oneTime) {
// There *might* be more items.
this.fetchOffset += this.fetchCount;
tizen.content.find(
library.prototype = {
set initialized(value) {this._initialized = value; },
- get initialized() { return this._initialized; }
+ get initialized() { return this._initialized; },
+ get items() { return this.mediaItems; },
+ get size() { return this.mediaItems.length; }
};
win.HoofbeatsLibrary = library;
var lib = new HoofbeatsLibrary();
stop();
lib.scan().then(function() {
- ok(lib.mediaItems.length > 0, "there are items in the library");
+ ok(lib.size > 0, "there are items in the library");
+ start();
+ });
+ });
+
+ test("scan with count", function() {
+ var lib = new HoofbeatsLibrary();
+ stop();
+ lib.scan(1).then(function() {
+ ok(lib.size == 1, "there is one item in the library");
start();
});
});