Skip to content

Instantly share code, notes, and snippets.

@jenweber
Last active October 6, 2018 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jenweber/3fcc2e4e044ae83908031defa0006959 to your computer and use it in GitHub Desktop.
Save jenweber/3fcc2e4e044ae83908031defa0006959 to your computer and use it in GitHub Desktop.
Data management demo
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
term: attr('string'),
url: attr('string'),
definitions: attr()
});
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('ember-data')
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
{
url: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal-seam_gas.aspx",
term: "coal-seam gas",
definitions: [
{
speech_type: "n.",
category: "Geology",
definition: "Natural gas, predominantly methane [CH4], generated during coal formation and adsorbed in coal.",
see: [
{
title: "unconventional resource",
link: "https://www.glossary.oilfield.slb.com/en/Terms/u/unconventional_resource.aspx"
}
],
more_details: [
{
title: "Learning to Produce Coalbed Methane",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/1991/or1991jan04_methane.aspx"
},
{
title: "Producing Natural Gas from Coal",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/2003/or2003aut02_gas_from_coal.aspx"
},
{
title: "Coalbed Methane: Clean Energy for the World",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/2009/or2009sum01_coalbed_methane.aspx"
}
],
synonyms: [
{
title: "coalbed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coalbed_methane.aspx"
},
{
title: "coal bed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal_bed_methane.aspx"
},
{
title: "coal-bed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal-bed_methane.aspx"
},
{
title: "CBM",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/cbm.aspx"
}
],
antonyms: [],
alternate_forms: "coal seam gas, CSG",
image: {
src: "https://www.glossary.oilfield.slb.com/en/Terms/c/en/~/media/PublicMedia/geology/coalbedMethane01.ashx",
caption: "Gas adsorption and desorption in coal. During coalification, the matrix shrinks, creating orthogonal fractures called cleats."
}
}
]
},
]
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
this.store.createRecord('term',
{
url: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal-seam_gas.aspx",
term: "coal-seam gas",
definitions: [
{
speech_type: "n.",
category: "Geology",
definition: "Natural gas, predominantly methane [CH4], generated during coal formation and adsorbed in coal.",
see: [
{
title: "unconventional resource",
link: "https://www.glossary.oilfield.slb.com/en/Terms/u/unconventional_resource.aspx"
}
],
more_details: [
{
title: "Learning to Produce Coalbed Methane",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/1991/or1991jan04_methane.aspx"
},
{
title: "Producing Natural Gas from Coal",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/2003/or2003aut02_gas_from_coal.aspx"
},
{
title: "Coalbed Methane: Clean Energy for the World",
link: "http://www.slb.com/resources/publications/industry_articles/oilfield_review/2009/or2009sum01_coalbed_methane.aspx"
}
],
synonyms: [
{
title: "coalbed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coalbed_methane.aspx"
},
{
title: "coal bed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal_bed_methane.aspx"
},
{
title: "coal-bed methane",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/coal-bed_methane.aspx"
},
{
title: "CBM",
link: "https://www.glossary.oilfield.slb.com/en/Terms/c/cbm.aspx"
}
],
antonyms: [],
alternate_forms: "coal seam gas, CSG",
image: {
src: "https://www.glossary.oilfield.slb.com/en/Terms/c/en/~/media/PublicMedia/geology/coalbedMethane01.ashx",
caption: "Gas adsorption and desorption in coal. During coalification, the matrix shrinks, creating orthogonal fractures called cleats."
}
}
]
}
)
return this.store.peekAll('term')
}
});
<h1>Welcome to {{appName}}</h1>
<br>
{{link-to 'ember-data' 'ember-data'}}
<br>
{{outlet}}
<br>
<br>
{{link-to 'application' 'application'}}
{{#each model as |term|}}
<div>{{term.term}}</div>
{{#each term.definitions as |def|}}
<div>{{def.category}}</div>
{{#each def.see as |see|}}
{{see.title}}
{{/each}}
{{/each}}
{{/each}}
{{#each model as |term|}}
<div>{{term.term}}</div>
{{#each term.definitions as |def|}}
<div>{{def.category}}</div>
{{#each def.see as |see|}}
{{see.title}}
{{/each}}
{{/each}}
{{/each}}
{
"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": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment