<commit_before>/* notepaneView Plugin
 * Depends:
 *    ui.core.js
 *    ui.view.js
 *

 Author 
 cf AUTHORS.txt 

 License
 Copyright (c) 2010-2012 Massachusetts Institute of Technology.
 MIT License (cf. MIT-LICENSE.txt or http://www.opensource.org/licenses/mit-license.php)
*/
/*global jQuery:true NB$:true */
(function($) {
    var $str     = "NB$" in window ? "NB$" : "jQuery";
    var V_OBJ = $.extend({},$.ui.view.prototype,{
        _f_location_seen: function(id_location){
		var self = this;
		return function(){
            var m = self._model;
            var o = m.get("comment", {ID_location: id_location}).items;
            var i;
            var new_seen = {};
            for (i in o){
			if (!(i in m.o.seen)){
            new_seen[i] = {id: i, id_location: id_location};
            $.concierge.logHistory("seen", i);
			}
            }            
            //            $.L("Marking thread " + id_location + " as seen !");
            self._model.add("seen", new_seen);
		};
        },
        _create: function() {
		$.ui.view.prototype._create.call(this);
		var self = this;
		self._maxpage =    0; //last (i.e. max page number of) page that has been rendered
		self.SEC_MULT_FACTOR = $.concierge.get_component("get_sec_mult_factor")();
		self.T_METRONOME = $.concierge.get_component("get_metronome_period_s")();
		self._page =    null; 
		self._scrollTimerID	=    null;
		self._seenTimerID	= null;
		self._id_location	= null; //location_id of selected thread
		self._is_first_stroke	= true;
		self._rendered		= false;
		self._filters		= {me: false, star: false, question: false, tag: false};
		self.QUESTION		= null;
		self.STAR		= null;
		self.element.addClass("notepaneView").append("<div class='notepaneView-header'><div class='filter-controls'><a title='toggle filter: threads in which I am tagged' class='filter' action='tag' id='filter_tag'><span>tag</span><div class='filter-count'>...</div></a><a title='toggle filter: threads in which I participated' class='filter' action='me' id='filter_me'><span>me</span><div class='filter-count'>...</div></a><a title='toggle filter: starred threads' class='filter' action='star' id='filter_star'><span><div class='nbicon staricon' style='margin-top: -3px'/></span><div class='filter-count'>...</div></a><a title='toggle filter: threads with standing questions' class='filter' action='question' id='filter_question'><span>    <div class='nbicon questionicon' style='margin-top: -3px'/>    </span><div class='filter-count'>...</div></a></div><span class='filter-msg-filtered'><span class='n_filtered'>0</span> threads out of <span class='n_total'>0</span></span><span class='filter-msg-unfiltered'><span class='n_unfiltered'>0</span> threads</span></div><div class='notepaneView-pages'/>");

                $("#filter_me").click(function() {$.concierge.trigger({type: "filter_toggle", value: "me"});});
                $("#filter_star").click(function() {$.concierge.trigger({type: "filter_toggle", value: "star"});});
                $("#filter_question").click(function() {$.concierge.trigger({type: "filter_toggle", value: "question"});});
                $("#filter_tag").click(function() {$.concierge.trigger({type: "filter_toggle", value: "tag"});});
        },
        _defaultHandler: function(evt){
		var self=this;
		if (self._id_source ===    $.concierge.get_state("file")){
            switch (evt.type){
            case "page":
                if (self._page !== parseInt(evt.value, 10)){
            self._page =  parseInt(evt.value, 10);  
            self._render();
			}
			break;
            case "filter_toggle": 
			if (evt.value in self._filters){
            self._filters[evt.value] = (!(self._filters[evt.value]));
            self._page =    1;
            self._maxpage = 0;
            self._render(true);
			}
			break;
            case "note_hover": 
			$("div.location-lens[id_item="+evt.value+"]", self.element).addClass("hovered");
			break;
            case "note_out": 
			$("div.location-lens[id_item="+evt.value+"]", self.element).removeClass("hovered");		
			break;
            case "warn_page_change": 
			$.L("[notepaneView11] TODO: warn_page_change");
			break;
            case "select_thread": 
			$("div.location-pagesummary.selected", self.element).removeClass("selected");
			if (self._seenTimerID != null){
            window.clearTimeout(self._seenTimerID);
			}
			self._seenTimerID = window.setTimeout(self._f_location_seen(evt.value), 1000);
			var o = self._model.o.location[evt.value];
			if (o.page !==  self._page){
            self._page =    o.page;
            self._render();
			}
			$("div.location-lens[id_item="+self._id_location+"]", self.element).removeClass("selected");
			self._id_location = evt.value;
			var sel = $("div.location-lens[id_item="+evt.value+"]",self.element).addClass("selected");
			var container = $("div.notepaneView-pages", self.element);
			if (sel.length>0){
            var scrollby;
            var h = sel.height() ;
            var H = container.height();
            var delta_top = sel.offset().top - container.offset().top;
            var delta_bottom = delta_top + h - H;
            if (delta_top > 0){ //selected note is not too high
				if (delta_bottom > 0) {//but it's too low... scroll down
                scrollby = delta_bottom + H/2-h; //delta_bottom is how much to scroll so that bottom of lens coincides with bottom of widget. 
                container.stop(true).animate({scrollTop: '+=' + scrollby + 'px'}, 300);
				}
            }
            else{ //too high: recenter: 
				scrollby = delta_top + (h-H)/2;
				container.stop(true).animate({scrollTop: '+='+scrollby+'px'}, 300);
            }
			}
			break;
            case "keydown": 
			self._keydown(evt.value);
			break;
            case "metronome": 
			//is there an annotation over the upcoming metronom period
			var p0 = Math.floor(evt.value * self.SEC_MULT_FACTOR);
			var p1 = p0 + self.SEC_MULT_FACTOR * self.T_METRONOME; 
			var locs = self._model.get("location", {page__in: [p0, p1]});
			if (!locs.is_empty()){
            var firstlocid = String(locs.first().ID);
            if (firstlocid !== self._id_location){
				console.log("New Thread");
				$.concierge.trigger({type:"select_thread", value: firstlocid});
            }
			}
			break;
            }	
		}	
        },
        // Given user me and full location set locs
        // Returns locs intersected with the ids of all locations user me is tagged in
        _get_tagged_locs: function(me, locs){
            var self = this;
            var m = self._model;
            var tags = m.get("tags", {user_id: me.id});
            var tag_loc_ids = {};
            for (var i in tags.items) {
                var new_loc_id = m.get("comment", {ID: tags.items[i].comment_id}).first().ID_location;
                tag_loc_ids[new_loc_id] = new_loc_id;
            }
            return locs.intersect(tag_loc_ids);
        },
        _update_filters: function(){
		var self = this;
		var m = self._model;
		var locs = m.get("location", {id_source:    self._id_source});
		var me = $.concierge.get_component("get_userinfo")();
		var n_unfiltered = locs.length();
		var filters_on = false;
		var $filters = $("a.filter", self.element).removeClass("active");
		var $filter_me = $filters.filter("[action=me]");
		var $filter_star = $filters.filter("[action=star]");
		var $filter_question = $filters.filter("[action=question]");<commit_msg>Function _get_in_range_locs can now detect all comments whose window we are in<commit_after>/* notepaneView Plugin
 * Depends:
 *    ui.core.js
 *    ui.view.js
 *

 Author 
 cf AUTHORS.txt 

 License
 Copyright (c) 2010-2012 Massachusetts Institute of Technology.
 MIT License (cf. MIT-LICENSE.txt or http://www.opensource.org/licenses/mit-license.php)
*/
/*global jQuery:true NB$:true */
(function($) {
    var $str     = "NB$" in window ? "NB$" : "jQuery";
    var V_OBJ = $.extend({},$.ui.view.prototype,{
        _f_location_seen: function(id_location){
		var self = this;
		return function(){
            var m = self._model;
            var o = m.get("comment", {ID_location: id_location}).items;
            var i;
            var new_seen = {};
            for (i in o){
			if (!(i in m.o.seen)){
            new_seen[i] = {id: i, id_location: id_location};
            $.concierge.logHistory("seen", i);
			}
            }            
            //            $.L("Marking thread " + id_location + " as seen !");
            self._model.add("seen", new_seen);
		};
        },
        _create: function() {
		$.ui.view.prototype._create.call(this);
		var self = this;
		self._maxpage =    0; //last (i.e. max page number of) page that has been rendered
		self.SEC_MULT_FACTOR = $.concierge.get_component("get_sec_mult_factor")();
		self.T_METRONOME = $.concierge.get_component("get_metronome_period_s")();
		self._page =    null; 
		self._scrollTimerID	=    null;
		self._seenTimerID	= null;
		self._id_location	= null; //location_id of selected thread
		self._is_first_stroke	= true;
		self._rendered		= false;
		self._filters		= {me: false, star: false, question: false, tag: false};
		self.QUESTION		= null;
		self.STAR		= null;
		self.element.addClass("notepaneView").append("<div class='notepaneView-header'><div class='filter-controls'><a title='toggle filter: threads in which I am tagged' class='filter' action='tag' id='filter_tag'><span>tag</span><div class='filter-count'>...</div></a><a title='toggle filter: threads in which I participated' class='filter' action='me' id='filter_me'><span>me</span><div class='filter-count'>...</div></a><a title='toggle filter: starred threads' class='filter' action='star' id='filter_star'><span><div class='nbicon staricon' style='margin-top: -3px'/></span><div class='filter-count'>...</div></a><a title='toggle filter: threads with standing questions' class='filter' action='question' id='filter_question'><span>    <div class='nbicon questionicon' style='margin-top: -3px'/>    </span><div class='filter-count'>...</div></a></div><span class='filter-msg-filtered'><span class='n_filtered'>0</span> threads out of <span class='n_total'>0</span></span><span class='filter-msg-unfiltered'><span class='n_unfiltered'>0</span> threads</span></div><div class='notepaneView-pages'/>");

                $("#filter_me").click(function() {$.concierge.trigger({type: "filter_toggle", value: "me"});});
                $("#filter_star").click(function() {$.concierge.trigger({type: "filter_toggle", value: "star"});});
                $("#filter_question").click(function() {$.concierge.trigger({type: "filter_toggle", value: "question"});});
                $("#filter_tag").click(function() {$.concierge.trigger({type: "filter_toggle", value: "tag"});});
        },
        _defaultHandler: function(evt){
		var self=this;
		if (self._id_source ===    $.concierge.get_state("file")){
            switch (evt.type){
            case "page":
                if (self._page !== parseInt(evt.value, 10)){
            self._page =  parseInt(evt.value, 10);  
            self._render();
			}
			break;
            case "filter_toggle": 
			if (evt.value in self._filters){
            self._filters[evt.value] = (!(self._filters[evt.value]));
            self._page =    1;
            self._maxpage = 0;
            self._render(true);
			}
			break;
            case "note_hover": 
			$("div.location-lens[id_item="+evt.value+"]", self.element).addClass("hovered");
			break;
            case "note_out": 
			$("div.location-lens[id_item="+evt.value+"]", self.element).removeClass("hovered");		
			break;
            case "warn_page_change": 
			$.L("[notepaneView11] TODO: warn_page_change");
			break;
            case "select_thread": 
			$("div.location-pagesummary.selected", self.element).removeClass("selected");
			if (self._seenTimerID != null){
            window.clearTimeout(self._seenTimerID);
			}
			self._seenTimerID = window.setTimeout(self._f_location_seen(evt.value), 1000);
			var o = self._model.o.location[evt.value];
			if (o.page !==  self._page){
            self._page =    o.page;
            self._render();
			}
			$("div.location-lens[id_item="+self._id_location+"]", self.element).removeClass("selected");
			self._id_location = evt.value;
			var sel = $("div.location-lens[id_item="+evt.value+"]",self.element).addClass("selected");
			var container = $("div.notepaneView-pages", self.element);
			if (sel.length>0){
            var scrollby;
            var h = sel.height() ;
            var H = container.height();
            var delta_top = sel.offset().top - container.offset().top;
            var delta_bottom = delta_top + h - H;
            if (delta_top > 0){ //selected note is not too high
				if (delta_bottom > 0) {//but it's too low... scroll down
                scrollby = delta_bottom + H/2-h; //delta_bottom is how much to scroll so that bottom of lens coincides with bottom of widget. 
                container.stop(true).animate({scrollTop: '+=' + scrollby + 'px'}, 300);
				}
            }
            else{ //too high: recenter: 
				scrollby = delta_top + (h-H)/2;
				container.stop(true).animate({scrollTop: '+='+scrollby+'px'}, 300);
            }
			}
			break;
            case "keydown": 
			self._keydown(evt.value);
			break;
            case "metronome": 
			//is there an annotation over the upcoming metronom period
			var p0 = Math.floor(evt.value * self.SEC_MULT_FACTOR);
			var p1 = p0 + self.SEC_MULT_FACTOR * self.T_METRONOME; 
			var locs = self._model.get("location", {page__in: [p0, p1]});
			if (!locs.is_empty()){
            var firstlocid = String(locs.first().ID);
            if (firstlocid !== self._id_location){
				console.log("New Thread");
				$.concierge.trigger({type:"select_thread", value: firstlocid});
            }
			}
			break;
            }	
		}	
        },
        // Given current timestamp (page) returns locations that have started and not ended
        _get_in_range_locs: function(page){
            var self = this;
            var m = self._model;
            // Get locations that have started
            var started_locs = m.get("location", {page__in: [0, page]});
            // Get locations that have not ended
            var not_ended_ids = {};
            for (var i in started_locs.items) {
                var cur_loc = started_locs.items[i];
                // Handle null duration here
                if (cur_loc.duration === null) {cur_loc.duration = 2;}
                var end_page = cur_loc.page + (cur_loc.duration * self.SEC_MULT_FACTOR);
                if (page < end_page) {not_ended_ids[cur_loc.ID] = cur_loc.ID;}
            }
            // Return the intersection of locations that started and locations that didn't end
            return started_locs.intersect(not_ended_ids);
        },
        // Given user me and full location set locs
        // Returns locs intersected with the ids of all locations user me is tagged in
        _get_tagged_locs: function(me, locs){
            var self = this;
            var m = self._model;
            var tags = m.get("tags", {user_id: me.id});
            var tag_loc_ids = {};
            for (var i in tags.items) {
                var new_loc_id = m.get("comment", {ID: tags.items[i].comment_id}).first().ID_location;
                tag_loc_ids[new_loc_id] = new_loc_id;
            }
            return locs.intersect(tag_loc_ids);
        },
        _update_filters: function(){
		var self = this;
		var m = self._model;
		var locs = m.get("location", {id_source:    self._id_source});
		var me = $.concierge.get_component("get_userinfo")();
		var n_unfiltered = locs.length();
		var filters_on = false;
		var $filters = $("a.filter", self.element).removeClass("active");
		var $filter_me = $filters.filter("[action=me]");
		var $filter_star = $filters.filter("[action=star]");
		var $filter_question = $filters.filter("[action=question]");
{'fraction_non_alphanumeric': 0.16205186161863502, 'fraction_numerical': 0.005399635838513216, 'mean_word_length': 2.67597507500577, 'pattern_counts': {'":': 16, '<': 86, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7477130', 'n_tokens_mistral': 5364, 'n_tokens_neox': 5023, 'n_words': 1086}