<commit_before>var commonModal = require('client/components/modal_common/index');
var config = require('./config.json');
var request = require('../../request');
var __ = require('locale/client/dashboard.lang.json');
var getErrorMessage = require('client/applications/dashboard/utils/error_message');

function pop(obj, parent, callback) {
  config.fields[0].text = obj.name;

  var props = {
    __: __,
    parent: parent,
    config: config,
    onInitialize: function(refs) {
      request.getInstances().then((instances) => {
        refs.instance.setState({
          data: instances,
          value: instances[0].id
        });
      });
    },
    onConfirm: function(refs, cb) {
      request.associateInstance(obj, refs.port.state.value).then((res) => {
        callback && callback(res);
        cb(true);
      }).catch((error) => {
        cb(false, getErrorMessage(error));
      });
    },
    onAction: function(field, status, refs) {
      switch (field) {
        case 'instance':
          var instances = refs.instance.state.data;
          var selected = refs.instance.state.value;

          var item = instances.filter((instance) => instance.id === selected)[0];

          if (instances.length > 0) {
            var ports = [];
            var addresses = item.addresses;

            for (let key in addresses) {
              for (let ele of addresses[key]) {
                if (ele['OS-EXT-IPS:type'] === 'fixed') {<commit_msg>fix floating ip attach instance which has ports<commit_after>var commonModal = require('client/components/modal_common/index');
var config = require('./config.json');
var request = require('../../request');
var __ = require('locale/client/dashboard.lang.json');
var getErrorMessage = require('client/applications/dashboard/utils/error_message');

function pop(obj, parent, callback) {
  config.fields[0].text = obj.name;

  var props = {
    __: __,
    parent: parent,
    config: config,
    onInitialize: function(refs) {
      request.getInstances().then((data) => {
        var instances = data.filter((item) => {
          var addresses = item.addresses;
          for (let key in addresses) {
            for (let ele of addresses[key]) {
              if (ele['OS-EXT-IPS:type'] === 'fixed') {
                return true;
              }
            }
          }

          return false;
        });

        if (instances.length > 0) {
          refs.instance.setState({
            data: instances,
            value: instances[0].id
          });
        } else {
          refs.tip_no_port_instance.setState({
            hide: true
          });
        }
      });
    },
    onConfirm: function(refs, cb) {
      request.associateInstance(obj, refs.port.state.value).then((res) => {
        callback && callback(res);
        cb(true);
      }).catch((error) => {
        cb(false, getErrorMessage(error));
      });
    },
    onAction: function(field, status, refs) {
      switch (field) {
        case 'instance':
          var instances = refs.instance.state.data;
          var selected = refs.instance.state.value;

          var item = instances.filter((instance) => instance.id === selected)[0];

          if (instances.length > 0) {
            var ports = [];
            var addresses = item.addresses;

            for (let key in addresses) {
              for (let ele of addresses[key]) {
                if (ele['OS-EXT-IPS:type'] === 'fixed') {
{'fraction_non_alphanumeric': 0.14726426076833526, 'fraction_numerical': 0.002619324796274738, 'mean_word_length': 2.127388535031847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2007797', 'n_tokens_mistral': 978, 'n_tokens_neox': 963, 'n_words': 207}