How to use the ember-data-model-fragments/attributes.fragmentArray function in ember-data-model-fragments

To help you get started, we’ve selected a few ember-data-model-fragments 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 danielspaniel / ember-data-change-tracker / tests / dummy / app / models / user.js View on Github external
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
import {array, fragment, fragmentArray} from 'ember-data-model-fragments/attributes';

export default Model.extend({
  changeTracker: {trackHasMany: true, auto: true, enableIsDirty: true},
  name: attr('string'),
  style: attr('string'),
  // object type
  info: attr('object'),
  blob: attr('json'),
  // fragments
  list: array('number'),
  location: fragment('location'),
  things: fragmentArray('things'),
  // associations
  company: belongsTo('company', { async: true, polymorphic: true }),
  profile: belongsTo('profile', { async: false }),
  projects: hasMany('project', { async: true }),
  pets: hasMany('pet', { async: false, polymorphic: true })
});
github hashicorp / consul / ui / packages / consul-ui / app / models / service-instance.js View on Github external
// unique, non-empty values, alpha sort
    return [...new Set(sources)].filter(Boolean).sort();
  }
};

export default class ServiceInstance extends Model {
  @attr('string') uid;

  @attr('string') Datacenter;
  // ProxyInstance is the ember-data model relationship
  @belongsTo('Proxy') ProxyInstance;
  // Proxy is the actual JSON api response
  @attr() Proxy;
  @attr() Node;
  @attr() Service;
  @fragmentArray('health-check') Checks;
  @attr('number') SyncTime;
  @attr() meta;
  @attr({ defaultValue: () => [] }) Resources; // []

  // The name is the Name of the Service (the grouping of instances)
  @alias('Service.Service') Name;

  // If the ID is blank fallback to the Service.Service (the Name)
  @or('Service.{ID,Service}') ID;
  @or('Service.Address', 'Node.Service') Address;
  @attr('string') SocketPath;

  @alias('Service.Tags') Tags;
  @alias('Service.Meta') Meta;
  @alias('Service.Namespace') Namespace;
github hashicorp / nomad / ui / app / models / node.js View on Github external
migratingAllocations: computed('allocations.@each.{isMigrating,isRunning}', function() {
    return this.allocations.filter(alloc => alloc.isRunning && alloc.isMigrating);
  }),
  lastMigrateTime: computed('allocations.@each.{isMigrating,isRunning,modifyTime}', function() {
    const allocation = this.allocations
      .filterBy('isRunning', false)
      .filterBy('isMigrating')
      .sortBy('modifyTime')
      .reverse()[0];
    if (allocation) {
      return allocation.modifyTime;
    }
  }),

  drivers: fragmentArray('node-driver'),
  events: fragmentArray('node-event'),
  hostVolumes: fragmentArray('host-volume'),

  detectedDrivers: computed('drivers.@each.detected', function() {
    return this.drivers.filterBy('detected');
  }),

  unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() {
    return this.detectedDrivers.filterBy('healthy', false);
  }),

  unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() {
    return this.unhealthyDrivers.mapBy('name');
  }),

  // A status attribute that includes states not included in node status.
  // Useful for coloring and sorting nodes
github jelhan / croodle / app / models / poll.js View on Github external
// polls description
  description: attr('string', {
    defaultValue: ''
  }),

  // ISO 8601 date + time string in UTC
  expirationDate: attr('string', {
    includePlainOnCreate: 'serverExpirationDate'
  }),

  // Must all options been answered?
  forceAnswer: attr('boolean'),

  // array of polls options
  options: fragmentArray('option'),

  // FindADate or MakeAPoll
  pollType: attr('string'),

  // timezone poll got created in (like "Europe/Berlin")
  timezone: attr('string'),

  // polls title
  title: attr('string'),

  // Croodle version poll got created with
  version: attr('string', {
    encrypted: false
  }),

  /*
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / app / models / deployment.js View on Github external
// If any task group is not promoted yet requires promotion and the deployment
  // is still running, the deployment needs promotion.
  requiresPromotion: computed('taskGroupSummaries.@each.promoted', function() {
    return this.status === 'running' &&
    this.taskGroupSummaries
      .toArray()
      .some(summary => summary.get('requiresPromotion') && !summary.get('promoted'));
  }),

  status: attr('string'),
  statusDescription: attr('string'),

  isRunning: equal('status', 'running'),

  taskGroupSummaries: fragmentArray('task-group-deployment-summary'),
  allocations: hasMany('allocations'),

  version: computed('versionNumber', 'job.versions.content.@each.number', function() {
    return (this.get('job.versions') || []).findBy('number', this.versionNumber);
  }),

  // Dependent keys can only go one level past an @each so an alias is needed
  versionSubmitTime: alias('version.submitTime'),

  placedCanaries: sumAggregation('taskGroupSummaries', 'placedCanaries'),
  desiredCanaries: sumAggregation('taskGroupSummaries', 'desiredCanaries'),
  desiredTotal: sumAggregation('taskGroupSummaries', 'desiredTotal'),
  placedAllocs: sumAggregation('taskGroupSummaries', 'placedAllocs'),
  healthyAllocs: sumAggregation('taskGroupSummaries', 'healthyAllocs'),
  unhealthyAllocs: sumAggregation('taskGroupSummaries', 'unhealthyAllocs'),
github hashicorp / nomad / ui / app / models / job-summary.js View on Github external
import { collect, sum } from '@ember/object/computed';
import Model from '@ember-data/model';
import { attr, belongsTo } from '@ember-data/model';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import sumAggregation from '../utils/properties/sum-aggregation';
import classic from 'ember-classic-decorator';

@classic
export default class JobSummary extends Model {
  @belongsTo('job') job;

  @fragmentArray('task-group-summary') taskGroupSummaries;

  // Aggregate allocation counts across all summaries
  @sumAggregation('taskGroupSummaries', 'queuedAllocs') queuedAllocs;
  @sumAggregation('taskGroupSummaries', 'startingAllocs') startingAllocs;
  @sumAggregation('taskGroupSummaries', 'runningAllocs') runningAllocs;
  @sumAggregation('taskGroupSummaries', 'completeAllocs') completeAllocs;
  @sumAggregation('taskGroupSummaries', 'failedAllocs') failedAllocs;
  @sumAggregation('taskGroupSummaries', 'lostAllocs') lostAllocs;

  @collect(
    'queuedAllocs',
    'startingAllocs',
    'runningAllocs',
    'completeAllocs',
    'failedAllocs',
    'lostAllocs'
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / app / models / allocation.js View on Github external
const taskGroups = this.get('job.taskGroups');
    return taskGroups && taskGroups.findBy('name', this.taskGroupName);
  }),

  unhealthyDrivers: computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]', function() {
    const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
    const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');

    if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
      return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
    }

    return [];
  }),

  states: fragmentArray('task-state'),
  rescheduleEvents: fragmentArray('reschedule-event'),

  hasRescheduleEvents: computed('rescheduleEvents.length', 'nextAllocation', function() {
    return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
  }),

  hasStoppedRescheduling: computed(
    'nextAllocation',
    'clientStatus',
    'followUpEvaluation.content',
    function() {
      return (
        !this.get('nextAllocation.content') &&
        !this.get('followUpEvaluation.content') &&
        this.clientStatus === 'failed'
      );
github hashicorp / nomad / ui / app / models / allocation.js View on Github external
@fragment('task-group', { defaultValue: null }) allocationTaskGroup;

  @computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]')
  get unhealthyDrivers() {
    const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
    const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');

    if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
      return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
    }

    return [];
  }

  @fragmentArray('task-state') states;
  @fragmentArray('reschedule-event') rescheduleEvents;

  @computed('rescheduleEvents.length', 'nextAllocation')
  get hasRescheduleEvents() {
    return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
  }

  @computed('clientStatus', 'followUpEvaluation.content', 'nextAllocation.content')
  get hasStoppedRescheduling() {
    return (
      !this.get('nextAllocation.content') &&
      !this.get('followUpEvaluation.content') &&
      this.clientStatus === 'failed'
    );
  }

  stop() {
github hashicorp / nomad / ui / app / models / allocation.js View on Github external
@fragment('task-group', { defaultValue: null }) allocationTaskGroup;

  @computed('taskGroup.drivers.[]', 'node.unhealthyDriverNames.[]')
  get unhealthyDrivers() {
    const taskGroupUnhealthyDrivers = this.get('taskGroup.drivers');
    const nodeUnhealthyDrivers = this.get('node.unhealthyDriverNames');

    if (taskGroupUnhealthyDrivers && nodeUnhealthyDrivers) {
      return intersection(taskGroupUnhealthyDrivers, nodeUnhealthyDrivers);
    }

    return [];
  }

  @fragmentArray('task-state') states;
  @fragmentArray('reschedule-event') rescheduleEvents;

  @computed('rescheduleEvents.length', 'nextAllocation')
  get hasRescheduleEvents() {
    return this.get('rescheduleEvents.length') > 0 || this.nextAllocation;
  }

  @computed('clientStatus', 'followUpEvaluation.content', 'nextAllocation.content')
  get hasStoppedRescheduling() {
    return (
      !this.get('nextAllocation.content') &&
      !this.get('followUpEvaluation.content') &&
      this.clientStatus === 'failed'
    );
  }
github streamlink / streamlink-twitch-gui / src / app / data / models / twitch / ticket / product / fragment.js View on Github external
import attr from "ember-data/attr";
import Fragment from "ember-data-model-fragments/fragment";
import { fragmentArray } from "ember-data-model-fragments/attributes";
import { fragment } from "utils/decorators";


export default class TwitchTicketProduct extends Fragment {
	/** @type {TwitchTicketProductEmoticon[]} */
	@fragmentArray( "twitch-ticket-product-emoticon" )
	emoticons;
	/** @type {TwitchTicketProductFeatures} */
	@fragment( "twitch-ticket-product-features" )
	features;
	@attr( "number" )
	interval_number;
	@attr( "string" )
	name;
	@attr( "string" )
	owner_name;
	@attr( "string" )
	period;
	@attr( "string" )
	price;
	@attr( "boolean" )
	recurring;