From ae5fc57b1c9f0aa10c525b699f4a7ceb3b4cb6db Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Tue, 11 Apr 2017 09:41:57 -0400 Subject: [PATCH 1/9] adds chunk MAS --- app/chunk/adapter.js | 8 ++++++++ tests/unit/chunk/adapter-test.js | 12 ++++++++++++ tests/unit/chunk/model-test.js | 12 ++++++++++++ tests/unit/chunk/serializer-test.js | 15 +++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 app/chunk/adapter.js create mode 100644 tests/unit/chunk/adapter-test.js create mode 100644 tests/unit/chunk/model-test.js create mode 100644 tests/unit/chunk/serializer-test.js diff --git a/app/chunk/adapter.js b/app/chunk/adapter.js new file mode 100644 index 000000000..92117f3b9 --- /dev/null +++ b/app/chunk/adapter.js @@ -0,0 +1,8 @@ +import ApplicationAdapter from './application'; + +export default ApplicationAdapter.extend({ + buildURL() { + let url = this._super(...arguments); + return url + '/'; + } +}); diff --git a/tests/unit/chunk/adapter-test.js b/tests/unit/chunk/adapter-test.js new file mode 100644 index 000000000..fed73f08e --- /dev/null +++ b/tests/unit/chunk/adapter-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:chunk', 'Unit | Adapter | chunk', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/chunk/model-test.js b/tests/unit/chunk/model-test.js new file mode 100644 index 000000000..bf1304c8c --- /dev/null +++ b/tests/unit/chunk/model-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('chunk', 'Unit | Model | chunk', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/chunk/serializer-test.js b/tests/unit/chunk/serializer-test.js new file mode 100644 index 000000000..2d6439f8c --- /dev/null +++ b/tests/unit/chunk/serializer-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('chunk', 'Unit | Serializer | chunk', { + // Specify the other units that are required for this test. + needs: ['serializer:chunk'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From 6970e52ce01adc6db694f8339bef63515e75c6b1 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Tue, 11 Apr 2017 09:42:47 -0400 Subject: [PATCH 2/9] look up listen live chunk on channel route --- app/channel/route.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/channel/route.js b/app/channel/route.js index 8bbff68c5..954e9dc3c 100644 --- a/app/channel/route.js +++ b/app/channel/route.js @@ -22,11 +22,16 @@ export default Route.extend(PlayParamMixin, { const listingSlug = `${inflector.pluralize(channelType)}/${params.slug}`; set(this, 'listingSlug', listingSlug); + let listenLive = this.store.findRecord('chunk', `shows-${params.slug}-listenlive`) + .then(c => this.store.createRecord('django-page', {text: c.get('content')})) + .catch(() => {}); + return this.store.find('django-page', listingSlug.replace(/\/*$/, '/')).then(page => { return waitFor({ page, channel: page.get('wnycChannel'), - user: this.get('session.data.authenticated') + user: this.get('session.data.authenticated'), + listenLive }); }) .catch(e => retryFromServer(e, listingSlug.replace(/\/*$/, '/'))); From c64ed430db9b294ee398298e6ea9a7649657d958 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Tue, 11 Apr 2017 09:45:02 -0400 Subject: [PATCH 3/9] fix import --- app/chunk/adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/chunk/adapter.js b/app/chunk/adapter.js index 92117f3b9..5670c5198 100644 --- a/app/chunk/adapter.js +++ b/app/chunk/adapter.js @@ -1,4 +1,4 @@ -import ApplicationAdapter from './application'; +import ApplicationAdapter from 'wqxr-web-client/adapters/application'; export default ApplicationAdapter.extend({ buildURL() { From 1c2d5e980320af332c1940982a841f986e1652e3 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Tue, 11 Apr 2017 09:45:11 -0400 Subject: [PATCH 4/9] pass in listenLive chunk might be getting time to refactor these components to produce more sensible yields --- app/channel/template.hbs | 4 ++-- app/components/channel-header/template.hbs | 3 +++ app/components/x-marquee/template.hbs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/channel/template.hbs b/app/channel/template.hbs index 8bbb09480..10ecdf1d3 100644 --- a/app/channel/template.hbs +++ b/app/channel/template.hbs @@ -28,9 +28,9 @@ {{/alt-channel-layout}} {{else}} {{#if model.channel.hasMarquee}} - {{x-marquee model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} + {{x-marquee listenLive=model.listenLive model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} {{else}} - {{channel-header model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} + {{channel-header listenLive=model.listenLive model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} {{/if}}
diff --git a/app/components/channel-header/template.hbs b/app/components/channel-header/template.hbs index d8899fb26..f953b5883 100644 --- a/app/components/channel-header/template.hbs +++ b/app/components/channel-header/template.hbs @@ -21,6 +21,9 @@ Produced by {{producing-orgs model.producingOrganizations}}. {{/if}} {{airings}} + {{#if listenLive}} + {{django-page page=listenLive}} + {{/if}}
diff --git a/app/components/x-marquee/template.hbs b/app/components/x-marquee/template.hbs index 7bcc94c5d..087a2f5d1 100644 --- a/app/components/x-marquee/template.hbs +++ b/app/components/x-marquee/template.hbs @@ -2,5 +2,5 @@
From d1bd58331fccda24b9f3062126ea20748cd76164 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Fri, 14 Apr 2017 16:00:50 -0400 Subject: [PATCH 5/9] use guidFor to get edembedded component id --- app/lib/alien-dom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/alien-dom.js b/app/lib/alien-dom.js index 77511900b..cd6ed6465 100644 --- a/app/lib/alien-dom.js +++ b/app/lib/alien-dom.js @@ -54,10 +54,10 @@ export function removeAlienListeners() { // destination. This runs in the django-page model's separateScripts method as well // as in the django-page component's didReceiveAttrs hook if an Alien DOM is present. export function embeddedComponentSetup(root = document) { - Array.from(root.querySelectorAll('[data-ember-component]')).forEach(function (el, i) { + Array.from(root.querySelectorAll('[data-ember-component]')).forEach(function (el) { // embedded ember components require an ID that is in sync with the // django-page document - el.id = el.id || `ember-component-${i}`; + el.id = el.id || Ember.guidFor(el); el.setAttribute('data-text-content', el.textContent.trim()); el.textContent = ''; }); From 4f0de7396e0aa06fbc1b7ea1d9e0666188dcecf6 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Thu, 20 Apr 2017 16:30:04 -0400 Subject: [PATCH 6/9] adds chunks to mirage --- mirage/config.js | 1 + mirage/factories/chunk.js | 6 ++++++ mirage/models/chunk.js | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 mirage/factories/chunk.js create mode 100644 mirage/models/chunk.js diff --git a/mirage/config.js b/mirage/config.js index 82a087c02..6268f42c4 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -46,6 +46,7 @@ export default function() { this.get(`${baseUrl}/api/v3/buckets/:slug/`, 'bucket'); this.get(`${baseUrl}/api/v3/story/detail/:id`, 'story'); this.get(`${baseUrl}/api/v3/channel/\*id`, 'api-response'); + this.get(`${baseUrl}/api/v3/chunks/:id/`, 'chunk'); /*------------------------------------------------------------ identity management (account) endpoints diff --git a/mirage/factories/chunk.js b/mirage/factories/chunk.js new file mode 100644 index 000000000..ff1670eb8 --- /dev/null +++ b/mirage/factories/chunk.js @@ -0,0 +1,6 @@ +import { Factory, faker } from 'ember-cli-mirage'; + +export default Factory.extend({ + slug: () => faker.lorem.words(2).join('-'), + content: faker.lorem.sentence +}); diff --git a/mirage/models/chunk.js b/mirage/models/chunk.js new file mode 100644 index 000000000..1486a7240 --- /dev/null +++ b/mirage/models/chunk.js @@ -0,0 +1,4 @@ +import { Model } from 'ember-cli-mirage'; + +export default Model.extend({ +}); From 0042347c1c1595d507a8f1b5b2acc07c77368cfa Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Thu, 20 Apr 2017 16:30:12 -0400 Subject: [PATCH 7/9] adds listen live chunk test --- tests/acceptance/viewing-show-test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/acceptance/viewing-show-test.js b/tests/acceptance/viewing-show-test.js index ab1f1aa38..624d8ef13 100644 --- a/tests/acceptance/viewing-show-test.js +++ b/tests/acceptance/viewing-show-test.js @@ -299,6 +299,26 @@ test('show pages with a play param', function(assert) { }); +test('show pages with a listen live chunk', function(assert) { + let show = server.create('show', { + id: 'shows/foo/' + }); + server.create('api-response', { id: 'shows/foo/recent_stories/1' }); + + server.create('chunk', { + id: 'shows-foo-listenlive', + content: 'foo bar text' + }); + server.create('django-page', {id: show.id}); + djangoPage + .bootstrap(show) + .visit(show); + + andThen(() => { + assert.equal(find('.channel-header .django-content').text().trim(), 'foo bar text'); + }); +}); + moduleForAcceptance('Acceptance | Django Page | Show Page Analytics'); test('metrics properly reports channel attrs', function(assert) { From 90854bcbc2572b9f7a2e0fb625f729fda298e00a Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Thu, 20 Apr 2017 16:30:47 -0400 Subject: [PATCH 8/9] can just use `pagecontent` attr on templates --- app/channel/route.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/channel/route.js b/app/channel/route.js index 954e9dc3c..d513f7b1b 100644 --- a/app/channel/route.js +++ b/app/channel/route.js @@ -23,8 +23,7 @@ export default Route.extend(PlayParamMixin, { set(this, 'listingSlug', listingSlug); let listenLive = this.store.findRecord('chunk', `shows-${params.slug}-listenlive`) - .then(c => this.store.createRecord('django-page', {text: c.get('content')})) - .catch(() => {}); + .catch(() => ''); return this.store.find('django-page', listingSlug.replace(/\/*$/, '/')).then(page => { return waitFor({ From a9822bcc7033c86ebcca699fc73ee92faafc4f94 Mon Sep 17 00:00:00 2001 From: Brian Whitton Date: Thu, 20 Apr 2017 16:31:09 -0400 Subject: [PATCH 9/9] pass in pagecontent to components also whitespace --- app/channel/template.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/channel/template.hbs b/app/channel/template.hbs index 10ecdf1d3..27cf25b75 100644 --- a/app/channel/template.hbs +++ b/app/channel/template.hbs @@ -28,9 +28,9 @@ {{/alt-channel-layout}} {{else}} {{#if model.channel.hasMarquee}} - {{x-marquee listenLive=model.listenLive model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} + {{x-marquee listenLive=model.listenLive.pagecontent model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} {{else}} - {{channel-header listenLive=model.listenLive model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} + {{channel-header listenLive=model.listenLive.pagecontent model=model.channel isStaff=session.data.isStaff adminURL=adminURL}} {{/if}}