<commit_before>define([
    "dojo/_base/lang",
    "dojo/dom",
    "dojo/dom-class",
    "dojo/dom-construct",
    "dojo/dom-geometry",
    "dojo/dom-style",
    "dojo/string",
    "dojo/_base/connect",
    "dojo/window",
    "dijit/registry",
    "dojox/mvc/getStateful",
    "anno/anno/AnnoDataHandler",
    "anno/common/Util",
    "anno/common/OAuthUtil"
],
    function (lang, dom, domClass, domConstruct, domGeom, domStyle, dojoString, connect, win, registry, getStateful, AnnoDataHandler, Util, OAuthUtil)
    {
        var _connectResults = []; // events connect results
        var app = null, eventsModel = null, needRefresh = true,
            lastOpenAnnoId = "";
        var emptyAnno = {
            "id": 0,
            "annoText": "0",
            "app": "0",
            "author": "0",
            "screenshot":"0",
            circleX: 0,
            circleY:0,
            level:1,
            deviceInfo:" ",
            created:"",
            comments:[{
                author:'',
                comment:''
            }]
        };

        var loadMyAnnos = function()
        {
            AnnoDataHandler.loadLocalAnnos(function (localAnnos){
                console.log("getting my stuff from server.");
                var APIConfig = {
                    name: Util.API.anno,
                    method: "anno.anno.mystuff",
                    parameter: {},
                    needAuth: true,
                    success: function(data)
                    {
                        var annoList = [];

                        if (data&&data.result)
                        {
                            annoList = data.result.anno_list||[];
                        }

                        var spliceArgs = [0, eventsModel.model.length], eventData, userInfo = Util.getCurrentUserInfo(), userName = userInfo.nickname;

                        for (var i= 0, l=localAnnos.length;i<l;i++)
                        {
                            eventData = lang.clone(emptyAnno);

                            eventData.annoText = localAnnos[i].comment;
                            eventData.annoType = localAnnos[i].anno_type;
                            eventData.annoIcon = localAnnos[i].anno_type == Util.annoType.SimpleComment?"icon-simplecomment":"icon-shapes";
                            eventData.app = localAnnos[i].app_name;
                            eventData.screenshot_key = localAnnos[i].screenshot_key;
                            eventData.author = userName;
                            eventData.id = localAnnos[i]._id;
                            eventData.circleX = parseInt(localAnnos[i].x, 10);
                            eventData.circleY = parseInt(localAnnos[i].y, 10);
                            // eventData.simple_circle_on_top = localAnnos[i].direction==0||localAnnos[i].direction=='false';
                            eventData.simple_circle_on_top = false;

                            eventData.deviceInfo = (localAnnos[i].model||'&nbsp;')+'&nbsp;'+(localAnnos[i].os_name||'&nbsp;')+(localAnnos[i].os_version||'&nbsp;');
                            eventData.vote = false;
                            eventData.flag = false;
                            eventData.level = localAnnos[i].level;
                            eventData.draw_elements = localAnnos[i].draw_elements||"";
                            eventData.comments = [];
                            eventData.created = eventData.when = Util.getTimeAgoString(parseInt(localAnnos[i].created));

                            eventData.lastActivityClass = "";
                            eventData.lastActivityText = "created";

                            eventData.app_icon_url = localAnnos[i].app_icon_url||"";
                            if (eventData.app_icon_url)
                            {
                                eventData.annoIcon = "hidden";
                                eventData.appIconClass = "";
                            }
                            else
                            {
                                eventData.appIconClass = "hidden";
                            }

                            spliceArgs.push(new getStateful(eventData));
                        }

                        for (var i = 0, l = annoList.length; i < l; i++)
                        {
                            eventData = lang.clone(emptyAnno);

                            eventData.annoText = annoList[i].anno_text;
                            eventData.annoType = annoList[i].anno_type;
                            eventData.annoIcon = annoList[i].anno_type == Util.annoType.SimpleComment?"icon-simplecomment":"icon-shapes";
                            eventData.app = annoList[i].app_name;
                            eventData.author = annoList[i].creator?annoList[i].creator.display_name||annoList[i].creator.user_email||annoList[i].creator.user_id:"";
                            eventData.id = annoList[i].id;
                            // eventData.circleX = parseInt(annoList[i].simple_x, 10);
                            // eventData.circleY = parseInt(annoList[i].simple_y, 10);
                            eventData.circleX = 0;
                            eventData.circleY = 0;
                            // eventData.simple_circle_on_top = annoList[i].simple_circle_on_top;
                            eventData.simple_circle_on_top = false;
                            eventData.created = Util.getTimeAgoString(annoList[i].created);
                            eventData.app_icon_url = annoList[i].app_icon_url||"";

                            eventData.readStatusClass = "";
                            if ('anno_read_status' in annoList[i]) {
                                eventData.read_status = annoList[i].anno_read_status || false;
                                eventData.readStatusClass = (eventData.read_status == true) ? "read" : "unread";
                            }

                            if (eventData.app_icon_url)
                            {
                                eventData.annoIcon = "hidden";
                                eventData.appIconClass = "";
                            }
                            else
                            {
                                eventData.appIconClass = "hidden";
                            }

                            handleAnnoActivityInfo(eventData, annoList[i]);

                            spliceArgs.push(new getStateful(eventData));
                        }

                        eventsModel.model.splice.apply(eventsModel.model, spliceArgs);
                        Util.hideLoadingIndicator();

                        drawAnnos(spliceArgs);
                    },
                    error: function()
                    {
                    }
                };

                Util.callGAEAPI(APIConfig);
            });
        };

        var handleAnnoActivityInfo = function(anno, annoData)
        {
            var lastActivity = annoData.last_activity;
            if (lastActivity == "UserSource" || lastActivity == "create")
            {
                anno.lastActivityClass = "icon-plus";
                anno.lastActivityText = "created";
            }
            else if (lastActivity == "vote")
            {
                anno.lastActivityClass = "icon-thumbs-up";
                anno.lastActivityText = "voted-up";
            }
            else if (lastActivity == "flag")
            {
                anno.lastActivityClass = "icon-flag";
                anno.lastActivityText = "flagged";
            }
            else if (lastActivity == "follwup")
            {
                anno.lastActivityClass = "icon-comment";
                anno.lastActivityText = "commented";
            }
            else if (lastActivity == "anno")
            {
                anno.lastActivityClass = "icon-pencil";
                anno.lastActivityText = "edited";
            }


            anno.when = Util.getTimeAgoString(annoData.last_update_time);
        };

        var drawAnnos = function(annos)
        {
            if (annos.length <= 2)
            {
                domStyle.set('listContainerMyStuff', 'display', 'none');
                domStyle.set('learnHowContainer', 'display', '');
            }
            else
            {
                domStyle.set('listContainerMyStuff', 'display', '');
                domStyle.set('learnHowContainer', 'display', 'none');
            }
        };

        var adjustSize = function()
        {
            var viewPoint = win.getBox();
            var parentBox = domGeom.getMarginBox("headingMyStuff");

            domStyle.set("listContainerMyStuff", "height", (viewPoint.h-parentBox.h)+"px");
        };

        var goBack = function()
        {
            needRefresh = true;
            history.back();
        };

        var annoMyStuffRead = window.annoMyStuffRead = function() {
            needRefresh = false;
            lastOpenAnnoId = this._index;
            if (domClass.contains(this.domNode, "unread")) {
                domClass.replace(this.domNode, "read", "unread");
            }
        };

        return {
            // simple view init
            init:function ()
            {
                app = this.app;
                eventsModel = this.loadedModels.mystuff;
                app.refreshMyActivites = loadMyAnnos;

                _connectResults.push(connect.connect(dom.byId("btnLearnHow"), 'click', function(e)
                {
                    Util.startActivity("Intro", false);
                }));

                _connectResults.push(connect.connect(dom.byId("iconBackMyStuff"), 'click', function(e) {
                    dojo.stopEvent(e);
                    goBack();
                }));

                _connectResults.push(connect.connect(dom.byId("navBtnBackMyStuff"), 'click', function(e) {
                    dojo.stopEvent(e);
                    goBack();
                }));
            },
            afterActivate: function()
            {
                // Analytics
                Util.screenGATracking(Util.analytics.category.my_activity);
                
                adjustSize();

                if (needRefresh)
                {
                    loadMyAnnos();
                }
                else
                {
                    // update opened anno activity info
                    var activityIndicator = dom.byId("annoActIndicator_"+lastOpenAnnoId);

                    var currentAnno = eventsModel.cursor;
                    if (activityIndicator&&currentAnno.lastActivityChangedClass)
                    {
                        domClass.remove(activityIndicator);
                        domClass.add(activityIndicator, "annoOrangeColor");
                        domClass.add(activityIndicator, currentAnno.lastActivityChangedClass);

                        dom.byId("annoActText_"+lastOpenAnnoId).innerHTML = currentAnno.lastActivityText;
                        dom.byId("annoActWhen_"+lastOpenAnnoId).innerHTML = Util.getTimeAgoString(new Date().getTime(), new Date(currentAnno.when));

                        currentAnno.lastActivityChangedClass = "";
                    }
                }

                document.removeEventListener("backbutton", goBack, false);
                document.addEventListener("backbutton", goBack, false);
            },
            beforeDeactivate: function()
            {
                document.removeEventListener("backbutton", goBack, false);
            },
            destroy:function ()
            {
                var connectResult = _connectResults.pop();
                while (connectResult)
                {
                    connect.disconnect(connectResult);
                    connectResult = _connectResults.pop();
                }

                document.removeEventListener("backbutton", goBack, false);
            }
        }
    });<commit_msg>[Client] Stopped showing loading indicator when MyActivity is loading and it has already data<commit_after>define([
    "dojo/_base/lang",
    "dojo/dom",
    "dojo/dom-class",
    "dojo/dom-construct",
    "dojo/dom-geometry",
    "dojo/dom-style",
    "dojo/string",
    "dojo/_base/connect",
    "dojo/window",
    "dijit/registry",
    "dojox/mvc/getStateful",
    "anno/anno/AnnoDataHandler",
    "anno/common/Util",
    "anno/common/OAuthUtil"
],
    function (lang, dom, domClass, domConstruct, domGeom, domStyle, dojoString, connect, win, registry, getStateful, AnnoDataHandler, Util, OAuthUtil)
    {
        var _connectResults = []; // events connect results
        var app = null, eventsModel = null, needRefresh = true,
            lastOpenAnnoId = "";
        var emptyAnno = {
            "id": 0,
            "annoText": "0",
            "app": "0",
            "author": "0",
            "screenshot":"0",
            circleX: 0,
            circleY:0,
            level:1,
            deviceInfo:" ",
            created:"",
            comments:[{
                author:'',
                comment:''
            }]
        };

        var loadMyAnnos = function()
        {
            var showLoadingSpinner = document.querySelectorAll("#annoListMyStuff li").length > 0 ? false : true;

            AnnoDataHandler.loadLocalAnnos(function (localAnnos){
                console.log("getting my stuff from server.");
                var APIConfig = {
                    name: Util.API.anno,
                    method: "anno.anno.mystuff",
                    parameter: {},
                    needAuth: true,
                    showLoadingSpinner: showLoadingSpinner,
                    success: function(data)
                    {
                        var annoList = [];

                        if (data&&data.result)
                        {
                            annoList = data.result.anno_list||[];
                        }

                        var spliceArgs = [0, eventsModel.model.length], eventData, userInfo = Util.getCurrentUserInfo(), userName = userInfo.nickname;

                        for (var i= 0, l=localAnnos.length;i<l;i++)
                        {
                            eventData = lang.clone(emptyAnno);

                            eventData.annoText = localAnnos[i].comment;
                            eventData.annoType = localAnnos[i].anno_type;
                            eventData.annoIcon = localAnnos[i].anno_type == Util.annoType.SimpleComment?"icon-simplecomment":"icon-shapes";
                            eventData.app = localAnnos[i].app_name;
                            eventData.screenshot_key = localAnnos[i].screenshot_key;
                            eventData.author = userName;
                            eventData.id = localAnnos[i]._id;
                            eventData.circleX = parseInt(localAnnos[i].x, 10);
                            eventData.circleY = parseInt(localAnnos[i].y, 10);
                            // eventData.simple_circle_on_top = localAnnos[i].direction==0||localAnnos[i].direction=='false';
                            eventData.simple_circle_on_top = false;

                            eventData.deviceInfo = (localAnnos[i].model||'&nbsp;')+'&nbsp;'+(localAnnos[i].os_name||'&nbsp;')+(localAnnos[i].os_version||'&nbsp;');
                            eventData.vote = false;
                            eventData.flag = false;
                            eventData.level = localAnnos[i].level;
                            eventData.draw_elements = localAnnos[i].draw_elements||"";
                            eventData.comments = [];
                            eventData.created = eventData.when = Util.getTimeAgoString(parseInt(localAnnos[i].created));

                            eventData.lastActivityClass = "";
                            eventData.lastActivityText = "created";

                            eventData.app_icon_url = localAnnos[i].app_icon_url||"";
                            if (eventData.app_icon_url)
                            {
                                eventData.annoIcon = "hidden";
                                eventData.appIconClass = "";
                            }
                            else
                            {
                                eventData.appIconClass = "hidden";
                            }

                            spliceArgs.push(new getStateful(eventData));
                        }

                        for (var i = 0, l = annoList.length; i < l; i++)
                        {
                            eventData = lang.clone(emptyAnno);

                            eventData.annoText = annoList[i].anno_text;
                            eventData.annoType = annoList[i].anno_type;
                            eventData.annoIcon = annoList[i].anno_type == Util.annoType.SimpleComment?"icon-simplecomment":"icon-shapes";
                            eventData.app = annoList[i].app_name;
                            eventData.author = annoList[i].creator?annoList[i].creator.display_name||annoList[i].creator.user_email||annoList[i].creator.user_id:"";
                            eventData.id = annoList[i].id;
                            // eventData.circleX = parseInt(annoList[i].simple_x, 10);
                            // eventData.circleY = parseInt(annoList[i].simple_y, 10);
                            eventData.circleX = 0;
                            eventData.circleY = 0;
                            // eventData.simple_circle_on_top = annoList[i].simple_circle_on_top;
                            eventData.simple_circle_on_top = false;
                            eventData.created = Util.getTimeAgoString(annoList[i].created);
                            eventData.app_icon_url = annoList[i].app_icon_url||"";

                            eventData.readStatusClass = "";
                            if ('anno_read_status' in annoList[i]) {
                                eventData.read_status = annoList[i].anno_read_status || false;
                                eventData.readStatusClass = (eventData.read_status == true) ? "read" : "unread";
                            }

                            if (eventData.app_icon_url)
                            {
                                eventData.annoIcon = "hidden";
                                eventData.appIconClass = "";
                            }
                            else
                            {
                                eventData.appIconClass = "hidden";
                            }

                            handleAnnoActivityInfo(eventData, annoList[i]);

                            spliceArgs.push(new getStateful(eventData));
                        }

                        eventsModel.model.splice.apply(eventsModel.model, spliceArgs);
                        Util.hideLoadingIndicator();

                        drawAnnos(spliceArgs);
                    },
                    error: function()
                    {
                    }
                };

                Util.callGAEAPI(APIConfig);
            });
        };

        var handleAnnoActivityInfo = function(anno, annoData)
        {
            var lastActivity = annoData.last_activity;
            if (lastActivity == "UserSource" || lastActivity == "create")
            {
                anno.lastActivityClass = "icon-plus";
                anno.lastActivityText = "created";
            }
            else if (lastActivity == "vote")
            {
                anno.lastActivityClass = "icon-thumbs-up";
                anno.lastActivityText = "voted-up";
            }
            else if (lastActivity == "flag")
            {
                anno.lastActivityClass = "icon-flag";
                anno.lastActivityText = "flagged";
            }
            else if (lastActivity == "follwup")
            {
                anno.lastActivityClass = "icon-comment";
                anno.lastActivityText = "commented";
            }
            else if (lastActivity == "anno")
            {
                anno.lastActivityClass = "icon-pencil";
                anno.lastActivityText = "edited";
            }


            anno.when = Util.getTimeAgoString(annoData.last_update_time);
        };

        var drawAnnos = function(annos)
        {
            if (annos.length <= 2)
            {
                domStyle.set('listContainerMyStuff', 'display', 'none');
                domStyle.set('learnHowContainer', 'display', '');
            }
            else
            {
                domStyle.set('listContainerMyStuff', 'display', '');
                domStyle.set('learnHowContainer', 'display', 'none');
            }
        };

        var adjustSize = function()
        {
            var viewPoint = win.getBox();
            var parentBox = domGeom.getMarginBox("headingMyStuff");

            domStyle.set("listContainerMyStuff", "height", (viewPoint.h-parentBox.h)+"px");
        };

        var goBack = function()
        {
            needRefresh = true;
            history.back();
        };

        var annoMyStuffRead = window.annoMyStuffRead = function() {
            needRefresh = false;
            lastOpenAnnoId = this._index;
            if (domClass.contains(this.domNode, "unread")) {
                domClass.replace(this.domNode, "read", "unread");
            }
        };

        return {
            // simple view init
            init:function ()
            {
                app = this.app;
                eventsModel = this.loadedModels.mystuff;
                app.refreshMyActivites = loadMyAnnos;

                _connectResults.push(connect.connect(dom.byId("btnLearnHow"), 'click', function(e)
                {
                    Util.startActivity("Intro", false);
                }));

                _connectResults.push(connect.connect(dom.byId("iconBackMyStuff"), 'click', function(e) {
                    dojo.stopEvent(e);
                    goBack();
                }));

                _connectResults.push(connect.connect(dom.byId("navBtnBackMyStuff"), 'click', function(e) {
                    dojo.stopEvent(e);
                    goBack();
                }));
            },
            afterActivate: function()
            {
                // Analytics
                Util.screenGATracking(Util.analytics.category.my_activity);
                
                adjustSize();

                if (needRefresh)
                {
                    loadMyAnnos();
                }
                else
                {
                    // update opened anno activity info
                    var activityIndicator = dom.byId("annoActIndicator_"+lastOpenAnnoId);

                    var currentAnno = eventsModel.cursor;
                    if (activityIndicator&&currentAnno.lastActivityChangedClass)
                    {
                        domClass.remove(activityIndicator);
                        domClass.add(activityIndicator, "annoOrangeColor");
                        domClass.add(activityIndicator, currentAnno.lastActivityChangedClass);

                        dom.byId("annoActText_"+lastOpenAnnoId).innerHTML = currentAnno.lastActivityText;
                        dom.byId("annoActWhen_"+lastOpenAnnoId).innerHTML = Util.getTimeAgoString(new Date().getTime(), new Date(currentAnno.when));

                        currentAnno.lastActivityChangedClass = "";
                    }
                }

                document.removeEventListener("backbutton", goBack, false);
                document.addEventListener("backbutton", goBack, false);
            },
            beforeDeactivate: function()
            {
                document.removeEventListener("backbutton", goBack, false);
            },
            destroy:function ()
            {
                var connectResult = _connectResults.pop();
                while (connectResult)
                {
                    connect.disconnect(connectResult);
                    connectResult = _connectResults.pop();
                }

                document.removeEventListener("backbutton", goBack, false);
            }
        }
    });
{'fraction_non_alphanumeric': 0.10390038756493775, 'fraction_numerical': 0.0019378246887111405, 'mean_word_length': 1.2134513597371783, 'pattern_counts': {'":': 14, '<': 9, '<?xml version=': 0, '>': 4, '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': '1556353', 'n_tokens_mistral': 6227, 'n_tokens_neox': 5909, 'n_words': 856}