<commit_before>define(['jquery', 'jquery-ui', 'util', 'view/helpers', 'view/internal', 'model/diff'],
function($, _unused_jquery_ui,  util,   view_helpers, internal,          model_diff) {

var d = null,
    msg_node = $('.info-card-message'),
    graph,
    node,
    setup_done = false,
    info = $('.info'),
    form = {
        name: info.find('#editformname'),
        type: info.find('#edittype'),
        url: info.find('#editurl'),
        status: info.find('#editstatus'),
        startdate: info.find("#editstartdate"),
        enddate: info.find("#editenddate"),
        description: info.find("#editdescription"),
    };


function clean_url(candidate_url)
{
    if (candidate_url.length == 0) {
        return '';
    }
    if (candidate_url.search('://') != -1) {
        return candidate_url;
    }
    return 'https://' + candidate_url;
}

function _get_form_data() {
    var ret = _.object(_.keys(form),_.values(form).map(function (x) { return x.val(); }));

    ret.url = clean_url(ret.url);
    return ret;
}

function commit()
{
    graph.update_node(node, _get_form_data());
}

function textarea_resize(text, max)
{
    var height;
    text.style.height = 'auto';
    height = text.scrollHeight;
    if (max) {
        height = Math.min(max, height);
    }
    text.style.height = height + 'px';
}

function setup_click_handlers(graph)
{
    if (setup_done) {
        return;
    }
    setup_done = true;
    $('#edit-node-dialog__delete').on('click', function (e) {
        e.preventDefault();
        hide();
        var topo_diff = model_diff.new_topo_diff({
                node_id_set_rm: [node.id]
            });
        graph.commit_and_tx_diff__topo(topo_diff);
        });
    $('#edit-node-dialog__save').on('click', function (e) {
        e.preventDefault();
        hide();
        commit();
    });
    // re-open dialog on node updates while it is open
    diffBusUnsubscribe = graph.diffBus.onValue(function (diff) {
        if (model_diff.is_topo_diff(diff) && _.contains(diff.node_id_set_rm, node.id)) {
            warning('node has been deleted');
            return;
        }
        if (!model_diff.is_attr_diff(diff) || _.contains(_.keys(model_diff.id_to_node_map), node.id)) {
            warning('node has been changed');
            return;
        }
        show(graph, node);
    });

    // auto save style handlers
    //info.
}

function warning(string)
{
    msg_node.text(string);
}

function show(_graph, d) {
    var f = false,
        t = true,
        visible = {
          "third-internship-proposal":  [t, t, t, t, f],
          "chainlink":                  [f, f, f, t, f],
          "skill":                      [f, f, f, t, t],
          "interest":                   [f, f, f, t, t],
          "_defaults":                  [f, f, f, t, t],
        },
        fields = ["#status", "#startdate", "#enddate", "#description", "#url"],
        flags = visible.hasOwnProperty(d.type) ? visible[d.type] : visible._defaults,
        i;

    graph = _graph;
    node = d;
    util.assert(graph.find_node__by_id(d.id) != null);

    setup_click_handlers(graph);

    internal.edit_tab.show('node');

    for (i = 0 ; i < flags.length; ++i) {
        var elem = info.find(fields[i]);
        elem[flags[i] ? 'show' : 'hide']();
    }

    $('.info').attr('class', 'info');
    $('.info').addClass('type-' + d.type); // Add a class to distinguish types for css

    var name_textarea = $('.info').find('#editformname');
    name_textarea.val(d.name);
    textarea_resize(name_textarea[0], 150);

    $("#editenddate").datepicker({
      inline: true,
      showOtherMonths: true,
      dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    });
    $("#editstartdate").datepicker({
      inline: true,
      showOtherMonths: true,
      dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    });

    var description = $('#editdescription');
    description.val(d.description);<commit_msg>client/node_info: track changes and commit on any field change. partially Fixes #43<commit_after>define(['jquery', 'jquery-ui', 'util', 'view/helpers', 'view/internal', 'model/diff'],
function($, _unused_jquery_ui,  util,   view_helpers, internal,          model_diff) {

var d = null,
    msg_node = $('.info-card-message'),
    graph,
    node,
    setup_done = false,
    info = $('.info'),
    form = {
        name: info.find('#editformname'),
        type: info.find('#edittype'),
        url: info.find('#editurl'),
        status: info.find('#editstatus'),
        startdate: info.find("#editstartdate"),
        enddate: info.find("#editenddate"),
        description: info.find("#editdescription"),
    },
    change_handlers = [];


function clean_url(candidate_url)
{
    if (candidate_url.length == 0) {
        return '';
    }
    if (candidate_url.search('://') != -1) {
        return candidate_url;
    }
    return 'https://' + candidate_url;
}

function _get_form_data() {
    var ret = _.object(_.keys(form),_.values(form).map(function (x) { return x.val(); }));

    ret.url = clean_url(ret.url);
    return ret;
}

function commit()
{
    graph.update_node(node, _get_form_data());
}

function textarea_resize(text, max)
{
    var height;
    text.style.height = 'auto';
    height = text.scrollHeight;
    if (max) {
        height = Math.min(max, height);
    }
    text.style.height = height + 'px';
}

function setup_change_handlers()
{
    disable_change_handlers();
    // auto save style handlers
    var streams = _.map(_.values(form), function (field) {
        return field.asEventStream('change');
    });
    var single = _.reduce(streams, function (stream_a, stream_b) { return stream_a.merge(stream_b); });
    change_handlers = [single.debounce(100).onValue(function () {
        commit();
    })];
}

function disable_change_handlers()
{
    _.each(change_handlers, function (unsub) { unsub(); });
    change_handlers = [];
}

function setup_click_handlers()
{
    setup_change_handlers();
    if (setup_done) {
        return;
    }
    setup_done = true;
    $('#edit-node-dialog__delete').on('click', function (e) {
        e.preventDefault();
        hide();
        var topo_diff = model_diff.new_topo_diff({
                node_id_set_rm: [node.id]
            });
        graph.commit_and_tx_diff__topo(topo_diff);
        });
    $('#edit-node-dialog__save').on('click', function (e) {
        e.preventDefault();
        hide();
        commit();
    });
    // re-open dialog on node updates while it is open
    diffBusUnsubscribe = graph.diffBus.onValue(function (diff) {
        if (model_diff.is_topo_diff(diff) && _.contains(diff.node_id_set_rm, node.id)) {
            warning('node has been deleted');
            return;
        }
        if (!model_diff.is_attr_diff(diff) || _.contains(_.keys(model_diff.id_to_node_map), node.id)) {
            warning('node has been changed');
            return;
        }
        show(graph, node);
    });
}

function warning(string)
{
    msg_node.text(string);
}

function show(_graph, d) {
    var f = false,
        t = true,
        visible = {
          "third-internship-proposal":  [t, t, t, t, f],
          "chainlink":                  [f, f, f, t, f],
          "skill":                      [f, f, f, t, t],
          "interest":                   [f, f, f, t, t],
          "_defaults":                  [f, f, f, t, t],
        },
        fields = ["#status", "#startdate", "#enddate", "#description", "#url"],
        flags = visible.hasOwnProperty(d.type) ? visible[d.type] : visible._defaults,
        i;

    graph = _graph;
    node = d;
    util.assert(graph.find_node__by_id(d.id) != null);

    setup_click_handlers();

    internal.edit_tab.show('node');

    for (i = 0 ; i < flags.length; ++i) {
        var elem = info.find(fields[i]);
        elem[flags[i] ? 'show' : 'hide']();
    }

    $('.info').attr('class', 'info');
    $('.info').addClass('type-' + d.type); // Add a class to distinguish types for css

    var name_textarea = $('.info').find('#editformname');
    name_textarea.val(d.name);
    textarea_resize(name_textarea[0], 150);

    $("#editenddate").datepicker({
      inline: true,
      showOtherMonths: true,
      dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    });
    $("#editstartdate").datepicker({
      inline: true,
      showOtherMonths: true,
      dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    });

    var description = $('#editdescription');
    description.val(d.description);
{'fraction_non_alphanumeric': 0.17307917202666354, 'fraction_numerical': 0.0022219623435855455, 'mean_word_length': 2.438681141938078, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3839580', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2775, 'n_words': 573}