<commit_before>'use strict';

/**
 * @ngdoc directive
 * @name labelsApp.directive:searchResultBox
 * @description
 * # searchResultBox
 */
angular.module('labelsApp')
  .directive('searchResultBox', function (ngDialog, LabelService, ResourcesService) {
    return {
        templateUrl: "views/directives/search-result-box.html",
        restrict: 'E',

        link: function postLink(scope, element, attrs) {

            scope.isSameVocab = function() {
                return scope.data.type === 'ls' && scope.data.scheme === scope.vocabulary.title.value;
            };

            scope.data = scope.box;


            if (scope.isSameVocab()) {
                scope.data.type = "label";
                console.log(scope.data);
            }

            /**
             * Opens a type-specific dialog that shows the connection (relation)
             * options for each type to link to the label.
             */
            scope.onClick = function() {
                ngDialog.open({
                    template: 'views/dialogs/add-resource.html',
                    className: 'bigdialog',
                    showClose: false,
                    closeByDocument: false,
                    disableAnimation: true,
                    scope: scope
                });
            };

            /**
             * Link a search result to the current label by added the resource's
             * information to the according relation-array of the label.
             * @param {string} relation - Label-to-Resource relation  (e.g. "broader" or "exactMatch")
             */
            scope.onAddClick = function(relation) {
                var updatedLabel = scope.label;

                if (!updatedLabel[relation]) {
                    updatedLabel[relation] = [];
                }

                if (relation === "broader" || relation === "related" || relation === "narrower") {  // same vocab
                    // just push label-id to array
                    var labelID = scope.data.uri.split("/").pop();
                    updatedLabel[relation].push(labelID);

                } else {
                    updatedLabel[relation].push({
                        type: scope.data.type,
                        uri: scope.data.uri
                    });
                }

                var updateObject = {
                    item: updatedLabel,
                    user: "demo"
                };

                LabelService.update({id: updatedLabel.id}, updateObject, function() {
                    // get all infos and add box temporarily
                    ResourcesService.get(scope.data.uri, function(resource) {

                        // success
                        scope.boxes.push({
                            relation: relation,
                            boxType: scope.data.type,
                            resource: resource
                        });

                    }, function(err) {
                        console.log(err);
                    });
                }, function(err) {
                    console.log(err);
                });
            };

            /**
             * Watcher that updates nanoscroller when box is extended.
             */
            scope.$watch("showMore", function() {
                console.log("showMore changed!");
            });

            // reload nanoscroller when directive rendered
            $(".nano").nanoScroller();
        }
    };
  });<commit_msg>fixed bug where added internal concepts would not contain information in detail view<commit_after>'use strict';

/**
 * @ngdoc directive
 * @name labelsApp.directive:searchResultBox
 * @description
 * # searchResultBox
 */
angular.module('labelsApp')
  .directive('searchResultBox', function (ngDialog, LabelService, ResourcesService) {
    return {
        templateUrl: "views/directives/search-result-box.html",
        restrict: 'E',

        link: function postLink(scope, element, attrs) {

            scope.isSameVocab = function() {
                return scope.data.type === 'ls' && scope.data.scheme === scope.vocabulary.title.value;
            };

            scope.data = scope.box;


            if (scope.isSameVocab()) {
                scope.data.type = "label";
                console.log(scope.data);
            }

            /**
             * Opens a type-specific dialog that shows the connection (relation)
             * options for each type to link to the label.
             */
            scope.onClick = function() {
                ngDialog.open({
                    template: 'views/dialogs/add-resource.html',
                    className: 'bigdialog',
                    showClose: false,
                    closeByDocument: false,
                    disableAnimation: true,
                    scope: scope
                });
            };

            /**
             * Link a search result to the current label by added the resource's
             * information to the according relation-array of the label.
             * @param {string} relation - Label-to-Resource relation  (e.g. "broader" or "exactMatch")
             */
            scope.onAddClick = function(relation) {
                var updatedLabel = scope.label;

                if (!updatedLabel[relation]) {
                    updatedLabel[relation] = [];
                }

                if (relation === "broader" || relation === "related" || relation === "narrower") {  // same vocab
                    // just push label-id to array
                    var labelID = scope.data.uri.split("/").pop();
                    updatedLabel[relation].push(labelID);

                } else {
                    updatedLabel[relation].push({
                        type: scope.data.type,
                        uri: scope.data.uri
                    });
                }

                var updateObject = {
                    item: updatedLabel,
                    user: "demo"
                };

                LabelService.update({id: updatedLabel.id}, updateObject, function() {
                    // get all infos and add box temporarily
                    if (labelID) {
                        LabelService.get({id: labelID}, function(concept) {

                            scope.boxes.push({
                                relation: relation,
                                boxType: scope.data.type,
                                resource: concept
                            });
                        }, function(err) {
                            console.log(err);
                        });
                    } else {
                        // get external resource
                        ResourcesService.get(scope.data.uri, function(resource) {
                            scope.boxes.push({
                                relation: relation,
                                boxType: scope.data.type,
                                resource: resource
                            });
                        }, function(err) {
                            console.log(err);
                        });
                    }

                }, function(err) {
                    console.log(err);
                });


            };

            /**
             * Watcher that updates nanoscroller when box is extended.
             */
            scope.$watch("showMore", function() {
                $(".nano").nanoScroller();
            });

            // reload nanoscroller when directive rendered
            $(".nano").nanoScroller();
        }
    };
  });
{'fraction_non_alphanumeric': 0.10362966859547607, 'fraction_numerical': 0.0, 'mean_word_length': 1.1142618849040868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5924401', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1660, 'n_words': 390}