зеркало из https://github.com/nextcloud/news.git
add a button for people to get out of add folder mode
This commit is contained in:
Родитель
adcf13d214
Коммит
59f42f80ad
|
@ -45,4 +45,16 @@
|
|||
border-top-left-radius: 0;
|
||||
height: 30px !important;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.add-new .back-button {
|
||||
border-radius: 0;
|
||||
width: 30px;
|
||||
background-image: url('%webroot%/core/img/actions/delete.svg');
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.add-new .back-button:hover {
|
||||
background-image: url('%webroot%/core/img/actions/delete-hover.svg');
|
||||
}
|
|
@ -21,7 +21,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
###
|
||||
|
||||
|
||||
angular.module('News').factory '_FeedController', ->
|
||||
angular.module('News').factory '_FeedController',
|
||||
['_ExistsError',
|
||||
(_ExistsError)->
|
||||
|
||||
class FeedController
|
||||
|
||||
|
@ -74,22 +76,29 @@ angular.module('News').factory '_FeedController', ->
|
|||
@_$scope.folderEmptyError = false
|
||||
@_$scope.folderExistsError = false
|
||||
|
||||
if angular.isUndefined(folderName) or folderName.trim() == ''
|
||||
@_$scope.folderEmptyError = true
|
||||
else
|
||||
folderName = folderName.trim()
|
||||
if @_folderModel.nameExists(folderName)
|
||||
@_$scope.folderExistsError = true
|
||||
|
||||
if not (@_$scope.folderEmptyError or @_$scope.folderExistsError)
|
||||
try
|
||||
@_isAddingFolder = true
|
||||
@_persistence.createFolder folderName, 0, =>
|
||||
@$scope.folderName = ''
|
||||
@$scope.addNewFolder = false
|
||||
@_folderBl.create folderName
|
||||
|
||||
# on success
|
||||
, =>
|
||||
@_$scope.folderName = ''
|
||||
@_$scope.addNewFolder = false
|
||||
@_isAddingFolder = false
|
||||
# on error
|
||||
, =>
|
||||
@_isAddingFolder = false
|
||||
|
||||
catch error
|
||||
if error instanceof _ExistsError
|
||||
@_$scope.folderExistsError = true
|
||||
else
|
||||
@_$scope.folderEmptyError = true
|
||||
|
||||
|
||||
@_$scope.$on 'moveFeedToFolder', (scope, data) =>
|
||||
console.log data
|
||||
|
||||
return FeedController
|
||||
return FeedController
|
||||
|
||||
]
|
|
@ -81,10 +81,31 @@ ItemModel, ShowAll, _ExistsError)->
|
|||
return @_folderModel.getAll()
|
||||
|
||||
|
||||
create: (folderName) ->
|
||||
if @_folderModel.nameExists(folderName)
|
||||
create: (folderName, onSuccess=null, onFailure=null) ->
|
||||
onSuccess or= ->
|
||||
onFailure or= ->
|
||||
|
||||
if angular.isUndefined(folderName) or folderName.trim() == ''
|
||||
throw new Error()
|
||||
|
||||
folderName = folderName.trim()
|
||||
|
||||
if @_folderModel.getByName(folderName)
|
||||
throw new _ExistsError()
|
||||
|
||||
folder =
|
||||
name: folderName
|
||||
|
||||
@_folderModel.add(folder)
|
||||
|
||||
success = (response) =>
|
||||
if response.status == 'error'
|
||||
folder.error = response.msg
|
||||
onFailure()
|
||||
else
|
||||
onSuccess()
|
||||
|
||||
@_persistence.createFolder folderName, 0, success
|
||||
|
||||
|
||||
return new FolderBl(FolderModel, FeedBl, ShowAll, ActiveFeed, Persistence,
|
||||
|
|
195
js/public/app.js
195
js/public/app.js
|
@ -258,91 +258,96 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
|
||||
(function() {
|
||||
angular.module('News').factory('_FeedController', function() {
|
||||
var FeedController;
|
||||
angular.module('News').factory('_FeedController', [
|
||||
'_ExistsError', function(_ExistsError) {
|
||||
var FeedController;
|
||||
|
||||
FeedController = (function() {
|
||||
function FeedController(_$scope, _persistence, _folderBl, _feedBl, _subscriptionsBl, _starredBl, _unreadCountFormatter) {
|
||||
var _this = this;
|
||||
FeedController = (function() {
|
||||
function FeedController(_$scope, _persistence, _folderBl, _feedBl, _subscriptionsBl, _starredBl, _unreadCountFormatter) {
|
||||
var _this = this;
|
||||
|
||||
this._$scope = _$scope;
|
||||
this._persistence = _persistence;
|
||||
this._folderBl = _folderBl;
|
||||
this._feedBl = _feedBl;
|
||||
this._subscriptionsBl = _subscriptionsBl;
|
||||
this._starredBl = _starredBl;
|
||||
this._unreadCountFormatter = _unreadCountFormatter;
|
||||
this._isAddingFolder = false;
|
||||
this._isAddingFeed = false;
|
||||
this._$scope.folderBl = this._folderBl;
|
||||
this._$scope.feedBl = this._feedBl;
|
||||
this._$scope.subscriptionsBl = this._subscriptionsBl;
|
||||
this._$scope.starredBl = this._starredBl;
|
||||
this._$scope.unreadCountFormatter = this._unreadCountFormatter;
|
||||
this._$scope.isAddingFolder = function() {
|
||||
return _this._isAddingFolder;
|
||||
};
|
||||
this._$scope.isAddingFeed = function() {
|
||||
return _this._isAddingFeed;
|
||||
};
|
||||
this._$scope.addFeed = function(feedUrl, parentFolderId) {
|
||||
var onError, onSuccess;
|
||||
this._$scope = _$scope;
|
||||
this._persistence = _persistence;
|
||||
this._folderBl = _folderBl;
|
||||
this._feedBl = _feedBl;
|
||||
this._subscriptionsBl = _subscriptionsBl;
|
||||
this._starredBl = _starredBl;
|
||||
this._unreadCountFormatter = _unreadCountFormatter;
|
||||
this._isAddingFolder = false;
|
||||
this._isAddingFeed = false;
|
||||
this._$scope.folderBl = this._folderBl;
|
||||
this._$scope.feedBl = this._feedBl;
|
||||
this._$scope.subscriptionsBl = this._subscriptionsBl;
|
||||
this._$scope.starredBl = this._starredBl;
|
||||
this._$scope.unreadCountFormatter = this._unreadCountFormatter;
|
||||
this._$scope.isAddingFolder = function() {
|
||||
return _this._isAddingFolder;
|
||||
};
|
||||
this._$scope.isAddingFeed = function() {
|
||||
return _this._isAddingFeed;
|
||||
};
|
||||
this._$scope.addFeed = function(feedUrl, parentFolderId) {
|
||||
var onError, onSuccess;
|
||||
|
||||
if (parentFolderId == null) {
|
||||
parentFolderId = 0;
|
||||
}
|
||||
_this._$scope.feedEmptyError = false;
|
||||
_this._$scope.feedError = false;
|
||||
if (angular.isUndefined(feedUrl) || feedUrl.trim() === '') {
|
||||
_this._$scope.feedEmptyError = true;
|
||||
}
|
||||
if (!_this._$scope.feedEmptyError) {
|
||||
_this._isAddingFeed = true;
|
||||
onError = function() {
|
||||
_this._$scope.feedError = true;
|
||||
return _this._isAddingFeed = false;
|
||||
};
|
||||
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) {
|
||||
_this._$scope.folderEmptyError = false;
|
||||
_this._$scope.folderExistsError = false;
|
||||
if (angular.isUndefined(folderName) || folderName.trim() === '') {
|
||||
_this._$scope.folderEmptyError = true;
|
||||
} else {
|
||||
folderName = folderName.trim();
|
||||
if (_this._folderModel.nameExists(folderName)) {
|
||||
_this._$scope.folderExistsError = true;
|
||||
if (parentFolderId == null) {
|
||||
parentFolderId = 0;
|
||||
}
|
||||
}
|
||||
if (!(_this._$scope.folderEmptyError || _this._$scope.folderExistsError)) {
|
||||
_this._isAddingFolder = true;
|
||||
return _this._persistence.createFolder(folderName, 0, function() {
|
||||
_this.$scope.folderName = '';
|
||||
_this.$scope.addNewFolder = false;
|
||||
return _this._isAddingFolder = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
this._$scope.$on('moveFeedToFolder', function(scope, data) {
|
||||
return console.log(data);
|
||||
});
|
||||
}
|
||||
_this._$scope.feedEmptyError = false;
|
||||
_this._$scope.feedError = false;
|
||||
if (angular.isUndefined(feedUrl) || feedUrl.trim() === '') {
|
||||
_this._$scope.feedEmptyError = true;
|
||||
}
|
||||
if (!_this._$scope.feedEmptyError) {
|
||||
_this._isAddingFeed = true;
|
||||
onError = function() {
|
||||
_this._$scope.feedError = true;
|
||||
return _this._isAddingFeed = false;
|
||||
};
|
||||
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) {
|
||||
var error;
|
||||
|
||||
_this._$scope.folderEmptyError = false;
|
||||
_this._$scope.folderExistsError = false;
|
||||
try {
|
||||
_this._isAddingFolder = true;
|
||||
return _this._folderBl.create(folderName, function() {
|
||||
_this._$scope.folderName = '';
|
||||
_this._$scope.addNewFolder = false;
|
||||
return _this._isAddingFolder = false;
|
||||
}, function() {
|
||||
return _this._isAddingFolder = false;
|
||||
});
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
if (error instanceof _ExistsError) {
|
||||
return _this._$scope.folderExistsError = true;
|
||||
} else {
|
||||
return _this._$scope.folderEmptyError = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
this._$scope.$on('moveFeedToFolder', function(scope, data) {
|
||||
return console.log(data);
|
||||
});
|
||||
}
|
||||
|
||||
return FeedController;
|
||||
|
||||
})();
|
||||
return FeedController;
|
||||
|
||||
})();
|
||||
return FeedController;
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
}).call(this);
|
||||
|
||||
|
@ -843,10 +848,38 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
return this._folderModel.getAll();
|
||||
};
|
||||
|
||||
FolderBl.prototype.create = function(folderName) {
|
||||
if (this._folderModel.nameExists(folderName)) {
|
||||
FolderBl.prototype.create = function(folderName, onSuccess, onFailure) {
|
||||
var folder, success,
|
||||
_this = this;
|
||||
|
||||
if (onSuccess == null) {
|
||||
onSuccess = null;
|
||||
}
|
||||
if (onFailure == null) {
|
||||
onFailure = null;
|
||||
}
|
||||
onSuccess || (onSuccess = function() {});
|
||||
onFailure || (onFailure = function() {});
|
||||
if (angular.isUndefined(folderName) || folderName.trim() === '') {
|
||||
throw new Error();
|
||||
}
|
||||
folderName = folderName.trim();
|
||||
if (this._folderModel.getByName(folderName)) {
|
||||
throw new _ExistsError();
|
||||
}
|
||||
folder = {
|
||||
name: folderName
|
||||
};
|
||||
this._folderModel.add(folder);
|
||||
success = function(response) {
|
||||
if (response.status === 'error') {
|
||||
folder.error = response.msg;
|
||||
return onFailure();
|
||||
} else {
|
||||
return onSuccess();
|
||||
}
|
||||
};
|
||||
return this._persistence.createFolder(folderName, 0, success);
|
||||
};
|
||||
|
||||
return FolderBl;
|
||||
|
|
|
@ -27,7 +27,8 @@ describe 'FolderBl', ->
|
|||
|
||||
beforeEach =>
|
||||
angular.module('News').factory 'Persistence', =>
|
||||
@persistence = {}
|
||||
@persistence =
|
||||
createFolder: ->
|
||||
|
||||
beforeEach inject (@FolderBl, @FolderModel, @FeedModel, @ShowAll,
|
||||
@ActiveFeed, @FeedType, @_ExistsError) =>
|
||||
|
@ -131,8 +132,64 @@ describe 'FolderBl', ->
|
|||
expect(@FolderBl.getAll()).toContain(item2)
|
||||
|
||||
|
||||
xit 'should not create a folder if it already exists', =>
|
||||
it 'should not create a folder if it already exists', =>
|
||||
item1 = {id: 4, open: true, name: 'john'}
|
||||
@FolderModel.add(item1)
|
||||
|
||||
expect(@FolderBl.create('johns')).toThrow(new @_ExistsError())
|
||||
expect =>
|
||||
@FolderBl.create('john')
|
||||
.toThrow(new @_ExistsError())
|
||||
|
||||
expect =>
|
||||
@FolderBl.create('johns')
|
||||
.not.toThrow(new @_ExistsError())
|
||||
|
||||
|
||||
it 'should not create folders that are empty', =>
|
||||
expect =>
|
||||
@FolderBl.create(' ')
|
||||
.toThrow(new Error())
|
||||
|
||||
|
||||
it 'should create a folder before theres a response from the server', =>
|
||||
@FolderBl.create('johns')
|
||||
expect(@FolderModel.size()).toBe(1)
|
||||
|
||||
|
||||
it 'should make a create folder request', =>
|
||||
@persistence.createFolder = jasmine.createSpy('add folder')
|
||||
|
||||
@FolderBl.create(' johns ')
|
||||
expect(@persistence.createFolder).toHaveBeenCalledWith('johns', 0,
|
||||
jasmine.any(Function))
|
||||
|
||||
|
||||
it 'should call the onSuccess function on response status ok', =>
|
||||
onSuccess = jasmine.createSpy('Success')
|
||||
@persistence.createFolder = jasmine.createSpy('add folder')
|
||||
@persistence.createFolder.andCallFake (folderName, parentId, success) =>
|
||||
response =
|
||||
status: 'ok'
|
||||
success(response)
|
||||
|
||||
@FolderBl.create(' johns ', onSuccess)
|
||||
|
||||
expect(onSuccess).toHaveBeenCalled()
|
||||
|
||||
|
||||
it 'should call the handle a response error when creating a folder', =>
|
||||
onSuccess = jasmine.createSpy('Success')
|
||||
onFailure = jasmine.createSpy('Failure')
|
||||
@persistence.createFolder = jasmine.createSpy('add folder')
|
||||
@persistence.createFolder.andCallFake (folderName, parentId, success) =>
|
||||
@response =
|
||||
status: 'error'
|
||||
msg: 'this is an error'
|
||||
success(@response)
|
||||
|
||||
@FolderBl.create(' johns ', onSuccess, onFailure)
|
||||
|
||||
expect(onSuccess).not.toHaveBeenCalled()
|
||||
expect(onFailure).toHaveBeenCalled()
|
||||
|
||||
expect(@FolderModel.getByName('johns').error).toBe(@response.msg)
|
|
@ -15,11 +15,18 @@
|
|||
<div class="add-new-popup">
|
||||
<fieldset class="personalblock">
|
||||
<p class="error">
|
||||
<span ng-show="feedEmptyError"><?php p($l->t('Address must not be empty!')); ?></span>
|
||||
<span ng-show="feedError">
|
||||
<?php p($l->t('Could not add feed! Check if feed contains valid RSS or exists already!')); ?>
|
||||
<span ng-show="feedEmptyError">
|
||||
<?php p($l->t('Error: address must not be empty!')); ?>
|
||||
</span>
|
||||
<span ng-show="feedExistsError">
|
||||
<?php p($l->t('Error: address exists already!')); ?>
|
||||
</span>
|
||||
<span ng-show="folderEmptyError">
|
||||
<?php p($l->t('Error: folder name must not be empty!')); ?>
|
||||
</span>
|
||||
<span ng-show="folderExistsError">
|
||||
<?php p($l->t('Error: folder exists already')); ?>
|
||||
</span>
|
||||
<span ng-show="folderExistsError"><?php p($l->t('Folder exists already')); ?></span>
|
||||
</p>
|
||||
<form>
|
||||
|
||||
|
@ -55,13 +62,18 @@
|
|||
placeholder="<?php p($l->t('Folder name')); ?>"
|
||||
autofocus
|
||||
ui-keyup="{13: 'addFolder(folderName)'}"/>
|
||||
<button title="<?php p($l->t('Add')); ?>"
|
||||
<button title="<?php p($l->t('Back')); ?>"
|
||||
ng-show="addNewFolder"
|
||||
ng-click="addNewFolder=false"
|
||||
ng-disabled="isAddingFolder()"
|
||||
class="back-button"></button>
|
||||
<button title="<?php p($l->t('Add')); ?>"
|
||||
ng-show="addNewFolder"
|
||||
ng-click="addFolder(folderName)"
|
||||
ng-disabled="isAddingFolder()"
|
||||
ng-class="{loading: isAddingFolder()}">
|
||||
<?php p($l->t('Create')); ?>
|
||||
</button>
|
||||
</button>
|
||||
</form>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
|
Загрузка…
Ссылка в новой задаче