summaryrefslogtreecommitdiffstats
path: root/js/app
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-13 17:28:07 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-13 17:28:38 +0200
commit38e4b6d7e973bc99811139066a7a047b4bd76a4c (patch)
treefb88f63c0a69cc527956715333dddd20d3b94f0b /js/app
parent8df86d1991e25dfaef8623e2f4945c67dbc5f318 (diff)
implement opml import, fix #23
Diffstat (limited to 'js/app')
-rw-r--r--js/app/controllers/settingscontroller.coffee12
-rw-r--r--js/app/services/bl/folderbl.coffee30
-rw-r--r--js/app/services/opmlparser.coffee4
-rw-r--r--js/app/services/services.coffee5
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()
-]
-