From 49dbf4a672df9f0f2382fd75b21cf454d88f4a1b Mon Sep 17 00:00:00 2001 From: Leonard Smith Date: Wed, 26 May 2021 16:53:40 -0500 Subject: [PATCH] Setup fetching commentary intros and articles --- app/router.js | 1 + app/routes/commentary-article.js | 13 +++++++++++++ app/routes/commentary-intro.js | 2 +- app/templates/commentary-article.hbs | 7 +++++++ tests/unit/routes/commentary-article-test.js | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/routes/commentary-article.js create mode 100644 app/templates/commentary-article.hbs create mode 100644 tests/unit/routes/commentary-article-test.js diff --git a/app/router.js b/app/router.js index 19a17db..47ed1c4 100644 --- a/app/router.js +++ b/app/router.js @@ -17,4 +17,5 @@ Router.map(function() { this.route('contact-us'); this.route('morph-legend'); this.route('commentary-intro', { path: '/commentary/:book_id' }); + this.route('commentary-article', { path: '/commentary/articles/:article_id' }); }); diff --git a/app/routes/commentary-article.js b/app/routes/commentary-article.js new file mode 100644 index 0000000..7d09682 --- /dev/null +++ b/app/routes/commentary-article.js @@ -0,0 +1,13 @@ +import Route from '@ember/routing/route'; +import fetch from 'fetch'; +import { htmlSafe } from '@ember/template'; + +export default class CommentaryArticleRoute extends Route { + async model(params) { + const response = await fetch(window.GwtFrontend.hostUrl + '/api/v1/commentary/articles/' + params.article_id); + const body = await response.text().then(function(text){ + return new htmlSafe(text); + }); + return { body }; + } +} diff --git a/app/routes/commentary-intro.js b/app/routes/commentary-intro.js index 2aaa2d9..4c758f8 100644 --- a/app/routes/commentary-intro.js +++ b/app/routes/commentary-intro.js @@ -4,7 +4,7 @@ import { htmlSafe } from '@ember/template'; export default class CommentaryIntroRoute extends Route { async model(params) { - const response = await fetch('http://gwt.api/api/v1/commentary/' + params.book_id + '/chapter/intro'); + const response = await fetch(window.GwtFrontend.hostUrl + '/api/v1/commentary/' + params.book_id + '/chapter/intro'); const body = await response.text().then(function(text){ return new htmlSafe(text); }); diff --git a/app/templates/commentary-article.hbs b/app/templates/commentary-article.hbs new file mode 100644 index 0000000..e0b05ce --- /dev/null +++ b/app/templates/commentary-article.hbs @@ -0,0 +1,7 @@ +{{page-title "Commentary Article"}} + +
+ {{{@model.body}}} +
+ +{{outlet}} \ No newline at end of file diff --git a/tests/unit/routes/commentary-article-test.js b/tests/unit/routes/commentary-article-test.js new file mode 100644 index 0000000..50dc50b --- /dev/null +++ b/tests/unit/routes/commentary-article-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | commentary-article', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:commentary-article'); + assert.ok(route); + }); +});