Skip to content

Commit 037e0f2

Browse files
authored
album tag counter (#887)
* added total tag counters to album cover cards * added number of tagged photos out of total * added photo tag counter in album view * fixed lint * lint fix 2 * added unit test for feature * fixed lint for unit test * fixed lint for unit test again
1 parent 7b79a90 commit 037e0f2

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

app/components/cards/photo-album-card.hbs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
src='{{album.albumMediumUrl}}'
66
class='card-img-rounded'
77
/>
8+
89
<div class='card-title-bar gradient-overlay-rounded'>
910
<div class='card-titles'>
1011
<h2 class='card-title'>{{album.title}}</h2>
1112
<h3 class='card-subtitle'>{{moment-format album.date 'DD-MM-YYYY'}}</h3>
1213
</div>
14+
{{#if album.amountOfTaggedPhotos}}
15+
<span class='album-tag-counter badge bg-info bottom-0 end-0'>
16+
<FaIcon @icon='tag' />
17+
{{album.amountOfTaggedPhotos}}/{{album.amountOfPhotos}}
18+
</span>
19+
{{/if}}
1320
</div>
1421
</div>
1522
</div>

app/models/photo-album.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export default class PhotoAlbum extends Model {
3535
return this.photos?.sortBy('exifDateTimeOriginal', 'createdAt');
3636
}
3737

38+
get amountOfTaggedPhotos() {
39+
var counter = 0;
40+
this.photos.content.forEach((photo) => {
41+
counter += photo.amountOfTags > 0 ? 1 : 0;
42+
});
43+
return counter;
44+
}
45+
46+
get amountOfPhotos() {
47+
return this.photos.length;
48+
}
49+
3850
// Methods
3951
isOwner(user) {
4052
if (user.get('id') === this.author.get('id')) {

app/styles/components/cards/photo-album-card.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@
1919
.card-title {
2020
font-size: 1.5rem;
2121
}
22+
23+
.album-tag-counter {
24+
position: absolute;
25+
bottom: 0;
26+
margin-right: 15px;
27+
margin-bottom: 1rem;
28+
padding-left: 5px;
29+
}
2230
}

app/templates/photo-albums/photo-album/photos/index.hbs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121
@route='photo-albums.photo-album.photos.photo'
2222
@model={{photo.id}}
2323
>
24-
{{#if photo.amountOfComments}}
24+
{{#if (or photo.amountOfComments photo.amountOfTags)}}
2525
<span class='comments-counter badge bg-info bottom-0 start-0'>
26-
<FaIcon @icon='comments' />
27-
{{photo.amountOfComments}}
26+
{{#if photo.amountOfComments}}
27+
<FaIcon @icon='comments' />
28+
{{photo.amountOfComments}}
29+
{{/if}}
30+
{{#if photo.amountOfTags}}
31+
<FaIcon @icon='tag' />
32+
{{photo.amountOfTags}}
33+
{{/if}}
2834
</span>
2935
{{/if}}
3036
<img class='image' src='{{photo.imageThumbUrl}}' />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
let album;
5+
let photos = [];
6+
7+
module('Unit | Model | photo-album', function (hooks) {
8+
setupTest(hooks);
9+
10+
hooks.beforeEach(function () {
11+
const store = this.owner.lookup('service:store');
12+
photos = [
13+
store.createRecord('Photo'),
14+
store.createRecord('Photo'),
15+
store.createRecord('Photo'),
16+
];
17+
album = store.createRecord('PhotoAlbum', { photos });
18+
});
19+
20+
test('Photo count', function (assert) {
21+
assert.expect(2);
22+
photos[0].amountOfTags = 0;
23+
photos[1].amountOfTags = 1;
24+
photos[2].amountOfTags = 5;
25+
assert.equal(album.amountOfPhotos, 3, 'Amount of photos is correct');
26+
assert.equal(
27+
album.amountOfTaggedPhotos,
28+
2,
29+
'Amount of tagged photos in album is correct'
30+
);
31+
});
32+
});

yarn.lock

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8827,24 +8827,10 @@ __metadata:
88278827
languageName: node
88288828
linkType: hard
88298829

8830-
"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30000844, caniuse-lite@npm:^1.0.30001313":
8831-
version: 1.0.30001458
8832-
resolution: "caniuse-lite@npm:1.0.30001458"
8833-
checksum: 258cc5a25babbbfe483bf788c6f321a19400ff80b2bf156b360bac09a6f9f4da44516350d187a30395667cb142c682d9ea96577ea0df236d35f76234b07ccb41
8834-
languageName: node
8835-
linkType: hard
8836-
8837-
"caniuse-lite@npm:^1.0.30001449":
8838-
version: 1.0.30001485
8839-
resolution: "caniuse-lite@npm:1.0.30001485"
8840-
checksum: 2db8a9e5facf8df5275c96e44714a6caf3b9485813be1fe0aa5a72a7ced974137adeeed806a9a97f713d2f6d1b5c342949b88355ee0323ba35656bfa00d57fea
8841-
languageName: node
8842-
linkType: hard
8843-
8844-
"caniuse-lite@npm:^1.0.30001541":
8845-
version: 1.0.30001547
8846-
resolution: "caniuse-lite@npm:1.0.30001547"
8847-
checksum: ec0fc2b46721887f6f4aca1f3902f03d9a1a07416d16a86b7cd4bfba60e7b6b03ab3969659d3ea0158cc2f298972c80215c06c9457eb15c649d7780e8f5e91a7
8830+
"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":
8831+
version: 1.0.30001668
8832+
resolution: "caniuse-lite@npm:1.0.30001668"
8833+
checksum: ce6996901b5883454a8ddb3040f82342277b6a6275876dfefcdecb11f7e472e29877f34cae47c2b674f08f2e71971dd4a2acb9bc01adfe8421b7148a7e9e8297
88488834
languageName: node
88498835
linkType: hard
88508836

0 commit comments

Comments
 (0)