Forked from emattias/controllers.application\.js
Last active
February 14, 2022 01:27
-
-
Save runspired/ee312c3971326dc26f10c7693febd718 to your computer and use it in GitHub Desktop.
Just use each
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 Controller from '@ember/controller'; | |
import { inject as service } from '@ember/service'; | |
import { action } from '@ember/object'; | |
import { dependentKeyCompat } from '@ember/object/compat'; | |
export default class ApplicationController extends Controller { | |
@service store; | |
appName = 'Ember Twiddle'; | |
constructor(){ | |
super(...arguments) | |
const bRecord = this.store.createRecord('b', { title: 'bRecord', rowOrderPosition: 1 }) | |
const bRecord2 = this.store.createRecord('b', { title: 'bRecord2', rowOrderPosition: 0 }) | |
const bRecord3 = this.store.createRecord('b', { title: 'bRecord3', rowOrderPosition: 2 }) | |
this.aRecord = this.store.createRecord('a', { | |
bRelation: [bRecord, bRecord2, bRecord3] | |
}); | |
} | |
@dependentKeyCompat | |
get bRecords() { | |
const rows = this.aRecord.bRelation.toArray() | |
rows.sort((a, b) => { | |
return a.rowOrderPosition > b.rowOrderPosition ? 1 : -1; | |
}); | |
return rows; | |
} | |
@action | |
bRecordDelete(bRecord) { | |
bRecord.deleteRecord() | |
} | |
@action | |
updatePosition(record, move) { | |
const records = this.bRecords; | |
let start = records.indexOf(record); | |
if (move === -1) { | |
let prev = records[start - 1]; | |
record.rowOrderPosition -= 1; | |
prev.rowOrderPosition += 1; | |
} else { | |
let next = records[start + 1]; | |
record.rowOrderPosition += 1; | |
next.rowOrderPosition -= 1; | |
} | |
} | |
} |
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 { helper } from '@ember/component/helper'; | |
export default helper(function eq(params/*, hash*/) { | |
return params[0] === params[1]; | |
}); |
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 { helper } from '@ember/component/helper'; | |
export default helper(function sum(params/*, hash*/) { | |
return params[0] + params[1]; | |
}); |
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 Model from 'ember-data/model'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
/* | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
*/ | |
export default class extends Model { | |
changeTracker = {only: ['bRelation'], auto: true}; | |
@hasMany('b') bRelation; | |
} |
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 Model, { attr } from '@ember-data/model'; | |
import { recordIdentifierFor } from "@ember-data/store"; | |
export default class extends Model { | |
@attr('string') text; | |
@attr('string') rowOrderPosition; | |
get lid() { | |
return recordIdentifierFor(this).lid; | |
} | |
} |
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 Route from '@ember/routing/route'; | |
export default 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.17.1", | |
"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.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.18.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment