summaryrefslogtreecommitdiffstats
path: root/js/controller
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-14 04:17:32 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-14 04:17:32 +0200
commit242fdbf9fcc39795fe5567eadcb55c6709b303c5 (patch)
tree6c85a9836080997bf223341e11eecdac3c51ac1e /js/controller
parent721ae0b8bbde9716ed9073439805fd6497abf508 (diff)
add import articles
Diffstat (limited to 'js/controller')
-rw-r--r--js/controller/SettingsController.js53
1 files changed, 41 insertions, 12 deletions
diff --git a/js/controller/SettingsController.js b/js/controller/SettingsController.js
index a4917d613..5e0eaf83c 100644
--- a/js/controller/SettingsController.js
+++ b/js/controller/SettingsController.js
@@ -8,10 +8,12 @@
* @copyright Bernhard Posselt 2014
*/
app.controller('SettingsController',
-function ($route, SettingsResource, FeedResource) {
+function ($route, $q, SettingsResource, ItemResource, OPMLParser,
+ OPMLImporter, Publisher) {
'use strict';
- this.importing = false;
+ this.isOPMLImporting = false;
+ this.isArticlesImporting = false;
this.opmlImportError = false;
this.articleImportError = false;
@@ -23,30 +25,57 @@ function ($route, SettingsResource, FeedResource) {
}
};
-
this.toggleSetting = function (key) {
set(key, !this.getSetting(key));
};
-
this.getSetting = function (key) {
return SettingsResource.get(key);
};
+ this.importOPML = function (content) {
+ this.opmlImportError = false;
+ this.articleImportError = false;
- this.feedSize = function () {
- return FeedResource.size();
- };
+ try {
+ this.isOPMLImporting = false;
+ var parsedContent = OPMLParser.parse(content);
+ var self = this;
+ var jobSize = 5;
- // TBD
- this.importOpml = function (content) {
- console.log(content);
- };
+ OPMLImporter.importFolders(parsedContent)
+ .then(function (feedQueue) {
+ return OPMLImporter.importFeedQueue(feedQueue, jobSize);
+ }).finally(function () {
+ self.isOPMLImporting = false;
+ });
+ } catch (error) {
+ this.isOPMLImporting = false;
+ this.opmlImportError = true;
+ }
+ };
this.importArticles = function (content) {
- console.log(content);
+ this.opmlImportError = false;
+ this.articleImportError = false;
+
+ try {
+ this.isArticlesImporting = true;
+ var articles = JSON.parse(content);
+
+ var self = this;
+ ItemResource.importArticles(articles).success(function (data) {
+ Publisher.publishAll(data);
+ }).finally(function () {
+ self.isArticlesImporting = false;
+ });
+
+ } catch (error) {
+ this.articleImportError = true;
+ this.isArticlesImporting = false;
+ }
};
}); \ No newline at end of file