Setup a new PhraseRow component to handle phrases in the word table
This commit is contained in:
parent
b67310ef7c
commit
fb7c8f193b
|
@ -10,7 +10,6 @@ export default class BookComponent extends Component {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Book: " + this.args.book.name);
|
|
||||||
let string = this.args.book.name.toLowerCase();
|
let string = this.args.book.name.toLowerCase();
|
||||||
if (this.isNumber(string.charAt(0))) {
|
if (this.isNumber(string.charAt(0))) {
|
||||||
return string.slice(0,1) + ' ' + string.charAt(2).toUpperCase() + string.slice(3);
|
return string.slice(0,1) + ' ' + string.charAt(2).toUpperCase() + string.slice(3);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{{#each this.phraseWords as |pw|}}
|
||||||
|
{{#if pw.rootRow}}
|
||||||
|
<tr class="{{this.selected}}" ...attributes>
|
||||||
|
<td rowspan="{{this.rowCount}}">{{pw.ulb}}</td>
|
||||||
|
<td>{{pw.greek}}</td>
|
||||||
|
<td>{{pw.morph}}</td>
|
||||||
|
</tr>
|
||||||
|
{{else}}
|
||||||
|
<tr {{on "click" (fn this.select pw)}} class="{{this.selected}}" ...attributes>
|
||||||
|
<td>{{pw.greek}}</td>
|
||||||
|
<td>{{pw.morph}}</td>
|
||||||
|
</tr>
|
||||||
|
{{/if}}
|
||||||
|
{{/each}}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,12 @@
|
||||||
<th>Morphology</th>
|
<th>Morphology</th>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each @model as |word|}}
|
{{#each @model as |word|}}
|
||||||
<Words::WordRow @model={{word}} />
|
{{#if word.isPhrase}}
|
||||||
|
{{#if word.isPhraseRoot}}
|
||||||
|
<Words::PhraseRow @model={{word}} @allWords={{@model}} />
|
||||||
|
{{/if}}
|
||||||
|
{{else}}
|
||||||
|
<Words::WordRow @model={{word}} />
|
||||||
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
import Component from '@glimmer/component';
|
||||||
|
|
||||||
|
export default class WordsWordTableComponent extends Component {
|
||||||
|
}
|
|
@ -1,14 +1,29 @@
|
||||||
import Model, { attr, belongsTo } from '@ember-data/model';
|
import Model, { attr, belongsTo } from '@ember-data/model';
|
||||||
|
|
||||||
export default class WordModel extends Model {
|
export default class WordModel extends Model {
|
||||||
@attr ulb;
|
@attr ('string') verseCode;
|
||||||
@attr greek;
|
@attr ('string') ulb;
|
||||||
@attr lemma;
|
@attr ('string') greek;
|
||||||
@attr morph;
|
@attr ('string') lemma;
|
||||||
@attr ogntSort;
|
@attr ('string') morph;
|
||||||
@attr strongsNumber;
|
@attr ('number') phraseId;
|
||||||
|
@attr ('number') sub;
|
||||||
|
@attr ('number') ogntSort;
|
||||||
|
@attr ('number') ulbSort;
|
||||||
|
@attr ('string') strongsNumber;
|
||||||
|
|
||||||
@belongsTo('verse') verse;
|
@belongsTo('verse') verse;
|
||||||
|
|
||||||
@belongsTo('lexical-entry') lexicalEntry;
|
@belongsTo('lexical-entry') lexicalEntry;
|
||||||
|
|
||||||
|
get isPhrase()
|
||||||
|
{
|
||||||
|
return this.phraseId !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPhraseRoot()
|
||||||
|
{
|
||||||
|
console.log("Called isPhraseRoot on " + this.verseCode)
|
||||||
|
return this.strongsNumber == '-1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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`<Words::PhraseRow />`);
|
||||||
|
|
||||||
|
assert.equal(this.element.textContent.trim(), '');
|
||||||
|
|
||||||
|
// Template block usage:
|
||||||
|
await render(hbs`
|
||||||
|
<Words::PhraseRow>
|
||||||
|
template block text
|
||||||
|
</Words::PhraseRow>
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(this.element.textContent.trim(), 'template block text');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue