Last active
April 4, 2019 16:52
-
-
Save jasonhofer/1c3c05a196a7ad18975b9c76fe59ac2f to your computer and use it in GitHub Desktop.
CC Certified
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 EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('application.index', {path: '/'}); | |
this.route('dashboard', {path: '/dashboard'}); | |
this.route('certifications', {path: '/programs'}, function () { | |
this.route('my-training-programs', {path: '/my-journey'}, function () { | |
this.route('training.program', {path: '/:program_id', resetNamespace: true}, function () { | |
this.route('level', {path: '/level'}); // "Redirects" to training.program-level | |
this.route('training.program-level', {path: '/level/:level_num', resetNamespace: true}); | |
}); | |
}); | |
}); | |
}); | |
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
import Ember from 'ember'; | |
// This "redirects" '/' to '/dashboard' | |
export default Ember.Route.extend({ | |
beforeModel() { | |
this.replaceWith('dashboard'); | |
}, | |
}); |
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'; | |
// This "redirects" '/programs' to '/programs/my-journey' | |
export default Ember.Route.extend({ | |
beforeModel() { | |
this.replaceWith('certifications.my-training-programs'); | |
}, | |
}); |
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'; | |
// This "redirects" '/programs/my-journey' to '/programs/my-journey/123' | |
// (But only if the user is assigned to a program.) | |
export default Ember.Route.extend({ | |
beforeModel() { | |
const programs = this.modelFor('certifications.my-training-programs'); | |
const primary = programs.filter(program => 'primary' === program.type)[0]; | |
if (primary) { | |
this.replaceWith('training.program', primary.id); | |
} | |
}, | |
}); |
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({ | |
mockStore: Ember.inject.service(), | |
model() { | |
return this.get('mockStore').findAll('program'); | |
}, | |
}); |
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({ | |
mockStore: Ember.inject.service(), | |
model(params) { | |
return this.get('mockStore').findLevelByNum(this.paramsFor('training.program').program_id, params.level_num); | |
}, | |
}); |
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'; | |
// This "redirects" '/programs/my-journey/123' to '/programs/my-journey/123/level' | |
export default Ember.Route.extend({ | |
beforeModel() { | |
this.replaceWith('training.program.level', this.paramsFor('training.program').program_id); | |
}, | |
}); |
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({ | |
mockStore: Ember.inject.service(), | |
model(params) { | |
const program = this.get('mockStore').findRecord('program', params.program_id); | |
Ember.set(program, 'levels', this.get('mockStore').findLevels(program.id)); | |
return program; | |
}, | |
}); |
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'; | |
// This "redirects" '/programs/my-journey/123/level' to '/programs/my-journey/123/level/1' | |
export default Ember.Route.extend({ | |
beforeModel() { | |
const program = this.modelFor('training.program'); | |
this.replaceWith('training.program-level', program.id, program.workingLevelNum || 1); | |
}, | |
}); |
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({ | |
findAll(modelName) { | |
return this.get(modelName); | |
}, | |
findRecord(modelName, id) { | |
return this.get(modelName) | |
.filter(model => model.id === ~~id)[0]; | |
}, | |
findLevels(programId) { | |
return this.get('programLevel').filter(level => level.program === ~~programId); | |
}, | |
findLevelByNum(programId, levelNum) { | |
return this.findLevels(programId).filter(level => level.levelNum === ~~levelNum)[0]; | |
}, | |
program: [ | |
{id: 1, title: 'Program 1', levels: [1,2], type: 'secondary'}, | |
{id: 2, title: 'Program 2', levels: [3,4,5], type: 'primary', workingLevelNum: 2}, | |
], | |
programLevel: [ | |
{id: 1, title: 'Level One', levelNum: 1, program: 1}, | |
{id: 2, title: 'Level Two', levelNum: 2, program: 1}, | |
{id: 3, title: 'Lvl 1', levelNum: 1, program: 2}, | |
{id: 4, title: 'Lvl 2', levelNum: 2, program: 2}, | |
{id: 5, title: 'Lvl 3', levelNum: 3, program: 2}, | |
], | |
}); |
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.13.0", | |
"ember-template-compiler": "2.13.0", | |
"ember-testing": "2.13.0" | |
}, | |
"addons": { | |
"ember-data": "2.13.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment