summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-22 02:15:56 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-22 02:15:56 +0200
commit2b4da592f1c8a2210f9ba49a9e24eb2056e5d4a8 (patch)
treea75d63fcfbe307bd22bef14f8befaa9545c8f544 /js
parentf0aae6875bc1da724d1960805f88b4b707742a44 (diff)
simplify star and read
Diffstat (limited to 'js')
-rw-r--r--js/Gruntfile.js4
-rw-r--r--js/README.md2
-rw-r--r--js/build/app.js49
-rw-r--r--js/service/FeedResource.js10
-rw-r--r--js/service/FolderResource.js10
-rw-r--r--js/service/ItemResource.js19
-rw-r--r--js/service/Resource.js4
-rw-r--r--js/tests/unit/controller/AppControllerSpec.js4
-rw-r--r--js/tests/unit/controller/ContentControllerSpec.js4
-rw-r--r--js/tests/unit/service/ItemResourceSpec.js24
-rw-r--r--js/tests/unit/service/ResourceSpec.js2
11 files changed, 100 insertions, 32 deletions
diff --git a/js/Gruntfile.js b/js/Gruntfile.js
index b45385dc5..518627c9c 100644
--- a/js/Gruntfile.js
+++ b/js/Gruntfile.js
@@ -139,7 +139,7 @@ module.exports = function (grunt) {
},
phpunit: {
classes: {
- dir: '../tests'
+ dir: '../tests/unit'
},
options: {
colors: true
@@ -175,7 +175,7 @@ module.exports = function (grunt) {
grunt.registerTask('default', ['jshint', 'concat', 'wrap', 'traceur', 'ngmin']);
grunt.registerTask('dev', ['watch:concat']);
grunt.registerTask('test', ['karma:unit']);
- grunt.registerTask('phpunit', ['watch:phpunit']);
+ grunt.registerTask('php', ['watch:phpunit']);
grunt.registerTask('e2e', ['protractor_webdriver', 'connect', 'protractor:chrome']);
grunt.registerTask('ci-unit', ['default', 'karma:continuous']);
grunt.registerTask('ci-e2e', ['protractor_webdriver', 'connect', 'protractor:phantomjs']);
diff --git a/js/README.md b/js/README.md
index 628e2c012..b529fbf6a 100644
--- a/js/README.md
+++ b/js/README.md
@@ -41,7 +41,7 @@ Single run mode:
## Testing
Watch mode:
- grunt phpunit
+ grunt php
grunt test
Single run mode:
diff --git a/js/build/app.js b/js/build/app.js
index 31ad58c70..eb88e72dc 100644
--- a/js/build/app.js
+++ b/js/build/app.js
@@ -202,42 +202,50 @@ var $__build_47_app__ = function () {
app.factory('FeedResource', [
'Resource',
'$http',
- function (Resource, $http) {
+ 'BASE_URL',
+ function (Resource, $http, BASE_URL) {
'use strict';
- var FeedResource = function FeedResource($http) {
+ var FeedResource = function FeedResource($http, BASE_URL) {
$traceurRuntime.superCall(this, $FeedResource.prototype, 'constructor', [
$http,
+ BASE_URL,
'url'
]);
};
var $FeedResource = FeedResource;
$traceurRuntime.createClass(FeedResource, {}, {}, Resource);
- return new FeedResource($http);
+ return new FeedResource($http, BASE_URL);
}
]);
app.factory('FolderResource', [
'Resource',
'$http',
- function (Resource, $http) {
+ 'BASE_URL',
+ function (Resource, $http, BASE_URL) {
'use strict';
- var FolderResource = function FolderResource($http) {
+ var FolderResource = function FolderResource($http, BASE_URL) {
$traceurRuntime.superCall(this, $FolderResource.prototype, 'constructor', [
$http,
+ BASE_URL,
'name'
]);
};
var $FolderResource = FolderResource;
$traceurRuntime.createClass(FolderResource, {}, {}, Resource);
- return new FolderResource($http);
+ return new FolderResource($http, BASE_URL);
}
]);
app.factory('ItemResource', [
'Resource',
'$http',
- function (Resource, $http) {
+ 'BASE_URL',
+ function (Resource, $http, BASE_URL) {
'use strict';
- var ItemResource = function ItemResource($http) {
- $traceurRuntime.superCall(this, $ItemResource.prototype, 'constructor', [$http]);
+ var ItemResource = function ItemResource($http, BASE_URL) {
+ $traceurRuntime.superCall(this, $ItemResource.prototype, 'constructor', [
+ $http,
+ BASE_URL
+ ]);
};
var $ItemResource = ItemResource;
$traceurRuntime.createClass(ItemResource, {
@@ -261,9 +269,25 @@ var $__build_47_app__ = function () {
},
getStarredCount: function () {
return this.starredCount;
+ },
+ markRead: function (itemId) {
+ var read = arguments[1] !== void 0 ? arguments[1] : true;
+ this.get(itemId).unread = !read;
+ },
+ markFeedRead: function (feedId) {
+ for (var $item in this.values.filter(function (i) {
+ return i.feedId === feedId;
+ })) {
+ try {
+ throw undefined;
+ } catch (item) {
+ item = $item;
+ this.markRead(item);
+ }
+ }
}
}, {}, Resource);
- return new ItemResource($http);
+ return new ItemResource($http, BASE_URL);
}
]);
app.service('Loading', function () {
@@ -342,12 +366,13 @@ var $__build_47_app__ = function () {
});
app.factory('Resource', function () {
'use strict';
- var Resource = function Resource(http) {
- var id = arguments[1] !== void 0 ? arguments[1] : 'id';
+ var Resource = function Resource(http, BASE_URL) {
+ var id = arguments[2] !== void 0 ? arguments[2] : 'id';
this.id = id;
this.values = [];
this.hashMap = {};
this.http = http;
+ this.BASE_URL = BASE_URL;
};
$traceurRuntime.createClass(Resource, {
receive: function (objs) {
diff --git a/js/service/FeedResource.js b/js/service/FeedResource.js
index 579396b9d..2eb9e4818 100644
--- a/js/service/FeedResource.js
+++ b/js/service/FeedResource.js
@@ -7,14 +7,16 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
-app.factory('FeedResource', (Resource, $http) => {
+app.factory('FeedResource', (Resource, $http, BASE_URL) => {
'use strict';
class FeedResource extends Resource {
- constructor ($http) {
- super($http, 'url');
+
+ constructor ($http, BASE_URL) {
+ super($http, BASE_URL, 'url');
}
+
}
- return new FeedResource($http);
+ return new FeedResource($http, BASE_URL);
}); \ No newline at end of file
diff --git a/js/service/FolderResource.js b/js/service/FolderResource.js
index 314900e37..1ea48e0bb 100644
--- a/js/service/FolderResource.js
+++ b/js/service/FolderResource.js
@@ -7,14 +7,16 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
-app.factory('FolderResource', (Resource, $http) => {
+app.factory('FolderResource', (Resource, $http, BASE_URL) => {
'use strict';
class FolderResource extends Resource {
- constructor ($http) {
- super($http, 'name');
+
+ constructor ($http, BASE_URL) {
+ super($http, BASE_URL, 'name');
}
+
}
- return new FolderResource($http);
+ return new FolderResource($http, BASE_URL);
}); \ No newline at end of file
diff --git a/js/service/ItemResource.js b/js/service/ItemResource.js
index 5750f2c6b..e6a8e1d2d 100644
--- a/js/service/ItemResource.js
+++ b/js/service/ItemResource.js
@@ -7,13 +7,13 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
-app.factory('ItemResource', (Resource, $http) => {
+app.factory('ItemResource', (Resource, $http, BASE_URL) => {
'use strict';
class ItemResource extends Resource {
- constructor ($http) {
- super($http);
+ constructor ($http, BASE_URL) {
+ super($http, BASE_URL);
}
receive (value, channel) {
@@ -39,7 +39,18 @@ app.factory('ItemResource', (Resource, $http) => {
return this.starredCount;
}
+ markRead (itemId, read=true) {
+ this.get(itemId).unread = !read;
+ //http.get();
+ }
+
+ markFeedRead (feedId) {
+ for (let item in this.values.filter(i => i.feedId === feedId)) {
+ this.markRead(item);
+ }
+ }
+
}
- return new ItemResource($http);
+ return new ItemResource($http, BASE_URL);
}); \ No newline at end of file
diff --git a/js/service/Resource.js b/js/service/Resource.js
index f71126f02..7683099da 100644
--- a/js/service/Resource.js
+++ b/js/service/Resource.js
@@ -12,11 +12,12 @@ app.factory('Resource', () => {
class Resource {
- constructor (http, id='id') {
+ constructor (http, BASE_URL, id='id') {
this.id = id;
this.values = [];
this.hashMap = {};
this.http = http;
+ this.BASE_URL = BASE_URL;
}
receive (objs) {
@@ -74,6 +75,7 @@ app.factory('Resource', () => {
getAll () {
return this.values;
}
+
}
return Resource;
diff --git a/js/tests/unit/controller/AppControllerSpec.js b/js/tests/unit/controller/AppControllerSpec.js
index fc5780a40..772fdc565 100644
--- a/js/tests/unit/controller/AppControllerSpec.js
+++ b/js/tests/unit/controller/AppControllerSpec.js
@@ -12,7 +12,9 @@ describe('AppController', () => {
let controller;
- beforeEach(module('News'));
+ beforeEach(module('News', ($provide) => {
+ $provide.value('BASE_URL', 'base');
+ }));
beforeEach(inject(($controller) => {
controller = $controller('AppController');
diff --git a/js/tests/unit/controller/ContentControllerSpec.js b/js/tests/unit/controller/ContentControllerSpec.js
index 1dbd3d936..422bd21f4 100644
--- a/js/tests/unit/controller/ContentControllerSpec.js
+++ b/js/tests/unit/controller/ContentControllerSpec.js
@@ -10,7 +10,9 @@
describe('ContentController', () => {
'use strict';
- beforeEach(module('News'));
+ beforeEach(module('News', ($provide) => {
+ $provide.value('BASE_URL', 'base');
+ }));
it('should publish data to models', inject(($controller, Publisher,
diff --git a/js/tests/unit/service/ItemResourceSpec.js b/js/tests/unit/service/ItemResourceSpec.js
index acbf0850c..8d0f1864e 100644
--- a/js/tests/unit/service/ItemResourceSpec.js
+++ b/js/tests/unit/service/ItemResourceSpec.js
@@ -10,7 +10,9 @@
describe('ItemResource', () => {
'use strict';
- beforeEach(module('News'));
+ beforeEach(module('News', ($provide) => {
+ $provide.value('BASE_URL', 'base');
+ }));
it('should receive the newestItemId', inject((ItemResource) => {
@@ -40,4 +42,24 @@ describe('ItemResource', () => {
expect(ItemResource.size()).toBe(2);
}));
+
+ it ('should mark item as read', inject((ItemResource) => {
+ ItemResource.receive([
+ {
+ id: 3,
+ feedId: 4,
+ unread: true
+ },
+ {
+ id: 4,
+ feedId: 3,
+ unread: true
+ }
+ ], 'items');
+
+ ItemResource.markRead(3);
+
+ expect(ItemResource.get(3).unread).toBe(false);
+ }));
+
}); \ No newline at end of file
diff --git a/js/tests/unit/service/ResourceSpec.js b/js/tests/unit/service/ResourceSpec.js
index 2fead3479..b1b8ed054 100644
--- a/js/tests/unit/service/ResourceSpec.js
+++ b/js/tests/unit/service/ResourceSpec.js
@@ -17,7 +17,7 @@ describe('Resource', () => {
beforeEach(inject((Resource, $http) => {
class ChildResource extends Resource {
constructor ($http) {
- super($http);
+ super($http, 'base');
}
}