<commit_before>angular.module('modulusOne.showControllers', [
  'ui'
])
.controller('ShowModuleCtrl', function($scope, module, Restangular, $stateParams,
    $state, getModule, $rootScope, readonlyAlert, Config, AuthService, $modal) {

    $scope.module = module;
    $rootScope.title = $scope.module.name;

    // Load all releases for this module.
    $scope.module.all('releases').getList({sort: 'moduleVersion',
      order: 'desc'})

    // Stick release variables into scope.
    .then(function(releases){
      $scope.latestRelease = releases[0] // release list sorted by dateCreated
      $scope.module.releases = releases
    })


    // Allow the view to access the logged-in user.
    $scope.user = AuthService.user;

    // Method to tell if we should autoscroll to the bottom of the page
    $scope.autoscrollToRelease = function () {
      return $state.is("show.newRelease");<commit_msg>MOD-89 - Show all module versions, sorted in the correct order<commit_after>angular.module('modulusOne.showControllers', [
  'ui'
])
.controller('ShowModuleCtrl', function($scope, module, Restangular, $stateParams,
    $state, getModule, $rootScope, readonlyAlert, Config, AuthService, $modal) {

    $scope.module = module;
    $rootScope.title = $scope.module.name;

    // Load all releases for this module.
    $scope.module.all('releases').getList({sort: 'moduleVersion',
      order: 'desc', max: '999'})

    var asInts = function(array) {
        var ret = new Array();
        for (var i = 0; i < array.length; ++i) {
          var maybe = parseFloat(array[i]);
          ret[i] = isNaN(maybe) ? 0 : maybe;
        }
        return ret;
    }

    // will sort by module version ascending
    // adapted from http://stackoverflow.com/a/6832721
    var versionCompare = function(v1, v2) {
        var v1parts = asInts(v1.split('.'));
        var v2parts = asInts(v2.split('.'));
        while (v1parts.length < v2parts.length) { v1parts.push(0); }
        while (v2parts.length < v1parts.length) { v2parts.push(0); }

        for (var i = 0; i < v1parts.length; ++i) {
            if (v1parts[i] == v2parts[i]) {
                continue;
            }
            else if (v1parts[i] > v2parts[i]) {
                return 1;
            }
            else {
                return -1;
            }
        }
        return 0;
    }

    // Stick release variables into scope.
    .then(function(releases){
      releases.sort(function(a, b) {
        return -versionCompare(a.moduleVersion, b.moduleVersion); // negative because we want descending version
      });
      $scope.latestRelease = releases[0] // release list sorted by moduleVersion
      $scope.module.releases = releases
    })


    // Allow the view to access the logged-in user.
    $scope.user = AuthService.user;

    // Method to tell if we should autoscroll to the bottom of the page
    $scope.autoscrollToRelease = function () {
      return $state.is("show.newRelease");
{'fraction_non_alphanumeric': 0.1307874281851977, 'fraction_numerical': 0.013180128421764109, 'mean_word_length': 2.5280095351609058, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4118210', 'n_tokens_mistral': 922, 'n_tokens_neox': 877, 'n_words': 233}