diff options
-rw-r--r-- | apps/files/js/tagsplugin.js | 11 | ||||
-rw-r--r-- | apps/files/tests/js/tagspluginspec.js | 36 | ||||
-rw-r--r-- | lib/private/repair.php | 4 | ||||
-rw-r--r-- | lib/repair/filletags.php | 41 |
4 files changed, 85 insertions, 7 deletions
diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index a6757431ffa..dec6063aa9b 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -110,10 +110,17 @@ dir + '/' + fileName, tags ).then(function(result) { + // response from server should contain updated tags + var newTags = result.tags; + if (_.isUndefined(newTags)) { + newTags = tags; + } + var fileInfo = context.fileList.files[$file.index()]; // read latest state from result - toggleStar($actionEl, (result.tags.indexOf(OC.TAG_FAVORITE) >= 0)); - $file.attr('data-tags', tags.join('|')); + toggleStar($actionEl, (newTags.indexOf(OC.TAG_FAVORITE) >= 0)); + $file.attr('data-tags', newTags.join('|')); $file.attr('data-favorite', !isFavorite); + fileInfo.tags = newTags; }); } }); diff --git a/apps/files/tests/js/tagspluginspec.js b/apps/files/tests/js/tagspluginspec.js index 66240575a5c..5309973cf4f 100644 --- a/apps/files/tests/js/tagspluginspec.js +++ b/apps/files/tests/js/tagspluginspec.js @@ -77,11 +77,39 @@ describe('OCA.Files.TagsPlugin tests', function() { }); describe('Applying tags', function() { it('sends request to server and updates icon', function() { - // TODO + var request; fileList.setFiles(testFiles); - }); - it('sends all tags to server when applyFileTags() is called ', function() { - // TODO + $tr = fileList.$el.find('tbody tr:first'); + $action = $tr.find('.action-favorite'); + $action.click(); + + expect(fakeServer.requests.length).toEqual(1); + var request = fakeServer.requests[0]; + expect(JSON.parse(request.requestBody)).toEqual({ + tags: ['tag1', 'tag2', OC.TAG_FAVORITE] + }); + request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ + tags: ['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE] + })); + + expect($tr.attr('data-favorite')).toEqual('true'); + expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]); + expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3', OC.TAG_FAVORITE]); + expect($action.find('img').attr('src')).toEqual(OC.imagePath('core', 'actions/starred')); + + $action.click(); + request = fakeServer.requests[1]; + expect(JSON.parse(request.requestBody)).toEqual({ + tags: ['tag1', 'tag2', 'tag3'] + }); + request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ + tags: ['tag1', 'tag2', 'tag3'] + })); + + expect($tr.attr('data-favorite')).toEqual('false'); + expect($tr.attr('data-tags').split('|')).toEqual(['tag1', 'tag2', 'tag3']); + expect(fileList.files[0].tags).toEqual(['tag1', 'tag2', 'tag3']); + expect($action.find('img').attr('src')).toEqual(OC.imagePath('core', 'actions/star')); }); }); }); diff --git a/lib/private/repair.php b/lib/private/repair.php index be607b44ed8..c4f057b53ae 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -12,6 +12,7 @@ use OC\Hooks\BasicEmitter; use OC\Hooks\Emitter; use OC\Repair\AssetCache; use OC\Repair\Collation; +use OC\Repair\FillETags; use OC\Repair\InnoDB; use OC\Repair\RepairConfig; use OC\Repair\RepairLegacyStorages; @@ -79,7 +80,8 @@ class Repair extends BasicEmitter { new RepairMimeTypes(), new RepairLegacyStorages(\OC::$server->getConfig(), \OC_DB::getConnection()), new RepairConfig(), - new AssetCache() + new AssetCache(), + new FillETags(\OC_DB::getConnection()) ); } diff --git a/lib/repair/filletags.php b/lib/repair/filletags.php new file mode 100644 index 00000000000..b94ae385f05 --- /dev/null +++ b/lib/repair/filletags.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Repair; + +use Doctrine\DBAL\Query\QueryBuilder; +use OC\Hooks\BasicEmitter; + +class FillETags extends BasicEmitter implements \OC\RepairStep { + + /** @var \OC\DB\Connection */ + protected $connection; + + /** + * @param \OC\DB\Connection $connection + */ + public function __construct($connection) { + $this->connection = $connection; + } + + public function getName() { + return 'Generate ETags for file where no ETag is present.'; + } + + public function run() { + $qb = $this->connection->createQueryBuilder(); + $qb->update('`*PREFIX*filecache`') + ->set('`etag`', $qb->expr()->literal('xxx')) + ->where($qb->expr()->eq('`etag`', $qb->expr()->literal(''))) + ->orWhere($qb->expr()->isNull('`etag`')); + + $result = $qb->execute(); + $this->emit('\OC\Repair', 'info', array("ETags have been fixed for $result files/folders.")); + } +} + |