<commit_before>// TODO:
// Record id when creating a new annotation.
// Finish polyline "NewAnnotationItem"
// Load annotation into layer when circle is clicked on.
// Right click menu to "delete, modify (record over), set name.
// Hover over circle to see annotation name.
// Finish remaining annotation items.
// Add camera view as annotation.




(function () {
    "use strict";

    function GirderWidget (layer, itemId) {
        if (itemId) {
            this.ImageItemId  = itemId;
            this.LoadGirderImageItem(itemId);
        }
        this.Radius = 7;
        this.AnnotationLayer = layer;

        var idx = 0;
        var y = 70 + (idx*6*this.Radius);
        var self = this;
        this.Plus = $('<img>')
            .appendTo(this.AnnotationLayer.GetCanvasDiv())
            .attr('src',SA.ImagePathUrl+'bluePlus.png')
            .css({'position':'absolute',
                  'left':(3*this.Radius)+'px',
                  'top': y+'px',
                  'width': (2*this.Radius)+'px',
                  'height': (2*this.Radius)+'px',
                  'opacity':'0.6'})
            .prop('title', "Add Annotation")
            .hover(function(){$(this).css({'opacity':'1'});},
                   function(){$(this).css({'opacity':'0.6'});})
            .click(function () { self.NewAnnotationItem();});

        this.AnnotationObjects = [];
        this.Highlighted = undefined;

        this.MenuAnnotationObject = undefined;
        this.Menu = $('<div>')
            .appendTo(this.AnnotationLayer.GetCanvasDiv())
            .hide()
            .mouseleave(function(){$(this).hide();})
            .css({'position'  :'absolute',
                  'background-color': '#FFFFFF',
                  'border'    :'1px solid #666666',
                  'box-sizing': 'border-box',
                  'left'      : '-78px',
                  'width'     : '100px',
                  'padding'   : '0px 2px'})

        $('<button>')
            .appendTo(this.Menu)
            .text("Snap Shot")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .prop('title', "Replace Annotation")
            .click(
                function(){
                    self.SnapShotAnnotation(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
        $('<button>')
            .appendTo(this.Menu)
            .text("Delete")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .click(
                function(){
                    self.DeleteAnnotation(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
        $('<button>')
            .appendTo(this.Menu)
            .text("Properties")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .click(
                function(){
                    // Not implemented yet.
                    //self.ShowAnnotationPropertiesDialog(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
    }

    // Create a new annotation item from the annotation layer.
    // Save it in the database.  Add the annotation as a dot in the GUI.
    GirderWidget.prototype.NewAnnotationItem = function() {
        var annot = {"elements": []};
        annot.name = "SA-"+this.AnnotationObjects.length;
        annot.elements = this.RecordAnnotation();

        // Make a new annotation in the database.
        var self = this;
        if (window.girder) { // Conditional is for testing in slide atlas.
            girder.restRequest({
                path:  "annotation?itemId="+this.ImageItemId,
                method: 'POST',
                contentType:'application/json',
                data: JSON.stringify(annot),
            }).done(function(retAnnot) {
                // This has the girder id.
                self.Highlight(self.AddAnnotation(retAnnot));
            });
        } else {
            // for debugging without girder.
            self.Highlight(self.AddAnnotation(
                {_id:'ABC',
                 annotation:annot,
                 itemId:self.ImageItemId}));
        }
    }

    GirderWidget.prototype.LoadGirderImageItem = function(itemId) {
        //var itemId = "564e42fe3f24e538e9a20eb9";
        var data= {"itemId": itemId,
                   "limit": 50,
                   "offset": 0,
                   "sort":"lowerName",
                   "sortdir":1};

        var self = this;
        // This gives an array of {_id:"....",annotation:{name:"...."},itemId:"...."}
        girder.restRequest({
            path:   "annotation",
            method: "GET",
            data:   JSON.stringify(data)
        }).done(function(data) {
            for (var i = 0; i < data.length; ++i) {
                self.LoadAnnotationItem(data[i]._id);
            }
        });
    }<commit_msg>forgot max. sortDir = 0<commit_after>// TODO:
// Record id when creating a new annotation.
// Finish polyline "NewAnnotationItem"
// Load annotation into layer when circle is clicked on.
// Right click menu to "delete, modify (record over), set name.
// Hover over circle to see annotation name.
// Finish remaining annotation items.
// Add camera view as annotation.




(function () {
    "use strict";

    function GirderWidget (layer, itemId) {
        if (itemId) {
            this.ImageItemId  = itemId;
            this.LoadGirderImageItem(itemId);
        }
        this.Radius = 7;
        this.AnnotationLayer = layer;

        var idx = 0;
        var y = 70 + (idx*6*this.Radius);
        var self = this;
        this.Plus = $('<img>')
            .appendTo(this.AnnotationLayer.GetCanvasDiv())
            .attr('src',SA.ImagePathUrl+'bluePlus.png')
            .css({'position':'absolute',
                  'left':(3*this.Radius)+'px',
                  'top': y+'px',
                  'width': (2*this.Radius)+'px',
                  'height': (2*this.Radius)+'px',
                  'opacity':'0.6'})
            .prop('title', "Add Annotation")
            .hover(function(){$(this).css({'opacity':'1'});},
                   function(){$(this).css({'opacity':'0.6'});})
            .click(function () { self.NewAnnotationItem();});

        this.AnnotationObjects = [];
        this.Highlighted = undefined;

        this.MenuAnnotationObject = undefined;
        this.Menu = $('<div>')
            .appendTo(this.AnnotationLayer.GetCanvasDiv())
            .hide()
            .mouseleave(function(){$(this).hide();})
            .css({'position'  :'absolute',
                  'background-color': '#FFFFFF',
                  'border'    :'1px solid #666666',
                  'box-sizing': 'border-box',
                  'left'      : '-78px',
                  'width'     : '100px',
                  'padding'   : '0px 2px'})

        $('<button>')
            .appendTo(this.Menu)
            .text("Snap Shot")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .prop('title', "Replace Annotation")
            .click(
                function(){
                    self.SnapShotAnnotation(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
        $('<button>')
            .appendTo(this.Menu)
            .text("Delete")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .click(
                function(){
                    self.DeleteAnnotation(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
        $('<button>')
            .appendTo(this.Menu)
            .text("Properties")
            .css({'margin': '2px 0px',
                  'width' : '100%'})
            .click(
                function(){
                    // Not implemented yet.
                    //self.ShowAnnotationPropertiesDialog(self.MenuAnnotationObject);
                    self.Menu.hide();
                });
    }

    // Create a new annotation item from the annotation layer.
    // Save it in the database.  Add the annotation as a dot in the GUI.
    GirderWidget.prototype.NewAnnotationItem = function() {
        var annot = {"elements": []};
        annot.name = "SA-"+this.AnnotationObjects.length;
        annot.elements = this.RecordAnnotation();

        // Make a new annotation in the database.
        var self = this;
        if (window.girder) { // Conditional is for testing in slide atlas.
            girder.restRequest({
                path:  "annotation?itemId="+this.ImageItemId,
                method: 'POST',
                contentType:'application/json',
                data: JSON.stringify(annot),
            }).done(function(retAnnot) {
                // This has the girder id.
                self.Highlight(self.AddAnnotation(retAnnot));
            });
        } else {
            // for debugging without girder.
            self.Highlight(self.AddAnnotation(
                {_id:'ABC',
                 annotation:annot,
                 itemId:self.ImageItemId}));
        }
    }

    GirderWidget.prototype.LoadGirderImageItem = function(itemId) {
        //var itemId = "564e42fe3f24e538e9a20eb9";
        var data= {"itemId": itemId,
                   "limit": 50,
                   "offset": 0,
                   "sort":"lowerName",
                   "sortdir":0};

        var self = this;
        // This gives an array of {_id:"....",annotation:{name:"...."},itemId:"...."}
        girder.restRequest({
            path:   "annotation",
            method: "GET",
            data:   JSON.stringify(data)
        }).done(function(data) {
            for (var i = 0; i < data.length; ++i) {
                self.LoadAnnotationItem(data[i]._id);
            }
        });
    }
{'fraction_non_alphanumeric': 0.14556962025316456, 'fraction_numerical': 0.012760310330747244, 'mean_word_length': 1.4714934409687184, 'pattern_counts': {'":': 12, '<': 15, '<?xml version=': 0, '>': 13, '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': '569513', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2606, 'n_words': 559}