Skip to content

Commit

Permalink
Updating from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
superlou committed Nov 10, 2018
1 parent 24e6edb commit 28ce1d2
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 58 deletions.
11 changes: 11 additions & 0 deletions app/components/player-controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Component from '@ember/component';
import { inject } from '@ember/service';
import { computed } from '@ember/object';

export default Component.extend({
player: inject(),

remaining: computed('player.position', 'player.duration', function() {
return this.get('player.duration') - this.get('player.position');
})
});
16 changes: 16 additions & 0 deletions app/helpers/format-seconds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { helper } from '@ember/component/helper';

Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}

export function formatSeconds(raw/*, hash*/) {
let minutes = Math.floor(raw / 60);
let seconds = Math.floor(raw % 60);
let tenths = Math.floor((raw % 1) * 10);
return `${minutes.pad(2)}:${seconds.pad(2)}.${tenths}`;
}

export default helper(formatSeconds);
4 changes: 4 additions & 0 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default Route.extend({
});
32 changes: 32 additions & 0 deletions app/services/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Service from '@ember/service';
import { inject } from '@ember/service';
import { later } from '@ember/runloop';

export default Service.extend({
ajax: inject(),
status: 'unknown',
source: null,
position: null,
duration: null,
volume: null,

update() {
this.get('ajax').request('http://loupi1:8910/api/player').then((result) => {
this.set('status', result.status);
this.set('source', result.source);
this.set('position', result.position);
this.set('duration', result.duration);
this.set('volume', result.volume);
}, (err) => {
this.set('status', 'unknown');
this.set('source', null);
});

later(this, this.update, 100);
},

init() {
this._super();
this.update();
}
});
6 changes: 2 additions & 4 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{!-- The following component displays Ember's default welcome message. --}}
{{welcome-page}}
{{!-- Feel free to remove this! --}}
{{player-controls}}

{{outlet}}
{{outlet}}
5 changes: 5 additions & 0 deletions app/templates/components/player-controls.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{player.status}}
{{player.source}}
{{format-seconds player.position}}
{{format-seconds player.duration}}
{{format-seconds remaining}}
1 change: 1 addition & 0 deletions app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Media</h1>
53 changes: 0 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"ember-qunit": "^3.4.1",
"ember-resolver": "^5.0.1",
"ember-source": "~3.5.0",
"ember-welcome-page": "^3.2.0",
"eslint-plugin-ember": "^5.2.0",
"loader.js": "^4.7.0",
"qunit-dom": "^0.8.0"
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/components/player-controls-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | player-controls', 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`{{player-controls}}`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
{{#player-controls}}
template block text
{{/player-controls}}
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
17 changes: 17 additions & 0 deletions tests/integration/helpers/format-seconds-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Helper | format-seconds', function(hooks) {
setupRenderingTest(hooks);

// Replace this with your real tests.
test('it renders', async function(assert) {
this.set('inputValue', '1234');

await render(hbs`{{format-seconds inputValue}}`);

assert.equal(this.element.textContent.trim(), '1234');
});
});
11 changes: 11 additions & 0 deletions tests/unit/routes/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Route | index', function(hooks) {
setupTest(hooks);

test('it exists', function(assert) {
let route = this.owner.lookup('route:index');
assert.ok(route);
});
});
12 changes: 12 additions & 0 deletions tests/unit/services/player-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Service | player', function(hooks) {
setupTest(hooks);

// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:player');
assert.ok(service);
});
});

0 comments on commit 28ce1d2

Please sign in to comment.