From fc1500af30dd3cfbfad6dbc84495acf7e0fd5577 Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Mon, 14 Oct 2024 22:30:13 +0200 Subject: [PATCH 1/8] added total tag counters to album cover cards --- app/components/cards/photo-album-card.hbs | 7 ++++++ app/models/photo-album.js | 11 ++++++++++ .../components/cards/photo-album-card.scss | 8 +++++++ yarn.lock | 22 ++++--------------- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/components/cards/photo-album-card.hbs b/app/components/cards/photo-album-card.hbs index d205ca647..042270d2b 100644 --- a/app/components/cards/photo-album-card.hbs +++ b/app/components/cards/photo-album-card.hbs @@ -5,11 +5,18 @@ src='{{album.albumMediumUrl}}' class='card-img-rounded' /> +

{{album.title}}

{{moment-format album.date 'DD-MM-YYYY'}}

+ {{#if album.amountOfTags}} + + + {{album.amountOfTags}} + + {{/if}}
\ No newline at end of file diff --git a/app/models/photo-album.js b/app/models/photo-album.js index d1f4f98c2..9eeb2860c 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -35,6 +35,17 @@ export default class PhotoAlbum extends Model { return this.photos?.sortBy('exifDateTimeOriginal', 'createdAt'); } + get amountOfTags() { + var c = 0 + for(var p of this.photos._objects){ + c += p.amountOfTags + console.log(c) + } + + //console.log(this.photos?._objects[1]?.amountOfTags) + return c + } + // Methods isOwner(user) { if (user.get('id') === this.author.get('id')) { diff --git a/app/styles/components/cards/photo-album-card.scss b/app/styles/components/cards/photo-album-card.scss index 6fa9418a4..f746809a1 100644 --- a/app/styles/components/cards/photo-album-card.scss +++ b/app/styles/components/cards/photo-album-card.scss @@ -19,4 +19,12 @@ .card-title { font-size: 1.5rem; } + + .album-tag-counter { + position: absolute; + bottom: 0; + margin-bottom: 1rem; + margin-right: 15px; + padding-left: 5px; + } } diff --git a/yarn.lock b/yarn.lock index 1f111a5f8..c3e9592c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8827,24 +8827,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30000844, caniuse-lite@npm:^1.0.30001313": - version: 1.0.30001458 - resolution: "caniuse-lite@npm:1.0.30001458" - checksum: 258cc5a25babbbfe483bf788c6f321a19400ff80b2bf156b360bac09a6f9f4da44516350d187a30395667cb142c682d9ea96577ea0df236d35f76234b07ccb41 - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001449": - version: 1.0.30001485 - resolution: "caniuse-lite@npm:1.0.30001485" - checksum: 2db8a9e5facf8df5275c96e44714a6caf3b9485813be1fe0aa5a72a7ced974137adeeed806a9a97f713d2f6d1b5c342949b88355ee0323ba35656bfa00d57fea - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001541": - version: 1.0.30001547 - resolution: "caniuse-lite@npm:1.0.30001547" - checksum: ec0fc2b46721887f6f4aca1f3902f03d9a1a07416d16a86b7cd4bfba60e7b6b03ab3969659d3ea0158cc2f298972c80215c06c9457eb15c649d7780e8f5e91a7 +"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30000844, caniuse-lite@npm:^1.0.30001313, caniuse-lite@npm:^1.0.30001449, caniuse-lite@npm:^1.0.30001541": + version: 1.0.30001668 + resolution: "caniuse-lite@npm:1.0.30001668" + checksum: ce6996901b5883454a8ddb3040f82342277b6a6275876dfefcdecb11f7e472e29877f34cae47c2b674f08f2e71971dd4a2acb9bc01adfe8421b7148a7e9e8297 languageName: node linkType: hard From 18ffadcefc6558685f1720cd507fad04c3580131 Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Mon, 14 Oct 2024 22:39:52 +0200 Subject: [PATCH 2/8] added number of tagged photos out of total --- app/components/cards/photo-album-card.hbs | 2 +- app/models/photo-album.js | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/components/cards/photo-album-card.hbs b/app/components/cards/photo-album-card.hbs index 042270d2b..ec5e0a436 100644 --- a/app/components/cards/photo-album-card.hbs +++ b/app/components/cards/photo-album-card.hbs @@ -14,7 +14,7 @@ {{#if album.amountOfTags}} - {{album.amountOfTags}} + {{album.amountOfTags}}, {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} {{/if}} diff --git a/app/models/photo-album.js b/app/models/photo-album.js index 9eeb2860c..455dbf840 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -36,14 +36,21 @@ export default class PhotoAlbum extends Model { } get amountOfTags() { - var c = 0 - for(var p of this.photos._objects){ - c += p.amountOfTags - console.log(c) + var counter = 0 + for(var photo of this.photos._objects){ + counter += photo.amountOfTags } - - //console.log(this.photos?._objects[1]?.amountOfTags) - return c + return counter + } + get amountOfTaggedPhotos() { + var counter = 0 + for(var photo of this.photos._objects){ + counter += photo.amountOfTags>0? 1 : 0 + } + return counter + } + get amountOfPhotos() { + return this.photos.length } // Methods From 5515fbe787db486a383ac32a3445b7e730ffe241 Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Tue, 15 Oct 2024 17:07:00 +0200 Subject: [PATCH 3/8] added photo tag counter in album view --- app/components/cards/photo-album-card.hbs | 2 +- app/styles/routes/photos.scss | 1 + .../photo-albums/photo-album/photos/index.hbs | 12 +++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/components/cards/photo-album-card.hbs b/app/components/cards/photo-album-card.hbs index ec5e0a436..92efc2d3a 100644 --- a/app/components/cards/photo-album-card.hbs +++ b/app/components/cards/photo-album-card.hbs @@ -14,7 +14,7 @@ {{#if album.amountOfTags}} - {{album.amountOfTags}}, {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} + {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} {{/if}} diff --git a/app/styles/routes/photos.scss b/app/styles/routes/photos.scss index 75776231e..6e1387823 100644 --- a/app/styles/routes/photos.scss +++ b/app/styles/routes/photos.scss @@ -8,6 +8,7 @@ bottom: 0; margin-bottom: 1rem; margin-left: 15px; + margin-right: 15px; padding-left: 5px; } diff --git a/app/templates/photo-albums/photo-album/photos/index.hbs b/app/templates/photo-albums/photo-album/photos/index.hbs index 77d05cdae..bbab2ce02 100644 --- a/app/templates/photo-albums/photo-album/photos/index.hbs +++ b/app/templates/photo-albums/photo-album/photos/index.hbs @@ -21,10 +21,16 @@ @route='photo-albums.photo-album.photos.photo' @model={{photo.id}} > - {{#if photo.amountOfComments}} + {{#if (or photo.amountOfComments photo.amountOfTags)}} - - {{photo.amountOfComments}} + {{#if photo.amountOfComments}} + + {{photo.amountOfComments}} + {{/if}} + {{#if photo.amountOfTags}} + + {{photo.amountOfTags}} + {{/if}} {{/if}} From acf65a9720a9ba0de0bdc6c421bac7a9af91852f Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Tue, 15 Oct 2024 17:21:03 +0200 Subject: [PATCH 4/8] fixed lint --- app/components/cards/photo-album-card.hbs | 8 +++--- app/models/photo-album.js | 26 ++++++++++--------- .../components/cards/photo-album-card.scss | 2 +- app/styles/routes/photos.scss | 1 - 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/components/cards/photo-album-card.hbs b/app/components/cards/photo-album-card.hbs index 92efc2d3a..048c9d2ba 100644 --- a/app/components/cards/photo-album-card.hbs +++ b/app/components/cards/photo-album-card.hbs @@ -12,10 +12,10 @@

{{moment-format album.date 'DD-MM-YYYY'}}

{{#if album.amountOfTags}} - - - {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} - + + + {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} + {{/if}} diff --git a/app/models/photo-album.js b/app/models/photo-album.js index 455dbf840..4fc174f82 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -36,21 +36,23 @@ export default class PhotoAlbum extends Model { } get amountOfTags() { - var counter = 0 - for(var photo of this.photos._objects){ - counter += photo.amountOfTags - } - return counter + var counter = 0; + for (var photo of this.photos._objects) { + counter += photo.amountOfTags; + } + return counter; } - get amountOfTaggedPhotos() { - var counter = 0 - for(var photo of this.photos._objects){ - counter += photo.amountOfTags>0? 1 : 0 - } - return counter + + get amountOfTaggedPhotos() { //not used anymore + var counter = 0; + for (var photo of this.photos._objects) { + counter += photo.amountOfTags>0? 1 : 0; + } + return counter; } + get amountOfPhotos() { - return this.photos.length + return this.photos.length; } // Methods diff --git a/app/styles/components/cards/photo-album-card.scss b/app/styles/components/cards/photo-album-card.scss index f746809a1..8ec6541d8 100644 --- a/app/styles/components/cards/photo-album-card.scss +++ b/app/styles/components/cards/photo-album-card.scss @@ -23,8 +23,8 @@ .album-tag-counter { position: absolute; bottom: 0; - margin-bottom: 1rem; margin-right: 15px; + margin-bottom: 1rem; padding-left: 5px; } } diff --git a/app/styles/routes/photos.scss b/app/styles/routes/photos.scss index 6e1387823..75776231e 100644 --- a/app/styles/routes/photos.scss +++ b/app/styles/routes/photos.scss @@ -8,7 +8,6 @@ bottom: 0; margin-bottom: 1rem; margin-left: 15px; - margin-right: 15px; padding-left: 5px; } From 0f81f0de3ebd1c516be743cf913e413ea632f9a9 Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Thu, 17 Oct 2024 14:57:00 +0200 Subject: [PATCH 5/8] lint fix 2 --- app/components/cards/photo-album-card.hbs | 2 +- app/models/photo-album.js | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/components/cards/photo-album-card.hbs b/app/components/cards/photo-album-card.hbs index 048c9d2ba..5d54d979c 100644 --- a/app/components/cards/photo-album-card.hbs +++ b/app/components/cards/photo-album-card.hbs @@ -11,7 +11,7 @@

{{album.title}}

{{moment-format album.date 'DD-MM-YYYY'}}

- {{#if album.amountOfTags}} + {{#if album.amountOfTaggedPhotos}} {{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}} diff --git a/app/models/photo-album.js b/app/models/photo-album.js index 4fc174f82..2320c1fe1 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -35,18 +35,10 @@ export default class PhotoAlbum extends Model { return this.photos?.sortBy('exifDateTimeOriginal', 'createdAt'); } - get amountOfTags() { + get amountOfTaggedPhotos() { var counter = 0; for (var photo of this.photos._objects) { - counter += photo.amountOfTags; - } - return counter; - } - - get amountOfTaggedPhotos() { //not used anymore - var counter = 0; - for (var photo of this.photos._objects) { - counter += photo.amountOfTags>0? 1 : 0; + counter += photo.amountOfTags > 0 ? 1 : 0; } return counter; } From 724051cd19676f48ac7504176cd4fa45cda0c4db Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Fri, 18 Oct 2024 12:29:32 +0200 Subject: [PATCH 6/8] added unit test for feature --- app/models/photo-album.js | 4 ++-- tests/unit/models/photo-album-test.js | 29 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/unit/models/photo-album-test.js diff --git a/app/models/photo-album.js b/app/models/photo-album.js index 2320c1fe1..bf22a1544 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -37,9 +37,9 @@ export default class PhotoAlbum extends Model { get amountOfTaggedPhotos() { var counter = 0; - for (var photo of this.photos._objects) { + this.photos.content.forEach((photo) => { counter += photo.amountOfTags > 0 ? 1 : 0; - } + }) return counter; } diff --git a/tests/unit/models/photo-album-test.js b/tests/unit/models/photo-album-test.js new file mode 100644 index 000000000..4e606d361 --- /dev/null +++ b/tests/unit/models/photo-album-test.js @@ -0,0 +1,29 @@ +import { run } from '@ember/runloop'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +let album; +let photos = []; + +module('Unit | Model | photo-album', function (hooks) { + setupTest(hooks); + + hooks.beforeEach(function () { + const store = this.owner.lookup('service:store'); + photos = [ + store.createRecord('Photo'), + store.createRecord('Photo'), + store.createRecord('Photo'), + ]; + album = store.createRecord('PhotoAlbum', { photos }); + }); + + test('Photo count', function (assert) { + assert.expect(2); + photos[0].amountOfTags = 0; + photos[1].amountOfTags = 1; + photos[2].amountOfTags = 5; + assert.equal(album.amountOfPhotos, 3, "Amount of photos is correct"); + assert.equal(album.amountOfTaggedPhotos, 2, "Amount of tags in album is correct"); + }); +}); \ No newline at end of file From b196b80f8c45f2d9a32aa6582d8b778dde224b6f Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Fri, 18 Oct 2024 12:43:14 +0200 Subject: [PATCH 7/8] fixed lint for unit test --- tests/unit/models/photo-album-test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/unit/models/photo-album-test.js b/tests/unit/models/photo-album-test.js index 4e606d361..042fef75e 100644 --- a/tests/unit/models/photo-album-test.js +++ b/tests/unit/models/photo-album-test.js @@ -1,4 +1,3 @@ -import { run } from '@ember/runloop'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; @@ -23,7 +22,7 @@ module('Unit | Model | photo-album', function (hooks) { photos[0].amountOfTags = 0; photos[1].amountOfTags = 1; photos[2].amountOfTags = 5; - assert.equal(album.amountOfPhotos, 3, "Amount of photos is correct"); - assert.equal(album.amountOfTaggedPhotos, 2, "Amount of tags in album is correct"); + assert.equal(album.amountOfPhotos, 3, 'Amount of photos is correct'); + assert.equal(album.amountOfTaggedPhotos, 2, 'Amount of tagged photos in album is correct'); }); -}); \ No newline at end of file +}); From 7a2252afa74608859ede6a91038ed4d156cecdb4 Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Fri, 18 Oct 2024 12:53:26 +0200 Subject: [PATCH 8/8] fixed lint for unit test again --- app/models/photo-album.js | 2 +- tests/unit/models/photo-album-test.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/photo-album.js b/app/models/photo-album.js index bf22a1544..f063eb8fb 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -39,7 +39,7 @@ export default class PhotoAlbum extends Model { var counter = 0; this.photos.content.forEach((photo) => { counter += photo.amountOfTags > 0 ? 1 : 0; - }) + }); return counter; } diff --git a/tests/unit/models/photo-album-test.js b/tests/unit/models/photo-album-test.js index 042fef75e..7cbef4cec 100644 --- a/tests/unit/models/photo-album-test.js +++ b/tests/unit/models/photo-album-test.js @@ -23,6 +23,10 @@ module('Unit | Model | photo-album', function (hooks) { photos[1].amountOfTags = 1; photos[2].amountOfTags = 5; assert.equal(album.amountOfPhotos, 3, 'Amount of photos is correct'); - assert.equal(album.amountOfTaggedPhotos, 2, 'Amount of tagged photos in album is correct'); + assert.equal( + album.amountOfTaggedPhotos, + 2, + 'Amount of tagged photos in album is correct' + ); }); });