Last active
January 29, 2016 02:00
-
-
Save Microfed/3385c09ae0772a3e6931 to your computer and use it in GitHub Desktop.
vsi
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'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
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'; | |
export default Ember.Service.extend({ | |
cachedCommands: {}, | |
fetchCommandsByHostId(id, force) { | |
return new Ember.RSVP.Promise((resolve, reject) => { | |
let dataFromServer = { commands: ['first', 'second', 'third']}; | |
let data = force ? dataFromServer: this.get('cachedCommands')[id] || dataFromServer; | |
data.hostId = id; | |
resolve(data); | |
}); | |
}, | |
validateCommandsForHost(id, commands) { | |
return new Ember.RSVP.Promise((resolve, reject) => { | |
let evaluation = ['no' + id, 'no', 'no']; | |
let newCommands = { hostId: id, commands: commands, evaluation: evaluation }; | |
this.get('cachedCommands')[id] = newCommands; | |
resolve(newCommands); | |
}); | |
} | |
}); |
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'; | |
let { computed } = Ember; | |
export default Ember.Component.extend({ | |
commands: computed('attrs.data.value.commands.[]', function() { | |
console.log('get commands', this.attrs.data.value.commands); | |
return this.attrs.data.value.commands.join('\n'); | |
}), | |
evaluation: computed('attrs.data.evaluation.[]', function() { | |
let evaluation = this.attrs.data.value.evaluation; | |
return evaluation ? evaluation.join('\n') : null; | |
}), | |
// fix two-way binding in textarea component. TODO: use one-way binding | |
didReceiveAttrs(){ | |
this._super(...arguments); | |
this.set('commands', this.attrs.data.value.commands.join('\n')); | |
}, | |
actions: { | |
validate() { | |
this.attrs.onValidate(this.get('commands').split('\n')); | |
} | |
} | |
}); |
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'; | |
export default Ember.Route.extend({ | |
beforeModel(){ | |
this.transitionTo('vsi.build.hosts'); | |
} | |
}); |
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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: config.locationType | |
}); | |
Router.map(function () { | |
this.route('vsi', function () { | |
this.route('build', function () { | |
this.route('hosts', function () { | |
this.route('host', {path: ':id'}, function () { | |
this.route('commands'); | |
}); | |
}); | |
}); | |
}); | |
}); | |
export default Router; |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.commands-container { | |
margin: 10px; | |
} | |
.commands, .evaluate, .evaluation { | |
display: inline-block; | |
} | |
.commands { | |
width: 200px; | |
} | |
.evaluate { | |
min-width: 100px; | |
vertical-align: middle; | |
} | |
.evaluation { | |
width: 200px; | |
} |
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.5.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"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.2.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js" | |
} | |
} |
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'; | |
export default Ember.Controller.extend({ | |
commands: Ember.inject.service(), | |
hostId: Ember.computed.reads('model.hostId'), | |
actions: { | |
evaluate(commands) { | |
let self = this; | |
return this.get('commands').validateCommandsForHost(this.get('hostId'),commands).then(function(newCommands) { | |
self.set('model', newCommands); | |
}); | |
} | |
} | |
}); |
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'; | |
export default Ember.Route.extend({ | |
commands: Ember.inject.service(), | |
model() { | |
let hostId = this.modelFor(this.routeName.replace('.commands', '')).id; | |
return this.get('commands').fetchCommandsByHostId(hostId); | |
} | |
}); |
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'; | |
export default Ember.Route.extend({ | |
afterModel() { | |
this.transitionTo(this.routeName + '.commands'); | |
} | |
}); |
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'; | |
export default Ember.Route.extend({ | |
model(){ | |
return [{ id: 0, ip: '1.1.1.1' }, { id: 1, ip: '2.2.2.2' }]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment