Last active
February 22, 2019 08:41
-
-
Save dnatochy/db81c18150886376e04be313bd392384 to your computer and use it in GitHub Desktop.
TestingEmberObjects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import Apk from '../models/apk'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init(){ | |
var object = { | |
category: 'Crazy', | |
status: 'LIVE', | |
deviceCompatibility: ['P5','P61','P61B'] | |
}; | |
this.set('apk', Apk.objectToEmber(object)); | |
//console.log(Apk.emberToObject(Apk.objectToEmber(object))); | |
}, | |
actions: { | |
updateCompat: function (model) { | |
//window.alert('hi'); | |
model.toggleProperty('selected'); console.log(this.get('apk.deviceCompatibility').map(x=>x.selected)); | |
//console.log(model); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import EmberObject from '@ember/object'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
var Apk = Ember.Object.extend({ | |
}); | |
const constants = { | |
hardware: { | |
P61: 'P61', | |
P5: 'P5', | |
P61B: 'P61B' | |
} | |
}; | |
const hardwareLabels = { | |
P61: 'POYNT_SMART_TERMINAL_V1', | |
P61B: 'POYNT_SMART_TERMINAL_V2', | |
P5: 'POYNT5' | |
}; | |
Apk.reopenClass({ | |
objectToEmber: function (object) { | |
if(object.deviceCompatibility){ | |
console.log('inside objectToEmber'); | |
console.log('object.deviceCompat: ' + JSON.stringify(object.deviceCompatibility)); | |
object.deviceCompatibility = Ember.ArrayProxy.create({ | |
content: object.deviceCompatibility.map(function (d) { | |
console.log('inside map: '); | |
console.log(d); | |
var returnValue = { | |
model: d, | |
label: hardwareLabels[d] | |
}; | |
if (Object.keys(constants.hardware).indexOf(d) !== -1){ | |
returnValue.selected = true; | |
}else { | |
returnValue.selected = false; | |
} | |
console.log(returnValue); | |
return Ember.Object.create(returnValue); | |
}) | |
}); | |
} | |
return Apk.create(object); | |
}, | |
emberToObject: function (version, application){ | |
var object = version instanceof Ember.Object ? version.getProperties( | |
'category', | |
'status' | |
) : version; | |
if (version.get('deviceCompatibility')){ | |
object.deviceCompatibility = version.get('deviceCompatibility').filter(function (element) { | |
//console.log(element.get('selected')); | |
return element.get('selected') === true; | |
}).map(function (element) { | |
return element.get('model'); | |
}); | |
} | |
return object; | |
} | |
}); | |
export default Apk; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.17.2", | |
"ember-template-compiler": "2.17.2", | |
"ember-testing": "2.17.2" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment