<commit_before>/** global Promise */
import {Router} from 'backbone';
import puppeteer from 'common/src/puppeteer';
import List from './application-list/application-list';
import Detail from './application-detail/application-detail';
import AppForm from './application-form/application-form';
import OAuthForm from './oauth-form/oauth-form';
import VersionForm from './version-form/version-form';
import VersionList from './version-list/version-list';
import VersionDetail from './version-detail/version-detail';
import ApprovalForm from './approval-form/approval-form';
import Flux from './flux';
import 'promise.prototype.finally';

const MAIN_VIEW_ID = '#yourturn-view',
      APP_ACTIONS = Flux.getActions('application'),
      APP_STORE = Flux.getStore('application');

class AppRouter extends Router {
    constructor() {
        this.routes = {
            'application': 'listApplications',
            'application/create': 'createApplication',
            'application/oauth/:id': 'configureOAuth',
            'application/edit/:id': 'editApplication',
            'application/detail/:id': 'listApplication',
            'application/detail/:id/version': 'listApplicationVersions',
            'application/detail/:id/version/create': 'createApplicationVersion',
            'application/detail/:id/version/detail/:ver': 'listApplicationVersion',
            'application/detail/:id/version/edit/:ver': 'editApplicationVersion',
            'application/detail/:id/version/approve/:ver': 'approveApplicationVersion'
        };

        super();
    }

    approveApplicationVersion(applicationId, versionId) {
        APP_ACTIONS.fetchApplication(applicationId);
        APP_ACTIONS.fetchApplicationVersion(applicationId, versionId);
        APP_ACTIONS.fetchApprovals(applicationId, versionId);

        puppeteer.show(new ApprovalForm({
            applicationId: applicationId,
            versionId: versionId
        }), MAIN_VIEW_ID);
    }

    createApplication() {
        APP_ACTIONS
        .fetchApplications()
        .finally(() => {
            puppeteer.show(new AppForm(), MAIN_VIEW_ID);
        });
    }

    createApplicationVersion(applicationId) {<commit_msg>#26 wait for app and version<commit_after>/** global Promise */
import {Router} from 'backbone';
import puppeteer from 'common/src/puppeteer';
import List from './application-list/application-list';
import Detail from './application-detail/application-detail';
import AppForm from './application-form/application-form';
import OAuthForm from './oauth-form/oauth-form';
import VersionForm from './version-form/version-form';
import VersionList from './version-list/version-list';
import VersionDetail from './version-detail/version-detail';
import ApprovalForm from './approval-form/approval-form';
import Flux from './flux';
import 'promise.prototype.finally';

const MAIN_VIEW_ID = '#yourturn-view',
      APP_ACTIONS = Flux.getActions('application'),
      APP_STORE = Flux.getStore('application'),
      SPINNER = $('<i class="fa fa-spin fa-circle-notch-o" />');

class AppRouter extends Router {
    constructor() {
        this.routes = {
            'application': 'listApplications',
            'application/create': 'createApplication',
            'application/oauth/:id': 'configureOAuth',
            'application/edit/:id': 'editApplication',
            'application/detail/:id': 'listApplication',
            'application/detail/:id/version': 'listApplicationVersions',
            'application/detail/:id/version/create': 'createApplicationVersion',
            'application/detail/:id/version/detail/:ver': 'listApplicationVersion',
            'application/detail/:id/version/edit/:ver': 'editApplicationVersion',
            'application/detail/:id/version/approve/:ver': 'approveApplicationVersion'
        };

        super();
    }

    approveApplicationVersion(applicationId, versionId) {
        let promises = [];
        if (!APP_STORE.getApplication(applicationId)) {
            promises.push(APP_ACTIONS.fetchApplication(applicationId));
        }
        if (!APP_STORE.getApplicationVersion(applicationId, versionId)) {
            promises.push(APP_ACTIONS.fetchApplicationVersion(applicationId, versionId));
        }

        APP_ACTIONS.fetchApprovals(applicationId, versionId);

        Promise
        .all(promises)
        .then(() => {
            puppeteer.show(new ApprovalForm({
                applicationId: applicationId,
                versionId: versionId
            }), MAIN_VIEW_ID);
        });
    }

    createApplication() {
        APP_ACTIONS
        .fetchApplications()
        .finally(() => {
            puppeteer.show(new AppForm(), MAIN_VIEW_ID);
        });
    }

    createApplicationVersion(applicationId) {
{'fraction_non_alphanumeric': 0.13037099140641376, 'fraction_numerical': 0.00041919932928107315, 'mean_word_length': 3.0926243567753002, 'pattern_counts': {'":': 0, '<': 4, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522747', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1285, 'n_words': 230}