async loadModel()

in sources/src/main/resources/META-INF/resources/view.js [519:584]


    async loadModel() {
        this.model = window.location.host.startsWith("localhost:")
            ? new DebugModel()
            : new Model();

        //
        // Clear all views.
        //
        new DefaultView().showAsync();

        //
        // Determine resource to load.
        //
        const settings = new LocalSettings();
        let resource;
        if (window.location.hash && window.location.hash.startsWith('#reload')) {
            //
            // Force environment dialog.
            //
            this.environment = null;
        }
        else if (window.location.hash && window.location.hash.startsWith('#!')) {
            resource = window.location.hash.substring(2);

            if (resource) {
                //
                // Extract environment name.
                //
                const regex = /^\/environments\/(.*?)(\/.*)?$/;
                const found = resource.match(regex);
                if (found && found.length >= 2) {
                    this.environment = found[1];

                    $('#jit-scope').text(this.environment);
                    $('title').text(`JIT Groups: ${this.environment}`);
                }
                else {
                    this.environment = null;
                }
            }
        }
        else if (settings.environment) {
            this.environment = settings.environment;
            resource = `/environments/${this.environment}`;

            $('#jit-scope').text(this.environment);
        }

        if (!this.environment) {
            //
            // Configuration incomplete, show dialog.
            //
            await this.selectScopeAsync();
            return null;
        }

        //
        // Initialize model.
        //
        await this.model.initialize(this.environment, resource);

        $("#signed-in-user").text(this.model.context.subject.email);
        $("#application-version").text(this.model.context.application.version);

        return this.model;
    }