From fb7c8f193b647302be160abd901462d068369208 Mon Sep 17 00:00:00 2001 From: Leonard Smith Date: Tue, 4 May 2021 17:03:43 -0500 Subject: [PATCH] Setup a new PhraseRow component to handle phrases in the word table --- app/components/book.js | 1 - app/components/words/phrase-row.hbs | 14 +++++++ app/components/words/phrase-row.js | 41 +++++++++++++++++++ app/components/words/word-table.hbs | 8 +++- app/components/words/word-table.js | 4 ++ app/models/word.js | 27 +++++++++--- .../components/words/phrase-row-test.js | 26 ++++++++++++ 7 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 app/components/words/phrase-row.hbs create mode 100644 app/components/words/phrase-row.js create mode 100644 app/components/words/word-table.js create mode 100644 tests/integration/components/words/phrase-row-test.js diff --git a/app/components/book.js b/app/components/book.js index 8bd2b83..b1018db 100644 --- a/app/components/book.js +++ b/app/components/book.js @@ -10,7 +10,6 @@ export default class BookComponent extends Component { return ''; } - console.log("Book: " + this.args.book.name); let string = this.args.book.name.toLowerCase(); if (this.isNumber(string.charAt(0))) { return string.slice(0,1) + ' ' + string.charAt(2).toUpperCase() + string.slice(3); diff --git a/app/components/words/phrase-row.hbs b/app/components/words/phrase-row.hbs new file mode 100644 index 0000000..eb04e30 --- /dev/null +++ b/app/components/words/phrase-row.hbs @@ -0,0 +1,14 @@ +{{#each this.phraseWords as |pw|}} + {{#if pw.rootRow}} + + {{pw.ulb}} + {{pw.greek}} + {{pw.morph}} + + {{else}} + + {{pw.greek}} + {{pw.morph}} + + {{/if}} +{{/each}} diff --git a/app/components/words/phrase-row.js b/app/components/words/phrase-row.js new file mode 100644 index 0000000..7f557db --- /dev/null +++ b/app/components/words/phrase-row.js @@ -0,0 +1,41 @@ +import WordsWordRowComponent from "./word-row"; +import { tracked } from "@glimmer/tracking"; + +export default class WordsPhraseRowComponent extends WordsWordRowComponent { + @tracked phraseWords = []; + + constructor(...args) { + super(...args); + this.phraseWords = this.getRelatedPhraseWords(); + } + + getRelatedPhraseWords() + { + let phraseWords = this.args.allWords.filter((word) => { + if (word.phraseId == this.args.model.phraseId) { + return word; + } + }); + + phraseWords.sort(function(a,b) { + return a.ogntSort - b.ogntSort; + }); + + /** + * The first item in the array should contain our ULB gloss. + * We need to take that gloss and add it to the next row in order + * for our table to render correctly. + */ + let ulbGloss = phraseWords.shift(); + phraseWords[0].ulb = ulbGloss.ulb; + phraseWords[0].rootRow = true; + + return phraseWords; + } + + get + rowCount() + { + return this.phraseWords.length; + } +} diff --git a/app/components/words/word-table.hbs b/app/components/words/word-table.hbs index 8cc2810..00808ef 100644 --- a/app/components/words/word-table.hbs +++ b/app/components/words/word-table.hbs @@ -6,6 +6,12 @@ Morphology {{#each @model as |word|}} - + {{#if word.isPhrase}} + {{#if word.isPhraseRoot}} + + {{/if}} + {{else}} + + {{/if}} {{/each}} diff --git a/app/components/words/word-table.js b/app/components/words/word-table.js new file mode 100644 index 0000000..1c9d304 --- /dev/null +++ b/app/components/words/word-table.js @@ -0,0 +1,4 @@ +import Component from '@glimmer/component'; + +export default class WordsWordTableComponent extends Component { +} diff --git a/app/models/word.js b/app/models/word.js index 68493f0..687e8b1 100644 --- a/app/models/word.js +++ b/app/models/word.js @@ -1,14 +1,29 @@ import Model, { attr, belongsTo } from '@ember-data/model'; export default class WordModel extends Model { - @attr ulb; - @attr greek; - @attr lemma; - @attr morph; - @attr ogntSort; - @attr strongsNumber; + @attr ('string') verseCode; + @attr ('string') ulb; + @attr ('string') greek; + @attr ('string') lemma; + @attr ('string') morph; + @attr ('number') phraseId; + @attr ('number') sub; + @attr ('number') ogntSort; + @attr ('number') ulbSort; + @attr ('string') strongsNumber; @belongsTo('verse') verse; @belongsTo('lexical-entry') lexicalEntry; + + get isPhrase() + { + return this.phraseId !== null; + } + + get isPhraseRoot() + { + console.log("Called isPhraseRoot on " + this.verseCode) + return this.strongsNumber == '-1'; + } } diff --git a/tests/integration/components/words/phrase-row-test.js b/tests/integration/components/words/phrase-row-test.js new file mode 100644 index 0000000..fb1ce2b --- /dev/null +++ b/tests/integration/components/words/phrase-row-test.js @@ -0,0 +1,26 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | words/phrase-row', function(hooks) { + setupRenderingTest(hooks); + + test('it renders', async function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + + await render(hbs``); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +});