<commit_before>import Ember from "ember";
import ParameterObserverModel from 'stromx-web/models/parameter-observer';
import InputObserverModel from 'stromx-web/models/input-observer';
import OutputObserverModel from 'stromx-web/models/output-observer';

export default Ember.Controller.extend({
  stream: Ember.inject.controller(),

  isParameterObserver: function() {
    return this.get('model') instanceof ParameterObserverModel;
  }.property('model'),

  isInputObserver: function() {
    return this.get('model') instanceof InputObserverModel;
  }.property('model'),

  isOutputObserver: function() {
    return this.get('model') instanceof OutputObserverModel;
  }.property('model'),

  updateZvalue: function(update) {
    var model = this.get('model');
    var zvalue = model.get('zvalue');
    var newZvalue = zvalue + update;
    var numObservers = view.get('observers.length');

    if (newZvalue < 0 || newZvalue >= numObservers) {
      return;
    }

    model.set('zvalue', newZvalue);
    model.save().then(function() {
      var view = model.get('view');
      view.then(function(view) {
        view.get('observers').forEach(function(observer) {
          observer.reload();
        });
      });
    });
  },

  actions: {
    moveUp: function() {
      this.updateZvalue(+1);
    },
    moveDown: function() {
      this.updateZvalue(-1);
    }
  }
});

<commit_msg>Fix observer controller<commit_after>import Ember from "ember";
import ParameterObserverModel from 'stromx-web/models/parameter-observer';
import InputObserverModel from 'stromx-web/models/input-observer';
import OutputObserverModel from 'stromx-web/models/output-observer';

export default Ember.Controller.extend({
  stream: Ember.inject.controller(),

  isParameterObserver: function() {
    return this.get('model') instanceof ParameterObserverModel;
  }.property('model'),

  isInputObserver: function() {
    return this.get('model') instanceof InputObserverModel;
  }.property('model'),

  isOutputObserver: function() {
    return this.get('model') instanceof OutputObserverModel;
  }.property('model'),

  updateZvalue: function(update) {
    var model = this.get('model');
    var zvalue = model.get('zvalue');
    var newZvalue = zvalue + update;
    var view = model.get('view');
    var numObservers = view.get('observers.length');

    if (newZvalue < 0 || newZvalue >= numObservers) {
      return;
    }

    model.set('zvalue', newZvalue);
    model.save().then(function() {
      view.then(function(view) {
        view.get('observers').forEach(function(observer) {
          observer.reload();
        });
      });
    });
  },

  actions: {
    moveUp: function() {
      this.updateZvalue(+1);
    },
    moveDown: function() {
      this.updateZvalue(-1);
    }
  }
});


{'fraction_non_alphanumeric': 0.14820143884892087, 'fraction_numerical': 0.002158273381294964, 'mean_word_length': 3.5966942148760332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4135002', 'n_tokens_mistral': 849, 'n_tokens_neox': 817, 'n_words': 160}