From 5524babf6cc1775e8e260a4b863dfcd1b345d93b Mon Sep 17 00:00:00 2001 From: Oskar Rough Date: Wed, 10 Oct 2018 11:22:07 +0200 Subject: [PATCH 1/3] Replace image model with a string on channel --- app/models/channel.js | 3 ++- app/models/image.js | 14 -------------- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 app/models/image.js diff --git a/app/models/channel.js b/app/models/channel.js index 04ddebfeb..51d509afa 100644 --- a/app/models/channel.js +++ b/app/models/channel.js @@ -82,12 +82,13 @@ export default DS.Model.extend(Validations, { coverImage: computed('images.[]', function () { return this.get('images.lastObject'); }), + // A Cloudinary media ID. Use the "cover-img" helper to generate a full URL. + image: attr('string'), // This property is toggled by the player setChannel. isInPlayer: false, // Relationships. - images: hasMany('image', {async: true}), tracks: hasMany('track', {async: true}), favoriteChannels: hasMany('channel', {inverse: null, async: true}), channelPublic: belongsTo('channelPublic', {async: true}), diff --git a/app/models/image.js b/app/models/image.js deleted file mode 100644 index 19baaae80..000000000 --- a/app/models/image.js +++ /dev/null @@ -1,14 +0,0 @@ -import DS from 'ember-data'; -import firebase from 'firebase'; - -const {Model, attr, belongsTo} = DS; - -export default Model.extend({ - created: attr('number', { - defaultValue() { - return firebase.database.ServerValue.TIMESTAMP; - } - }), - src: attr('string'), - channel: belongsTo('channel') -}); From 3d0c2fb1e52c901b54e16c7fa7d1d94362fb7502 Mon Sep 17 00:00:00 2001 From: Oskar Rough Date: Wed, 10 Oct 2018 11:23:08 +0200 Subject: [PATCH 2/3] Simpler image logic --- app/channel/route.js | 9 ++------- app/channels/index/controller.js | 2 +- app/components/channel-card/template.hbs | 3 ++- app/components/channel-header/template.hbs | 4 ++-- app/components/map-world/template.hbs | 2 +- app/components/page-welcome/template.hbs | 2 +- app/models/channel.js | 6 +----- app/services/player.js | 6 +----- app/settings/channel/index/template.hbs | 9 ++++++--- 9 files changed, 17 insertions(+), 26 deletions(-) diff --git a/app/channel/route.js b/app/channel/route.js index a33acfbad..43df11cba 100644 --- a/app/channel/route.js +++ b/app/channel/route.js @@ -30,15 +30,10 @@ export default Route.extend({ const headData = get(this, 'headData') const description = model.get('body') const slug = model.get('slug') + const image = model.get('image') set(headData, 'description', description) set(headData, 'slug', slug) - // Because images come from a model relationship… - model.get('images').then(images => { - const image = images.get('lastObject.src') - if (image) { - set(headData, 'image', image) - } - }) + set(headData, 'image', image) }, serialize(model) { diff --git a/app/channels/index/controller.js b/app/channels/index/controller.js index ba1ee7481..520fa827d 100644 --- a/app/channels/index/controller.js +++ b/app/channels/index/controller.js @@ -2,7 +2,7 @@ import Controller from '@ember/controller'; import {computed} from '@ember/object' export default Controller.extend({ - filteredModel: computed.filterBy('model', 'coverImage'), + filteredModel: computed.filterBy('model', 'image'), actions: { refreshSelection() { diff --git a/app/components/channel-card/template.hbs b/app/components/channel-card/template.hbs index 36789f9f6..d5a36aff0 100644 --- a/app/components/channel-card/template.hbs +++ b/app/components/channel-card/template.hbs @@ -1,5 +1,6 @@ {{#link-to "channel" channel title=title}} - {{channel-cover src=channel.coverImage.src}} + {{channel-cover src=channel.image}} +

{{channel.title}}

diff --git a/app/components/channel-header/template.hbs b/app/components/channel-header/template.hbs index 326036aa4..eeae19e7f 100644 --- a/app/components/channel-header/template.hbs +++ b/app/components/channel-header/template.hbs @@ -2,12 +2,12 @@ {{#if channel.canEdit}} {{#link-to "settings.channel"}}
- {{channel-cover src=channel.coverImage.src}} + {{channel-cover src=channel.image}}
{{/link-to}} {{else}}
- {{channel-cover src=channel.coverImage.src}} + {{channel-cover src=channel.image}}
{{/if}} diff --git a/app/components/map-world/template.hbs b/app/components/map-world/template.hbs index 859cd2336..834c979cc 100644 --- a/app/components/map-world/template.hbs +++ b/app/components/map-world/template.hbs @@ -25,7 +25,7 @@ {{!-- Icon markers icon=(icon className="ImageMapMarker" - iconUrl=(if item.coverImage.src (cover-img item.coverImage.src size=32 format='awebp') "favicon-32x32.png") + iconUrl=(if item.image (cover-img item.image size=32 format='awebp') "favicon-32x32.png") ) icon=(if item.isFavorite iconFavorite iconDefault) --}} diff --git a/app/components/page-welcome/template.hbs b/app/components/page-welcome/template.hbs index 38d1fa545..ba1f9ce44 100644 --- a/app/components/page-welcome/template.hbs +++ b/app/components/page-welcome/template.hbs @@ -20,7 +20,7 @@ {{#link-to 'settings.channel'}} {{/link-to}} {{#link-to 'channels.search'}} diff --git a/app/models/channel.js b/app/models/channel.js index 51d509afa..045344e28 100644 --- a/app/models/channel.js +++ b/app/models/channel.js @@ -78,10 +78,6 @@ export default DS.Model.extend(Validations, { lat: 'coordinatesLatitude' }), - // Set the latest image as the cover image. - coverImage: computed('images.[]', function () { - return this.get('images.lastObject'); - }), // A Cloudinary media ID. Use the "cover-img" helper to generate a full URL. image: attr('string'), @@ -121,7 +117,7 @@ export default DS.Model.extend(Validations, { } }), - isExperienced: computed.and('images.firstObject', 'totalTracks', 'favoriteChannels.firstObject'), + isExperienced: computed.and('image', 'totalTracks', 'favoriteChannels.firstObject'), // Is already a favorite channel of session.currentUser. isFavorite: computed('model', 'session.currentUser.channels.firstObject.favoriteChannels.[]', function () { diff --git a/app/services/player.js b/app/services/player.js index 979521436..985a17c70 100644 --- a/app/services/player.js +++ b/app/services/player.js @@ -174,11 +174,7 @@ export default Service.extend({ }); cleanedChannel.query = query cleanedChannel.tracks = tracks.reverse() - - // Get a full image src to pass. - const imageModel = channelModel.get('coverImage') - const src = coverImg([imageModel.get('src')], {size: 56}) - cleanedChannel.image = src + cleanedChannel.image = coverImg([cleanedChannel.image], {size: 56}) return cleanedChannel }, diff --git a/app/settings/channel/index/template.hbs b/app/settings/channel/index/template.hbs index 26abad994..520a3bac3 100644 --- a/app/settings/channel/index/template.hbs +++ b/app/settings/channel/index/template.hbs @@ -3,15 +3,18 @@

- {{#if model.coverImage}} + {{#if model.image}}
- {{channel-cover src=model.coverImage.src}} + {{channel-cover src=model.image}}
{{else}} - {{cloudinary-upload cloudName='radio4000' unsignedUploadPreset='tc44ivjo' didUpload=(action "saveImage")}} + {{cloudinary-upload + cloudName='radio4000' + unsignedUploadPreset='tc44ivjo' + didUpload=(action "saveImage")}} {{/if}} From 98f4672d386ebbcbeb6fae533bf11adc9ab07e57 Mon Sep 17 00:00:00 2001 From: Oskar Rough Date: Wed, 10 Oct 2018 11:23:32 +0200 Subject: [PATCH 3/3] Update add/delete image methods --- app/channels/search/route.js | 2 +- app/channels/search/template.hbs | 1 - app/components/channel-card/template.hbs | 1 + app/settings/channel/index/controller.js | 33 ++++++++++++------------ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/channels/search/route.js b/app/channels/search/route.js index 8805be6f2..45278ff48 100644 --- a/app/channels/search/route.js +++ b/app/channels/search/route.js @@ -1,4 +1,4 @@ -import Route from '@ember/routing/route'; +import Route from '@ember/routing/route' export default Route.extend({ // When search changes the url, don't replace (add) to the history. diff --git a/app/channels/search/template.hbs b/app/channels/search/template.hbs index d67d5e94c..c174bcc7c 100644 --- a/app/channels/search/template.hbs +++ b/app/channels/search/template.hbs @@ -73,7 +73,6 @@
-

Each radio is curated by one human. Listen, discover someone's personal selection.
diff --git a/app/components/channel-card/template.hbs b/app/components/channel-card/template.hbs index d5a36aff0..bcdbffce0 100644 --- a/app/components/channel-card/template.hbs +++ b/app/components/channel-card/template.hbs @@ -13,6 +13,7 @@ showText=false }}

+

{{link-hashtags (do-truncate channel.body 200) channel.slug}}

diff --git a/app/settings/channel/index/controller.js b/app/settings/channel/index/controller.js index d4d19f38d..0d62bda91 100644 --- a/app/settings/channel/index/controller.js +++ b/app/settings/channel/index/controller.js @@ -1,6 +1,6 @@ import Ember from 'ember' import Controller from '@ember/controller' -import {get} from '@ember/object' +import {get, set} from '@ember/object' import {task} from 'ember-concurrency' import clean from 'radio4000/utils/clean' import ValidateSlug from 'radio4000/mixins/validate-slug' @@ -30,7 +30,7 @@ export default Controller.extend(ValidateSlug, { if (slugChanged) { try { yield get(this, 'validateSlug').perform(newSlug) - channel.set('slug', newSlug) + set(channel, 'slug', newSlug) } catch (err) { messages.warning(err) return @@ -66,30 +66,29 @@ export default Controller.extend(ValidateSlug, { actions: { saveImage(cloudinaryId) { + const messages = get(this, 'flashMessages') + const channel = get(this, 'model') + if (!cloudinaryId) { throw new Error('Could not save image. Missing cloudinary id') } - const channel = get(this, 'model') - const image = this.store.createRecord('image', { - src: cloudinaryId, - channel - }) - // save and add it to the channel - return image + + channel.set('image', cloudinaryId) + + return channel .save() - .then(image => { - channel.get('images').addObject(image) - channel.save().then(() => { - debug('Saved channel with image') - }) + .then(() => { + debug('Saved channel with image') }) - .catch(err => { - Ember.debug('could not save image', err) + .catch(() => { + messages.warning('Could not save the image to your channel') + channel.set('image', undefined) }) }, deleteImage() { - return this.get('model.coverImage').destroyRecord() + set(this, 'model.image', undefined) + return this.get('model').save() }, goBack() {