<commit_before>define([
    'jquery',
    'underscore',
    'backbone',
    'knockout',
    'knockout-mapping',
    'arches',
    'views/components/widgets/resource-instance-multiselect',
    'views/resource/related-resources-node-list',
    'utils/ontology',
    'views/components/related-resources-graph',
    'plugins/knockout-select2',
    'bindings/datepicker',
    'bindings/datatable'
], function($, _, Backbone, ko, koMapping, arches, ResourceInstanceSelect, RelatedResourcesNodeList, ontologyUtils) {
    return ko.components.register('related-resources-manager', {
        viewModel: Backbone.View.extend({
            initialize: function(options) {
                var self = this;
                this.searchResults = options.searchResultsVm;
                this.editingInstanceId = options.editing_instance_id;
                this.graph = options.graph;
                this.loading = options.loading;
                this.rootOntologyClass  = '';
                this.activeTab = ko.observable();
                if (this.graph) {
                    if(!!options.graph.ontologyclass){
                        this.rootOntologyClass = options.graph.ontologyclass;
                    }else{
                        if(options.graph.root){
                            this.rootOntologyClass = options.graph.root.ontologyclass;
                        }
                    }
                }
                this.graphIsSemantic = !!this.rootOntologyClass;
                this.makeFriendly = ontologyUtils.makeFriendly;
                this.getSelect2ConfigForOntologyProperties = ontologyUtils.getSelect2ConfigForOntologyProperties;
                this.graphNameLookup = _.indexBy(arches.resources, 'graphid');
                this.currentResource = ko.observable();
                this.currentResourceSubscriptions = [];
                this.resourceEditorContext = options.resourceEditorContext;
                this.containerBottomMargin = ko.observable(0);
                this.showRelatedProperties = ko.observable(false);
                this.showGraph = ko.observable(this.editingInstanceId === undefined);
                this.displaySplash = ko.observable(false);
                this.graphNodeSelection = ko.observableArray();
                this.graphNodeList = ko.observableArray();
                this.newResource = ko.observableArray();
                this.filter = ko.observable('');
                this.selectedResourceRelationship = ko.observable();
                this.relationshipCandidates = ko.observableArray([]);
                this.relationshipCandidateIds = ko.observable([]);
                this.selectedOntologyClass = ko.observable();
                this.reportResourceId = ko.observable();
                this.reportGraphId = ko.observable(null);
                this.resourceRelationships = ko.observableArray();
                this.paginator = koMapping.fromJS({});
                this.totalRelationships = ko.observable(0);
                this.relationshipsInFilter = ko.computed(function() {
                    return self.resourceRelationships().filter(function(relationship) {
                        return self.filter().toLowerCase() === '' || relationship.resource.displayname.toLowerCase().includes(self.filter().toLowerCase());
                    });
                });

                this.toggleTab = function(tabName) {
                    if (self.activeTab() === tabName) {
                        self.activeTab(null);
                    } else {
                        self.activeTab(tabName);
                    }
                };

                this.toggleSelectedResourceRelationship = function(resourceRelationship) {
                    if (self.selectedResourceRelationship() === resourceRelationship) {
                        self.selectedResourceRelationship(null);
                    } else {
                        self.selectedResourceRelationship(resourceRelationship);
                    }
                };

                this.selectedResourceRelationship.subscribe(function(resourceRelationship) {
                    if (!!resourceRelationship) {
                        self.selectedOntologyClass(resourceRelationship.resource.root_ontology_class);
                    } else {
                        self.selectedOntologyClass(undefined);
                    }
                });

                this.selectedOntologyClass.subscribe(function() {
                    if (self.graphIsSemantic) {
                        self.relationshipTypes(self.validproperties[self.selectedOntologyClass()]);
                    } else {
                        self.relationshipTypes(options.relationship_types.values);
                    }
                });

                // this.fdgNodeListView = new RelatedResourcesNodeList({
                //     items: self.graphNodeList
                // });

                // this.disableSearchResults = function(result) {
                //     var resourceinstanceid = this.editingInstanceId;
                //     var graph = this.graph;
                //     if (result._id === resourceinstanceid || _.contains(graph.relatable_resources, result._source.graph_id) === false) {
                //         return true;
                //     } else {
                //         return false;
                //     }
                // };

                // this.showGraph.subscribe(function(val) {
                //     this.graphNodeList([]);
                // }, this);

                // this.panelPosition = ko.computed(function() {
                //     var res = { x: 0, y: 0, first: [0, 0], second: [0, 0] };
                //     var nodes = self.graphNodeSelection();
                //     if (nodes.length === 2) {
                //         res.x = nodes[0].absX < nodes[1].absX ? nodes[0].absX : nodes[1].absX;
                //         res.y = nodes[0].absY < nodes[1].absY ? nodes[0].absY : nodes[1].absY;
                //         res.first = nodes[0];
                //         res.second = nodes[1];
                //     }
                //     return res;
                // });

                // this.selected = ko.computed(function() {
                //     var res = _.filter(
                //         self.resourceRelationships(),
                //         function(rr) {
                //             if (rr.selected() === true) {
                //                 return rr;
                //             }
                //         }, self);
                //     if (self.graphIsSemantic && self.resourceEditorContext === true) {
                //         if (res.length > 0 && self.graphIsSemantic) {
                //             self.selectedOntologyClass(res[0].resource.root_ontology_class);
                //             self.resourceRelationships().forEach(function(rr) {
                //                 if (rr.resource.root_ontology_class !== self.selectedOntologyClass()) {
                //                     rr.unselectable(true);
                //                 }
                //             });
                //         } else {
                //             self.selectedOntologyClass(undefined);
                //             self.resourceRelationships().forEach(function(rr) {
                //                 rr.unselectable(false);
                //             });
                //         }
                //     }
                //     return res;
                // });

                this.dirty = ko.computed(function() {
                    return self.resourceRelationships().some(function(rr) {
                        return rr.dirty();
                    }, self);
                });


                this.newPage = function(page, e) {
                    if (page) {
                        this.currentResource().get(page);
                    }
                };

                var getNodeData = function(nodeid, relationship) {
                    $.ajax({
                        url: arches.urls.api_nodes(nodeid),
                        context: this,
                        dataType: 'json'
                    })
                        .done(function(data) {
                            relationship.node.name(data[0].name);
                            relationship.node.ontologyclass(data[0].ontologyclass);
                        })
                        .fail(function(data) {
                            console.log('Failed to get Node data', data);
                        });
                };
<commit_msg>fixes errors and cleans up re: #7529<commit_after>define([
    'jquery',
    'underscore',
    'backbone',
    'knockout',
    'knockout-mapping',
    'arches',
    'views/components/widgets/resource-instance-multiselect',
    'views/resource/related-resources-node-list',
    'utils/ontology',
    'views/components/related-resources-graph',
    'plugins/knockout-select2',
    'bindings/datepicker',
    'bindings/datatable'
], function($, _, Backbone, ko, koMapping, arches, ResourceInstanceSelect, RelatedResourcesNodeList, ontologyUtils) {
    return ko.components.register('related-resources-manager', {
        viewModel: Backbone.View.extend({
            initialize: function(options) {
                var self = this;
                this.searchResults = options.searchResultsVm;
                this.editingInstanceId = options.editing_instance_id;
                this.graph = options.graph;
                this.loading = options.loading;
                this.rootOntologyClass  = '';
                this.activeTab = ko.observable();
                if (this.graph) {
                    if(!!options.graph.ontologyclass){
                        this.rootOntologyClass = options.graph.ontologyclass;
                    }else{
                        if(options.graph.root){
                            this.rootOntologyClass = options.graph.root.ontologyclass;
                        }
                    }
                }
                this.graphIsSemantic = !!this.rootOntologyClass;
                this.makeFriendly = ontologyUtils.makeFriendly;
                this.getSelect2ConfigForOntologyProperties = ontologyUtils.getSelect2ConfigForOntologyProperties;
                this.graphNameLookup = _.indexBy(arches.resources, 'graphid');
                this.currentResource = ko.observable();
                this.currentResourceSubscriptions = [];
                this.resourceEditorContext = options.resourceEditorContext;
                this.containerBottomMargin = ko.observable(0);
                this.showRelatedProperties = ko.observable(false);
                this.showGraph = ko.observable(this.editingInstanceId === undefined);
                this.displaySplash = ko.observable(false);
                this.graphNodeSelection = ko.observableArray();
                this.graphNodeList = ko.observableArray();
                this.newResource = ko.observableArray();
                this.filter = ko.observable('');
                this.selectedResourceRelationship = ko.observable();
                this.relationshipCandidates = ko.observableArray([]);
                this.relationshipCandidateIds = ko.observable([]);
                this.selectedOntologyClass = ko.observable();
                this.reportResourceId = ko.observable();
                this.reportGraphId = ko.observable(null);
                this.resourceRelationships = ko.observableArray();
                this.paginator = koMapping.fromJS({});
                this.totalRelationships = ko.observable(0);
                this.relationshipsInFilter = ko.computed(function() {
                    return self.resourceRelationships().filter(function(relationship) {
                        return self.filter().toLowerCase() === '' || relationship.resource.displayname.toLowerCase().includes(self.filter().toLowerCase());
                    });
                });

                this.toggleTab = function(tabName) {
                    if (self.activeTab() === tabName) {
                        self.activeTab(null);
                    } else {
                        self.activeTab(tabName);
                    }
                };

                this.toggleSelectedResourceRelationship = function(resourceRelationship) {
                    if (self.selectedResourceRelationship() === resourceRelationship) {
                        self.selectedResourceRelationship(null);
                    } else {
                        self.selectedResourceRelationship(resourceRelationship);
                    }
                };

                this.selectedResourceRelationship.subscribe(function(resourceRelationship) {
                    if (!!resourceRelationship) {
                        self.selectedOntologyClass(resourceRelationship.resource.root_ontology_class);
                    } else {
                        self.selectedOntologyClass(undefined);
                    }
                });

                this.selectedOntologyClass.subscribe(function() {
                    if (self.graphIsSemantic) {
                        self.relationshipTypes(self.validproperties[self.selectedOntologyClass()]);
                    } else {
                        self.relationshipTypes(options.relationship_types.values);
                    }
                });

                this.disableSearchResults = function(result) {
                    var resourceinstanceid = this.editingInstanceId;
                    var graph = this.graph;
                    if (result._id === resourceinstanceid || _.contains(graph.relatable_resources, result._source.graph_id) === false) {
                        return true;
                    } else {
                        return false;
                    }
                };

                this.selected = ko.computed(function() {
                    var res = _.filter(
                        self.resourceRelationships(),
                        function(rr) {
                            if (rr.selected() === true) {
                                return rr;
                            }
                        }, self);
                    if (self.graphIsSemantic && self.resourceEditorContext === true) {
                        if (res.length > 0 && self.graphIsSemantic) {
                            self.selectedOntologyClass(res[0].resource.root_ontology_class);
                            self.resourceRelationships().forEach(function(rr) {
                                if (rr.resource.root_ontology_class !== self.selectedOntologyClass()) {
                                    rr.unselectable(true);
                                }
                            });
                        } else {
                            self.selectedOntologyClass(undefined);
                            self.resourceRelationships().forEach(function(rr) {
                                rr.unselectable(false);
                            });
                        }
                    }
                    return res;
                });

                this.dirty = ko.computed(function() {
                    return self.resourceRelationships().some(function(rr) {
                        return rr.dirty();
                    }, self);
                });


                this.newPage = function(page, e) {
                    if (page) {
                        this.currentResource().get(page);
                    }
                };

                var getNodeData = function(nodeid, relationship) {
                    $.ajax({
                        url: arches.urls.api_nodes(nodeid),
                        context: this,
                        dataType: 'json'
                    })
                        .done(function(data) {
                            relationship.node.name(data[0].name);
                            relationship.node.ontologyclass(data[0].ontologyclass);
                        })
                        .fail(function(data) {
                            console.log('Failed to get Node data', data);
                        });
                };

{'fraction_non_alphanumeric': 0.10305461277383524, 'fraction_numerical': 0.0024066646096883677, 'mean_word_length': 1.2483351831298557, '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': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5043274', 'n_tokens_mistral': 3922, 'n_tokens_neox': 3579, 'n_words': 492}