Skip to content

Instantly share code, notes, and snippets.

@jphager2
Last active April 14, 2016 11:59
Show Gist options
  • Save jphager2/947422588f494104f89fdaf8e569ea84 to your computer and use it in GitHub Desktop.
Save jphager2/947422588f494104f89fdaf8e569ea84 to your computer and use it in GitHub Desktop.
Component Example
import Ember from 'ember';
export default Ember.Component.extend({
activityAction: Ember.computed('m.state', function() {
const states = ["a", "b", "c", "d", "e", "f"];
let activity = this.get('m');
let state = activity.get('state');
let index = states.indexOf(state);
var path = null;
var text = null;
if (index === 0) { // To Approve
path = "index";
text = "Schválit případ";
} else if (index === 1) { // More Info
path = "index";
text = "Poskytovat více informací";
} else if (index === 2) { // To Submit
path = "index";
text = "Dokončit případ";
} else if (index === 5) { // To Confirm
path = "index";
text = "Potvrdí aktivitu";
}
return { path: path, text: text };
}),
shouldDisplay: Ember.computed('m.state', function() {
return this.get("path");
}),
path: Ember.computed('m.state', function() {
return this.get("activityAction.path");
}),
text: Ember.computed('m.state', function() {
return this.get("activityAction.text");
}),
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Component Example',
activities: [
Ember.Object.create({ name: "A", state: "a" }),
Ember.Object.create({ name: "B", state: "b" }),
Ember.Object.create({ name: "C", state: "c" }),
Ember.Object.create({ name: "D", state: "d" }),
Ember.Object.create({ name: "E", state: "e" }),
Ember.Object.create({ name: "F", state: "f" }),
],
});
<div class="page-header">
<h1>Activities</h1>
</div>
{{outlet}}
<br>
<br>
{{#each activities as |activity|}}
{{ activity-state-action m=activity }}
{{/each}}
{{#if shouldDisplay}}
{{#link-to path class="btn btn-success btn-sm active" }}
{{ text }}: {{ m.name }}
{{/link-to}}
{{else}}
{{yield}}
{{/if}}
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment