<commit_before>import ModalFunctionality from 'discourse/mixins/modal-functionality';
const BufferedProxy = window.BufferedProxy; // import BufferedProxy from 'ember-buffered-proxy/proxy';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import computed from "ember-addons/ember-computed-decorators";
import Ember from 'ember';

const SortableArrayProxy = Ember.ArrayProxy.extend(Ember.SortableMixin);

export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, {

  @computed("site.categories")
  categoriesBuffered(categories) {
    const bufProxy = Ember.ObjectProxy.extend(BufferedProxy);
    return categories.map(c => bufProxy.create({ content: c }));
  },

  categoriesOrdered: function() {
    return SortableArrayProxy.create({
      sortProperties: ['content.position'],
      content: this.get('categoriesBuffered')
    });
  }.property('categoriesBuffered'),

  showFixIndices: function() {
    const cats = this.get('categoriesOrdered');
    const len = cats.get('length');
    for (let i = 0; i < len; i++) {
      if (cats.objectAt(i).get('position') !== i) {
        return true;
      }
    }
    return false;
  }.property('categoriesOrdered.@each.position'),

  showApplyAll: function() {
    let anyChanged = false;
    this.get('categoriesBuffered').forEach(bc => { anyChanged = anyChanged || bc.get('hasBufferedChanges') });
    return anyChanged;
  }.property('categoriesBuffered.@each.hasBufferedChanges'),
<commit_msg>Do fix positions upon opening dialog<commit_after>import ModalFunctionality from 'discourse/mixins/modal-functionality';
const BufferedProxy = window.BufferedProxy; // import BufferedProxy from 'ember-buffered-proxy/proxy';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { on, default as computed } from "ember-addons/ember-computed-decorators";
import Ember from 'ember';

const SortableArrayProxy = Ember.ArrayProxy.extend(Ember.SortableMixin);

export default Ember.Controller.extend(ModalFunctionality, Ember.Evented, {

  @on('init')
  _fixOrder() {
    this.send('fixIndices');
  },

  @computed("site.categories")
  categoriesBuffered(categories) {
    const bufProxy = Ember.ObjectProxy.extend(BufferedProxy);
    return categories.map(c => bufProxy.create({ content: c }));
  },

  categoriesOrdered: function() {
    return SortableArrayProxy.create({
      sortProperties: ['content.position'],
      content: this.get('categoriesBuffered')
    });
  }.property('categoriesBuffered'),

  showFixIndices: function() {
    const cats = this.get('categoriesOrdered');
    const len = cats.get('length');
    for (let i = 0; i < len; i++) {
      if (cats.objectAt(i).get('position') !== i) {
        return true;
      }
    }
    return false;
  }.property('categoriesOrdered.@each.position'),

  showApplyAll: function() {
    let anyChanged = false;
    this.get('categoriesBuffered').forEach(bc => { anyChanged = anyChanged || bc.get('hasBufferedChanges') });
    return anyChanged;
  }.property('categoriesBuffered.@each.hasBufferedChanges'),

{'fraction_non_alphanumeric': 0.1403220506079527, 'fraction_numerical': 0.0006572461386789353, 'mean_word_length': 4.5144927536231885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1464678', 'n_tokens_mistral': 911, 'n_tokens_neox': 892, 'n_words': 179}