How to use ember-data - 10 common examples

To help you get started, we’ve selected a few ember-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emberjs / data / tests / helpers / store.js View on Github external
}

  registry.register(
    'service:store',
    DS.Store.extend({
      adapter: adapter,
    })
  );

  registry.optionsForType('serializer', { singleton: false });
  registry.optionsForType('adapter', { singleton: false });
  registry.register('adapter:-default', DS.Adapter);

  registry.register('serializer:-default', DS.JSONAPISerializer);
  registry.register('serializer:-json', DS.JSONSerializer);
  registry.register('serializer:-rest', DS.RESTSerializer);

  registry.register('adapter:-rest', DS.RESTAdapter);
  registry.register('adapter:-json-api', DS.JSONAPIAdapter);

  registry.injection('serializer', 'store', 'service:store');

  env.store = container.lookup('service:store');
  env.restSerializer = container.lookup('serializer:-rest');
  env.restSerializer.store = env.store;
  env.serializer = env.store.serializerFor('-default');
  env.serializer.store = env.store;
  // lazily create the adapter method because some tets depend on
  // modifiying the adapter in the container after setupStore is
  // called
  Object.defineProperty(env, 'adapter', {
    get() {
github emberjs / data / tests / helpers / store.js View on Github external
registry.register('model:' + dasherize(prop), options[prop]);
  }

  registry.register(
    'service:store',
    DS.Store.extend({
      adapter: adapter,
    })
  );

  registry.optionsForType('serializer', { singleton: false });
  registry.optionsForType('adapter', { singleton: false });
  registry.register('adapter:-default', DS.Adapter);

  registry.register('serializer:-default', DS.JSONAPISerializer);
  registry.register('serializer:-json', DS.JSONSerializer);
  registry.register('serializer:-rest', DS.RESTSerializer);

  registry.register('adapter:-rest', DS.RESTAdapter);
  registry.register('adapter:-json-api', DS.JSONAPIAdapter);

  registry.injection('serializer', 'store', 'service:store');

  env.store = container.lookup('service:store');
  env.restSerializer = container.lookup('serializer:-rest');
  env.restSerializer.store = env.store;
  env.serializer = env.store.serializerFor('-default');
  env.serializer.store = env.store;
  // lazily create the adapter method because some tets depend on
  // modifiying the adapter in the container after setupStore is
  // called
  Object.defineProperty(env, 'adapter', {
github ember-data / ember-data-filter / tests / test-helper.js View on Github external
QUnit.begin(() => {
  RSVP.configure('onerror', reason => {
    // only print error messages if they're exceptions;
    // otherwise, let a future turn of the event loop
    // handle the error.
    if (reason && reason instanceof Error) {
      throw reason;
    }
  });

  // Prevent all tests involving serialization to require a container
  DS.JSONSerializer.reopen({
    transformFor(attributeType) {
      return this._super(attributeType, true) || transforms[attributeType];
    }
  });

});
github apache / ambari / contrib / views / files / src / main / resources / ui / app / adapters / application.js View on Github external
* with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import DS from 'ember-data';
import Ember from 'ember';
import ENV from 'files-view/config/environment';

export default DS.RESTAdapter.extend({
  init: function () {
    Ember.$.ajaxSetup({
      cache: false
    });
  },

  namespace: Ember.computed(function() {
    var parts = window.location.pathname.split('/').filter(function(i) {
      return i !== "";
    });
    var view = parts[parts.length - 3];
    var version = '/versions/' + parts[parts.length - 2];
    var instance = parts[parts.length - 1];

    if (!/^(\d+\.){2,3}\d+$/.test(parts[parts.length - 2])) { // version is not present
      instance = parts[parts.length - 2];
github 7cart / 7cart / front / app / adapters / application.js View on Github external
import DS from 'ember-data';
import config from 'front/config/environment';
import { isPresent } from '@ember/utils';
import { computed } from '@ember/object';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import { inject as service } from '@ember/service';
import FastbootAdapter from 'ember-data-storefront/mixins/fastboot-adapter';

export default DS.JSONAPIAdapter.extend(DataAdapterMixin, FastbootAdapter, {
  fastboot: service(),
  host: computed('fastboot.isFastBoot', function() {
    let fastboot = this.fastboot;

    if (fastboot.isFastBoot) {
      // docker network alias
      return config.APP.backendDockerHost;
    } else {
      return config.APP.backendHost;
    }
  }),
  namespace: config.APP.backendNamespace,
  init() {
    this._super(...arguments);
    this.headers = {
      'Accept-Language':'en'
github mgenev / how-to-sane / client / app / models / event.js View on Github external
import DS from 'ember-data';

export default DS.Model.extend({
    // relationships
    vendor: DS.belongsTo('vendor'),
    users: DS.hasMany('user'),

    // attributes
    title: DS.attr('string'),
    date: DS.attr('date'),
    tags: DS.attr('array')
});
github HospitalRun / hospitalrun-frontend / app / models / visit.js View on Github external
function paymentStateAcceptance(object) {
  return !Object.keys(PAYMENT_STATES)
    .some((state) => PAYMENT_STATES[state] === object.get('paymentState'));
}

export default AbstractModel.extend({
  // Attributes
  customForms: DS.attr('custom-forms'),
  dischargeInfo: DS.attr('string'),
  endDate: DS.attr('date'), // if visit type is outpatient, startDate and endDate are equal
  examiner: DS.attr('string'),
  hasAppointment: DS.attr('boolean', { defaultValue: false }),
  history: DS.attr('string'), // No longer used
  historySince: DS.attr('string'), // History of the Present Illness -- no longer used
  location: DS.attr('string'),
  notes: DS.attr('string'), // this field is being deprecated in favor of patient-note
  outPatient: DS.attr('boolean'),
  paymentState: DS.attr('string', { defaultValue: PAYMENT_STATES.PENDING }),
  primaryDiagnosis: DS.attr('string'), // No longer used -- diagnoses are stored in diagnoses hasMany relationship
  primaryBillingDiagnosis: DS.attr('string'), // AKA final diagnosis
  primaryBillingDiagnosisId: DS.attr('string'),
  reasonForVisit: DS.attr('string'),
  startDate: DS.attr('date'),
  status: DS.attr('string'),
  visitType: DS.attr(),

  // Associations
  charges: DS.hasMany('proc-charge', { async: false }),
  diagnoses: DS.hasMany('diagnosis', { async: false }),
  imaging: DS.hasMany('imaging', { async: true }),
  labs: DS.hasMany('lab', { async: true }),
github givanse / mvc-tree / app / models / grid-node.js View on Github external
col: Ember.computed('column', function() {
    return this.get('column.col');
  }),

  template: DS.attr('string'),

  x: DS.attr('number'),
  y: DS.attr('number'),
  x_padded: DS.attr('number'),
  y_padded: DS.attr('number'),
  rx: DS.attr('number'),
  ry: DS.attr('number'),
  cx: DS.attr('number'),
  cy: DS.attr('number'),
  width: DS.attr('number'),
  height: DS.attr('number'),

  svgenv: Ember.inject.service('svg-environment'),

  _addNodeValues: Ember.on('ready', function() {
    var svgenv = this.get('svgenv');

    if ( ! svgenv ) {
      throw new Ember.Error('svgenv has not been injected yet');
    }

    // TODO: use uppercase names for absolute values

    // x
    this.set('x', this.get('col') * svgenv.get('colW'));
    this.set('x_padded', svgenv.get('paddingL') + this.get('x'));
    this.set('cx', this.get('x') + (svgenv.get('colW') / 2));
github elwayman02 / ember-data-github / addon / models / github-repository.js View on Github external
cloneUrl: attr('string'),
  gitUrl: attr('string'),
  sshUrl: attr('string'),
  svnUrl: attr('string'),

  // Urls
  archiveUrl: attr('string'),
  assigneesUrl: attr('string'),
  blobsUrl: attr('string'),
  branchesUrl: attr('string'),
  collaboratorsUrl: attr('string'),
  commentsUrl: attr('string'),
  commitsUrl: attr('string'),
  compareUrl: attr('string'),
  contentsUrl: attr('string'),
  contributorsUrl: attr('string'),
  deploymentsUrl: attr('string'),
  downloadsUrl: attr('string'),
  eventsUrl: attr('string'),
  forksUrl: attr('string'),
  gitCommitsUrl: attr('string'),
  gitRefsUrl: attr('string'),
  gitTagsUrl: attr('string'),
  hooksUrl: attr('string'),
  htmlUrl: attr('string'),
  issueCommentUrl: attr('string'),
  issueEventsUrl: attr('string'),
  issuesUrl: attr('string'),
  keysUrl: attr('string'),
  labelsUrl: attr('string'),
  mergesUrl: attr('string'),
github noironetworks / aci-containers / vendor / github.com / hashicorp / consul / ui-v2 / app / models / service.js View on Github external
Meta: attr(),
  Address: attr('string'),
  TaggedAddresses: attr(),
  Port: attr('number'),
  EnableTagOverride: attr('boolean'),
  CreateIndex: attr('number'),
  ModifyIndex: attr('number'),
  // TODO: These should be typed
  ChecksPassing: attr(),
  ChecksCritical: attr(),
  ChecksWarning: attr(),
  Nodes: attr(),
  Datacenter: attr('string'),
  Node: attr(),
  Service: attr(),
  Checks: attr(),
  SyncTime: attr('number'),
  meta: attr(),
  passing: computed('ChecksPassing', 'Checks', function() {
    let num = 0;
    // TODO: use typeof
    if (get(this, 'ChecksPassing') !== undefined) {
      num = get(this, 'ChecksPassing');
    } else {
      num = get(get(this, 'Checks').filterBy('Status', 'passing'), 'length');
    }
    return {
      length: num,
    };
  }),
  hasStatus: function(status) {
    let num = 0;