diff options
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/controllers/settingscontroller.coffee | 12 | ||||
-rw-r--r-- | js/app/services/bl/folderbl.coffee | 30 | ||||
-rw-r--r-- | js/app/services/opmlparser.coffee | 4 | ||||
-rw-r--r-- | js/app/services/services.coffee | 5 |
4 files changed, 36 insertions, 15 deletions
diff --git a/js/app/controllers/settingscontroller.coffee b/js/app/controllers/settingscontroller.coffee index 07cf7360a..2df604c42 100644 --- a/js/app/controllers/settingscontroller.coffee +++ b/js/app/controllers/settingscontroller.coffee @@ -22,11 +22,15 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').controller 'SettingsController', -['$scope', 'FeedBl', ($scope, FeedBl) -> - - $scope.import = (fileContent) -> - console.log fileContent +['$scope', 'FeedBl', 'FolderBl', ($scope, FeedBl, FolderBl) -> $scope.feedBl = FeedBl + $scope.import = (fileContent) => + $scope.error = false + try + FolderBl.import(fileContent) + catch error + $scope.error = true + ]
\ No newline at end of file diff --git a/js/app/services/bl/folderbl.coffee b/js/app/services/bl/folderbl.coffee index ddb1f88c4..a74ecc42f 100644 --- a/js/app/services/bl/folderbl.coffee +++ b/js/app/services/bl/folderbl.coffee @@ -23,14 +23,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory 'FolderBl', ['_Bl', 'FolderModel', 'FeedBl', 'Persistence', 'FeedType', 'ActiveFeed', -'ItemModel', 'ShowAll', '_ExistsError', +'ItemModel', 'ShowAll', '_ExistsError', 'OPMLParser', (_Bl, FolderModel, FeedBl, Persistence, FeedType, ActiveFeed, -ItemModel, ShowAll, _ExistsError)-> +ItemModel, ShowAll, _ExistsError, OPMLParser)-> class FolderBl extends _Bl constructor: (@_folderModel, @_feedBl, @_showAll, activeFeed, - persistence, @_feedType, itemModel) -> + persistence, @_feedType, itemModel, @_opmlParser) -> super(activeFeed, persistence, itemModel, @_feedType.Folder) @@ -123,7 +123,29 @@ ItemModel, ShowAll, _ExistsError)-> @_folderModel.removeByName(folderName) + import: (xml) -> + opml = @_opmlParser.parseXML(xml) + + @_importElement(opml, 0) + + + _importElement: (opml, parentFolderId) -> + for item in opml.getItems() + if item.isFolder() + try + @create item.getName(), (data) => + @_importElement(item, data.folders[0].id) + catch error + if error instanceof _ExistsError + folder = @_folderModel.getByName(item.getName()) + @_importElement(item, folder.id) + else + try + @_feedBl.create(item.getUrl(), parentFolderId) + catch error + + return new FolderBl(FolderModel, FeedBl, ShowAll, ActiveFeed, Persistence, - FeedType, ItemModel) + FeedType, ItemModel, OPMLParser) ]
\ No newline at end of file diff --git a/js/app/services/opmlparser.coffee b/js/app/services/opmlparser.coffee index 9586cbaf2..904ff2954 100644 --- a/js/app/services/opmlparser.coffee +++ b/js/app/services/opmlparser.coffee @@ -20,7 +20,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. ### -angular.module('News').factory '_OPMLParser', -> +angular.module('News').factory 'OPMLParser', -> class Feed @@ -75,4 +75,4 @@ angular.module('News').factory '_OPMLParser', -> @_recursivelyParse($outline, folder) - return OPMLParser + return new OPMLParser() diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee index 837e2004c..83e76e20e 100644 --- a/js/app/services/services.coffee +++ b/js/app/services/services.coffee @@ -99,8 +99,3 @@ FolderModel, FeedModel) -> ] -# other classes -angular.module('News').factory 'OPMLParser', ['_OPMLParser', (_OPMLParser) -> - return new _OPMLParser() -] - |