<commit_before>import { hash, all } from 'rsvp';
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import { get, set, setProperties } from '@ember/object';
import { randomStr } from 'shared/utils/util';
import C from 'ui/utils/constants';

export default Route.extend({
  modalService: service('modal'),
  catalog:      service(),
  scope:        service(),
  clusterStore: service(),
  store:        service(),
  globalStore:  service(),

  parentRoute: 'multi-cluster-apps.catalog',

  model(params/* , transition*/) {
    var store = get(this, 'globalStore');

    var dependencies = {
      tpl:        get(this, 'catalog').fetchTemplate(params.template),
      projects:   this.scope.getAllProjects(),
      clusters:   this.scope.getAllClusters(),
    };

    if ( params.upgrade ) {
      dependencies.upgrade = get(this, 'catalog').fetchTemplate(`${ params.template }-${ params.upgrade }`, true);
    }

    if (params.appId) {
      dependencies.app = store.find('multiclusterapp', params.appId);
    }

    return hash(dependencies, 'Load dependencies').then((results) => {
      var app                = get(results, 'app');
      var def                = get(results, 'tpl.defaultVersion');
      let kind = 'helm';
      let neuApp = null;
      var links;
      let catalogTemplateUrl = null;

      // get diff versions
      links = results.tpl.versionLinks;

      if (app && params.appId && !params.upgrade) {
        def = get(app, 'externalIdInfo.version');
      }

      if ( !links[def] ) {
        def = get(results, 'tpl.latestVersion');
      }<commit_msg>Can upgrade legacy multi-cluster apps<commit_after>import { hash, all } from 'rsvp';
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import { get, set, setProperties } from '@ember/object';
import { randomStr } from 'shared/utils/util';
import C from 'ui/utils/constants';

export default Route.extend({
  modalService: service('modal'),
  catalog:      service(),
  scope:        service(),
  clusterStore: service(),
  store:        service(),
  globalStore:  service(),

  parentRoute: 'multi-cluster-apps.catalog',

  model(params/* , transition*/) {
    var store = get(this, 'globalStore');

    var dependencies = {
      projects:   this.scope.getAllProjects(),
      clusters:   this.scope.getAllClusters(),
    };



    if (params.appId) {
      dependencies.app = store.find('multiclusterapp', params.appId);
      dependencies.app.then((appData) => {
        const getCurrentVersion = (app) => {
          const templateVersionId = app.templateVersionId;
          const splitId = templateVersionId.split('-');
          const currentVersion = splitId[splitId.length - 1];

          return currentVersion;
        }
        const currentVersion = getCurrentVersion(appData);

        // If an app ID is given, the current app version will be used in the
        // multi-cluster app launch route.
        dependencies.upgrade = get(this, 'catalog').fetchTemplate(`${ params.template }-${ params.upgrade }`, true, currentVersion);

        dependencies.tpl = get(this, 'catalog').fetchTemplate(params.template, false, currentVersion);
      })
        .catch((err) => {
          throw new Error(err);
        })
    } else {
      // If an app ID is not given, the current app version will not be used
      // in the multi-cluster app launch route.
      if ( params.upgrade ) {
        dependencies.upgrade = get(this, 'catalog').fetchTemplate(`${ params.template }-${ params.upgrade }`, true);
      }
      dependencies.tpl = get(this, 'catalog').fetchTemplate(params.template)
    }

    return hash(dependencies, 'Load dependencies').then((results) => {
      var app                = get(results, 'app');
      var def                = get(results, 'tpl.defaultVersion');
      let kind = 'helm';
      let neuApp = null;
      var links;
      let catalogTemplateUrl = null;

      // get diff versions
      links = results.tpl.versionLinks;

      if (app && params.appId && !params.upgrade) {
        def = get(app, 'externalIdInfo.version');
      }

      if ( !links[def] ) {
        def = get(results, 'tpl.latestVersion');
      }
{'fraction_non_alphanumeric': 0.138468809073724, 'fraction_numerical': 0.00023629489603024575, 'mean_word_length': 2.661764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '981327', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1183, 'n_words': 308}