ourEvents: computed('mySchedule', 'fromTimeStamp', 'toTimeStamp', 'selectedSchool', 'selectedView', function(){
   if(this.get('mySchedule')) {
     return DS.PromiseArray.create({
       promise: this.get('userEvents').getEvents(this.get('fromTimeStamp'), this.get('toTimeStamp'))
     });
   } else {
     let deferred = RSVP.defer();
     this.get('selectedSchool').then(school => {
       this.get('schoolEvents').getEvents(school.get('id'), this.get('fromTimeStamp'), this.get('toTimeStamp')).then(events => {
         if(this.get('selectedView') === 'day'){
           deferred.resolve(events);
         } else {
           let sessionEvents = {};
           let promises = [];
           events.forEach(event => {
             if(event.name === 'Scheduled'){
               let sid = 'sched' + moment(event.startDate).unix() + moment(event.endDate).unix();
               if(!(sid in sessionEvents)){
                 sessionEvents[sid] = [];
               }
               sessionEvents[sid].pushObject(event);
             }
             else {
               promises.pushObject(this.get('schoolEvents').getSessionForEvent(event).then(session => {
                 let sid = session.get('id') + moment(event.startDate).format() +
                     moment(event.endDate).format();
                 if(!(sid in sessionEvents)){
                   sessionEvents[sid] = [];
                 }
                 sessionEvents[sid].pushObject(event);
               }));
             }
           });
           RSVP.all(promises).then(() => {
             let singleEventPerSessionAndTime = [];
             for(let id in sessionEvents){
               singleEventPerSessionAndTime.pushObject(sessionEvents[id].get('firstObject'));
             }
             deferred.resolve(singleEventPerSessionAndTime);
           });
         }
       });
     });
     return DS.PromiseArray.create({
       promise: deferred.promise
     });
   }
 }),
 function(){
   var defer = Ember.RSVP.defer();
   var self = this;
   var filter = this.get('filter');
   var exp = new RegExp(filter, 'gi');
   var activeGroupFilter = function(learnerGroup) {
     var searchTerm = learnerGroup.get('title') + learnerGroup.get('allParentsTitle');
     return (
       learnerGroup.get('title') !== undefined &&
       self.get('selectedLearnerGroups') &&
       exp.test(searchTerm) &&
       !self.get('selectedLearnerGroups').contains(learnerGroup)
     );
   };
   this.get('content.topLevelLearnerGroups').then(function(cohortGroups){
     let learnerGroups = [];
     var promises = [];
     cohortGroups.forEach(function(learnerGroup){
       learnerGroups.pushObject(learnerGroup);
       var promise = new Ember.RSVP.Promise(function(resolve) {
         learnerGroup.get('allDescendants').then(function(descendants){
           learnerGroups.pushObjects(descendants);
           resolve();
         });
       });
       promises.pushObject(promise);
     });
     Ember.RSVP.all(promises).then(function(){
       defer.resolve(learnerGroups.filter(activeGroupFilter).sortBy('sortTitle'));
     });
   });
   return DS.PromiseArray.create({
     promise: defer.promise
   });
 }
Example #3
0
 allDescendants: computed('children.@each.allDescendants.[]', function(){
   var deferred = Ember.RSVP.defer();
   this.get('children').then(function(learnerGroups){
     var groups = [];
     var promises = [];
     learnerGroups.forEach(function(learnerGroup){
       groups.pushObject(learnerGroup);
       var promise = new Ember.RSVP.Promise(function(resolve) {
         learnerGroup.get('allDescendants').then(function(descendants){
           descendants.forEach(function(descendant){
             groups.pushObject(descendant);
           });
           resolve();
         });
       });
       promises.pushObject(promise);
     });
     Ember.RSVP.all(promises).then(function(){
       deferred.resolve(groups);
     });
   });
   return DS.PromiseArray.create({
     promise: deferred.promise
   });
 }),
Example #4
0
  usersOnlyAtThisLevel: computed('users.[]', 'allDescendants.[]', function(){
    var deferred = Ember.RSVP.defer();
    this.get('users').then(users => {
      this.get('allDescendants').then(descendants => {
        var membersAtThisLevel = [];
        var promises = [];
        users.forEach(user => {
          let promise = user.get('learnerGroups').then(userGroups => {
            var subGroups = userGroups.filter(group => descendants.contains(group));
            if(subGroups.length === 0){
              membersAtThisLevel.pushObject(user);
            }
          });
          promises.pushObject(promise);
        });
        Ember.RSVP.all(promises).then(() => {
          deferred.resolve(membersAtThisLevel.sortBy('fullName'));
        });

      });

    });
    return DS.PromiseArray.create({
      promise: deferred.promise
    });
  }),
test("presence on empty DS.PromiseArray", function(assert) {
  this.register('validator:presence', PresenceValidator);

  var Validations = buildValidations({
    friends: validator('presence', true)
  });

  var user = setupObject(this, Ember.Object.extend(Validations), {
    friends: DS.PromiseArray.create()
  });

  const {
    validations,
    model
  } = user.get('validations').validateSync();

  assert.equal(model, user, 'expected model to be the correct model');
  assert.deepEqual(validations.get('content').getEach('attribute').sort(), ['friends'].sort());

  let friends = validations.get('content').findBy('attribute', 'friends');

  assert.equal(friends.get('isValid'), false);
  assert.equal(friends.get('message'), "This field can't be blank");

});
  eventsWithSelectedCourses: computed('ourEvents.[]', 'selectedCourses.[]', function(){
    let selectedCourses = this.get('selectedCourses').mapBy('id');
    let events = this.get('ourEvents');
    if(selectedCourses.length === 0) {
      return events;
    }
    let matchingEvents = [];
    let defer = RSVP.defer();
    let promises = [];
    events.forEach(event => {
      if (event.ilmEvent || event.offering) {
        promises.pushObject(this.get('userEvents').getCourseIdForEvent(event).then(courseId => {
          if (selectedCourses.contains(courseId)) {
            matchingEvents.pushObject(event);
          }
        }));
      }
    });

    RSVP.all(promises).then(()=> {
      defer.resolve(matchingEvents);
    });
    return DS.PromiseArray.create({
      promise: defer.promise
    });
  }),
    function(){
      var offerings = this.get('offerings');
      if(offerings == null){
        return Ember.A();
      }
      var deferred = Ember.RSVP.defer();
      offerings.then(function(offerings){
        let dateBlocks = {};
        offerings.forEach(function(offering){
          let key = offering.get('dateKey');
          if(!(key in dateBlocks)){
            dateBlocks[key] = OfferingDateBlock.create({
              dateKey: key
            });
          }
          dateBlocks[key].addOffering(offering);

        });
        //convert indexed object to array
        let dateBlockArray = [];
        for(let key in dateBlocks){
          dateBlockArray.pushObject(dateBlocks[key]);
        }
        deferred.resolve(dateBlockArray.sortBy('dateStamp'));
      });
      return DS.PromiseArray.create({
        promise: deferred.promise
      });
    }
 academicYears: computed('allAcademicYears.[]', 'academicYearSelectedByUser', function(){
   return DS.PromiseArray.create({
     promise: this.get('allAcademicYears').then(years => {
       return years.sortBy('title');
     })
   });
 }),
 patientVisitsForSelect: function() {
   return DS.PromiseArray.create({
     promise: this.get('patientVisits').then(function(patientVisits) {
       return patientVisits.map(SelectValues.selectObjectMap);
     })
   });
 }.property('patientVisits.[]'),
  rawFindFromStore: function() {
    var store = this.get('store');
    var modelName = this.get('modelName');
    var parentRecordType = this.get('parentRecordType');
    var parentRecordId = this.get('parentRecordId');
    var ops = this.get('paramsForBackend');
    var res;
    var url;
    var modelPath;
    var IHPromise;

    if( Ember.isEmpty(parentRecordType) || Ember.isEmpty(parentRecordId) ) {
        res = store.find(modelName, ops);
    }
    else {
        var type = store.modelFor(modelName);
        var adapter = store.adapterFor(modelName);
        var recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray(type, ops);
        var serializer = this.IHSerializerForAdapter(adapter, type);
        var label = "DS: PagedRemoteArray Query on hasManyLinks for" + type;
        modelPath = store.adapterFor(parentRecordType).pathForType(modelName);
        url = store.adapterFor(parentRecordType).buildURL(parentRecordType, parentRecordId) + '/' + modelPath;
        IHPromise = this.IHGetJSON(adapter, url, 'GET', ops);
        IHPromise = Ember.RSVP.Promise.cast(IHPromise, label);
        IHPromise = this._IHGuard(IHPromise, this._IHBind(this._IHObjectIsAlive, store));
        IHPromise = this.IHReturnPromise(IHPromise, serializer, type, recordArray, store);
        var promiseArray = DS.PromiseArray.create({
          promise: Ember.RSVP.Promise.resolve(IHPromise, label)
        });
        res = promiseArray;
    }
    return res;
  },
Example #11
0
  _lots: Ember.computed('lots.@each.count', 'lots.@each.valid', function () {
    const promise = this.get('lots').then(lots => {
      return lots.filterBy('valid');
    });

    return DS.PromiseArray.create({
      promise: promise
    });
  }),
Example #12
0
    _items: Ember.computed('items.@each', function () {
      const promise = this.get('items').then(items => {
        return items;
      });

      return DS.PromiseArray.create({
        promise: promise
      });
    }),
Example #13
0
 currentDevDependencies: function() {
     return DS.PromiseArray.create({
         promise: this.get('currentVersion.dependencies').then(function(deps) {
             return deps.filter(function(dep) {
                 return dep.get('kind') === 'dev';
             });
         }),
     });
 }.property('currentVersion.dependencies'),
 allSchools: computed(function(){
   return DS.PromiseArray.create({
     promise: this.get('currentUser.model').then(user => {
       return user.get('schools').then(schools => {
         return schools;
       });
     })
   });
 }),
 sessionTypes: computed('selectedSchool.sessionTypes.[]', 'selectedSessionTypes.[]', function(){
   return DS.PromiseArray.create({
     promise: this.get('selectedSchool').then(school => {
       return school.get('sessionTypes').then( types => {
         return types.sortBy('title');
       });
     })
   });
 }),
Example #16
0
var toPromiseProxy = function(content) {
  var promise = Ember.RSVP.resolve(content);

    if (Ember.isArray(content)) {
      return DS.PromiseArray.create({promise: promise});
    }

    return DS.PromiseObject.create({promise: promise});
};
 topics: computed('selectedSchool.topics.[]', 'selectedTopics.[]', function(){
   return DS.PromiseArray.create({
     promise: this.get('selectedSchool').then(school => {
       return school.get('topics').then( topics => {
         return topics.sortBy('title');
       });
     })
   });
 }),
 patientProcedures: Ember.computed('patientVisits.[]', function() {
   let patient = get(this, 'model.patient');
   return DS.PromiseArray.create({
     promise: get(this, 'patientVisits').then((patientVisits) => {
       return get(patient, 'operationReports').then((operationReports) => {
         return this._getPatientProcedures(operationReports, patientVisits);
       });
     })
   });
 }),
Example #19
0
 currentDevDependencies: computed('currentVersion.dependencies', function() {
     var deps = this.get('currentVersion.dependencies');
     if (deps === null) {
         return [];
     }
     return DS.PromiseArray.create({
         promise: deps.then((deps) => {
             return deps.filterBy('kind', 'dev');
         }),
     });
 }),
Example #20
0
 displayedAuthors: computed('currentVersion.authors.[]', function() {
     return DS.PromiseArray.create({
         promise: this.get('currentVersion.authors').then((authors) => {
             var ret = authors.slice();
             var others = authors.get('meta');
             for (var i = 0; i < others.names.length; i++) {
                 ret.push({ name: others.names[i] });
             }
             return ret;
         })
     });
 }),
Example #21
0
  courses: computed('offerings.[]', 'ilmSessions.[]', function(){
    var defer = Ember.RSVP.defer();
    let promises = [];
    let allCourses = [];
    promises.pushObject(new Ember.RSVP.Promise(resolve => {
      this.get('offerings').then(offerings => {
        if(!offerings.length){
          resolve();
        }
        let promises = [];
        offerings.forEach(offering => {
          promises.pushObject(offering.get('session').then(session =>{
            return session.get('course').then(course => {
              allCourses.pushObject(course);
            });
          }));
        });
        Ember.RSVP.all(promises).then(()=>{
          resolve();
        });
      });
    }));
    promises.pushObject(new Ember.RSVP.Promise(resolve => {
      this.get('ilmSessions').then(ilmSessions => {
        if(!ilmSessions.length){
          resolve();
        }
        let promises = [];
        ilmSessions.forEach(ilmSession => {
          promises.pushObject(ilmSession.get('session').then(session =>{
            if(!session){
              return;
            }
            return session.get('course').then(course => {
              allCourses.pushObject(course);
            });
          }));
        });
        Ember.RSVP.all(promises).then(()=>{
          resolve();
        });
      });
    }));

    Ember.RSVP.all(promises).then(()=>{
      defer.resolve(allCourses.uniq());
    });

    return DS.PromiseArray.create({
      promise: defer.promise
    });
  }),
 allCohorts: computed('selectedSchool', 'selectedAcademicYear', function(){
   let defer = RSVP.defer();
   this.get('selectedSchool').then(school => {
     this.get('selectedAcademicYear').then(year => {
       school.getCohortsForYear(year.get('title')).then(cohorts => {
         defer.resolve(cohorts.sortBy('displayTitle'));
       });
     });
   });
   return DS.PromiseArray.create({
     promise: defer.promise
   });
 }),
  patientVisits: function() {
    let patient = this.get('model.patient');
    let visitPromise;

    if (!Ember.isEmpty(patient) && this.get('findPatientVisits')) {
      visitPromise = this.getPatientVisits(patient);
    } else {
      visitPromise = Ember.RSVP.resolve([]);
    }
    return DS.PromiseArray.create({
      promise: visitPromise
    });
  }.property('model.patient.id', 'newVisitAdded'),
Example #24
0
 ticketIdsToObjects: function(value) {
     var promises = [];
     if (value) {
         for (var i = 0; i < value.length; i++) {
             promises.pushObject(
                 this.store.findRecord('task', value[i])
             );
         }
     }
     return DS.PromiseArray.create({
         promise: Ember.RSVP.Promise.all(promises, 'TicketIDs ' + value + ' to Objects')
     });
 },
Example #25
0
 fetch: function(lotId, token) {
   var link = ENV.APP.API_SERVER + (ENV.APP.API_BASE ? '/' + ENV.APP.API_BASE : '')
              + '/v1/lots/'
              + lotId + '/ancestry';
   return DS.PromiseArray.create({
     promise: Ember.$.ajax({
       dataType: "json",
       url: link,
       type: 'GET',
       success: d => d.map(it => Ember.Object.create(it)),
       beforeSend: xhr => xhr.setRequestHeader('Authorization', 'Bearer ' + token)
     })
   });
 }
Example #26
0
  associatedLearnerGroups: computed('sessions.[].associatedLearnerGroups.[]', function(){
    var deferred = Ember.RSVP.defer();
    this.get('sessions').then(function(sessions){
      Ember.RSVP.all(sessions.mapBy('associatedLearnerGroups')).then(function(sessionLearnerGroups){
        var allGroups = [].concat.apply([],sessionLearnerGroups);
        var groups = allGroups?allGroups.uniq().sortBy('title'):[];
        deferred.resolve(groups);
      });
    });

    return DS.PromiseArray.create({
      promise: deferred.promise
    });
  }),
Example #27
0
  allDescendantUsers: computed('users.[]', 'children.@each.users.[]', function(){
    var deferred = Ember.RSVP.defer();
    this.get('users').then(users => {
      this.get('children').then(children => {
        Ember.RSVP.map(children.mapBy('allDescendantUsers'), childUsers => {
          users.addObjects(childUsers);
        }).then(() => {
          deferred.resolve(users.uniq());
        });
      });
    });

    return DS.PromiseArray.create({
      promise: deferred.promise
    });
  }),
    function(){
      var deferred = Ember.RSVP.defer();
      this.get('learnerGroup.usersOnlyAtThisLevel').then(currentUsers => {
        this.get('learnerGroup.topLevelGroup').then(topLevelGroup => {
          topLevelGroup.get('allDescendantUsers').then(users => {
            let filteredUsers = users.filter(
              user => !currentUsers.contains(user)
            );
            deferred.resolve(filteredUsers.sortBy('fullName'));
          });
        });
      });

      return DS.PromiseArray.create({
        promise: deferred.promise
      });
    }
test('it throws a helpful assertion if groups contain promises, as they are not supported', async function(assert) {
  let smallOptions = DS.PromiseArray.create({
    promise: RSVP.resolve(['one', 'two', 'three'])
  });
  this.groupedNumbers = [
    { groupName: 'Smalls', options: smallOptions  },
    { groupName: 'Mediums', options: ['four', 'five', 'six'] }
  ];

  await smallOptions;
  assert.expectAssertion(() => {
    this.render(hbs`
      {{#power-select options=groupedNumbers onchange=(action (mut foo)) as |option|}}
        {{option}}
      {{/power-select}}
    `);
  }, 'ember-power-select doesn\'t support promises inside groups');
});
Example #30
0
 competencies: computed('objectives.@each.treeCompetencies', function(){
   var defer = Ember.RSVP.defer();
   this.get('objectives').then(function(objectives){
     var promises = objectives.getEach('treeCompetencies');
     Ember.RSVP.all(promises).then(function(trees){
       var competencies = trees.reduce(function(array, set){
         return array.pushObjects(set.toArray());
       }, []);
       competencies = competencies.uniq().filter(function(item){
         return item != null;
       });
       defer.resolve(competencies);
     });
   });
   return DS.PromiseArray.create({
     promise: defer.promise
   });
 }),