<commit_before>/*$.Cow.ConnectWidget = {
init: function(){
var widget = $('#connect');
var cow = $('#cow').data('cow');
cow.events.bind('connected',{}, this._onConnect);
},
_onConnect: function() {
}
}
*/
(function($) {
$.widget("cow.PeersWidget", {
    options: {
        // The cow.core instance
        core: undefined,
        name: '#myname'
    },
 _create: function() {
        var core;
        var self = this;        
        var element = this.element;

        core = $(this.options.core).data('cow');
        this.core=core;
        core.bind("ws-disconnected", {widget: self}, self._onPeerStoreChanged);
        core.bind("ws-peerInfo", {widget: self}, self._onPeerStoreChanged);
        core.bind("ws-peerGone", {widget: self}, self._onPeerStoreChanged);
        core.bind("peerStoreChanged" ,{widget: self}, self._onPeerStoreChanged);
       
        
        element.delegate('.location','click', function(){
            var owner = $(this).attr('owner');
            var peer = core.getPeerByUid(owner);
            var location = peer.position().point;
            self.core.center({position:location});
        });
        
        element.delegate('.extent','click', function(){
            var owner = $(this).attr('owner');
            var peer = core.getPeerByUid(owner);
            var bbox = peer.view().extent;
            self.core.center({view:bbox});
        });
        
        //Preliminary peerjs video connection
        element.delegate('.videoconnection','click', function(){
            var owner = $(this).attr('owner');
            $('#videopanel').add("button").on("click",function(e){
                console.log("Closing "  + owner);
                self.peer1.managers[owner].close();
                $('#videopanel').hide();
            });
            
            $('#videopanel').show();
            
            mc = self.peer1.call(owner, ls);
            tmp = self.peer1;
            mc.on('stream', function(s){
                window.remote = s;
                  z = $('<video></video>', {src: URL.createObjectURL(s), autoplay: true}).appendTo('#videoplace');
              });
            
         });
        
        element.delegate('.herd','click', function(){
            var herd = $(this).attr('herd');
            self.core.activeHerd = herd;
            if (self.core.me())
                self.core.me().herd({uid: herd});
            
            self.core.featurestore().clear(); //Clear featurestore
            //self.core.options.storename = "store_"+herd; //TODO: the link between activeHerd and storename can be better
            self.core.localdbase().loadFromDB();//Fill featurestore with what we have
            
            
        });
        
        $(this.options.name).change(function(){
            self.core.me().owner({"name":$(this).val()});
            
        });

    },
    _destroy: function() {
        this.element.removeClass('ui-dialog ui-widget ui-widget-content ' +
                                 'ui-corner-all')
            .empty();
    },
    
    
    _onPeerStoreChanged: function(evt) {
    console.log('_onNewPeer');
        var self = evt.data.widget;
        self._updateList(evt);
    },
    
    _updateList: function(evt) {        
        var self = evt.data.widget;
        var peers = self.core.peers();
        var herds = [];
        var element = self.element;
        
        $.each(self.core.herds(),function(i) {
            herds[i] = {};
            herds[i].uid = this.uid;
            herds[i].name = this.name;
            herds[i].peers = [];
        });<commit_msg>update the list when offline<commit_after>/*$.Cow.ConnectWidget = {
init: function(){
var widget = $('#connect');
var cow = $('#cow').data('cow');
cow.events.bind('connected',{}, this._onConnect);
},
_onConnect: function() {
}
}
*/
(function($) {
$.widget("cow.PeersWidget", {
    options: {
        // The cow.core instance
        core: undefined,
        name: '#myname'
    },
 _create: function() {
        var core;
        var self = this;        
        var element = this.element;

        core = $(this.options.core).data('cow');
        this.core=core;
        core.bind("ws-disconnected", {widget: self}, self._onPeerStoreChanged);
        core.bind("ws-peerInfo", {widget: self}, self._onPeerStoreChanged);
        core.bind("ws-peerGone", {widget: self}, self._onPeerStoreChanged);
        core.bind("peerStoreChanged" ,{widget: self}, self._onPeerStoreChanged);
       
        
        element.delegate('.location','click', function(){
            var owner = $(this).attr('owner');
            var peer = core.getPeerByUid(owner);
            var location = peer.position().point;
            self.core.center({position:location});
        });
        
        element.delegate('.extent','click', function(){
            var owner = $(this).attr('owner');
            var peer = core.getPeerByUid(owner);
            var bbox = peer.view().extent;
            self.core.center({view:bbox});
        });
        
        //Preliminary peerjs video connection
        element.delegate('.videoconnection','click', function(){
            var owner = $(this).attr('owner');
            $('#videopanel').add("button").on("click",function(e){
                console.log("Closing "  + owner);
                self.peer1.managers[owner].close();
                $('#videopanel').hide();
            });
            
            $('#videopanel').show();
            
            mc = self.peer1.call(owner, ls);
            tmp = self.peer1;
            mc.on('stream', function(s){
                window.remote = s;
                  z = $('<video></video>', {src: URL.createObjectURL(s), autoplay: true}).appendTo('#videoplace');
              });
            
         });
        
        element.delegate('.herd','click', function(){
            var herd = $(this).attr('herd');
            self.core.activeHerd = herd;
            if (self.core.me())
                self.core.me().herd({uid: herd});
            self._updateList(self);
            self.core.featurestore().clear(); //Clear featurestore
            //self.core.options.storename = "store_"+herd; //TODO: the link between activeHerd and storename can be better
            self.core.localdbase().loadFromDB();//Fill featurestore with what we have
            
            
        });
        
        $(this.options.name).change(function(){
            self.core.me().owner({"name":$(this).val()});
            
        });

    },
    _destroy: function() {
        this.element.removeClass('ui-dialog ui-widget ui-widget-content ' +
                                 'ui-corner-all')
            .empty();
    },
    
    
    _onPeerStoreChanged: function(evt) {
    console.log('_onNewPeer');
        var self = evt.data.widget;
        self._updateList(self);
    },
    
    _updateList: function(self) {        
        var peers = self.core.peers();
        var herds = [];
        var element = self.element;
        
        $.each(self.core.herds(),function(i) {
            herds[i] = {};
            herds[i].uid = this.uid;
            herds[i].name = this.name;
            herds[i].peers = [];
        });
{'fraction_non_alphanumeric': 0.1665741254858412, 'fraction_numerical': 0.000832870627429206, 'mean_word_length': 1.754204892966361, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4409131', 'n_tokens_mistral': 2052, 'n_tokens_neox': 2047, 'n_words': 350}