Last active
August 2, 2018 11:45
-
-
Save zen-ninja/6a71a1d14df19d49c8ab3817b141644e to your computer and use it in GitHub Desktop.
ember assessment
This file contains 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 fetch from 'fetch'; | |
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Week 1 Ember Assesment' | |
}); |
This file contains 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 { inject } from '@ember/service' | |
export default Ember.Controller.extend({ | |
selectedBreed: null, | |
router: inject(), | |
actions: { | |
selectBreed(parentBreed, subBreed) { | |
let concatBreeds = ''; | |
let breed; | |
concatBreeds = `${parentBreed}-${subBreed}`; | |
if(subBreed === '') { | |
breed = parentBreed; | |
} | |
else { | |
breed = concatBreeds; | |
} | |
this.set('selectedBreed', breed); | |
console.log('selectedBreed: ', this.selectedBreed); | |
this.get('router').transitionTo('gallery', { | |
queryParams: { | |
selectedBreed: breed | |
} | |
}); | |
} | |
} | |
}); |
This file contains 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 {computed} from '@ember/object'; | |
export default Ember.Controller.extend({ | |
queryParams: ['selectedBreed'], | |
images: null, | |
currentIndex: 0, | |
currentImage: computed('images.[]', 'currentIndex', function(){ | |
return this.get('images').objectAt(this.get('currentIndex')); | |
}), | |
isNextEnabled: computed('images.length', 'currentIndex', function() { | |
return this.get('currentIndex') < this.get('images.length') - 1; | |
}), | |
isPreviousEnabled: computed('currentIndex', function() { | |
return this.get('currentIndex') !== 0; | |
}), | |
actions: { | |
showNextImage() { | |
this.incrementProperty('currentIndex'); | |
}, | |
showPrevImage() { | |
this.decrementProperty('currentIndex'); | |
} | |
} | |
}); |
This file contains 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'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: '/' | |
}); | |
Router.map(function() { | |
this.route('breeds', { path: 'breeds' }); | |
this.route('gallery', { path: 'gallery' }); | |
this.route('index', { path: '/' }); | |
}); | |
export default Router; |
This file contains 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 DS from 'ember-data'; | |
import fetch from "fetch"; | |
import Ember from "ember"; | |
const listOfDogBreeds = 'https://dog.ceo/api/breeds/list/all'; | |
export default Ember.Route.extend({ | |
model() { | |
return fetch(listOfDogBreeds).then(function(response) { | |
return response.json(); | |
}); | |
}, | |
setupController(controller, model) { | |
this._super(controller, null); | |
let breeds = [] | |
Object.keys(model.message).forEach( parentBreed => { | |
let breedEntry = {}; | |
breedEntry.title = parentBreed; | |
breedEntry.subBreeds = []; | |
model.message[parentBreed].forEach(subBreed => { | |
breedEntry.subBreeds.push({ | |
title: subBreed | |
}); | |
}); | |
breeds.push(breedEntry); | |
}); | |
controller.set('breeds', breeds); | |
} | |
}); |
This file contains 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 fetch from 'fetch'; | |
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model(params) { | |
var url = `https://dog.ceo/api/breed/${params.selectedBreed}/images`; | |
var dogName = params.selectedBreed; | |
return fetch(url).then(function(response) { | |
return response.json(); | |
}); | |
}, | |
setupController(controller, model) { | |
this._super(controller, null); | |
controller.set('images', model.message); | |
controller.set('dog', model.dogName); | |
} | |
}); |
This file contains 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({ | |
}); |
This file contains 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.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0", | |
"ember-fetch": "5.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment