summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-26 18:04:02 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-26 18:04:02 +0100
commitc8d3f8fb4681f6993f1c9389e507df0724f56579 (patch)
tree312b48cdbc17c23d1e7aac6513f40e0a5813fdbf /js
parent8e1e0f5281c1ee49fe7f6d84ba8f2b709ebf7f40 (diff)
added casting information for data objects
Diffstat (limited to 'js')
-rw-r--r--js/app/controllers/feedcontroller.coffee39
-rw-r--r--js/app/directives/addfolderselect.coffee42
-rw-r--r--js/app/services/models/feedmodel.coffee5
-rw-r--r--js/public/app.js100
-rw-r--r--js/tests/controllers/feedcontrollerSpec.coffee28
-rw-r--r--js/tests/services/models/feedmodelSpec.coffee2
6 files changed, 165 insertions, 51 deletions
diff --git a/js/app/controllers/feedcontroller.coffee b/js/app/controllers/feedcontroller.coffee
index 7a61f4ab1..a8be616d9 100644
--- a/js/app/controllers/feedcontroller.coffee
+++ b/js/app/controllers/feedcontroller.coffee
@@ -78,29 +78,27 @@ angular.module('News').factory '_FeedController', ->
@$scope.addFeed = (feedUrl, parentFolderId=0) =>
@$scope.feedEmptyError = false
- @$scope.feedExistsError = false
@$scope.feedError = false
if angular.isUndefined(feedUrl) or feedUrl.trim() == ''
@$scope.feedEmptyError = true
- else
- feedUrl = feedUrl.trim()
- for feed in @_feedModel.getAll()
- if feedUrl == feed.url
- @$scope.feedExistsError = true
-
- if not (@$scope.feedEmptyError or @$scope.feedExistsError)
+ if not @$scope.feedEmptyError
@_isAddingFeed = true
- onSuccess = =>
- @$scope.feedUrl = ''
- @_isAddingFeed = false
onError = =>
@$scope.feedError = true
@_isAddingFeed = false
- @_persistence.createFeed(feedUrl, parentFolderId, onSuccess,
- onError)
+
+ onSuccess = (data) =>
+ if data.status == 'error'
+ onError()
+ else
+ @$scope.feedUrl = ''
+ @_isAddingFeed = false
+
+ @_persistence.createFeed(feedUrl.trim(), parentFolderId,
+ onSuccess, onError)
@$scope.addFolder = (folderName) =>
@$scope.folderEmptyError = false
@@ -137,11 +135,20 @@ angular.module('News').factory '_FeedController', ->
isShown: (type, id) ->
- if @isShowAll()
+ hasUnread = @getUnreadCount(type, id) > 0
+ if hasUnread
return true
else
- return @getUnreadCount(type, id) > 0
-
+ if @isShowAll()
+ switch type
+ when @_feedType.Subscriptions
+ return @_feedModel.size() > 0
+ when @_feedType.Folder
+ return @_folderModel.size() > 0
+ when @_feedType.Feed
+ return @_feedModel.size() > 0
+ return false
+
isShowAll: ->
return @_showAll.getShowAll()
diff --git a/js/app/directives/addfolderselect.coffee b/js/app/directives/addfolderselect.coffee
new file mode 100644
index 000000000..1c3f39f04
--- /dev/null
+++ b/js/app/directives/addfolderselect.coffee
@@ -0,0 +1,42 @@
+###
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+###
+
+
+###
+Turns a normal select into a folder select with the ability to create new
+folders
+###
+angular.module('News').directive 'addFolderSelect', ['$rootScope', ->
+
+ return (scope, elm, attr) ->
+
+ options =
+ singleSelect: true
+ selectedFirst: true
+ createText: $(elm).data('create')
+ createdCallback: (selected, value) ->
+ console.log selected
+ console.log value
+
+ $(elm).multiSelect(options)
+
+] \ No newline at end of file
diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee
index def720edf..046ac7ec2 100644
--- a/js/app/services/models/feedmodel.coffee
+++ b/js/app/services/models/feedmodel.coffee
@@ -32,8 +32,9 @@ angular.module('News').factory '_FeedModel',
add: (item) ->
- if item.icon == 'url()'
- item.icon = 'url(' + @_utils.imagePath('news', 'rss.svg') + ')'
+ if item.faviconLink == null
+ item.faviconLink = 'url(' +
+ @_utils.imagePath('news', 'rss.svg') + ')'
super(item)
diff --git a/js/public/app.js b/js/public/app.js
index e720ed428..505eb558c 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -88,6 +88,58 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+Turns a normal select into a folder select with the ability to create new
+folders
+*/
+
+
+(function() {
+
+ angular.module('News').directive('addFolderSelect', [
+ '$rootScope', function() {
+ return function(scope, elm, attr) {
+ var options;
+ options = {
+ singleSelect: true,
+ selectedFirst: true,
+ createText: $(elm).data('create'),
+ createdCallback: function(selected, value) {
+ console.log(selected);
+ return console.log(value);
+ }
+ };
+ return $(elm).multiSelect(options);
+ };
+ }
+ ]);
+
+}).call(this);
+
+// Generated by CoffeeScript 1.4.0
+
+/*
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
(function() {
angular.module('News').controller('SettingsController', [
@@ -196,36 +248,30 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
return _this.toggleFolder(folderId);
};
this.$scope.addFeed = function(feedUrl, parentFolderId) {
- var feed, onError, onSuccess, _i, _len, _ref;
+ var onError, onSuccess;
if (parentFolderId == null) {
parentFolderId = 0;
}
_this.$scope.feedEmptyError = false;
- _this.$scope.feedExistsError = false;
_this.$scope.feedError = false;
if (angular.isUndefined(feedUrl) || feedUrl.trim() === '') {
_this.$scope.feedEmptyError = true;
- } else {
- feedUrl = feedUrl.trim();
- _ref = _this._feedModel.getAll();
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- feed = _ref[_i];
- if (feedUrl === feed.url) {
- _this.$scope.feedExistsError = true;
- }
- }
}
- if (!(_this.$scope.feedEmptyError || _this.$scope.feedExistsError)) {
+ if (!_this.$scope.feedEmptyError) {
_this._isAddingFeed = true;
- onSuccess = function() {
- _this.$scope.feedUrl = '';
- return _this._isAddingFeed = false;
- };
onError = function() {
_this.$scope.feedError = true;
return _this._isAddingFeed = false;
};
- return _this._persistence.createFeed(feedUrl, parentFolderId, onSuccess, onError);
+ onSuccess = function(data) {
+ if (data.status === 'error') {
+ return onError();
+ } else {
+ _this.$scope.feedUrl = '';
+ return _this._isAddingFeed = false;
+ }
+ };
+ return _this._persistence.createFeed(feedUrl.trim(), parentFolderId, onSuccess, onError);
}
};
this.$scope.addFolder = function(folderName) {
@@ -272,11 +318,23 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
};
FeedController.prototype.isShown = function(type, id) {
- if (this.isShowAll()) {
+ var hasUnread;
+ hasUnread = this.getUnreadCount(type, id) > 0;
+ if (hasUnread) {
return true;
} else {
- return this.getUnreadCount(type, id) > 0;
+ if (this.isShowAll()) {
+ switch (type) {
+ case this._feedType.Subscriptions:
+ return this._feedModel.size() > 0;
+ case this._feedType.Folder:
+ return this._folderModel.size() > 0;
+ case this._feedType.Feed:
+ return this._feedModel.size() > 0;
+ }
+ }
}
+ return false;
};
FeedController.prototype.isShowAll = function() {
@@ -616,8 +674,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
}
FeedModel.prototype.add = function(item) {
- if (item.icon === 'url()') {
- item.icon = 'url(' + this._utils.imagePath('news', 'rss.svg') + ')';
+ if (item.faviconLink === null) {
+ item.faviconLink = 'url(' + this._utils.imagePath('news', 'rss.svg') + ')';
}
return FeedModel.__super__.add.call(this, item);
};
diff --git a/js/tests/controllers/feedcontrollerSpec.coffee b/js/tests/controllers/feedcontrollerSpec.coffee
index af4c8f9a7..8ef621030 100644
--- a/js/tests/controllers/feedcontrollerSpec.coffee
+++ b/js/tests/controllers/feedcontrollerSpec.coffee
@@ -171,7 +171,8 @@ describe '_FeedController', ->
expect(@ActiveFeed.getType()).toBe(4)
- it 'should return true when calling isShown and ShowAll is set to true', =>
+ it 'should return true when calling isShown and there are feeds', =>
+ @FeedModel.add({id: 3})
@ShowAll.setShowAll(true)
expect(@scope.isShown(3, 4)).toBeTruthy()
@@ -340,15 +341,6 @@ describe '_FeedController', ->
expect(@persistence.createFeed).not.toHaveBeenCalled()
- it 'should not add feeds that already exist client side', =>
- @FeedModel.add({id: 3, url: 'ola'})
- @persistence.createFeed = jasmine.createSpy('create')
- @scope.addFeed('ola')
-
- expect(@scope.feedExistsError).toBeTruthy()
- expect(@persistence.createFeed).not.toHaveBeenCalled()
-
-
it 'should set isAddingFeed to true if there were no problems', =>
@persistence.createFeed = jasmine.createSpy('create')
@scope.addFeed('ola')
@@ -358,7 +350,9 @@ describe '_FeedController', ->
it 'should should reset the feedurl and set isAddingFeed to false on succ',=>
@persistence.createFeed =
jasmine.createSpy('create').andCallFake (arg1, arg2, func) =>
- func()
+ data =
+ status: 'success'
+ func(data)
@scope.addFeed(' Ola')
expect(@scope.feedUrl).toBe('')
@@ -375,6 +369,18 @@ describe '_FeedController', ->
expect(@scope.feedError).toBeTruthy()
+ it 'should should set isAddingFeed to false on serverside error',=>
+ @persistence.createFeed =
+ jasmine.createSpy('create').andCallFake (arg1, arg2, func) =>
+ data =
+ status: 'error'
+ func(data)
+ @scope.addFeed('Ola')
+
+ expect(@scope.isAddingFeed()).toBeFalsy()
+ expect(@scope.feedError).toBeTruthy()
+
+
it 'should create a create new feed request if everything was ok', =>
@persistence.createFeed = jasmine.createSpy('create')
@scope.addFeed('Ola')
diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee
index 9732d0e82..caddb35c0 100644
--- a/js/tests/services/models/feedmodelSpec.coffee
+++ b/js/tests/services/models/feedmodelSpec.coffee
@@ -36,7 +36,7 @@ describe '_FeedModel', ->
it 'should bind an imagepath to the item if the url is empty', =>
item =
id: 3
- icon: 'url()'
+ faviconLink: null
utils =
imagePath: jasmine.createSpy('utils')