<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 */
/*global console:false*/

(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};
		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 participated' class='filter' action='me' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'me'})\"><span>me</span><div class='filter-count'>...</div></a><a title='toggle filter: starred threads' class='filter' action='star' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'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' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'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'/>");
		$("body").append("<ul id='contextmenu_notepaneView' class='contextMenu'><li class='reply'><a href='#reply'>Reply</a></li></ul>");                },
        _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){
				$.concierge.trigger({type:"select_thread", value: firstlocid});
            }
			}
			break;
            }	
		}	
        },
        _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]");
  var locs_me        = locs.intersect(m.get("comment", {id_author: me.id}).values("ID_location"));
        var locs_star        = m.get("threadmark", {active: true, type: self._STAR });
        var locs_question    = m.get("threadmark", {active: true, type: self._QUESTION });

        var locs_filtered = locs;
        if (self._filters.me){
            $filter_me.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_me.items);
        }
        if (self._filters.star){
            $filter_star.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_star.values("location_id"));
        }
        if (self._filters.question){
            $filter_question.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_question.values("location_id"));
        }
        var n_me =  locs_me;
        var n_star = locs_star;
        var n_question = locs_question;

     $("div.filter-count", $filter_me).text(n_me.length());
     $("div.filter-count", $filter_star).text(n_star.length());    
     $("div.filter-count", $filter_question).text(n_question.length());    
     if (filters_on){
    $("span.filter-msg-unfiltered", self.element).hide();
    $("span.filter-msg-filtered", self.element).show();
    $("span.n_total", self.element).text(n_unfiltered);
    $("span.n_filtered", self.element).text(locs_filtered.length());
     } 
     else{
    $("span.filter-msg-unfiltered", self.element).show();
    $("span.filter-msg-filtered", self.element).hide();    
    $("span.n_unfiltered", self.element).text(locs.length());
     }
     },
     _lens: function(l){
     var self = this;
     var m = self._model;
     var me = $.concierge.get_component("get_userinfo")();
    
     var numnotes = m.get("comment", {ID_location: l.ID}).length();
     var numseen = m.get("seen", {id_location: l.ID}).length();
     var numstar = m.get("threadmark",    {active: true, type: self._STAR, location_id: l.ID }).length();
     var numquestion = m.get("threadmark",    {active: true, type: self._QUESTION, location_id: l.ID }).length();

     var unseen_me = m.get("comment", {ID_location: l.ID, id_author: me.id}).length() -    m.get("seen", {ID_location: l.ID, id_author: me.id}).length(); 
     var numnew    = numnotes - numseen - unseen_me; //so that notes that I've authored but that I haven't seen don't count.    
     var lf_numnotes =    "<ins class='locationflag "+(numnew>0?"lf-numnewnotes":"lf-numnotes")+"'>"+numnotes+"</ins>";
     var lf_admin    = m.get("comment", {ID_location: l.ID, admin:1}).is_empty() ? "" : "<ins class='locationflag'><div class='nbicon adminicon' title='An instructor/admin has participated to this thread'>&nbsp;</div></ins>";
     var lf_me_private =    m.get("comment", {ID_location: l.ID, id_author:me.id}).is_empty() ? "": (m.get("comment", {ID_location: l.ID, type:1}).is_empty() ?    "<ins class='locationflag'><div class='nbicon meicon' title='I participated to this thread'/></ins>" : "<ins class='locationflag'><div class='nbicon privateicon' title='I have private comments in    this thread'/></ins>" );
     var bold_cl    = numnew > 0 ? "location-bold" : "";
     var lf_star    = numstar > 0 ? "<ins class='locationflag'><div class='nbicon staricon-hicontrast' title='This thread has been starred'/></ins>" : "";
     var lf_question    = numquestion > 0 ? "<ins class='locationflag'><div class='nbicon questionicon-hicontrast' title='A reply is requested on this thread'/></ins>" : "";
     var root =    m.get("comment", {ID_location: l.ID, id_parent: null}).first();
     var body = root.body.replace(/\s/g, "") === "" ? "<span class='empty_comment'>Empty Comment</span>" : $.E(root.body.substring(0, 200));
     return "<div class='location-flags'>"+lf_numnotes+lf_admin+lf_me_private+lf_star+lf_question+"</div><div class='location-shortbody "+(numquestion>0?"replyrequested":"")+"'><div class='location-shortbody-text "+bold_cl+"'>"+body+" -l.ID: " + l.ID +"</div></div>";
     }, 
     _keydown: function(event){
     var self=this;
     var codes = {37: {sel: "prev", no_sel: "last", dir: "up", msg:"No more comments above..."}, 39: {sel: "next", no_sel:"first", dir: "down", msg:"No more comments below..."}}; 
     var new_sel, id_item, id_new;

     if (event.shiftKey || event.altKey || event.ctrlKey) {
    // We aren ot expecting shift, alt, or ctrl with our key codes, so we let others handle this
    return true;
     }

     if (event.keyCode in codes){
    var sel = $("div.location-lens.selected", self.element);
    if (sel.length){
    new_sel = sel[codes[event.keyCode].sel]("div.location-lens");
    if (new_sel.length){
    self._is_first_stroke = true;
    new_sel.click();
    }     
    else { // we need to find a following location on subsequent pages
    id_item = sel.attr("id_item");<commit_msg>revert some debug msg<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};
		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 participated' class='filter' action='me' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'me'})\"><span>me</span><div class='filter-count'>...</div></a><a title='toggle filter: starred threads' class='filter' action='star' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'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' href=\"javascript:$.concierge.trigger({type: 'filter_toggle', value:'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'/>");
		$("body").append("<ul id='contextmenu_notepaneView' class='contextMenu'><li class='reply'><a href='#reply'>Reply</a></li></ul>");                },
        _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){
				$.concierge.trigger({type:"select_thread", value: firstlocid});
            }
			}
			break;
            }	
		}	
        },
        _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]");
  var locs_me        = locs.intersect(m.get("comment", {id_author: me.id}).values("ID_location"));
        var locs_star        = m.get("threadmark", {active: true, type: self._STAR });
        var locs_question    = m.get("threadmark", {active: true, type: self._QUESTION });

        var locs_filtered = locs;
        if (self._filters.me){
            $filter_me.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_me.items);
        }
        if (self._filters.star){
            $filter_star.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_star.values("location_id"));
        }
        if (self._filters.question){
            $filter_question.addClass("active");
            filters_on = true;
            locs_filtered = locs_filtered.intersect(locs_question.values("location_id"));
        }
        var n_me =  locs_me;
        var n_star = locs_star;
        var n_question = locs_question;

     $("div.filter-count", $filter_me).text(n_me.length());
     $("div.filter-count", $filter_star).text(n_star.length());    
     $("div.filter-count", $filter_question).text(n_question.length());    
     if (filters_on){
    $("span.filter-msg-unfiltered", self.element).hide();
    $("span.filter-msg-filtered", self.element).show();
    $("span.n_total", self.element).text(n_unfiltered);
    $("span.n_filtered", self.element).text(locs_filtered.length());
     } 
     else{
    $("span.filter-msg-unfiltered", self.element).show();
    $("span.filter-msg-filtered", self.element).hide();    
    $("span.n_unfiltered", self.element).text(locs.length());
     }
     },
     _lens: function(l){
     var self = this;
     var m = self._model;
     var me = $.concierge.get_component("get_userinfo")();
     var numnotes = m.get("comment", {ID_location: l.ID}).length();
     var numseen = m.get("seen", {id_location: l.ID}).length();
     var numstar = m.get("threadmark",    {active: true, type: self._STAR, location_id: l.ID }).length();
     var numquestion = m.get("threadmark",    {active: true, type: self._QUESTION, location_id: l.ID }).length();

     var unseen_me = m.get("comment", {ID_location: l.ID, id_author: me.id}).length() -    m.get("seen", {ID_location: l.ID, id_author: me.id}).length(); 
     var numnew    = numnotes - numseen - unseen_me; //so that notes that I've authored but that I haven't seen don't count.    
     var lf_numnotes =    "<ins class='locationflag "+(numnew>0?"lf-numnewnotes":"lf-numnotes")+"'>"+numnotes+"</ins>";
     var lf_admin    = m.get("comment", {ID_location: l.ID, admin:1}).is_empty() ? "" : "<ins class='locationflag'><div class='nbicon adminicon' title='An instructor/admin has participated to this thread'>&nbsp;</div></ins>";
     var lf_me_private =    m.get("comment", {ID_location: l.ID, id_author:me.id}).is_empty() ? "": (m.get("comment", {ID_location: l.ID, type:1}).is_empty() ?    "<ins class='locationflag'><div class='nbicon meicon' title='I participated to this thread'/></ins>" : "<ins class='locationflag'><div class='nbicon privateicon' title='I have private comments in    this thread'/></ins>" );
     var bold_cl    = numnew > 0 ? "location-bold" : "";
     var lf_star    = numstar > 0 ? "<ins class='locationflag'><div class='nbicon staricon-hicontrast' title='This thread has been starred'/></ins>" : "";
     var lf_question    = numquestion > 0 ? "<ins class='locationflag'><div class='nbicon questionicon-hicontrast' title='A reply is requested on this thread'/></ins>" : "";
     var root =    m.get("comment", {ID_location: l.ID, id_parent: null}).first();
     var body = root.body.replace(/\s/g, "") === "" ? "<span class='empty_comment'>Empty Comment</span>" : $.E(root.body.substring(0, 200));
     return "<div class='location-flags'>"+lf_numnotes+lf_admin+lf_me_private+lf_star+lf_question+"</div><div class='location-shortbody "+(numquestion>0?"replyrequested":"")+"'><div class='location-shortbody-text "+bold_cl+"'>"+body+"</div></div>";
     }, 
     _keydown: function(event){
     var self=this;
     var codes = {37: {sel: "prev", no_sel: "last", dir: "up", msg:"No more comments above..."}, 39: {sel: "next", no_sel:"first", dir: "down", msg:"No more comments below..."}}; 
     var new_sel, id_item, id_new;

     if (event.shiftKey || event.altKey || event.ctrlKey) {
    // We aren ot expecting shift, alt, or ctrl with our key codes, so we let others handle this
    return true;
     }

     if (event.keyCode in codes){
    var sel = $("div.location-lens.selected", self.element);
    if (sel.length){
    new_sel = sel[codes[event.keyCode].sel]("div.location-lens");
    if (new_sel.length){
    self._is_first_stroke = true;
    new_sel.click();
    }     
    else { // we need to find a following location on subsequent pages
    id_item = sel.attr("id_item");
{'fraction_non_alphanumeric': 0.17509404251596536, 'fraction_numerical': 0.0049864403814189485, 'mean_word_length': 3.0623667377398722, 'pattern_counts': {'":': 22, '<': 137, '<?xml version=': 0, '>': 153, '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': '809935', 'n_tokens_mistral': 7831, 'n_tokens_neox': 7399, 'n_words': 1525}