Commit 2eaa14ba authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Eliminate passing around the store in DocTests controller.

Encapsulate interaction with grid store inside DocTests index component
by adding addExample method.
parent a2875c47
Loading
Loading
Loading
Loading
+5 −21
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ Ext.define('Docs.controller.DocTests', {

        this.control({
            '#doctestsgrid': {
                afterrender: this.onGridAfterRender
                afterrender: this.locateExamples
            }
        });
    },
@@ -60,27 +60,23 @@ Ext.define('Docs.controller.DocTests', {

    /**
     * Locates all examples.
     *
     * @param {Ext.data.Store} store The data store used to populate the grid.
     * @private
     */
    locateExamples: function(store) {
    locateExamples: function() {
        this.classesLeft = Docs.data.classes.length;
        this.getIndex().disable();
        store.removeAll();
        Ext.each(Docs.data.classes, function(cls) {
            this.locateClsExamples(store, cls.name);
            this.locateClsExamples(cls.name);
        }, this);
    },

    /**
     * Locates all inline examples attached to a class file.
     *
     * @param {Ext.data.Store} store The data store used to populate the grid.
     * @param {String} cls The Ext class name being interrogated.
     * @private
     */
    locateClsExamples: function(store, cls) {
    locateClsExamples: function(cls) {
        var baseUrl = this.getBaseUrl() + '/output/',
            url = baseUrl + cls + '.js';

@@ -98,14 +94,13 @@ Ext.define('Docs.controller.DocTests', {
                        id += '-' + exampleIdx.toString();
                    }

                    store.add({
                    this.getIndex().addExample({
                        id: id,
                        name: name,
                        href: document.location.href.replace(/#.*/, '#!/api/' + json.name),
                        code: exampleCode,
                        status: '<span class="doc-test-ready">ready</span>'
                    });
                    this.getIndex().setStatus(true, store.getCount() + " examples loaded.");
                }, this);

                this.classesLeft--;
@@ -139,16 +134,5 @@ Ext.define('Docs.controller.DocTests', {
            }
        }, this);
        return exampleCodes;
    },

    /**
     * Called after view's grid is rendered.
     *
     * @param {Ext.grid.Panel} grid The grid panel that was rendered.
     * @private
     */
    onGridAfterRender: function(grid) {
        var store = grid.getStore();
        this.locateExamples(store);
    }
});
+10 −0
Original line number Diff line number Diff line
@@ -114,6 +114,15 @@ Ext.define('Docs.view.doctests.Index', {
        return Docs.data.doctests ? {cls: 'doctests', href: '#!/doctests', tooltip: 'DocTests'} : false;
    },

    /**
     * Adds new example to full list of examples.
     * @param {Docs.model.DocTest} example The DocTest model instance or config for it.
     */
    addExample: function(example) {
        this.store.add(example);
        this.setStatus(true, this.store.getCount() + " examples loaded.");
    },

    /**
     * Executes an example.
     *
@@ -177,6 +186,7 @@ Ext.define('Docs.view.doctests.Index', {
     * Sets the status text displayed on doctests panel.
     * @param {Boolean} ok True to show positive status.
     * @param {String} message The text to display.
     * @private
     */
    setStatus: function(ok, message) {
        var cls = ok ? 'doc-test-success' : 'doc-test-failure';