private dialogValues()

in gui/frontend/src/modules/mrs/dialogs/MrsServiceDialog.tsx [114:316]


    private dialogValues(request: IDialogRequest): IDialogValues {
        const mainSection: IDialogSection = {
            caption: request.title,
            values: {
                servicePath: {
                    type: "text",
                    caption: "REST Service Path",
                    value: request.values?.servicePath as string,
                    horizontalSpan: 3,
                    options: [CommonDialogValueOption.AutoFocus],
                    description: "The URL context root of this service, has to start with / and needs to be unique.",
                },
                name: {
                    type: "text",
                    caption: "REST Service Name",
                    value: request.values?.name as string,
                    horizontalSpan: 3,
                    description: "The descriptive name of the REST service.",
                },
                makeDefaultTitle: {
                    type: "description",
                    caption: "REST Service Flags",
                    horizontalSpan: 2,
                    options: [
                        CommonDialogValueOption.Grouped,
                        CommonDialogValueOption.NewGroup,
                    ],
                },
                enabled: {
                    type: "boolean",
                    caption: "Enabled",
                    value: (request.values?.enabled ?? true) as boolean,
                    horizontalSpan: 2,
                    options: [
                        CommonDialogValueOption.Grouped,
                    ],
                },
                makeDefault: {
                    type: "boolean",
                    caption: "Default",
                    value: (request.values?.isCurrent ?? true) as boolean,
                    horizontalSpan: 2,
                    options: [
                        CommonDialogValueOption.Grouped,
                    ],
                },
                published: {
                    type: "boolean",
                    caption: "Published",
                    value: (request.values?.published ?? false) as boolean,
                    horizontalSpan: 2,
                    options: [
                        CommonDialogValueOption.Grouped,
                    ],
                },
            },
        };

        const settingsSection: IDialogSection = {
            caption: "Settings",
            groupName: "group1",
            values: {},
        };

        request.parameters ??= {};
        const authApps = request.parameters.authApps as IMrsAuthAppData[] ?? [];
        const linkedAuthApps = request.parameters.linkedAuthApps as IMrsAuthAppData[] ?? [];

        settingsSection.values.linkedAuthApps = {
            type: "checkList",
            caption: "Linked REST Authentication Apps",
            checkList: Object.values(authApps).map((app) => {
                // When the REST service is initialized, pre-select the MRS authentication if available, otherwise MySQL
                const defaultAuthApp = authApps.find((app) => {
                    return app.name === "MRS";
                }) ? "MRS" : "MySQL";

                const linked = (request.parameters?.init === true)
                    ? app.name === defaultAuthApp
                    : linkedAuthApps.find((linkedApp) => {
                        return linkedApp.id === app.id;
                    }) !== undefined;

                const result: ICheckboxProperties = {
                    id: app.id,
                    caption: app.name,
                    checkState: linked ? CheckState.Checked : CheckState.Unchecked,
                };

                return { data: result };
            }),
            horizontalSpan: 3,
            description: "Select one or more REST authentication app. This allows REST users of those applications "
                + "to authenticate.",
        };

        settingsSection.values.comments = {
            type: "text",
            caption: "Comments",
            value: request.values?.comments as string,
            multiLine: true,
            multiLineCount: 4,
            horizontalSpan: 5,
            description: "Comments to describe this REST Service.",
        };

        const optionsSection: IDialogSection = {
            caption: "Options",
            groupName: "group1",
            values: {
                options: {
                    type: "text",
                    caption: "Options:",
                    value: request.values?.options as string,
                    horizontalSpan: 8,
                    multiLine: true,
                    multiLineCount: 8,
                    description: "Additional options in JSON format",
                },
                metadata: {
                    type: "text",
                    caption: "Metadata:",
                    value: request.values?.metadata as string,
                    horizontalSpan: 8,
                    multiLine: true,
                    multiLineCount: 8,
                    description: "Metadata settings in JSON format",
                },
            },
        };

        const authSection: IDialogSection = {
            caption: "Authentication Details",
            groupName: "group1",
            values: {
                authPath: {
                    type: "text",
                    caption: "Authentication Path:",
                    value: request.values?.authPath as string,
                    horizontalSpan: 4,
                    description: "The path used for authentication.",
                },
                authCompletedUrl: {
                    type: "text",
                    caption: "Redirection URL:",
                    value: request.values?.authCompletedUrl as string,
                    horizontalSpan: 4,
                    description: "The authentication workflow will redirect to this URL after login.",
                },
                authCompletedUrlValidation: {
                    type: "text",
                    caption: "Redirection URL Validation:",
                    value: request.values?.authCompletedUrlValidation as string,
                    horizontalSpan: 4,
                    description: "A regular expression to validate the /login?onCompletionRedirect "
                        + "parameter set by the app.",
                },
                authCompletedPageContent: {
                    type: "text",
                    caption: "Authentication Completed Page Content:",
                    value: request.values?.authCompletedPageContent as string,
                    multiLine: true,
                    horizontalSpan: 4,
                    description: "If this field is set its content will replace the page content of the "
                        + "/completed page.",
                },
            },
        };

        let protocol = "HTTPS";
        if (request.values?.protocols !== undefined) {
            const protocols = request.values?.protocols as string[];
            if (protocols.length >= 1) {
                protocol = protocols[protocols.length - 1];
            }
        }

        const advancedSection: IDialogSection = {
            caption: "Advanced",
            groupName: "group1",
            values: {
                protocols: {
                    type: "choice",
                    caption: "Supported Protocols",
                    horizontalSpan: 3,
                    choices: ["HTTP", "HTTPS"],
                    value: protocol,
                    description: "The protocol the REST service is accessed on. HTTPS is preferred.",
                },
            },
        };

        return {
            id: "mainSection",
            sections: new Map<string, IDialogSection>([
                ["mainSection", mainSection],
                ["settingsSection", settingsSection],
                ["optionsSection", optionsSection],
                ["authSection", authSection],
                ["advancedSection", advancedSection],
            ]),
        };
    }