Skip to content

Commit

Permalink
add level button with initial behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyknown committed Dec 18, 2015
1 parent 6aacdc0 commit 49fd740
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ember from 'ember';

export default Ember.Controller.extend({
isOn: null
isOn: null,
level: null
});
22 changes: 19 additions & 3 deletions app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import Ember from 'ember';

export default Ember.Route.extend({
levels: [1,2,3,4],

setupController(controller) {
controller.set('isOn', false);
},

actions: {
turnOn() {
this.controllerFor('application').set('isOn', true);
this.set('isOn', true);
const c = this.controllerFor('application');
c.set('isOn', true);
c.set('level', this.get('levels').objectAt(0));
},
turnOff() {
this.controllerFor('application').set('isOn', false);
const c = this.controllerFor('application');
c.set('isOn', false);
},
nextLevel() {
if (this.controllerFor('application').get('isOn')) {
const c = this.controllerFor('application');
const level = c.get('level');
const levelIndex = this.get('levels').indexOf(level);
const nextLevel = this.get('levels').objectAt(
(levelIndex + 1) % this.get('levels').length
);
c.set('level', nextLevel);
}
}
}
});
5 changes: 5 additions & 0 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div id="display">
{{#if isOn}}
ON
{{level}}
{{else}}
OFF
{{/if}}
Expand All @@ -13,3 +14,7 @@
<button {{action 'turnOn'}}>
ON
</button>

<button {{action 'nextLevel'}}>
LEVEL
</button>

0 comments on commit 49fd740

Please sign in to comment.