<commit_before>define([
    "jquery",
    "base1/cockpit",
    "base1/angular",
    "kubernetes/app"
], function($, cockpit, angular) {
    'use strict';

    var _ = cockpit.gettext;

    return angular.module('kubernetes.images', ['ngRoute'])
        .config([
            '$routeProvider',
            function($routeProvider) {
                $routeProvider.when('/images', {
                    templateUrl: 'views/images.html',
                    controller: 'ImagesCtrl'
                });
            }
        ])

        .provider('ImageRegistry',
            function() {
                var unique = 0;
                var client = null;
                var scopes = { };
                var timeout = null;

                /* The actual singleton object we return */
                var repositories = { };

                function ImageRepository(repo) {
                    var self = this;
                    self.name = repo;
                    self.images = { };
                    self.imagestreams = { };

                    /*
                     * ImageRepository.tags:
                     *
                     * Returns a map of image -> tag. Tag value will be null
                     * for any image that is not tagged.
                     */
                    self.tags = function tags() {
                        var result = { };

                        /* Account for any untagged images */
                        angular.forEach(self.images, function(image) {
                            result[image.metadata.name] = null;
                        });

                        /* The only source of tags we have is currently from ImageStream items */
                        angular.forEach(self.imagestreams, function(imagestream) {
                            if (imagestream.status && imagestream.status.tags) {
                                imagestream.status.tags.forEach(function(tag) {
                                    if (tag.items) {
                                        tag.items.forEach(function(item) {
                                            result[item.image] = tag.tag;
                                        });
                                    }
                                });
                            }
                        });

                        return result;
                    };

                    self.latest = function latest() {
                        var result = null;
                        angular.forEach(self.images, function(image) {
                            var meta = image.dockerImageMetadata || { };
                            var created = meta.Created || null;
                            if (created && (!result || created > result))
                                result = created;
                        });
                        return result;
                    };
                }

                /*
                 * I'm not completely happy with this. We could be
                 * firing way too many $digests for the entire scope
                 * because other things from other code, could be triggering
                 * while waiting for the the timeout.
                 */

                function digest() {
                    timeout = null;
                    for (var id in scopes)
                        scopes[id].$digest();
                }

                function trigger() {
                    if (timeout === null)
                        timeout = window.setTimeout(digest, 100);
                }

                function repo_qualify(repo) {
                    if (repo && repo.indexOf('/') === -1)
                        return "library/" + repo;
                    return repo;
                }

                function image_repo(image) {
                    var ref = image.dockerImageReference || "";
                    return repo_qualify(ref.split('@')[0]);
                }

                function image_added(ev, image, key) {
                    var repo = image_repo(image);
                    if (repo) {
                        var repository = repositories[repo];
                        if (!repository)
                            repository = repositories[repo] = new ImageRepository(repo);
                        repository.images[key] = image;
                    }
                    trigger();
                }

                function image_removed(ev, image, key) {
                    var repo = image_repo(image);<commit_msg>kubernetes: Parse image repo tags and source registry correctly<commit_after>define([
    "jquery",
    "base1/cockpit",
    "base1/angular",
    "kubernetes/app"
], function($, cockpit, angular) {
    'use strict';

    var _ = cockpit.gettext;

    return angular.module('kubernetes.images', ['ngRoute'])
        .config([
            '$routeProvider',
            function($routeProvider) {
                $routeProvider.when('/images', {
                    templateUrl: 'views/images.html',
                    controller: 'ImagesCtrl'
                });
            }
        ])

        .provider('ImageRegistry',
            function() {
                var unique = 0;
                var client = null;
                var scopes = { };
                var timeout = null;

                /* The actual singleton object we return */
                var repositories = { };

                function ImageRepository(repo) {
                    var self = this;
                    self.repo = repo;
                    self.images = { };
                    self.imagestreams = { };

                    /* Split out repository name and source */
                    var parts = repo.split("/");
                    if (parts.length == 3) {
                        self.name = parts.slice(1).join("/");
                        self.source = parts[1];
                    } else {
                        self.name = repo;
                        self.source = null;
                    }

                    /*
                     * ImageRepository.tags:
                     *
                     * Returns a map of image -> tag. Tag value will be null
                     * for any image that is not tagged.
                     */
                    self.tags = function tags() {
                        var result = { };

                        /* Account for any untagged images */
                        angular.forEach(self.images, function(image) {
                            result[image.metadata.name] = null;
                        });

                        /* The only source of tags we have is currently from ImageStream items */
                        angular.forEach(self.imagestreams, function(imagestream) {
                            if (imagestream.status && imagestream.status.tags) {
                                imagestream.status.tags.forEach(function(tag) {
                                    if (tag.items) {
                                        tag.items.forEach(function(item) {
                                            result[item.image] = tag.tag;
                                        });
                                    }
                                });
                            }
                        });

                        return result;
                    };

                    self.latest = function latest() {
                        var result = null;
                        angular.forEach(self.images, function(image) {
                            var meta = image.dockerImageMetadata || { };
                            var created = meta.Created || null;
                            if (created && (!result || created > result))
                                result = created;
                        });
                        return result;
                    };
                }

                /*
                 * I'm not completely happy with this. We could be
                 * firing way too many $digests for the entire scope
                 * because other things from other code, could be triggering
                 * while waiting for the the timeout.
                 */

                function digest() {
                    timeout = null;
                    for (var id in scopes)
                        scopes[id].$digest();
                }

                function trigger() {
                    if (timeout === null)
                        timeout = window.setTimeout(digest, 100);
                }

                function repo_qualify(repo) {
                    if (repo && repo.indexOf('/') === -1)
                        return "library/" + repo;
                    return repo;
                }

                function image_repo(image) {
                    var ref = image.dockerImageReference || "";
                    return repo_qualify(ref.split(':')[0].split('@')[0]);
                }

                function image_added(ev, image, key) {
                    var repo = image_repo(image);
                    if (repo) {
                        var repository = repositories[repo];
                        if (!repository)
                            repository = repositories[repo] = new ImageRepository(repo);
                        repository.images[key] = image;
                    }
                    trigger();
                }

                function image_removed(ev, image, key) {
                    var repo = image_repo(image);
{'fraction_non_alphanumeric': 0.08927263212977499, 'fraction_numerical': 0.0020931449502878076, 'mean_word_length': 0.8576982892690513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5685680', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1868, 'n_words': 492}