Skip to content

Instantly share code, notes, and snippets.

@ashish2199
Last active May 10, 2020 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashish2199/f4b1c91186bcad4d3758179ce5b9111b to your computer and use it in GitHub Desktop.
Save ashish2199/f4b1c91186bcad4d3758179ce5b9111b to your computer and use it in GitHub Desktop.
Quiz
import Component from '@glimmer/component';
export default class extends Component {
}
import Controller from '@ember/controller';
export default Controller.extend({
appName: 'Quiz',
quizStarted:Ember.computed('currentRouteName',function(){
if(this.get('currentRouteName') === 'quiz'){
return false;
}
return true;
}),
});
import DS from 'ember-data';
export default DS.Model.extend({
text: DS.attr('string'),
question: DS.belongsTo('question'),
});
import DS from 'ember-data';
import { computed } from '@ember/object';
export default DS.Model.extend({
text: DS.attr('string'),
options: DS.hasMany('option'),
});
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('quiz');
});
export default Router;
import Route from '@ember/routing/route';
export default Route.extend({
model(){
let option1 = this.store.createRecord('option',{
text:'Mumbai'
})
let option2 = this.store.createRecord('option',{
text:'New Delhi'
})
let option3 = this.store.createRecord('option',{
text:'Chennai'
})
let option4 = this.store.createRecord('option',{
text:'Kolkata'
})
let questionRecord = this.store.createRecord('question',{
text: 'Which is the capital of India ?',
options:[option1,option2,option3,option4]
})
return {question:questionRecord}
}
});
<h1>Welcome to {{this.appName}}</h1>
<br>
{{#if quizStarted}}
{{#link-to 'quiz'}}Start{{/link-to}}
{{else}}
{{#link-to 'index'}}Back{{/link-to}}
{{/if}}
<br>
{{outlet}}
Question : {{q.text}}
<br>
Options :
<br>
{{yield}}
<br>
Answer the question below
<br>
<br>
{{quiz-question q=model.question}}
{
"version": "0.17.0",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-data": "3.16.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment