From: Wojciech Kosowicz Date: Fri, 20 Mar 2015 14:40:13 +0000 (+0100) Subject: [Content] Playlist fixes X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~261 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9481963b3669bac847753632bafe985b9eabd79d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Content] Playlist fixes [Verification] 202/230 tests passed Change-Id: I3dec19f796db5c60be1fd8f8514c4830fb2486f2 Signed-off-by: Wojciech Kosowicz --- diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc index b7949b80..cc42d489 100755 --- a/src/content/content_instance.cc +++ b/src/content/content_instance.cc @@ -396,8 +396,8 @@ void ContentInstance::ContentManagerRemoveplaylist(const picojson::value& args, void ContentInstance::ContentManagerPlaylistAdd(const picojson::value& args, picojson::object& out) { int ret; if(ContentManager::getInstance()->isConnected()) { - std::string playlist_id = args.get("playlist_id").get(); - std::string content_id = args.get("content_id").get(); + std::string playlist_id = args.get("playlistId").get(); + std::string content_id = args.get("contentId").get(); ret = ContentManager::getInstance()->playlistAdd(playlist_id, content_id); if(ret != MEDIA_CONTENT_ERROR_NONE) { ReportError(ContentManager::getInstance()->convertError(ret),out); diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index b7b6e993..82c8a837 100755 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -925,7 +925,7 @@ int ContentManager::playlistRemove(std::string playlist_id, int member_id) { void ContentManager::playlistAddbatch(const std::shared_ptr& user_data) { int ret = MEDIA_CONTENT_ERROR_NONE; - std::string playlist_id = user_data->args.get("playlist_id").get(); + std::string playlist_id = user_data->args.get("playlistId").get(); media_playlist_h playlist = NULL; ret = media_playlist_get_playlist_from_db(std::stoi(playlist_id), &playlist); @@ -961,7 +961,7 @@ void ContentManager::playlistGet(const std::shared_ptr& user_ int ret = MEDIA_CONTENT_ERROR_NONE; media_playlist_h playlist = NULL; - std::string playlist_id = user_data->args.get("playlist_id").get(); + std::string playlist_id = user_data->args.get("playlistId").get(); ret = media_playlist_get_playlist_from_db(std::stoi(playlist_id), &playlist); if(ret != MEDIA_CONTENT_ERROR_NONE && playlist == NULL) { UnknownException err("Getting playlist is failed."); diff --git a/src/content/js/manager.js b/src/content/js/manager.js index 3753cb4d..c3bfc061 100644 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -199,7 +199,12 @@ ContentManager.prototype.getPlaylists = function(successCallback, errorCallback) native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback, native_.getResultObject(result)); + var out = []; + result = native_.getResultObject(result); + for (var i = 0, max = result.length; i < max; i++) { + out.push(new Playlist(result[i])); + } + native_.callIfPossible(args.successCallback, out); }; native_.call('ContentManager_getPlaylists', data, callback); @@ -223,7 +228,7 @@ ContentManager.prototype.createPlaylist = function(name, successCallback, errorC native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback, native_.getResultObject(result)); + native_.callIfPossible(args.successCallback, new Playlist(native_.getResultObject(result))); }; native_.call('ContentManager_createPlaylist', data, callback); diff --git a/src/content/js/playlist.js b/src/content/js/playlist.js index fffc47a6..7607d8bd 100644 --- a/src/content/js/playlist.js +++ b/src/content/js/playlist.js @@ -75,15 +75,15 @@ function Playlist(data) { Playlist.prototype.add = function (item) { var args = validator_.validateArgs(arguments, [ - {name: 'item', type: types_.PLATFORM_OBJECT, values: tizen.Content} + {name: 'item', type: types_.PLATFORM_OBJECT, values: Content} ]); var data = { - item: args.item + contentId: args.item.id, + playlistId: this.id, }; - var result = native_.callSync('Playlist_add', data); - + var result = native_.callSync('ContentPlaylist_add', data); if (native_.isFailure(result)) { throw native_.getErrorObject(result); } @@ -91,13 +91,14 @@ Playlist.prototype.add = function (item) { Playlist.prototype.addBatch = function (items, successCallback, errorCallback) { var args = validator_.validateArgs(arguments, [ - {name: 'items', type: types_.PLATFORM_OBJECT, values: tizen.Content}, + {name: 'items', type: types_.ARRAY, values: Content}, {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); var data = { - items: args.items + playlistId: this.id, + contents: args.items }; var callback = function (result) { @@ -108,12 +109,12 @@ Playlist.prototype.addBatch = function (items, successCallback, errorCallback) { native_.callIfPossible(args.successCallback); }; - native_.call('Playlist_addBatch', data, callback); + native_.call('ContentPlaylist_addBatch', data, callback); }; Playlist.prototype.remove = function (item) { var args = validator_.validateArgs(arguments, [ - {name: 'item', type: types_.PLATFORM_OBJECT, values: tizen.PlaylistItem} + {name: 'item', type: types_.PLATFORM_OBJECT, values: PlaylistItem} ]); var data = { @@ -129,7 +130,7 @@ Playlist.prototype.remove = function (item) { Playlist.prototype.removeBatch = function (items, successCallback, errorCallback) { var args = validator_.validateArgs(arguments, [ - {name: 'items', type: types_.PLATFORM_OBJECT, values: tizen.PlaylistItem}, + {name: 'items', type: types_.PLATFORM_OBJECT, values: PlaylistItem}, {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]); @@ -158,8 +159,9 @@ Playlist.prototype.get = function (successCallback, errorCallback, count, offset ]); var data = { - count: args.count, - offset: args.offset + playlistId: this.id, + count: type_.isNullOrUndefined(args.count) ? -1 : args.count, + offset: type_.isNullOrUndefined(args.offset) ? -1 : args.offset }; var callback = function (result) { @@ -167,15 +169,20 @@ Playlist.prototype.get = function (successCallback, errorCallback, count, offset native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); return; } - native_.callIfPossible(args.successCallback, native_.getResultObject(result)); + result = native_.getResultObject(result); + var out = []; + for (var i = 0, max = result.length; i < max; i++) { + out.push(new PlaylistItem(createContentObject_(result[i]))); + } + native_.callIfPossible(args.successCallback, out); }; - native_.call('Playlist_get', data, callback); + native_.call('ContentPlaylist_get', data, callback); }; Playlist.prototype.setOrder = function (items, successCallback, errorCallback) { var args = validator_.validateArgs(arguments, [ - {name: 'items', type: types_.PLATFORM_OBJECT, values: tizen.PlaylistItem}, + {name: 'items', type: types_.PLATFORM_OBJECT, values: PlaylistItem}, {name: 'successCallback', type: types_.FUNCTION, optional: true, nullable: true}, {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} ]);