Example #1
0
test("belongsTo supports relationships to models with id 0", function(assert) {
  assert.expect(5);

  var Tag = DS.Model.extend({
    name: DS.attr('string'),
    people: DS.hasMany('person', { async: false })
  });
  Tag.toString = function() { return "Tag"; };

  var Person = DS.Model.extend({
    name: DS.attr('string'),
    tag: DS.belongsTo('tag', { async: false })
  });

  var env = setupStore({ tag: Tag, person: Person });
  var store = env.store;
  env.adapter.shouldBackgroundReloadRecord = () => false;

  run(function() {
    store.push({
      data: [{
        type: 'tag',
        id: '0',
        attributes: {
          name: 'friendly'
        }
      }, {
        type: 'tag',
        id: '2',
        attributes: {
          name: 'smarmy'
        }
      }, {
        type: 'tag',
        id: '12',
        attributes: {
          name: 'oohlala'
        }
      }, {
        type: 'person',
        id: '1',
        attributes: {
          name: 'Tom Dale'
        },
        relationships: {
          tag: {
            data: { type: 'tag', id: '0' }
          }
        }
      }]
    });
  });

  run(function() {
    store.findRecord('person', 1).then(assert.wait(function(person) {
      assert.equal(get(person, 'name'), "Tom Dale", "precond - retrieves person record from store");

      assert.equal(get(person, 'tag') instanceof Tag, true, "the tag property should return a tag");
      assert.equal(get(person, 'tag.name'), "friendly", "the tag should have name");

      assert.strictEqual(get(person, 'tag'), get(person, 'tag'), "the returned object is always the same");
      assert.asyncEqual(get(person, 'tag'), store.findRecord('tag', 0), "relationship object is the same as object retrieved directly");
    }));
  });
});
import DS from 'ember-data';

/**
 * A location to use in the openweather.org api
 */
var Location = DS.Model.extend({
    name: DS.attr(),
    country: DS.attr(),
    scale: DS.attr('string', {defaultValue: 'F'}),
    scope: DS.attr('number', {defaultValue: 5}),
    lat: DS.attr('number', {defaultValue: null}),
    lon: DS.attr('number', {defaultValue: null}),
    isValid: function(){
        return (
            this.get('name') !== null &&
            this.get('name') !== '' &&
            this.get('country') !== null &&
            this.get('country') !== '' &&
            this.get('lat') !== null &&
            this.get('lon') !== null
        );
    }.observes('name','country','lat','lon')
});
/**
 * Never got this working to try with fixtures. Something to do with using local storage
 */
Location.reopenClass({
    FIXTURES: [
        {id: 1, name: 'Milwaukee', country: 'WI', scale: 'F', scope: 5, lon: -87.91, lat:43.04},
        {id: 2, name: 'Chicago, IL', country: 'IL', scale: 'F', scope: 14, lon :-87.63, lat :41.88},
        {id: 3, name: 'London, GB', country: 'GB', scale: 'C', scope: 5, lon:-0.13, lat:51.51}
Example #3
0
import DS from 'ember-data';
import { belongsTo } from 'ember-data/relationships';
import Faker from 'faker';

export default DS.Model.extend({
    title: DS.attr('string'),
    releaseYear: DS.attr('date'),
    //library: DS.belongsTo('library'),
    //author: DS.belongsTo('author')

    author: DS.belongsTo('author', {inverse: 'books', async: true}),
    library: DS.belongsTo('library', {inverse: 'books', async: true}),

    randomize(author, library) {
        this.set('title', this._bookTitle());
        this.set('author', author);
        this.set('releaseYear', this._randomYear());
        this.set('library', library);

        return this;
    },

    _bookTitle() {
        return `${Faker.commerce.productName()} Cookbook`;
    },

    _randomYear() {
        return new Date(this._getRandomArbitrary(1900, 2015));
    },

    _getRandomArbitrary(min, max) {
import DS from 'ember-data';

export default DS.Model.extend({
  reviewer: DS.attr(),
  review: DS.attr(),
  rating: DS.attr(),
  restaurant: DS.belongsTo('restaurant', { async: true})
});
Example #5
0
import DS from 'ember-data';

export default DS.Model.extend({
  user: DS.hasMany('user'),

  text: DS.attr('string'),

  state: DS.attr('boolean', {
    defaultsValue: false
  }),

  products: DS.belongsTo('product'),

  services: DS.belongsTo('service')
});
  order: {
    description: 'Order',
    validators: [
      validator('ds-error'),
      validator('belongs-to'),
      validator('presence', true)
    ]
  },
  line: {
    description: 'Order Line',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  questions: {
    description: 'Order Selection Questions',
    validators: [
      validator('ds-error'),
      validator('has-many'),
      validator('length', {
        min: 1
      })
    ]
  }
});

export default DS.Model.extend(Validations, {
  order: DS.belongsTo('order', { async: true }),
  line: DS.belongsTo('order-line', { async: true }),
  questions: DS.hasMany('order-selection-question', { async: true }),
  quantity: DS.attr('number')
});
Example #7
0
import DS from 'ember-data';

export default DS.Model.extend({
  user: DS.attr(),
  answer: DS.attr(),
  date: DS.attr(),
  rating: DS.attr(),
  question: DS.belongsTo('question', {async: true})
});
Example #8
0
import DS from 'ember-data';

export default DS.Model.extend({
  user: DS.attr(),
  date: DS.attr(),
  title: DS.attr(),
  body: DS.attr()
});
Example #9
0
import DS from 'ember-data';

export default DS.Model.extend({
  code:    DS.attr('string'),
  type:    DS.attr('string'),
  number:  DS.attr('string'),
  matters: DS.hasMany('matter')
});

import DS from 'ember-data';
import Ember from 'ember';
import { formatUtcTimestamp } from '../helpers/format-utc-timestamp';

export default DS.Model.extend({
  // properties
  certificateBody: DS.attr('string'),
  privateKey: DS.attr('string'),
  commonName: DS.attr('string'),
  issuerCountry: DS.attr('string'),
  issuerOrganization: DS.attr('string'),
  issuerWebsite: DS.attr('string'),
  issuerCommonName: DS.attr('string'),
  subjectCountry: DS.attr('string'),
  subjectState: DS.attr('string'),
  subjectLocale: DS.attr('string'),
  subjectOrganization: DS.attr('string'),
  createdAt: DS.attr('iso-8601-timestamp'),
  notBefore: DS.attr('iso-8601-timestamp'),
  notAfter: DS.attr('iso-8601-timestamp'),

  // relationships
  stack: DS.belongsTo('stack', {async: true}),
  operations: DS.hasMany('operation', {async:true}),
  vhosts: DS.hasMany('vhost', {async:true}),
  apps: DS.hasMany('app', {async:true}),

  inUse: Ember.computed.gt('vhosts.length', 0),
  name: Ember.computed('commonName', 'notBefore', 'notAfter', 'issuerOrganization', function() {
    const cn = this.get('commonName');
    const startDate = formatUtcTimestamp(this.get('notBefore'), true);
Example #11
0
import DS from 'ember-data';

export default DS.Model.extend({
  createdAt:   DS.attr('date'),
  description: DS.attr('string'),
  friend:      DS.belongsTo('friend'),
  notes:       DS.attr('string'),
  state:       DS.attr('string', {
    defaultValue: 'borrowed'
  })
});
import DS from 'ember-data';

export default DS.Model.extend({

  countries: DS.attr('array'),

  description: DS.attr('string'),
  expiration_date: DS.attr('string'),
  industries: DS.attr('array'),
  ita_industries: DS.attr('array'),
  report_type: DS.attr('string'),
  title: DS.attr('string'),
  url: DS.attr('string'),

  searchResultHeader: function() {
    return this.get('title');
  }.property('title')
});
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.


import DS from 'ember-data';


var Immunization = DS.Model.extend({
    identifier: DS.hasMany('identifier', {embedded: true}),
    status: DS.attr('string'),
    date: DS.attr('date'),
    vaccineCode: DS.belongsTo('codeable-concept', {embedded: true}),
    patient: DS.belongsTo('reference', {embedded: true}),
    wasNotGiven: DS.attr('boolean'),
    reported: DS.attr('boolean'),
    performer: DS.belongsTo('reference', {embedded: true}),
    requester: DS.belongsTo('reference', {embedded: true}),
    encounter: DS.belongsTo('reference', {embedded: true}),
    manufacturer: DS.belongsTo('reference', {embedded: true}),
    location: DS.belongsTo('reference', {embedded: true}),
    lotNumber: DS.attr('string'),
    expirationDate: DS.attr('date'),
    site: DS.belongsTo('codeable-concept', {embedded: true}),
    route: DS.belongsTo('codeable-concept', {embedded: true}),
    doseQuantity: DS.belongsTo('quantity', {embedded: true}),
import DS from 'ember-data';

export default DS.Model.extend({
    candidates: DS.hasMany('candicharge', {async: true}),

  	votes: DS.attr('string'),
  	percent: DS.attr('string'),
    politicalForce: DS.belongsTo('political-force', {async: true}),

  	//Legislative
  	assemblyman: DS.hasOneFragment('vote', { defaultValue: { votes: 0, percent: 0, positions: 0 } }),
  	diputies: DS.hasOneFragment('vote', { defaultValue: { votes: 0, percent: 0, positions: 0 } }),
  	senators: DS.hasOneFragment('vote', { defaultValue: { votes: 0, percent: 0, positions: 0 } }),

  	//Referendum
  	proposal: DS.attr('string'),
  	positiveVotes: DS.hasOneFragment('vote', { defaultValue: { votes: 0, percent: 0, positions: 0 } }),
  	negativeVotes: DS.hasOneFragment('vote', { defaultValue: { votes: 0, percent: 0, positions: 0 } }),

  	//Legislative
  	provinceStatuses: DS.hasMany('province-status', {async: true}),

    votesCount: Ember.computed('votes', function () {
      if (this.get('assemblyman').get('votes') > 0) {
        return parseInt(this.get('assemblyman').get('votes'));
      } else {
        if (this.get('diputies').get('votes') > 0) {
          return parseInt(this.get('diputies').get('votes'));
        } else {
          if (this.get('senators').get('votes') > 0) {
            return parseInt(this.get('senators').get('votes'));
Example #15
0
import DS from 'ember-data';

var User = DS.Model.extend({
    name: DS.attr('string'),
    dob: DS.attr('date')
});

User.reopenClass({
    FIXTURES: [{
        id: 1,
        name: 'Johnny Jameson',
        dob: 534211200
    }, {
        id: 2,
        name: 'James Johnson',
        dob: 534241200
    }]
});

export default User;
Example #16
0
import DS from 'ember-data';

var Division = DS.Model.extend({
  name: DS.attr( 'string' )
});

Division.reopenClass({
  FIXTURES: [
    { id: 1, name: 'A' },
    { id: 2, name: 'B' },
    { id: 3, name: 'BB' }
  ]
});

export default Division;
Example #17
0
import DS from 'ember-data';
 
var entry = DS.Model.extend({
  date: DS.attr('string'),
    title: DS.attr('string'),
    url: DS.attr('string'),
    description:DS.attr('string')
});
 
export default entry;
import DS from 'ember-data';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  type: {
    description: 'Order Line Type',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  order: {
    description: 'Order',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  selections: {
    description: 'Order Selections',
    validators: [
      validator('ds-error'),
      validator('has-many'),
      validator('presence', true)
    ]
  }
});

export default DS.Model.extend(Validations, {
  order: DS.belongsTo('order', { async: true }),
  selections: DS.hasMany('order-selection', { async: true }),
  type: DS.attr('string')
});
Example #19
0
import DS from 'ember-data';

export default DS.Model.extend({
  fieldName: DS.attr('string'),
  xOrigin: DS.attr('string'),
  yOrigin: DS.attr('string')
});
import DS from 'ember-data';

var ContractTermComponent = DS.Model.extend({
    identifier: DS.belongsTo('identifier', {embedded: true}),
    issued: DS.attr('date'),
    applies: DS.belongsTo('period', {embedded: true}),
    type: DS.belongsTo('codeable-concept', {embedded: true}),
    subType: DS.belongsTo('codeable-concept', {embedded: true}),
    subject: DS.belongsTo('reference', {embedded: true}),
    action: DS.hasMany('codeable-concept', {embedded: true}),
    actionReason: DS.hasMany('codeable-concept', {embedded: true}),
    actor:  DS.hasMany('contract-term-actor-component', {embedded: true}),
    text: DS.attr('string'),
    valuedItem:  DS.hasMany('contract-term-valued-item-component', {embedded: true}),
    group: DS.hasMany('contract-term-component', {embedded: true})
});
export default ContractTermComponent;
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  address: DS.attr('string'),
  phone: DS.attr('string'),
  reviews: DS.hasMany('review', {async: true})
});
import DS from 'ember-data';
import { computed } from '@ember/object';

export default DS.Model.extend({
	session: DS.belongsTo('brewing-session'),
	recipeEntry: DS.belongsTo('mash-recipe-entry'),
	weight: DS.attr('number'),
	amount: computed('weight', 'session.totalMaltWeight', function () {
		return this.get('weight') / this.get('session.totalMaltWeight') * 100;
	}),
	weightedExtract: computed('amount', 'recipeEntry.ingredient.extractYield', function () {
		return this.get('recipeEntry.ingredient.extractYield') * (this.get('amount') / 100);
	}),
});
import DS from 'ember-data';
import Ember from 'ember';

export default DS.Model.extend({
  name: DS.attr('string'),
  artistId: DS.attr('number'),
  phone: DS.attr('string'),
  email: DS.attr('string'),
  dateOnWaitingList: DS.attr('date'),
  status: DS.attr('number'),
  local: DS.attr('boolean'),
  location: DS.attr('string'),
  credit: DS.attr('string'),
  want: DS.attr('string'),
  notes: DS.attr('string'),

  statusText: Ember.computed('status', function() {
    switch (this.get('status')) {
      case 1:
        return "Ongoing";
      case 2:
        return "Waiting";
      case 3:
        return "Finished";
      case 4:
        return "On Hold";
    }
  }),

  formattedDateOnWaitingList: Ember.computed('dateOnWaitingList', function() {
    var date = this.get('dateOnWaitingList');
Example #24
0
import DS from 'ember-data';

export default DS.Model.extend({
  cart: DS.belongsTo('cart'),
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  street: DS.attr('string'),
  zip: DS.attr('number'),
  city: DS.attr('string'),
  phone: DS.attr('string'),
  email: DS.attr('string')
});
//       endorse or promote products derived from this software without specific
//       prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.


import DS from 'ember-data';


var Order = DS.Model.extend({
    identifier: DS.hasMany('identifier', {embedded: true}),
    date: DS.attr('date'),
    subject: DS.belongsTo('reference', {embedded: true}),
    source: DS.belongsTo('reference', {embedded: true}),
    target: DS.belongsTo('reference', {embedded: true}),
    reasonCodeableConcept: DS.belongsTo('codeable-concept', {embedded: true}),
    reasonReference: DS.belongsTo('reference', {embedded: true}),
    when:  DS.belongsTo('order-when-component', {embedded: true}),
    detail: DS.hasMany('reference', {embedded: true})
});
export default Order;
Example #26
0
/* global Ember */
import DS from 'ember-data';
import config from '../config/environment';

export default DS.Model.extend({
  filename: DS.attr('string'),
  type: DS.attr('string'),

  path: Ember.computed('id', function(){
    return config.staticHostURL + this.get('id');
  }),

  extension: Ember.computed('filname', function(){
    let filename = this.get('filename');
    let ext = filename.replace(/.*\./, '');
    return ext;
  }),

  isImage: Ember.computed('filname', function(){
    let filename = this.get('filename');
    let ext = filename.replace(/.*\./, '');
    return ['jpg', 'gif', 'png', 'svg', 'tif'].any(function(type){
      return type === ext;
    });
  }),

  parent: Ember.computed('id', function(){
    return this.get('id').substr(0, this.get('id').lastIndexOf("/"));
  })

});
Example #27
0
var get = Ember.get;
var Post, Comment, Misc, env;
var run = Ember.run;

module("integration/client_id_generation - Client-side ID Generation", {
  beforeEach() {
    Comment = DS.Model.extend({
      post: DS.belongsTo('post', { async: false })
    });

    Post = DS.Model.extend({
      comments: DS.hasMany('comment', { async: false })
    });

    Misc = DS.Model.extend({
      foo: DS.attr('string')
    });

    env = setupStore({
      post: Post,
      comment: Comment,
      misc: Misc
    });
  },

  afterEach() {
    run(env.container, 'destroy');
  }
});

test("If an adapter implements the `generateIdForRecord` method, the store should be able to assign IDs without saving to the persistence layer.", function(assert) {
Example #28
0
import DS from 'ember-data';

var Gallery = DS.Model.extend({
    title: DS.attr('string'),
    img: DS.attr('string'),
    lng: DS.attr('number'),
    lat: DS.attr('number'),
	desc: DS.attr('string'),
	isFavorite: DS.attr('boolean')
});

export default Gallery;
Example #29
0
import DS from 'ember-data';

export default DS.Model.extend({
  // last_login: DS.attr('date')
  // is_superuser: DS.attr('boolean'),
  // first_name: DS.attr('string'),
  // last_name: DS.attr('string'),
  // is_staff: DS.attr('boolean'),
  // is_active: DS.attr('boolean')
  // date_joined: DS.attr('date'),
  username: DS.attr('string'),
  email: DS.attr('string')
});

/*
  PRIMARY KEY: id
  UNIQUE KEY: username
*/

// class Profile(models.Model):
//     user = models.OneToOneField(User)
//     agency = models.ForeignKey(Agency)
//     higher_up = models.ForeignKey('self', blank=True, null=True)
//     LANGS = (
//         ('en', 'English'),
//         ('es', 'Spanish'),
//     )
//     language = models.CharField(max_length=2,choices=LANGS)

//     TYPES = (
//         ('P', 'Participant'),
Example #30
0
import DS from 'ember-data';

export default DS.Model.extend({
  author: DS.attr(),
  text: DS.attr(),
  product: DS.belongsTo('product', { async: true }),
  rating: DS.attr()
});