Skip to content

Commit

Permalink
Merge pull request #3 from brancusi/dev
Browse files Browse the repository at this point in the history
Dev
brancusi authored Apr 23, 2017

Verified

This commit was signed with the committer’s verified signature.
YuanYuYuan Yuyuan Yuan
2 parents dadb5c6 + ffe07cf commit 3655c15
Showing 24 changed files with 123 additions and 152 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ module.exports = {
rules: {
},
globals: {
"RecordRTC": true
"RecordRTC": true,
"Twilio": true
}
};
9 changes: 6 additions & 3 deletions app/components/audio-recorder/styles.styl
Original file line number Diff line number Diff line change
@@ -14,7 +14,10 @@
.btn:hover
background: rgba(off-white, 1)

.btn:active
background: hot-pink
opacity: 1
.record-button
color: slate

.record-button:active
color: off-white
background: rgba(red, 0.6)
opacity: 1
3 changes: 2 additions & 1 deletion app/components/audio-recorder/template.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{ui/icon-button
class='record-button'
loading=saving
disabled=saving
mouseDown=(action 'startRecording')
mouseUp=(action 'stopRecording')
leftIcon="microphone"}}
leftIcon="circle"}}

{{#if hasAudio}}
{{ui/icon-button
6 changes: 3 additions & 3 deletions app/components/communication/video-chat/component.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ const Video = Twilio.Video;

export default Ember.Component.extend({
startVideo() {
const { token, identity } = this.get("twilioData");
const { token } = this.get("twilioData");

Video.connect(token, {name: "my-room"})
.then(room => {
@@ -15,8 +15,8 @@ export default Ember.Component.extend({
room.on('participantConnected', ::this.participantConnected);

room.on('participantDisconnected', ::this.participantDisconnected);
room.once('disconnected', error => room.participants.forEach(::this.participantDisconnected));
}, e => console.log(e));
room.once('disconnected', () => room.participants.forEach(::this.participantDisconnected));
});
},

attachTracks(tracks, container) {
3 changes: 1 addition & 2 deletions app/components/conversation-group/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from 'ember';
import computed from 'ember-computed-decorators';

const { isPresent, computed: { alias, sort, gt } } = Ember;
const { computed: { alias, sort, gt } } = Ember;

export default Ember.Component.extend({
sortAsc: ["position:asc"],
3 changes: 3 additions & 0 deletions app/components/conversation-group/styles.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
&
margin-top: 3em

.conversation-container
padding: 0 2em

.create-conversation
width: 100%
padding: 1em
5 changes: 2 additions & 3 deletions app/components/flash-card-group/component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Ember from 'ember';
import computed from 'ember-computed-decorators';

const { isPresent, computed: { alias, sort, gt } } = Ember;
const { computed: { alias, sort, gt } } = Ember;

export default Ember.Component.extend({
classNames: ['card-1'],

sortAsc: ["position:asc"],
sortedFlashCards: sort('model.activeFlashCards', 'sortAsc'),
flashCardCount: alias("sortedFlashCards.length"),
17 changes: 6 additions & 11 deletions app/components/flash-card/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Ember from 'ember';
import _ from 'lodash';
import computed from 'ember-computed-decorators';

const TONE_REGEX = /([aeiouAEIOU][1234])/g;

@@ -56,10 +55,6 @@ const TONE_MAPPING = {
"U4": "Ù"
};

const {
computed: { notEmpty }
} = Ember;

export default Ember.Component.extend({
classNames: ['card-2', 'stretch'],

@@ -69,7 +64,7 @@ export default Ember.Component.extend({
},

actions: {
processChange(str) {
processChange(model, str) {
const editor = this.$(".pinyinEditor")[0];
let cursorPosition = editor.selectionStart;
let newStr = str;
@@ -80,16 +75,16 @@ export default Ember.Component.extend({
cursorPosition = cursorPosition - matches.length;
}

this.set("model.pinyin", newStr);
model.set("text", newStr);

this.get("saveModel")(this.get("model"));
this.get("saveModel")(model);

Ember.run.scheduleOnce('afterRender', this, this.setSelection, editor, cursorPosition, cursorPosition);
},

handleUpdate(key, str) {
this.get("model").set(key, str);
this.get("saveModel")(this.get("model"));
handleUpdate(model, str) {
model.set('text', str);
this.get("saveModel")(model);
}
}
});
4 changes: 2 additions & 2 deletions app/components/flash-card/styles.styl
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
min-width: 18em
width: 18em
margin: 0.5em
border-bottom-left-radius: 10px
border-bottom-right-radius: 10px

.inputContainer
margin-left: 1em
@@ -20,8 +22,6 @@ textarea
background: rgba(white, 0.75)

.fieldsContainer
// margin: 0.5em

+below(700px)
flex-direction: column

14 changes: 7 additions & 7 deletions app/components/flash-card/template.hbs
Original file line number Diff line number Diff line change
@@ -15,30 +15,30 @@

<div class="col fieldsContainer">
<div class="col inputContainer">
{{one-way-textarea model.chinese
{{one-way-textarea model.chinese.text
placeholder='汉语...'
update=(action "handleUpdate" "chinese")
update=(action "handleUpdate" model.chinese)
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck=false}}
</div>

<div class="col inputContainer">
{{one-way-textarea model.pinyin
{{one-way-textarea model.pinyin.text
placeholder='Pinyin...'
class="pinyinEditor"
update=(action 'processChange')
update=(action 'processChange' model.pinyin)
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck=false}}
</div>

<div class="col inputContainer">
{{one-way-textarea model.english
{{one-way-textarea model.english.text
placeholder='English...'
update=(action "handleUpdate" "english")
update=(action "handleUpdate" model.english)
autocomplete="off"
autocorrect="off"
autocapitalize="off"
@@ -47,7 +47,7 @@
</div>

<div class="audioUiContainer row right">
{{audio-recorder
{{audio-recorder
model=model
created=(action onAudioCreated model)}}
</div>
5 changes: 2 additions & 3 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -12,11 +12,10 @@
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/wo-pinyin.css">

<!-- <script src="https://cdn.webrtc-experiment.com/MediaStreamRecorder.js"></script> -->
<script src="https://cdn.WebRTC-Experiment.com/RecordRTC.js"></script>
<script src="//media.twiliocdn.com/sdk/js/video/releases/1.0.0-beta6/twilio-video.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500&amp;subset=latin-ext" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,600,700,800,900&amp;subset=latin-ext" rel="stylesheet">

{{content-for "head-footer"}}
</head>
4 changes: 2 additions & 2 deletions app/models/conversation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DS from 'ember-data';
import computed from 'ember-computed-decorators';
import Ember from 'ember';

const { empty, filterBy } = Ember.computed;
const { filterBy, empty } = Ember.computed;

export default DS.Model.extend({
title: DS.attr('string'),
7 changes: 4 additions & 3 deletions app/models/flash-card.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import DS from 'ember-data';

export default DS.Model.extend({
pinyin: DS.attr('string'),
chinese: DS.attr('string'),
english: DS.attr('string'),
pinyin: DS.belongsTo('translation', {inverse: null}),
chinese: DS.belongsTo('translation', {inverse: null}),
english: DS.belongsTo('translation', {inverse: null}),

audioUrl: DS.attr('string'),
ts: DS.attr('number'),
position: DS.attr('number', {defaultValue: 1}),
7 changes: 7 additions & 0 deletions app/models/translation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DS from 'ember-data';

export default DS.Model.extend({
text: DS.attr('string'),
lang: DS.attr('string'),
flashCard: DS.belongsTo('flash-card', {inverse: null})
});
67 changes: 56 additions & 11 deletions app/routes/lesson.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Ember from 'ember';
import firebase from 'firebase';
import { v4 as uuid } from 'uuid';
import moment from 'moment';
import _ from 'lodash';

export default Ember.Route.extend({
setupController(controller, model) {
@@ -21,14 +19,27 @@ export default Ember.Route.extend({

const record = await this.store.findRecord('lesson', params.id)
.catch(() => {
const lesson = this.store.createRecord('lesson', {id:params.id, date:new Date()}),
conversation = this.store.createRecord('conversation', {lesson}),
flashCard = this.store.createRecord('flash-card', {conversation});

const chinese = this.store.createRecord('translation', { flashCard, lang: 'chinese' });
const pinyin = this.store.createRecord('translation', { flashCard, lang: 'pinyin' });
const english = this.store.createRecord('translation', { flashCard, lang: 'english' });

const lesson = this.store.createRecord('lesson', {id:params.id, date:new Date()});
const conversation = this.store.createRecord('conversation', {lesson});

const flashCard = this.store
.createRecord('flash-card', {
conversation,
chinese,
pinyin,
english
});

return lesson.save()
.then(lesson => conversation.save())
.then(conversation => flashCard.save())
.then(flashCard => lesson);
.then(() => conversation.save())
.then(() => flashCard.save())
.then(() => Ember.RSVP.all([chinese.save(), pinyin.save(), english.save()]))
.then(() => lesson);
});

return {
@@ -70,11 +81,21 @@ export default Ember.Route.extend({
const conversation = this.store
.createRecord('conversation', { lesson, position: newPosition });

const chinese = this.store.createRecord('translation', { flashCard, lang: 'chinese' });
const pinyin = this.store.createRecord('translation', { flashCard, lang: 'pinyin' });
const english = this.store.createRecord('translation', { flashCard, lang: 'english' });

const flashCard = this.store
.createRecord('flash-card', { conversation });
.createRecord('flash-card', {
conversation,
chinese,
pinyin,
english
});

await conversation.save();
await flashCard.save();
await Ember.RSVP.all([chinese.save(), pinyin.save(), english.save()]);
await lesson.save();
},

@@ -97,17 +118,30 @@ export default Ember.Route.extend({
},

saveModel(model) {
model.save();
if(model.then !== undefined) {
model.then(res => res.save());
} else {
model.save();
}
},

async destroyFlashCard(conversation, flashCard) {
flashCard.deleteRecord();

const chinese = await flashCard.get('chinese');
const pinyin = await flashCard.get('pinyin');
const english = await flashCard.get('english');

chinese.deleteRecord();
pinyin.deleteRecord();
english.deleteRecord();

if(conversation.get("isEmpty")) {
conversation.deleteRecord();
}

await flashCard.save();
await Ember.RSVP.all([chinese.save(), pinyin.save(), english.save()]);
await conversation.save();
},

@@ -144,10 +178,21 @@ export default Ember.Route.extend({
newPosition = 1;
}

const chinese = this.store.createRecord('translation', { flashCard, lang: 'chinese' });
const pinyin = this.store.createRecord('translation', { flashCard, lang: 'pinyin' });
const english = this.store.createRecord('translation', { flashCard, lang: 'english' });

const flashCard = this.store
.createRecord('flash-card', { conversation, position: newPosition });
.createRecord('flash-card', {
conversation,
position: newPosition,
chinese,
pinyin,
english
});

await flashCard.save();
await Ember.RSVP.all([chinese.save(), pinyin.save(), english.save()]);
await conversation.save();
}
}
4 changes: 4 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
env: {
embertest: true
},
globals: {
"RecordRTC": true,
"Twilio": true
}
};

This file was deleted.

25 changes: 0 additions & 25 deletions tests/integration/components/conversation-group/component-test.js

This file was deleted.

25 changes: 0 additions & 25 deletions tests/integration/components/flash-card-group/component-test.js

This file was deleted.

11 changes: 0 additions & 11 deletions tests/integration/components/flash-card/component-test.js

This file was deleted.

12 changes: 0 additions & 12 deletions tests/unit/controllers/lesson-test.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/unit/models/flash-card-test.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit';

moduleForModel('flash-card', 'Unit | Model | flash card', {
// Specify the other units that are required for this test.
needs: ['model:lesson']
needs: ['model:conversation', 'model:translation']
});

test('it exists', function(assert) {
2 changes: 1 addition & 1 deletion tests/unit/models/lesson-test.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit';

moduleForModel('lesson', 'Unit | Model | lesson', {
// Specify the other units that are required for this test.
needs: ['model:flash-card']
needs: ['model:conversation']
});

test('it exists', function(assert) {
12 changes: 12 additions & 0 deletions tests/unit/models/translation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';

moduleForModel('translation', 'Unit | Model | translation', {
// Specify the other units that are required for this test.
needs: ['model:flash-card']
});

test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});

0 comments on commit 3655c15

Please sign in to comment.