<commit_before>'use strict';

let angular = require('angular');

module.exports = angular
  .module('spinnaker.core.delivery.filter.executionFilter.model', [
    require('../../filterModel/filter.model.service.js'),
    require('../../navigation/urlParser.service.js'),
    require('../../cache/viewStateCache.js')
  ])
  .factory('ExecutionFilterModel', function($rootScope, filterModelService, urlParser, viewStateCache) {

    var filterModel = this;
    var mostRecentParams = null;

    // Store count globally for 180 days
    var configViewStateCache = viewStateCache.createCache('executionFilters', {
      version: 1,
      maxAge: 180 * 24 * 60 * 60 * 1000,
    });

    function getCachedViewState() {
      let cached = configViewStateCache.get('#global') || {},
          defaults = { count: 2, groupBy: 'name', showDurations: false };
      return angular.extend(defaults, cached);
    }

    var groupCount = getCachedViewState().count;
    var groupBy = getCachedViewState().groupBy;
    var showDurations = getCachedViewState().showDurations;

    this.mostRecentApplication = null;

    var filterModelConfig = [
      { model: 'filter', param: 'q', clearValue: '', type: 'string', filterLabel: 'search', },
      { model: 'pipeline', param: 'pipeline', type: 'object', },
      { model: 'status', type: 'object', },
    ];

    filterModelService.configureFilterModel(this, filterModelConfig);

    function cacheConfigViewState() {
      configViewStateCache.put('#global', { count: groupCount, groupBy: groupBy, showDurations: showDurations });
    }

    // A nice way to avoid watches is to define a property on an object
    Object.defineProperty(this.sortFilter, 'count', {
      get: function() {
        return groupCount;
      },
      set: function(count) {
        groupCount = count;
        cacheConfigViewState();
      }
    });

    Object.defineProperty(this.sortFilter, 'groupBy', {
      get: function() {
        return groupBy;
      },
      set: function(grouping) {
        groupBy = grouping;
        cacheConfigViewState();
      }
    });

    Object.defineProperty(this.sortFilter, 'showDurations', {
      get: function() {
        return groupCount;
      },
      set: function(count) {
        groupCount = count;
        cacheConfigViewState();
      }
    });

    function isExecutionState(stateName) {
      return stateName === 'home.applications.application.executions' ||
        stateName === 'home.project.application.executions';
    }

    function isExecutionStateOrChild(stateName) {
      return isExecutionState(stateName) || isChildState(stateName);
    }

    function isChildState(stateName) {
      return stateName.indexOf('executions.execution') > -1;
    }

    function movingToExecutionsState(toState) {
      return isExecutionStateOrChild(toState.name);
    }

    function movingFromExecutionsState (toState, fromState) {
      return isExecutionStateOrChild(fromState.name) && !isExecutionStateOrChild(toState.name);
    }

    function fromApplicationListState(fromState) {
      return fromState.name === 'home.applications';
    }
<commit_msg>(core) persist stage duration selection (#2327)<commit_after>'use strict';

let angular = require('angular');

module.exports = angular
  .module('spinnaker.core.delivery.filter.executionFilter.model', [
    require('../../filterModel/filter.model.service.js'),
    require('../../navigation/urlParser.service.js'),
    require('../../cache/viewStateCache.js')
  ])
  .factory('ExecutionFilterModel', function($rootScope, filterModelService, urlParser, viewStateCache) {

    var filterModel = this;
    var mostRecentParams = null;

    // Store count globally for 180 days
    var configViewStateCache = viewStateCache.createCache('executionFilters', {
      version: 1,
      maxAge: 180 * 24 * 60 * 60 * 1000,
    });

    function getCachedViewState() {
      let cached = configViewStateCache.get('#global') || {},
          defaults = { count: 2, groupBy: 'name', showDurations: false };
      return angular.extend(defaults, cached);
    }

    var groupCount = getCachedViewState().count;
    var groupBy = getCachedViewState().groupBy;
    var showStageDuration = getCachedViewState().showStageDuration;

    this.mostRecentApplication = null;

    var filterModelConfig = [
      { model: 'filter', param: 'q', clearValue: '', type: 'string', filterLabel: 'search', },
      { model: 'pipeline', param: 'pipeline', type: 'object', },
      { model: 'status', type: 'object', },
    ];

    filterModelService.configureFilterModel(this, filterModelConfig);

    function cacheConfigViewState() {
      configViewStateCache.put('#global', { count: groupCount, groupBy: groupBy, showStageDuration: showStageDuration });
    }

    // A nice way to avoid watches is to define a property on an object
    Object.defineProperty(this.sortFilter, 'count', {
      get: function() {
        return groupCount;
      },
      set: function(count) {
        groupCount = count;
        cacheConfigViewState();
      }
    });

    Object.defineProperty(this.sortFilter, 'groupBy', {
      get: function() {
        return groupBy;
      },
      set: function(grouping) {
        groupBy = grouping;
        cacheConfigViewState();
      }
    });

    Object.defineProperty(this.sortFilter, 'showStageDuration', {
      get: function() {
        return showStageDuration;
      },
      set: function(newVal) {
        showStageDuration = newVal;
        cacheConfigViewState();
      }
    });

    function isExecutionState(stateName) {
      return stateName === 'home.applications.application.executions' ||
        stateName === 'home.project.application.executions';
    }

    function isExecutionStateOrChild(stateName) {
      return isExecutionState(stateName) || isChildState(stateName);
    }

    function isChildState(stateName) {
      return stateName.indexOf('executions.execution') > -1;
    }

    function movingToExecutionsState(toState) {
      return isExecutionStateOrChild(toState.name);
    }

    function movingFromExecutionsState (toState, fromState) {
      return isExecutionStateOrChild(fromState.name) && !isExecutionStateOrChild(toState.name);
    }

    function fromApplicationListState(fromState) {
      return fromState.name === 'home.applications';
    }

{'fraction_non_alphanumeric': 0.12701676684593483, 'fraction_numerical': 0.006643467257197089, 'mean_word_length': 3.198539176626826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1218262', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1740, 'n_words': 359}