<commit_before>import BaseApp from "base_app";
import helpers from "helpers";
import Base64 from "base64";
import _ from "lodash";
import iorad from './lib/iorad';

window.helpers = helpers;
window.Base64 = Base64;

const App = {
    settings: {},
    categoriesList: [],
    lastSectionsList: [],
    timeout: 0,
    lastCategoryId: 0,
    lastSectionId: 0,
    myDefaultLocale: "",
    SOLUTION_APP_LOCATION: "nav_bar",
    TICKETING_APP_LOCATION_PATTERN: /ticket_sidebar$/,
    currentPluginType: "",
    addToHelpCenter: false,
    addToHelpCenterAsDraft: false,
    pluginTypes: {
        SOLUTION: "zendeskapp_solutions",
        // this is a nav bar app that creates tutorials.
        TICKETING: "zendeskapp_ticketing" // this is a ticket sidebar app that creates tutorials for existing and new tickets.
    },
    TICKET_COMMENT_FORMAT: '<p><a href="%@" target="_blank">%@</a></p>',
    events: {
        "app.activated": "init",
        "pane.activated": "runSolutionApp",
        "pane.deactivated": "onModalHidden",
        "fetchCategories.done": "onFetchCategories",
        "fetchSections.done": "onFetchSections",
        "createArticle.done": "onCreateArticle",
        "createArticle.fail": "onCreateArticleFailed",
        "fetchLocales.done": "onLocaleLoaded",
        "click .btn-iorad-widget": "submitNewTutorial",
        "click #addToHelpCenterToggle": "onAddToHelpCenterToggleClicked",
        "click #addToHelpCenterAsDraftToggle": "onAddToHelpCenterAsDraftToggleClicked",
        "change .categoryOptions": "updateSectionOptions",
        "editorClosed": "onIoradClose"
    },
    requests: require("./lib/requests.js"),

    init: function () {
        const that = this;
        that.zafClient.metadata().then(function (metadata) {
            that.settings = metadata.settings;
            that.addToHelpCenterAsDraft = that.settings.addToHelpCenterAsDraft;
            that.ajax("fetchLocales");

            that.runTicketingApp();
            that.runSolutionApp();
        });
    },
    // conditionally run app based on app current location
    runSolutionApp: function () {
        if (this.currentLocation() === this.SOLUTION_APP_LOCATION) {
            // load post to solutions app.
            this.currentPluginType = this.pluginTypes.SOLUTION;
            this.startFetchCategories();
        }
    },
    runTicketingApp: function () {
        if (this.TICKETING_APP_LOCATION_PATTERN.test(this.currentLocation())) {
            // load ticketing app.
            this.currentPluginType = this.pluginTypes.TICKETING;
            this.showTicketingView();
        }
    },
    startFetchCategories: function () {
        this.ajax("fetchCategories");
    },
    onLocaleLoaded: function (data) {
        this.myDefaultLocale = data.default_locale;
    },
    onModalHidden: function () {
        if (this.currentPluginType === this.pluginTypes.SOLUTION) {
            this.initializeSolutionAppControl();
        } else {
            this.showTicketingView();
        }
    },
    onIoradClose: function (data) {
        if (this.currentPluginType === this.pluginTypes.SOLUTION || this.addToHelpCenter) {
            this.createArticle(data);
        } else if (this.currentPluginType === this.pluginTypes.TICKETING) {
            this.addIoradPlayerUrlToNewTicketComment(data);
        }
    },
    onFetchCategories: function (data) {
        this.categoriesList = data.categories;

        _.each(this.categoriesList, function (category) {
            category.selected = false;
        });

        this.categoriesList[0].selected = true;

        if (this.currentPluginType === this.pluginTypes.SOLUTION) {
            this.initializeSolutionAppControl();
        } else {
            this.initializeTicketingAppControl();
        }
    },
    onFetchSections: function (data) {<commit_msg>ensure tutorial was created at least with one step<commit_after>import BaseApp from "base_app";
import helpers from "helpers";
import Base64 from "base64";
import _ from "lodash";
import iorad from './lib/iorad';

window.helpers = helpers;
window.Base64 = Base64;

const App = {
    settings: {},
    categoriesList: [],
    lastSectionsList: [],
    timeout: 0,
    lastCategoryId: 0,
    lastSectionId: 0,
    myDefaultLocale: "",
    SOLUTION_APP_LOCATION: "nav_bar",
    TICKETING_APP_LOCATION_PATTERN: /ticket_sidebar$/,
    currentPluginType: "",
    addToHelpCenter: false,
    addToHelpCenterAsDraft: false,
    pluginTypes: {
        SOLUTION: "zendeskapp_solutions",
        // this is a nav bar app that creates tutorials.
        TICKETING: "zendeskapp_ticketing" // this is a ticket sidebar app that creates tutorials for existing and new tickets.
    },
    TICKET_COMMENT_FORMAT: '<p><a href="%@" target="_blank">%@</a></p>',
    events: {
        "app.activated": "init",
        "pane.activated": "runSolutionApp",
        "pane.deactivated": "onModalHidden",
        "fetchCategories.done": "onFetchCategories",
        "fetchSections.done": "onFetchSections",
        "createArticle.done": "onCreateArticle",
        "createArticle.fail": "onCreateArticleFailed",
        "fetchLocales.done": "onLocaleLoaded",
        "click .btn-iorad-widget": "submitNewTutorial",
        "click #addToHelpCenterToggle": "onAddToHelpCenterToggleClicked",
        "click #addToHelpCenterAsDraftToggle": "onAddToHelpCenterAsDraftToggleClicked",
        "change .categoryOptions": "updateSectionOptions",
        "editorClosed": "onIoradClose"
    },
    requests: require("./lib/requests.js"),

    init: function () {
        const that = this;
        that.zafClient.metadata().then(function (metadata) {
            that.settings = metadata.settings;
            that.addToHelpCenterAsDraft = that.settings.addToHelpCenterAsDraft;
            that.ajax("fetchLocales");

            that.runTicketingApp();
            that.runSolutionApp();
        });
    },
    // conditionally run app based on app current location
    runSolutionApp: function () {
        if (this.currentLocation() === this.SOLUTION_APP_LOCATION) {
            // load post to solutions app.
            this.currentPluginType = this.pluginTypes.SOLUTION;
            this.startFetchCategories();
        }
    },
    runTicketingApp: function () {
        if (this.TICKETING_APP_LOCATION_PATTERN.test(this.currentLocation())) {
            // load ticketing app.
            this.currentPluginType = this.pluginTypes.TICKETING;
            this.showTicketingView();
        }
    },
    startFetchCategories: function () {
        this.ajax("fetchCategories");
    },
    onLocaleLoaded: function (data) {
        this.myDefaultLocale = data.default_locale;
    },
    onModalHidden: function () {
        if (this.currentPluginType === this.pluginTypes.SOLUTION) {
            this.initializeSolutionAppControl();
        } else {
            this.showTicketingView();
        }
    },
    onIoradClose: function (data) {
        if (data.steps && data.steps.length > 0) {
            if (this.currentPluginType === this.pluginTypes.SOLUTION || this.addToHelpCenter) {
                this.createArticle(data);
            } else if (this.currentPluginType === this.pluginTypes.TICKETING) {
                this.addIoradPlayerUrlToNewTicketComment(data);
            }
        }
    },
    onFetchCategories: function (data) {
        this.categoriesList = data.categories;

        _.each(this.categoriesList, function (category) {
            category.selected = false;
        });

        this.categoriesList[0].selected = true;

        if (this.currentPluginType === this.pluginTypes.SOLUTION) {
            this.initializeSolutionAppControl();
        } else {
            this.initializeTicketingAppControl();
        }
    },
    onFetchSections: function (data) {
{'fraction_non_alphanumeric': 0.11806981519507187, 'fraction_numerical': 0.003208418891170431, 'mean_word_length': 2.641588785046729, 'pattern_counts': {'":': 26, '<': 11, '<?xml version=': 0, '>': 12, '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': '5319286', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2208, 'n_words': 420}