<commit_before>'use strict';

var sampleTableData = [];

/**
 * called when user clicks on listView. The _event will provide
 * the index of the item clicked in the listView
 *
 * @param {Object} _event
 */
function listItemClicked(_event) {
    // display to console log the _event object for debugging
    Ti.API.debug(JSON.stringify(_event, null, 2));

    // get data using index provided, the items are in the section
    // so we use the index against the section, not the listView
    var currentItem = $.listSection.getItemAt(_event.itemIndex);

    // we save the data as a property so that is how we access
    // the data, we do not need the data array in this case
    var sessionInfo = currentItem.properties.data;

    // now display the data
    alert("clicked on " + JSON.stringify(sessionInfo, null, 2));
}

// lets get some real data!!
var parseService = require('parseREST');

// set the API Credentials
parseService.init();

function saveSessionClicked() {
    var queryResults;
    
    parseService.createObject('TutorSession', {
        sessionName : $.sessionName.value,
        sessionLocation : $.sessionLocation.value
    }).then(function(_queryResult) {
        console.log("Success Happened: " + JSON.stringify(_queryResult));
        queryResults = _queryResult;
        return parseService.getObjects('TutorSession');
    }).then(function(_sessions) {
        updateList(_sessions.response.results);
    }, function(_error) {
        console.log("Some Error Happened: " + JSON.stringify(_error));
    });
}

function updateList(_data) {
    var items = _.map(_data, function(element) {

        return {
            properties : {
                data : element // save all attributes
            },
            // bind the labels using the bindId
            name : {
                text : element.sessionName
            },
            location : {
                text : element.sessionLocation
            }
        };
    });
    // add the items to the section in the ListView
    $.listSection.setItems(items);

}

/**
 * logging in a user and then testing some of the functionality
 * of the rest service
 */
parseService.loginUser("<EMAIL>", "password").then(function(_result) {
    console.log(JSON.stringify(_result, null, 2));
    return parseService.getObjects('TutorSession');
}).then(function(_sessions) {
    console.log("getTutorSessions: " + JSON.stringify(_sessions.response, null, 2));

    updateList(_sessions.response.results);

}, function(_error) {
    Ti.API.error('ERROR: ' + JSON.stringify(_error, null, 2));
});

Ti.App.addEventListener("parse.push.recieved", function(_event) {
    //if clicks push tray, it will take to alert list page

    OS_IOS && Titanium.UI.iPhone.setAppBadge(0);
});
// open the view
$.index.open();<commit_msg>more complex query example<commit_after>'use strict';

var sampleTableData = [];

/**
 * called when user clicks on listView. The _event will provide
 * the index of the item clicked in the listView
 *
 * @param {Object} _event
 */
function listItemClicked(_event) {
    // display to console log the _event object for debugging
    Ti.API.debug(JSON.stringify(_event, null, 2));

    // get data using index provided, the items are in the section
    // so we use the index against the section, not the listView
    var currentItem = $.listSection.getItemAt(_event.itemIndex);

    // we save the data as a property so that is how we access
    // the data, we do not need the data array in this case
    var sessionInfo = currentItem.properties.data;

    // now display the data
    alert("clicked on " + JSON.stringify(sessionInfo, null, 2));
}

// lets get some real data!!
var parseService = require('parseREST');

// set the API Credentials
parseService.init();

function saveSessionClicked() {
    var queryResults;

    parseService.createObject('TutorSession', {
        sessionName : $.sessionName.value,
        sessionLocation : $.sessionLocation.value
    }).then(function(_queryResult) {
        console.log("Success Happened: " + JSON.stringify(_queryResult));
        queryResults = _queryResult;
        return parseService.getObjects('TutorSession');
    }).then(function(_sessions) {
        updateList(_sessions.response.results);
    }, function(_error) {
        console.log("Some Error Happened: " + JSON.stringify(_error));
    });
}

function updateList(_data) {
    var items = _.map(_data, function(element) {

        return {
            properties : {
                data : element // save all attributes
            },
            // bind the labels using the bindId
            name : {
                text : element.sessionName
            },
            location : {
                text : element.sessionLocation
            }
        };
    });
    // add the items to the section in the ListView
    $.listSection.setItems(items);

}

function whereQueryExample() {

// find all tutoring sessions that are being done by
// the tutors with the specified ids
var whereQueryStr = {
    "tutor" : {
        "$inQuery" : {
            "where" : {
                "objectId" : {
                    "$in" : ["SCV3V0GqRr", "9uKbg0Hzeb"]
                }
            },
            "className" : "_User"
        }
    }
};

return parseService.getObjects('TutorSession', {
    "urlparams" : {
        "where" : whereQueryStr
    }
});
}

/**
 * logging in a user and then testing some of the functionality
 * of the rest service
 */
parseService.loginUser("aaronsaunders", "password").then(function(_result) {
    console.log("Success: " + JSON.stringify(_result, null, 2));
    //return parseService.getObjects('TutorSession');

    return whereQueryExample();

}).then(function(_sessions) {
    console.log("getTutorSessions: " + JSON.stringify(_sessions.response, null, 2));

    //updateList(_sessions.response.results);

}, function(_error) {
    Ti.API.error('ERROR: ' + JSON.stringify(_error, null, 2));
});

Ti.App.addEventListener("parse.push.recieved", function(_event) {
    //if clicks push tray, it will take to alert list page

    OS_IOS && Titanium.UI.iPhone.setAppBadge(0);
});
// open the view
$.index.open();
{'fraction_non_alphanumeric': 0.11986356992041579, 'fraction_numerical': 0.0025986681825564397, 'mean_word_length': 2.702946482260974, 'pattern_counts': {'":': 0, '<': 4, '<?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': '2452543', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1699, 'n_words': 490}