Skip to content

Commit

Permalink
music route now has detail and listen links for each song
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchadwick committed Jun 4, 2024
1 parent d8c6b31 commit 3c12ee3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
8 changes: 6 additions & 2 deletions app/adapters/song.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import ENV from 'remember-stuff/config/environment';

export default class SongAdapter extends JSONAPIAdapter {
host = 'https://music.nebyoolae.com';
host = ENV.APP.MUSIC_API_ROOT;
namespace = 'jsonapi/views';
viewType = 'songs';
viewId = 'songs_neb_5';
viewArgs = 'include=field_album_id,field_album_id.field_album_cover,field_artist_id';

pathForType() {
return 'songs/songs_neb_5?include=field_album_id,field_album_id.field_album_cover,field_artist_id';
return `${this.viewType}/${this.viewId}?${this.viewArgs}`;
}
}
4 changes: 3 additions & 1 deletion app/models/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default class SongModel extends Model {
@attr title;
@attr album;
@attr artist;
@attr url;
@attr fileUrl;
@attr detailUrl;
@attr nid;

get fullSongTitle() {
return `${this.title} on ${this.album} by ${this.artist || ''}`;
Expand Down
17 changes: 17 additions & 0 deletions app/routes/music.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { action } from '@ember/object';

export default class SongsRoute extends Route {
@service store;
@service headData;

// beforeModel() {
// this.store.unloadAll('song');
// }

model() {
console.log('this.store', this.store);

return this.store.findAll('song');
}

afterModel() {
this.headData.routeTitle = 'Songs';
}

@action
loading(transition) {
transition.promise.finally(() => {
let start = new Date();
console.log(`Took ${new Date() - start}ms to load`);
});

return true;
}
}
5 changes: 4 additions & 1 deletion app/serializers/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ENV from 'remember-stuff/config/environment';

export default class SongSerializer extends JSONAPISerializer {
normalize(type, payload) {
const remoteDetailUrl = `${ENV.APP.MUSIC_API_ROOT}${payload.path.alias}`;
const remoteFileUrl = `${ENV.APP.MUSIC_API_ROOT}/${payload.field_local_link.uri.split('internal:/')[1]}`;

return {
Expand All @@ -11,9 +12,11 @@ export default class SongSerializer extends JSONAPISerializer {
type: type.modelName,
attributes: {
title: payload.title,
url: remoteFileUrl,
detailUrl: remoteDetailUrl,
fileUrl: remoteFileUrl,
artist: payload.field_artist_id.name,
album: payload.field_album_id.name,
nid: payload.drupal_internal__nid,
},
},
};
Expand Down
22 changes: 17 additions & 5 deletions app/templates/music.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
<ul>
{{#each @model as |song|}}
<li>
<a href={{song.url}} target="_blank" rel="noopener noreferrer">
{{song.title}}
<a href={{song.detailUrl}}
target="_blank"
rel="noopener noreferrer"
title={{t "general.info"}}
>
<FaIcon @icon="circle-info" />
</a>
<a href={{song.fileUrl}}
target="_blank"
rel="noopener noreferrer"
title={{t "general.listen"}}
>
<FaIcon @icon="ear-listen" />
</a>
<strong>{{song.title}}</strong>
{{t "general.from"}}
<strong>{{song.album}}</strong>
{{t "general.to"}}
<em>{{song.artist}}</em>
<em>{{song.album}}</em>
{{t "general.by"}}
{{song.artist}}
</li>
{{/each}}
</ul>
Expand Down

0 comments on commit 3c12ee3

Please sign in to comment.