<commit_before>import Ember from 'ember';
import DS from 'ember-data';

const { Controller, computed, RSVP, inject, isPresent, isEmpty } = Ember;
const { sort, gt } = computed;
const { service } = inject;
const { PromiseArray } = DS;

export default Controller.extend({
  store: service(),
  flashMessages: service(),
  queryParams: ['offset', 'limit', 'filter', 'school'],
  offset: 0,
  limit: 25,
  filter: '',
  school: null,
  hasMoreThanOneSchool: gt('model.schools.length', 1),
  sortSchoolsBy:['title'],
  sortedSchools: sort('model.schools', 'sortSchoolsBy'),
  selectedSchool: computed('model.schools.[]', 'model.primarySchool', 'school', function(){
    let schools = this.get('model.schools');
    if(isPresent(this.get('school'))){
      let school =  schools.find(school => {
        return school.get('id') === this.get('school');
      });
      if(school){
        return school;
      }
    }
    return this.get('model.primarySchool');
  }),

  deletedUpdates: [],
  updatesBeingSaved: [],

  allUpdates: computed('selectedSchool', function(){
    let defer = RSVP.defer();
    let school = this.get('selectedSchool');
    this.get('store').query('pending-user-update', {
      limit: 1000,
      filters: {
        schools: [school.get('id')]
      }
    }).then(updates => {
      //preload user for each update
      RSVP.all(updates.mapBy('user')).then(() => {
        defer.resolve(updates);
      });
    });

    return PromiseArray.create({
      promise: defer.promise
    });
  }),

  displayedUpdates: computed('<EMAIL>', 'filter', 'offset', 'limit', function(){
    const limit = this.get('limit');
    const offset = this.get('offset');
    const end = limit + offset;
    const filter = this.get('filter');
    const exp = new RegExp(filter, 'gi');

    return this.get('allUpdates')
      .sortBy('user.lastName', 'user.firstName')
      .slice(offset, end).filter(update => {
        return !this.get('deletedUpdates').includes(update) &&
        (isEmpty(update.get('user.fullName')) || update.get('user.fullName').match(exp));
      });
  }),
  actions: {
    changeSelectedSchool(schoolId){
      this.set('school', schoolId);
    },
    updateEmailAddress(update){
      this.get('updatesBeingSaved').pushObject(update);
      update.get('user').then(user => {
        user.set('email', update.get('value'));
        user.save().then(() => {<commit_msg>replaced promise implementation in allUpdates comp prop.<commit_after>import Ember from 'ember';

const { Controller, computed, RSVP, inject, isPresent, isEmpty } = Ember;
const { sort, gt } = computed;
const { service } = inject;
const { all, Promise } = RSVP;

export default Controller.extend({
  store: service(),
  flashMessages: service(),
  queryParams: ['offset', 'limit', 'filter', 'school'],
  offset: 0,
  limit: 25,
  filter: '',
  school: null,
  hasMoreThanOneSchool: gt('model.schools.length', 1),
  sortSchoolsBy:['title'],
  sortedSchools: sort('model.schools', 'sortSchoolsBy'),
  selectedSchool: computed('model.schools.[]', 'model.primarySchool', 'school', function(){
    let schools = this.get('model.schools');
    if(isPresent(this.get('school'))){
      let school =  schools.find(school => {
        return school.get('id') === this.get('school');
      });
      if(school){
        return school;
      }
    }
    return this.get('model.primarySchool');
  }),

  deletedUpdates: [],
  updatesBeingSaved: [],

  allUpdates: computed('selectedSchool', function(){
    return new Promise(resolve => {
      let school = this.get('selectedSchool');
      this.get('store').query('pending-user-update', {
        limit: 1000,
        filters: {
          schools: [school.get('id')]
        }
      }).then(updates => {
        //preload user for each update
        all(updates.mapBy('user')).then(() => {
          resolve(updates);
        });
      });
    });
  }),

  displayedUpdates: computed('<EMAIL>', 'filter', 'offset', 'limit', function(){
    const limit = this.get('limit');
    const offset = this.get('offset');
    const end = limit + offset;
    const filter = this.get('filter');
    const exp = new RegExp(filter, 'gi');

    return this.get('allUpdates')
      .sortBy('user.lastName', 'user.firstName')
      .slice(offset, end).filter(update => {
        return !this.get('deletedUpdates').includes(update) &&
        (isEmpty(update.get('user.fullName')) || update.get('user.fullName').match(exp));
      });
  }),
  actions: {
    changeSelectedSchool(schoolId){
      this.set('school', schoolId);
    },
    updateEmailAddress(update){
      this.get('updatesBeingSaved').pushObject(update);
      update.get('user').then(user => {
        user.set('email', update.get('value'));
        user.save().then(() => {
{'fraction_non_alphanumeric': 0.1825063078216989, 'fraction_numerical': 0.00336417157275021, 'mean_word_length': 3.3049773755656107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773192', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1459, 'n_words': 289}