{"size": 1364, "ext": "js", "max_stars_repo_path": "app/components/dialogs/user-statistics-modal.js", "max_stars_repo_name": "SREnity/travis-web", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T08:30:55.000Z", "max_issues_repo_path": "app/components/dialogs/user-statistics-modal.js", "max_issues_repo_name": "SREnity/travis-web", "max_issues_repo_issues_event_min_datetime": "2015-01-05T19:56:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:36:48.000Z", "max_forks_repo_path": "app/components/dialogs/user-statistics-modal.js", "max_forks_repo_name": "PowerOlive/travis-web", "max_forks_repo_forks_event_min_datetime": "2015-01-14T14:58:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-16T15:30:41.000Z"}
{"max_stars_count": 522, "max_issues_count": 1143, "max_forks_count": 352, "avg_line_length": 27.28, "max_line_length": 104, "alphanum_fraction": 0.651026393}
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import moment from 'moment';

export default Component.extend({
  store: service(),
  dateCenter: null,
  dateRange: null,
  showDatePicker: false,
  perPage: 10,
  users: reads('owner.executionsPerSender'),
  usersCount: reads('owner.executionsPerSender.length'),

  init() {
    this._super(...arguments);
    this.page = 1;
  },

  showPrev: computed('page', 'usersCount', function () {
    return this.page > 1;
  }),

  showNext: computed('page', 'usersCount', function () {
    return this.page < this.maxPages;
  }),

  maxPages: computed('usersCount', function () {
    return Math.ceil(this.usersCount / this.perPage);
  }),

  usersToShow: computed('users', 'page', function () {
    return this.users.slice((this.page - 1) * this.perPage, this.page * this.perPage);
  }),

  actions: {
    datePicker() {
      this.set('showDatePicker', !this.showDatePicker);
      if (!this.showDatePicker) {
        this.account.fetchExecutionsPerSender.perform(moment(this.dateRange.start).format('YYYY-MM-DD'),
          moment(this.dateRange.end || this.dateRange.start).format('YYYY-MM-DD'));
      }
    },
    setPage(newPage) {
      this.set('page', newPage);
    }
  }
});
