All files / src/libs/Modals CreateNewTaskModal.ts

0% Statements 0/34
0% Branches 0/13
0% Functions 0/7
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101                                                                                                                                                                                                         
import Lng from 'src/classes/Lng';
import type { ILogger, ILogger_ } from 'src/interfaces/ILogger';
import Prj from 'src/main';
import { Field, FormConfiguration } from 'src/types/ModalFormType';
import CreateNewTaskManagementModal from './CreateNewTaskManagementModal';
import { Inject } from '../DependencyInjection/decorators/Inject';
import { HelperObsidian } from '../Helper/Obsidian';
 
/**
 * Represents a modal to create a new task.
 */
export default class CreateNewTaskModal extends CreateNewTaskManagementModal {
    /**
     * Constructs the form configuration
     * @returns The form configuration
     */
    protected override constructForm(): FormConfiguration {
        const form = super.constructForm();
        form.title = `${Lng.gt('New')} ${Lng.gt('Project')}`;
 
        const typeFieldIndex = form.fields.findIndex(
            (field) => field.name === 'type',
        );
 
        Iif (
            typeFieldIndex !== -1 &&
            form.fields[typeFieldIndex].input.type === 'select'
        ) {
            const selectInput = form.fields[typeFieldIndex].input as {
                type: 'select';
                options: { value: string; label: string }[];
            };
 
            selectInput.options = [{ value: 'Task', label: Lng.gt('Task') }];
        }
 
        // SubType
        const subType: Field = {
            name: 'subtype',
            label: Lng.gt('SubType'),
            description: Lng.gt('SubTypeDescription'),
            isRequired: false,
            input: {
                type: 'select',
                source: 'fixed',
                options: [],
            },
        };
 
        const taskSubTypes =
            this._IPrjSettings.prjSettings.subTaskTemplates?.map((value) => ({
                value: value.template,
                label: value.label,
            }));
 
        Iif (taskSubTypes && subType.input.type === 'select') {
            subType.input.options.push({ value: '', label: Lng.gt('None') });
            subType.input.options.push(...taskSubTypes);
        }
 
        // Fügen Sie das subType-Feld direkt nach dem typeField ein
        Iif (typeFieldIndex !== -1) {
            form.fields.splice(typeFieldIndex + 1, 0, subType);
        }
 
        return form;
    }
 
    @Inject('IPrj')
    // eslint-disable-next-line @typescript-eslint/naming-convention
    protected static _IPrj: Prj;
    @Inject('ILogger_', (x: ILogger_) => x.getLogger('CreateNewTaskModal'))
    protected static _ILogger: ILogger;
 
    /**
     * Registers the command to open the modal
     * @remarks No cleanup needed
     */
    public static registerCommand(): void {
        this._ILogger.trace("Registering 'CreateNewTaskModal' commands");
 
        this._IPrj.addCommand({
            id: 'create-new-task-file',
            name: `${Lng.gt('New task')}`,
            /**
             *
             */
            callback: async () => {
                const modal = new CreateNewTaskModal();
                const result = await modal.openForm();
 
                Iif (result) {
                    const prj = await modal.evaluateForm(result);
 
                    Iif (prj) await HelperObsidian.openFile(prj.file);
                }
            },
        });
    }
}
 
Zur TypeDoc-Dokumentation