<commit_before>/*global L */
/*jslint nomen: true, sloppy : true, plusplus: true, vars: true, newcap: true, regexp: true*/

var ScrollWindow = function(args) {

    try {
        var number, folderName, folder, directoryContents, scrollableView;
        folderName = Ti.App.Properties.getString('scrapbook') || Titanium.Filesystem.applicationDataDirectory + 'scrapbook';
        folder = Ti.Filesystem.getFile(folderName);
        directoryContents = folder.getDirectoryListing();

        scrollableView = Ti.UI.createScrollableView({
            showPagingControl : false
        });

        var getEvents = function() {
            var items = [], events = [], photos = [];
            models.events.sync();
            events = models.events.get();
            photos = models.photos.get();
            //get the first photo for the event
            _.each(events, function(event) {
                var first, obj, contents;
                //if photos not stored already, add them to the events object
                if (!event.photos) {
                    event.photos = [];
                    _.each(photos, function(photo) {
                        //if the photo is of this event
                        if (photo.Events.indexOf(event.id) !== -1) {
                            event.photos.push(photo);
                        }
                    });
                }
                //get the first photo (for now)
                first = _.first(event.photos);
                obj = {
                    "path" : '/scrapbook/' + first.Name
                };
                //look up the photo details
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = event.Name;
                    contents.subTitle = event.StartDate;
                    //TODO decorate contents with details of the event here
                    items.push(contents);
                }
            });
            //update the model with photos (assume that they have not been added)
            models.events.merge(events);
            return items;

        };

        var getPeople = function() {
            var items = [], people;
            models.people.sync();
            people = models.people.get();
            _.each(people, function(person) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + person.KeyPhoto
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = person.Name;
                    contents.subTitle = person.Relationship;
                    //TODO decorate details of the person here
                    items.push(contents);
                }
            });

            return items;
        };

        var getPhotos = function() {
            var photos, items = [];
            photos = models.photos.get();
            _.each(photos, function(photo) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + photo.Name
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = photo.Title;
                    //TODO decorate details of the person here
                    items.push(contents);
                }
            });
            
            return items;
        };
        var getPostcards = function() {
            var cards = [], items = [];
            models.postcards.sync();
            postcards = models.postcards.get();
            _.each(postcards, function(postcard) {
                var card = models.photos.get({
                    'id' : postcard.PhotoID
                });
                if (card && card[0]) {
                    card = card[0];
                    card.title = postcard.Message;
                    cards.push(card);
                }
            });
            _.each(cards, function(card) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + card.Name
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = card.title;
                    //TODO decorate details of the postcard here
                    items.push(contents);
                }
            });
            return items;
        };
        var addImages = function(args) {

            var contents, pictures = [], photos = [], views = [], events, people, postcards;

            try {
                
                //photos used throughout regardless of type
                models.photos.sync();

                switch (args) {
                    case 'events':
                        contents = getEvents();
                        break;
                    case 'people':
                        contents = getPeople();
                        break;
                    case 'postcards':
                        contents = getPostcards();
                        break;
                    default:
                        contents = getPhotos();
                        break;
                }

                //remove child windows from scrollableView

                if (scrollableView.children) {
                    _.each(scrollableView.children, function(kid) {
                        scrollableView.remove(kid);
                    });
                }

                if (!contents || _.size(directoryContents) === 0 || !directoryContents) {
                    throw new Error('no contents');
                }

                //get a list of photographs
                _.each(contents, function(item) {

                    if (item.mime_type.indexOf("image") !== -1) {
                        pictures.push(item.path);
                    }

                });

                //check that the file exists and create an imageView if it does.
                _.each(pictures, function(picture) {

                    var view, image;
                    var fileName = Titanium.Filesystem.applicationDataDirectory + picture;
                    var file = Ti.Filesystem.getFile(fileName);

                    if (file.exists()) {
                        view = Ti.UI.createView({
                            backgroundColor : '#fff',
                            top : 10
                        });
                        image = Ti.UI.createImageView({
                            image : fileName,
                            height : Ti.UI.SIZE,
                            width : Ti.UI.SIZE
                        });
                        view.add(image);
                        views.push(view);
                    } else {
                        Ti.API.error(fileName + ' is missing');
                    }

                });

            } catch (ex) {

                msg = ex || ex.message;
                Ti.API.error(msg);

            } finally {

                number = _.size(views);
                return views;
            }

        };

        scrollableView.views = addImages(args);

        //get the number of views (photos)
        number = number ? number : _.size(scrollableView.getViews());
        var t = 0;
        var interval = Ti.App.Properties.getInt('interval') || 5000;<commit_msg>basic titles<commit_after>/*global L */
/*jslint nomen: true, sloppy : true, plusplus: true, vars: true, newcap: true, regexp: true*/

var ScrollWindow = function(args) {

    try {
        var number, folderName, folder, directoryContents, scrollableView;
        folderName = Ti.App.Properties.getString('scrapbook') || Titanium.Filesystem.applicationDataDirectory + 'scrapbook';
        folder = Ti.Filesystem.getFile(folderName);
        directoryContents = folder.getDirectoryListing();

        scrollableView = Ti.UI.createScrollableView({
            showPagingControl : false
        });

        var getEvents = function() {
            var items = [], events = [], photos = [];
            models.events.sync();
            events = models.events.get();
            photos = models.photos.get();
            //get the first photo for the event
            _.each(events, function(event) {
                var first, obj, contents;
                //if photos not stored already, add them to the events object
                if (!event.photos) {
                    event.photos = [];
                    _.each(photos, function(photo) {
                        //if the photo is of this event
                        if (photo.Events.indexOf(event.id) !== -1) {
                            event.photos.push(photo);
                        }
                    });
                }
                //get the first photo (for now)
                first = _.first(event.photos);
                obj = {
                    "path" : '/scrapbook/' + first.Name
                };
                //look up the photo details
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = event.Name;
                    contents.subTitle = event.StartDate;
                    //TODO decorate contents with details of the event here
                    items.push(contents);
                }
            });
            //update the model with photos (assume that they have not been added)
            models.events.merge(events);
            return items;

        };

        var getPeople = function() {
            var items = [], people;
            models.people.sync();
            people = models.people.get();
            _.each(people, function(person) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + person.KeyPhoto
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = person.Name;
                    contents.subTitle = person.Relationship;
                    //TODO decorate details of the person here
                    items.push(contents);
                }
            });

            return items;
        };

        var getPhotos = function() {
            var photos, items = [];
            photos = models.photos.get();
            _.each(photos, function(photo) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + photo.Name
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = photo.Title;
                    //TODO decorate details of the person here
                    items.push(contents);
                }
            });

            return items;
        };
        var getPostcards = function() {
            var cards = [], items = [];
            models.postcards.sync();
            postcards = models.postcards.get();
            _.each(postcards, function(postcard) {
                var card = models.photos.get({
                    'id' : postcard.PhotoID
                });
                if (card && card[0]) {
                    card = card[0];
                    card.title = postcard.Message;
                    cards.push(card);
                }
            });
            _.each(cards, function(card) {
                var obj, contents;
                obj = {
                    "path" : '/scrapbook/' + card.Name
                };
                contents = models.contents.get(obj);
                if (contents && contents[0]) {
                    contents = contents[0];
                    contents.title = card.title;
                    //TODO decorate details of the postcard here
                    items.push(contents);
                }
            });
            return items;
        };
        var addImages = function(args) {

            var contents, pictures = [], photos = [], views = [], events, people, postcards;

            try {

                //photos used throughout regardless of type
                models.photos.sync();

                switch (args) {
                    case 'events':
                        contents = getEvents();
                        break;
                    case 'people':
                        contents = getPeople();
                        break;
                    case 'postcards':
                        contents = getPostcards();
                        break;
                    default:
                        contents = getPhotos();
                        break;
                }

                //remove child windows from scrollableView

                if (scrollableView.children) {
                    _.each(scrollableView.children, function(kid) {
                        scrollableView.remove(kid);
                    });
                }

                if (!contents || _.size(directoryContents) === 0 || !directoryContents) {
                    throw new Error('no contents');
                }

                //get a list of photographs
                _.each(contents, function(item) {

                    if (item.mime_type.indexOf("image") !== -1) {
                        pictures.push({
                            file : item.path,
                            title : item.title || '',
                            subTitle : item.subTitle || ''
                        });
                    }

                });

                //check that the file exists and create an imageView if it does.
                _.each(pictures, function(picture) {

                    var view, image, lbl, subLbl;
                    var fileName = Titanium.Filesystem.applicationDataDirectory + picture.file;
                    var file = Ti.Filesystem.getFile(fileName);

                    if (file.exists()) {
                        view = Ti.UI.createView({
                            backgroundColor : 'white',
                            top : 10,
                            height : '100%',
                            width : '85%',
                            layout : 'vertical'
                        });
                        lbl = Ti.UI.createLabel({
                            text : picture.title + (picture.subTitle ? ': ' + picture.subTitle : ''),
                            font : {
                                fontSize : 10
                            },
                            color : 'black',
                            height : 20,
                            width : '100%',
                            top : 10,
                            textAlign : 'center'
                        });
                        image = Ti.UI.createImageView({
                            image : fileName,
                            height : '70%'
                        });
                        view.add(lbl);
                        view.add(image);
                        views.push(view);
                    } else {
                        Ti.API.error(fileName + ' is missing');
                    }

                });

            } catch (ex) {

                msg = ex || ex.message;
                Ti.API.error(msg);

            } finally {

                number = _.size(views);
                return views;
            }

        };

        scrollableView.views = addImages(args);

        //get the number of views (photos)
        number = number ? number : _.size(scrollableView.getViews());
        var t = 0;
        var interval = Ti.App.Properties.getInt('interval') || 5000;
{'fraction_non_alphanumeric': 0.10034214618973561, 'fraction_numerical': 0.003483670295489891, 'mean_word_length': 0.9842014317452481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2213388', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3432, 'n_words': 862}