Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Created August 25, 2017 21:31
Show Gist options
  • Save kumkanillam/4acc114017f5b6aeb9b0125d2aae8d98 to your computer and use it in GitHub Desktop.
Save kumkanillam/4acc114017f5b6aeb9b0125d2aae8d98 to your computer and use it in GitHub Desktop.
report rule test
import Ember from 'ember';
import ReportRule from './../utils/report-rule';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
componentName: true,
reportRules: undefined,
init(){
this._super(...arguments);
this.set('reportRules',[]);
},
actions:{
addRule(){
var filters = this.get('reportRules');
console.log('Ember.isEmpty(filters)',Ember.isEmpty(filters));
if (Ember.isEmpty(filters)) {
filters = [];
let temp={};
temp.id=1;
temp.names=['first'];
filters.pushObject(ReportRule.create(temp));
this.set('reportRules', filters);
} else {
let temp={};
temp.id=filters.length+1;
temp.names=['Next'+temp.id];
filters.pushObject(ReportRule.create(temp));
}
},
deleteRule(index){
if (this.get('reportRules').length > 0) {
this.get('reportRules').removeAt(index);
// this.get('reportRules').removeObject(index);
}
console.log(' CurrentRules:', this.get('reportRules'));
},
}
});
import Ember from 'ember';
export default Ember.Service.extend({
serviceName:'My-Service',
});
<h1>Welcome to {{appName}}</h1>
{{#if componentName}}
Hi
{{/if}}
<br>
{{#each reportRules as |filter index|}}
{{log ' filter ' filter}}
{{filter.id}} {{get filter.names '0'}}<button {{action 'deleteRule' index}}> Del</button>
{{/each}}
<br>
<button {{action 'addRule'}}> Add </button>
{{outlet}}
<br>
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
import Ember from 'ember';
export default Ember.Object.extend({
myService:Ember.inject.service(),
id:'',
names:[],
init(){
this._super(...arguments);
console.log(' arg ',this.get('myService'),' name ',this.get('myService.serviceName'));
//this.set('names',['init']);
//this.set('names',[]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment