diff --git a/src/app/entry/extendedDescriptorLanguage.ts b/src/app/entry/extendedDescriptorLanguage.ts index b154fffcae..9c5c444b58 100644 --- a/src/app/entry/extendedDescriptorLanguage.ts +++ b/src/app/entry/extendedDescriptorLanguage.ts @@ -11,7 +11,7 @@ export interface ExtendedDescriptorLanguageBean extends DescriptorLanguageBean { toolDescriptorEnum: ToolDescriptor.TypeEnum; workflowDescriptorEnum: Workflow.DescriptorTypeEnum; plainTRS: string; - sourceFileTypeEnum: SourceFile.TypeEnum[]; + descriptorFileTypes: SourceFile.TypeEnum[]; toolTab: { // Example: If rowIdentifier is "tool ID", then the the first column of each row will say something like "tool ID: hello-world" rowIdentifier: string; @@ -19,6 +19,7 @@ export interface ExtendedDescriptorLanguageBean extends DescriptorLanguageBean { workflowStepHeader: string; }; workflowLaunchSupport: boolean; + testParameterFileType: SourceFile.TypeEnum; } const extendedCWL: ExtendedDescriptorLanguageBean = { @@ -31,12 +32,13 @@ const extendedCWL: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: ToolDescriptor.TypeEnum.CWL, workflowDescriptorEnum: Workflow.DescriptorTypeEnum.CWL, plainTRS: 'PLAIN-CWL', - sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTORECWL], + descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTORECWL], toolTab: { rowIdentifier: 'tool\xa0ID', workflowStepHeader: 'Tool Excerpt' }, - workflowLaunchSupport: true + workflowLaunchSupport: true, + testParameterFileType: SourceFile.TypeEnum.CWLTESTJSON }; const extendedWDL: ExtendedDescriptorLanguageBean = { @@ -49,12 +51,13 @@ const extendedWDL: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: ToolDescriptor.TypeEnum.WDL, workflowDescriptorEnum: Workflow.DescriptorTypeEnum.WDL, plainTRS: 'PLAIN-WDL', - sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTOREWDL], + descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTOREWDL], toolTab: { rowIdentifier: 'task\xa0ID', workflowStepHeader: 'Task Excerpt' }, - workflowLaunchSupport: true + workflowLaunchSupport: true, + testParameterFileType: SourceFile.TypeEnum.WDLTESTJSON }; const extendedNFL: ExtendedDescriptorLanguageBean = { @@ -67,12 +70,13 @@ const extendedNFL: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: ToolDescriptor.TypeEnum.NFL, workflowDescriptorEnum: Workflow.DescriptorTypeEnum.NFL, plainTRS: 'PLAIN-NFL', - sourceFileTypeEnum: [SourceFile.TypeEnum.NEXTFLOW, SourceFile.TypeEnum.NEXTFLOWCONFIG], + descriptorFileTypes: [SourceFile.TypeEnum.NEXTFLOW, SourceFile.TypeEnum.NEXTFLOWCONFIG], toolTab: { rowIdentifier: 'process\xa0name', workflowStepHeader: 'Process Excerpt' }, - workflowLaunchSupport: true + workflowLaunchSupport: true, + testParameterFileType: SourceFile.TypeEnum.NEXTFLOWTESTPARAMS }; const extendedService: ExtendedDescriptorLanguageBean = { @@ -86,12 +90,13 @@ const extendedService: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: ToolDescriptor.TypeEnum.SERVICE, workflowDescriptorEnum: Workflow.DescriptorTypeEnum.Service, plainTRS: 'PLAIN-SERVICE', - sourceFileTypeEnum: [], + descriptorFileTypes: [], toolTab: { rowIdentifier: 'tool\xa0ID', workflowStepHeader: 'Service' }, - workflowLaunchSupport: true + workflowLaunchSupport: true, + testParameterFileType: SourceFile.TypeEnum.DOCKSTORESERVICETESTJSON }; const extendedGalaxy: ExtendedDescriptorLanguageBean = { @@ -104,12 +109,13 @@ const extendedGalaxy: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: ToolDescriptor.TypeEnum.GXFORMAT2, workflowDescriptorEnum: Workflow.DescriptorTypeEnum.Gxformat2, plainTRS: '', - sourceFileTypeEnum: [SourceFile.TypeEnum.DOCKSTOREGXFORMAT2], + descriptorFileTypes: [SourceFile.TypeEnum.DOCKSTOREGXFORMAT2], toolTab: { rowIdentifier: 'tool\xa0ID', workflowStepHeader: 'Tool Excerpt' }, - workflowLaunchSupport: false + workflowLaunchSupport: false, + testParameterFileType: SourceFile.TypeEnum.GXFORMAT2TESTFILE }; export const extendedUnknownDescriptor: ExtendedDescriptorLanguageBean = { @@ -122,12 +128,13 @@ export const extendedUnknownDescriptor: ExtendedDescriptorLanguageBean = { toolDescriptorEnum: null, workflowDescriptorEnum: null, plainTRS: null, - sourceFileTypeEnum: [], + descriptorFileTypes: [], toolTab: { rowIdentifier: 'tool\xa0ID', workflowStepHeader: 'Tool Excerpt' }, - workflowLaunchSupport: false + workflowLaunchSupport: false, + testParameterFileType: null }; export const extendedDescriptorLanguages: ExtendedDescriptorLanguageBean[] = [ extendedCWL, diff --git a/src/app/shared/code-editor-list/code-editor-list.component.ts b/src/app/shared/code-editor-list/code-editor-list.component.ts index 5b3a12cc6f..7dadc24d35 100644 --- a/src/app/shared/code-editor-list/code-editor-list.component.ts +++ b/src/app/shared/code-editor-list/code-editor-list.component.ts @@ -2,8 +2,12 @@ import { Component, Input } from '@angular/core'; import { Observable } from 'rxjs'; import { WorkflowQuery } from '../state/workflow.query'; +import { SourceFile } from '../swagger'; import { ToolDescriptor } from './../../shared/swagger/model/toolDescriptor'; import { WorkflowVersion } from './../../shared/swagger/model/workflowVersion'; +import { CodeEditorListService } from './code-editor-list.service'; + +export type FileCategory = 'descriptor' | 'dockerfile' | 'testParam'; @Component({ selector: 'app-code-editor-list', @@ -11,17 +15,15 @@ import { WorkflowVersion } from './../../shared/swagger/model/workflowVersion'; styleUrls: ['./code-editor-list.component.scss'] }) export class CodeEditorListComponent { - @Input() sourcefiles: Array; + @Input() sourcefiles: SourceFile[]; @Input() editing: boolean; - @Input() fileType: string; + @Input() fileType: FileCategory; @Input() descriptorType: ToolDescriptor.TypeEnum; @Input() entryType: string; @Input() entrypath: string; @Input() selectedVersion: WorkflowVersion; protected published$: Observable; public downloadFilePath: string; - NEXTFLOW_CONFIG_PATH = '/nextflow.config'; - NEXTFLOW_PATH = '/main.nf'; public DescriptorType = ToolDescriptor.TypeEnum; constructor(private workflowQuery: WorkflowQuery) { @@ -32,21 +34,12 @@ export class CodeEditorListComponent { * Adds a new file editor */ addFile() { - const filesToAdd = []; - const newFilePath = this.getDefaultPath(); - if (!this.hasPrimaryDescriptor() && this.fileType === 'descriptor') { - if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) { - filesToAdd.push(this.createFileObject(this.NEXTFLOW_PATH)); - filesToAdd.push(this.createFileObject(this.NEXTFLOW_CONFIG_PATH)); - } else { - filesToAdd.push(this.createFileObject('/Dockstore' + newFilePath)); - } - } else if (!this.hasPrimaryTestParam() && this.fileType === 'testParam') { - filesToAdd.push(this.createFileObject('/test.' + this.descriptorType.toLowerCase() + newFilePath)); - } else { - filesToAdd.push(this.createFileObject('/' + newFilePath)); + let descriptorType = this.descriptorType; + // determineFilesToAdd gets really confusing when it needs to handle a falsey descriptorType, setting it here (no end effect) + if (this.fileType === 'dockerfile') { + descriptorType = ToolDescriptor.TypeEnum.CWL; } - + const filesToAdd = CodeEditorListService.determineFilesToAdd(descriptorType, this.fileType, this.sourcefiles); if (this.sourcefiles === undefined) { this.sourcefiles = []; } @@ -55,14 +48,6 @@ export class CodeEditorListComponent { }); } - createFileObject(newFilePath) { - return { - content: '', - path: newFilePath, - type: this.getFileType(newFilePath) - }; - } - /** * Deletes the file at the given index by setting content to null. * If it is a new file being deleted (not from previous version) then just remove from the list @@ -76,148 +61,36 @@ export class CodeEditorListComponent { } /** - * Get the file type enum - * @return {string} The file type enum - */ - getFileType(filepath) { - if (this.fileType === 'descriptor') { - if (this.descriptorType) { - if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) { - if (filepath === this.NEXTFLOW_CONFIG_PATH) { - return 'NEXTFLOW_CONFIG'; - } else { - return 'NEXTFLOW'; - } - } else { - return 'DOCKSTORE_' + this.descriptorType; - } - } else { - return 'DOCKSTORE_CWL'; - } - } else if (this.fileType === 'testParam') { - if (this.descriptorType) { - if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) { - return 'NEXTFLOW_TEST_PARAMS'; - } else { - return this.descriptorType + '_TEST_JSON'; - } - } else { - return 'CWL_TEST_JSON'; - } - } else if (this.fileType === 'dockerfile') { - return 'DOCKERFILE'; - } else { - return null; - } - } - - /** - * Get the default path extension - * @return {string}the default path extension - */ - getDefaultPath() { - if (this.fileType === 'descriptor') { - if (this.descriptorType) { - if (this.descriptorType === this.DescriptorType.NFL) { - return '.nf'; - } else { - return '.' + this.descriptorType.toLowerCase(); - } - } else { - return '.cwl'; - } - } else if (this.fileType === 'testParam') { - return '.json'; - } else if (this.fileType === 'dockerfile') { - return 'Dockerfile'; - } - } - - /** + * TODO: Fix the execution of this function. This function is being executed a bajillion times. * Returns true if path is the primary descriptor, false otherwise - * @param path Path to check - * @return {boolean} Is path for primary descriptor + * + * @param {string} path Path to check + * @returns {boolean} Is path for primary descriptor + * @memberof CodeEditorListComponent */ isPrimaryDescriptor(path: string): boolean { - return path === '/Dockstore.cwl' || path === '/Dockstore.wdl' || path === this.NEXTFLOW_CONFIG_PATH || path === this.NEXTFLOW_PATH; + return this.fileType === 'descriptor' && CodeEditorListService.isPrimaryDescriptor(path); } /** + * TODO: Fix the execution of this function. This function is being executed a bajillion times. * Returns true if path is the dockerfile, false otherwise * @param path Path to check * @return {boolean} Is path for dockerfile */ isDockerFile(path: string): boolean { - return path === '/Dockerfile'; + return this.fileType === 'dockerfile' && path === '/Dockerfile'; } /** - * TODO: Fix this execution of this function. This function is being executed a bajillion times + * TODO: Fix the execution of this function. This function is being executed a bajillion times. * Determines whether to show the current sourcefile based on the descriptor type and tab * @param type sourcefile type * @return {boolean} whether or not to show file */ - showSourcefile(type: string): boolean { - if (type === null || type === undefined) { - return true; - } else if (this.fileType === 'dockerfile') { - return true; - } else if (this.fileType === 'descriptor') { - return ( - (this.descriptorType === ToolDescriptor.TypeEnum.CWL && type === 'DOCKSTORE_CWL') || - (this.descriptorType === ToolDescriptor.TypeEnum.WDL && type === 'DOCKSTORE_WDL') || - (this.descriptorType === ToolDescriptor.TypeEnum.NFL && (type === 'NEXTFLOW' || type === 'NEXTFLOW_CONFIG')) - ); - } else if (this.fileType === 'testParam') { - return ( - (this.descriptorType === ToolDescriptor.TypeEnum.CWL && type === 'CWL_TEST_JSON') || - (this.descriptorType === ToolDescriptor.TypeEnum.WDL && type === 'WDL_TEST_JSON') || - (this.descriptorType === ToolDescriptor.TypeEnum.NFL && type === 'NEXTFLOW_TEST_PARAMS') - ); - } else { - return true; - } - } - - /** - * Checks for the given descriptor type, does there already exist a primary descriptor - * @return {boolean} whether or not version has a primary descriptor - */ - hasPrimaryDescriptor(): boolean { - if (this.descriptorType === null || this.descriptorType === undefined) { - return false; - } - - const pathToFind = '/Dockstore.' + this.descriptorType.toLowerCase(); - if (this.descriptorType === ToolDescriptor.TypeEnum.NFL) { - return this.hasFilePath(this.NEXTFLOW_PATH) && this.hasFilePath(this.NEXTFLOW_CONFIG_PATH); - } - return this.hasFilePath(pathToFind); - } - - /** - * Checks for the given descriptor type, does there already exist a primary test json - * @return {boolean} whether or not version has a primary test json - */ - hasPrimaryTestParam(): boolean { - if (this.descriptorType === null || this.descriptorType === undefined) { - return false; - } - const pathToFind = 'test.' + this.descriptorType.toLowerCase() + '.json'; - return this.hasFilePath(pathToFind); - } - - /** - * Determines if there exists a sourcefile with the given file path - * @param path File path to look for - * @return {boolean} Whether a sourcefile with the path exists - */ - hasFilePath(path: string): boolean { - for (const sourcefile of this.sourcefiles) { - if (sourcefile.path === path) { - return true; - } - } - return false; + showSourcefile(type: SourceFile.TypeEnum): boolean { + const fileType = this.fileType; + const descriptorType = this.descriptorType; + return CodeEditorListService.showSourcefile(type, fileType, descriptorType); } } diff --git a/src/app/shared/code-editor-list/code-editor-list.service.spec.ts b/src/app/shared/code-editor-list/code-editor-list.service.spec.ts new file mode 100644 index 0000000000..c65005b79c --- /dev/null +++ b/src/app/shared/code-editor-list/code-editor-list.service.spec.ts @@ -0,0 +1,178 @@ +import { TestBed } from '@angular/core/testing'; + +import { SourceFile, ToolDescriptor } from '../swagger'; +import { CodeEditorListService } from './code-editor-list.service'; + +describe('CodeEditorListService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: CodeEditorListService = TestBed.get(CodeEditorListService); + expect(service).toBeTruthy(); + }); + it('should be able to know if path is a primary descriptor', () => { + expect(CodeEditorListService.isPrimaryDescriptor('/Dockstore.cwl')).toBe(true); + expect(CodeEditorListService.isPrimaryDescriptor('/Dockstore.wdl')).toBe(true); + expect(CodeEditorListService.isPrimaryDescriptor('/nextflow.config')).toBe(true); + expect(CodeEditorListService.isPrimaryDescriptor('/main.nf')).toBe(true); + expect(CodeEditorListService.isPrimaryDescriptor('/Dockstore.yml')).toBe(true); + expect(CodeEditorListService.isPrimaryDescriptor(null)).toBe(false); + expect(CodeEditorListService.isPrimaryDescriptor('/Dockstore.potato')).toBe(false); + }); + + it('should be able to know if path is a primary descriptor', () => { + // Brand new hosted workflow with no descriptors + const primaryCWLFile: SourceFile = { + content: '', + absolutePath: '/Dockstore.cwl', + path: '/Dockstore.cwl', + type: SourceFile.TypeEnum.DOCKSTORECWL + }; + const secondaryCWLFile = { content: '', absolutePath: '/.cwl', path: '/.cwl', type: SourceFile.TypeEnum.DOCKSTORECWL }; + const primaryWDLFile = { content: '', absolutePath: '/Dockstore.wdl', path: '/Dockstore.wdl', type: SourceFile.TypeEnum.DOCKSTOREWDL }; + const secondaryWDLFile = { content: '', absolutePath: '/.wdl', path: '/.wdl', type: SourceFile.TypeEnum.DOCKSTOREWDL }; + const firstPrimaryNFLFile = { content: '', absolutePath: '/main.nf', path: '/main.nf', type: SourceFile.TypeEnum.NEXTFLOW }; + const secondPrimaryNFLFile = { + content: '', + absolutePath: '/nextflow.config', + path: '/nextflow.config', + type: SourceFile.TypeEnum.NEXTFLOWCONFIG + }; + const secondaryNFLFile = { content: '', absolutePath: '/.nf', path: '/.nf', type: SourceFile.TypeEnum.NEXTFLOW }; + const primaryNFLFiles = [firstPrimaryNFLFile, secondPrimaryNFLFile]; + const primaryGalaxyFile = { + content: '', + absolutePath: '/Dockstore.yml', + path: '/Dockstore.yml', + type: SourceFile.TypeEnum.DOCKSTOREGXFORMAT2 + }; + const secondaryGalaxyFile = { + content: '', + absolutePath: '/.yml', + path: '/.yml', + type: SourceFile.TypeEnum.DOCKSTOREGXFORMAT2 + }; + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'descriptor', [])).toEqual([primaryCWLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.WDL, 'descriptor', [])).toEqual([primaryWDLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.NFL, 'descriptor', [])).toEqual(primaryNFLFiles); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.GXFORMAT2, 'descriptor', [])).toEqual([primaryGalaxyFile]); + + const testCWLFile = { content: '', absolutePath: '/test.cwl.json', path: '/test.cwl.json', type: SourceFile.TypeEnum.CWLTESTJSON }; + const testWDLFile = { content: '', absolutePath: '/test.wdl.json', path: '/test.wdl.json', type: SourceFile.TypeEnum.WDLTESTJSON }; + // Weird because NFL doesn't have test parameter files + const testNFLFile = { + content: '', + absolutePath: '/test.nfl.json', + path: '/test.nfl.json', + type: SourceFile.TypeEnum.NEXTFLOWTESTPARAMS + }; + const testGalaxyFile = { + content: '', + absolutePath: '/test.galaxy.json', + path: '/test.galaxy.json', + type: SourceFile.TypeEnum.GXFORMAT2TESTFILE + }; + const testDockerFile = { + content: '', + absolutePath: '/Dockerfile', + path: '/Dockerfile', + type: SourceFile.TypeEnum.DOCKERFILE + }; + // Brand new hosted workflow with no test parameter file + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'testParam', [])).toEqual([testCWLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.WDL, 'testParam', [])).toEqual([testWDLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.NFL, 'testParam', [])).toEqual([testNFLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.GXFORMAT2, 'testParam', [])).toEqual([testGalaxyFile]); + + // When there's already the primary descriptor + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'descriptor', [primaryCWLFile])).toEqual([ + secondaryCWLFile + ]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.WDL, 'descriptor', [primaryWDLFile])).toEqual([ + secondaryWDLFile + ]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.NFL, 'descriptor', primaryNFLFiles)).toEqual([ + secondaryNFLFile + ]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.GXFORMAT2, 'descriptor', [primaryGalaxyFile])).toEqual([ + secondaryGalaxyFile + ]); + + // When there's already a test parameter file + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'testParam', [testCWLFile])).toEqual([testCWLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.WDL, 'testParam', [testWDLFile])).toEqual([testWDLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.NFL, 'testParam', [testNFLFile])).toEqual([testNFLFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.GXFORMAT2, 'testParam', [testGalaxyFile])).toEqual([ + testGalaxyFile + ]); + + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'dockerfile', [])).toEqual([testDockerFile]); + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.WDL, 'dockerfile', [])).toEqual([testDockerFile]); + + expect(CodeEditorListService.determineFilesToAdd(null, null, null)).toEqual([]); + + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.CWL, 'dockerfile', [])).toEqual([testDockerFile]); + + // Unhandled hosted workflow descriptor type + const weirdServiceFile = { + content: '', + absolutePath: '/Dockstore.service', + path: '/Dockstore.service', + type: SourceFile.TypeEnum.DOCKSTORECWL + }; + expect(CodeEditorListService.determineFilesToAdd(ToolDescriptor.TypeEnum.SERVICE, 'descriptor', [])).toEqual([weirdServiceFile]); + }); + it('should be able to determine whether to show the sourcefile in the current tab or not', () => { + // Descriptor tab + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTORECWL, 'descriptor', ToolDescriptor.TypeEnum.CWL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.CWLTESTJSON, 'descriptor', ToolDescriptor.TypeEnum.CWL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREWDL, 'descriptor', ToolDescriptor.TypeEnum.WDL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.WDLTESTJSON, 'descriptor', ToolDescriptor.TypeEnum.WDL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOW, 'descriptor', ToolDescriptor.TypeEnum.NFL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWCONFIG, 'descriptor', ToolDescriptor.TypeEnum.NFL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWTESTPARAMS, 'descriptor', ToolDescriptor.TypeEnum.NFL)).toBe( + false + ); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREGXFORMAT2, 'descriptor', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(true); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.GXFORMAT2TESTFILE, 'descriptor', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(false); + + // Test file tab + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTORECWL, 'testParam', ToolDescriptor.TypeEnum.CWL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.CWLTESTJSON, 'testParam', ToolDescriptor.TypeEnum.CWL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREWDL, 'testParam', ToolDescriptor.TypeEnum.WDL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.WDLTESTJSON, 'testParam', ToolDescriptor.TypeEnum.WDL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOW, 'testParam', ToolDescriptor.TypeEnum.NFL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWCONFIG, 'testParam', ToolDescriptor.TypeEnum.NFL)).toBe(false); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWTESTPARAMS, 'testParam', ToolDescriptor.TypeEnum.NFL)).toBe( + true + ); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREGXFORMAT2, 'testParam', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(false); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.GXFORMAT2TESTFILE, 'testParam', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(true); + + // Dockerfile tab, everything is true because something else handles it...? + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTORECWL, 'dockerfile', ToolDescriptor.TypeEnum.CWL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.CWLTESTJSON, 'dockerfile', ToolDescriptor.TypeEnum.CWL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREWDL, 'dockerfile', ToolDescriptor.TypeEnum.WDL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.WDLTESTJSON, 'dockerfile', ToolDescriptor.TypeEnum.WDL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOW, 'dockerfile', ToolDescriptor.TypeEnum.NFL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWCONFIG, 'dockerfile', ToolDescriptor.TypeEnum.NFL)).toBe(true); + expect(CodeEditorListService.showSourcefile(SourceFile.TypeEnum.NEXTFLOWTESTPARAMS, 'dockerfile', ToolDescriptor.TypeEnum.NFL)).toBe( + true + ); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.DOCKSTOREGXFORMAT2, 'dockerfile', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(true); + expect( + CodeEditorListService.showSourcefile(SourceFile.TypeEnum.GXFORMAT2TESTFILE, 'dockerfile', ToolDescriptor.TypeEnum.GXFORMAT2) + ).toBe(true); + expect(CodeEditorListService.showSourcefile(null, null, null)).toBe(true); + }); +}); diff --git a/src/app/shared/code-editor-list/code-editor-list.service.ts b/src/app/shared/code-editor-list/code-editor-list.service.ts new file mode 100644 index 0000000000..96a8378b36 --- /dev/null +++ b/src/app/shared/code-editor-list/code-editor-list.service.ts @@ -0,0 +1,360 @@ +import { Injectable } from '@angular/core'; +import { DescriptorLanguageService } from '../entry/descriptor-language.service'; +import { SourceFile, ToolDescriptor, Validation } from '../swagger'; +import { FileCategory } from './code-editor-list.component'; + +/** + * This service currently only handles CWL, WDL, NFL, and Galaxy. All plugin languages and SERVICE will not work correctly. + * + * @export + * @class CodeEditorListService + */ +@Injectable({ + providedIn: 'root' +}) +export class CodeEditorListService { + static readonly NEXTFLOW_CONFIG_PATH = '/nextflow.config'; + static readonly NEXTFLOW_PATH = '/main.nf'; + constructor() {} + /** + * Determines whether to show the current sourcefile based on the descriptor type and tab + * + * @static + * @param {(SourceFile.TypeEnum | null | undefined)} sourcefileType + * @param {FileCategory} fileCategory + * @param {ToolDescriptor.TypeEnum} descriptorType + * @returns {boolean} Whether to show sourcefile or not + * @memberof CodeEditorListService + */ + static showSourcefile( + sourcefileType: SourceFile.TypeEnum | null | undefined, + fileCategory: FileCategory | null | undefined, + descriptorType: ToolDescriptor.TypeEnum | null | undefined + ): boolean { + if (!sourcefileType || !fileCategory || !descriptorType) { + return true; + } + switch (fileCategory) { + case 'dockerfile': { + return true; + } + case 'descriptor': { + return ( + (descriptorType === ToolDescriptor.TypeEnum.CWL && sourcefileType === SourceFile.TypeEnum.DOCKSTORECWL) || + (descriptorType === ToolDescriptor.TypeEnum.WDL && sourcefileType === SourceFile.TypeEnum.DOCKSTOREWDL) || + (descriptorType === ToolDescriptor.TypeEnum.NFL && + (sourcefileType === SourceFile.TypeEnum.NEXTFLOW || sourcefileType === SourceFile.TypeEnum.NEXTFLOWCONFIG)) || + (descriptorType === ToolDescriptor.TypeEnum.GXFORMAT2 && sourcefileType === Validation.TypeEnum.DOCKSTOREGXFORMAT2) + ); + } + case 'testParam': { + return ( + (descriptorType === ToolDescriptor.TypeEnum.CWL && sourcefileType === SourceFile.TypeEnum.CWLTESTJSON) || + (descriptorType === ToolDescriptor.TypeEnum.WDL && sourcefileType === SourceFile.TypeEnum.WDLTESTJSON) || + (descriptorType === ToolDescriptor.TypeEnum.NFL && sourcefileType === SourceFile.TypeEnum.NEXTFLOWTESTPARAMS) || + (descriptorType === ToolDescriptor.TypeEnum.GXFORMAT2 && sourcefileType === Validation.TypeEnum.GXFORMAT2TESTFILE) + ); + } + } + } + + /** + * Determines whether the path is a primary descriptor. + * This is kind of easy to break. + * @static + * @param {(string | null)} path + * @returns {boolean} + * @memberof CodeEditorListService + */ + static isPrimaryDescriptor(path: string | null): boolean { + if (!path) { + return false; + } + const primaryDescriptors = [ + // CWL + '/Dockstore.cwl', + // WDL + '/Dockstore.wdl', + // NFL + CodeEditorListService.NEXTFLOW_CONFIG_PATH, + CodeEditorListService.NEXTFLOW_PATH, + // Galaxy + '/Dockstore.yml' + ]; + return primaryDescriptors.includes(path); + } + + /** + * Determines the SourceFile(s) to add. DescriptorType should be truthy even if it's a Dockerfile. + * + * @static + * @param {(ToolDescriptor.TypeEnum | null | undefined)} descriptorType The descriptor type + * @param {(FileCategory | null | undefined)} fileType The tab the user is currently on + * @param {(SourceFile[] | null | undefined)} sourcefiles The existing sourcefiles + * @returns {SourceFile[]} + * @memberof CodeEditorListService + */ + static determineFilesToAdd( + descriptorType: ToolDescriptor.TypeEnum | null | undefined, + fileType: FileCategory | null | undefined, + sourcefiles: SourceFile[] | null | undefined + ): SourceFile[] { + if (!descriptorType || !fileType || !sourcefiles) { + return []; + } + const filesToAdd: SourceFile[] = []; + const newFilePath = CodeEditorListService.getDefaultPath(fileType, descriptorType); + if (!CodeEditorListService.hasPrimaryDescriptor(descriptorType, sourcefiles) && fileType === 'descriptor') { + switch (descriptorType) { + case ToolDescriptor.TypeEnum.NFL: { + const nextflowConfigFile = CodeEditorListService.createSourceFile(CodeEditorListService.NEXTFLOW_PATH, descriptorType, fileType); + if (nextflowConfigFile) { + CodeEditorListService.pushFileIfNotNull(filesToAdd, nextflowConfigFile); + } + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile(CodeEditorListService.NEXTFLOW_CONFIG_PATH, descriptorType, fileType) + ); + break; + } + case ToolDescriptor.TypeEnum.CWL: + case ToolDescriptor.TypeEnum.WDL: + case ToolDescriptor.TypeEnum.GXFORMAT2: { + const defaultDescriptorPath = DescriptorLanguageService.toolDescriptorTypeEnumToDefaultDescriptorPath(descriptorType); + if (defaultDescriptorPath) { + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile(defaultDescriptorPath, descriptorType, fileType) + ); + } + break; + } + default: { + CodeEditorListService.unhandledHostedWorkflowDescriptorType(descriptorType); + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile('/Dockstore' + newFilePath, descriptorType, fileType) + ); + } + } + } else if (!CodeEditorListService.hasPrimaryTestParam(descriptorType, sourcefiles) && fileType === 'testParam') { + if (descriptorType === ToolDescriptor.TypeEnum.GXFORMAT2) { + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile('/test.galaxy.json', descriptorType, fileType) + ); + } else { + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile('/test.' + descriptorType.toLowerCase() + newFilePath, descriptorType, fileType) + ); + } + } else { + CodeEditorListService.pushFileIfNotNull( + filesToAdd, + CodeEditorListService.createSourceFile('/' + newFilePath, descriptorType, fileType) + ); + } + return filesToAdd; + } + + /** + * Handles when the sourcefile is falsey + * + * @private + * @static + * @param {SourceFile[]} filesToAdd + * @param {(SourceFile | null | undefined)} sourcefile + * @memberof CodeEditorListService + */ + private static pushFileIfNotNull(filesToAdd: SourceFile[], sourcefile: SourceFile | null | undefined) { + if (sourcefile) { + filesToAdd.push(sourcefile); + } + } + + /** + * Get the file type enum + * + * @private + * @static + * @param {string} filepath Path of the file + * @param {ToolDescriptor.TypeEnum} descriptorType Descriptor type + * @param {FileCategory} fileType Weird string denoting the file category + * @returns {(SourceFile.TypeEnum | null)} + * @memberof CodeEditorListService + */ + private static getFileType( + filepath: string, + descriptorType: ToolDescriptor.TypeEnum, + fileType: FileCategory + ): SourceFile.TypeEnum | null { + switch (fileType) { + case 'descriptor': { + switch (descriptorType) { + case ToolDescriptor.TypeEnum.NFL: { + if (filepath === CodeEditorListService.NEXTFLOW_CONFIG_PATH) { + return SourceFile.TypeEnum.NEXTFLOWCONFIG; + } else { + return SourceFile.TypeEnum.NEXTFLOW; + } + } + case ToolDescriptor.TypeEnum.CWL: + case ToolDescriptor.TypeEnum.WDL: + case ToolDescriptor.TypeEnum.GXFORMAT2: { + const descriptorFileTypes = DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType) + .descriptorFileTypes; + if (descriptorFileTypes && descriptorFileTypes.length > 0) { + return descriptorFileTypes[0]; + } else { + CodeEditorListService.unhandledHostedWorkflowDescriptorType(descriptorType); + // Defaulting to CWL for some reason + return SourceFile.TypeEnum.DOCKSTORECWL; + } + } + default: { + CodeEditorListService.unhandledHostedWorkflowDescriptorType(descriptorType); + // Defaulting to CWL for some reason + return SourceFile.TypeEnum.DOCKSTORECWL; + } + } + } + case 'testParam': { + return DescriptorLanguageService.toolDescriptorTypeEnumTotestParameterFileType(descriptorType); + } + case 'dockerfile': { + return SourceFile.TypeEnum.DOCKERFILE; + } + } + } + + /** + * Create the bare minimum sourcefile to add + * + * @private + * @static + * @param {string} newFilePath + * @param {ToolDescriptor.TypeEnum} descriptorType + * @param {FileCategory} fileType + * @returns {(SourceFile | null)} + * @memberof CodeEditorListService + */ + private static createSourceFile(newFilePath: string, descriptorType: ToolDescriptor.TypeEnum, fileType: FileCategory): SourceFile | null { + const type = CodeEditorListService.getFileType(newFilePath, descriptorType, fileType); + if (type) { + return { + // Absolute path is completely unused by the backend + absolutePath: newFilePath, + content: '', + path: newFilePath, + type: type + }; + } else { + return null; + } + } + + /** + * Get the default path extension + * + * @private + * @static + * @param {FileCategory} fileType Weird string denoting the type of file it is + * @param {ToolDescriptor.TypeEnum} descriptorType The descriptor type (used when fileType is descriptor) + * @returns {string} The default path extension + * @memberof CodeEditorListService + */ + private static getDefaultPath(fileType: FileCategory, descriptorType: ToolDescriptor.TypeEnum): string { + switch (fileType) { + case 'descriptor': { + switch (descriptorType) { + case ToolDescriptor.TypeEnum.NFL: { + return '.nf'; + } + case ToolDescriptor.TypeEnum.GXFORMAT2: { + return '.yml'; + } + default: { + return '.' + descriptorType.toLowerCase(); + } + } + } + case 'testParam': { + return '.json'; + } + case 'dockerfile': { + return 'Dockerfile'; + } + } + } + + /** + * Determines if there exists a sourcefile with the given file path + * + * @private + * @static + * @param {string} path File path to look for + * @param {Array} sourcefiles Current sourcefiles + * @returns {boolean} Whether a sourcefile with the path exists + * @memberof CodeEditorListService + */ + private static hasFilePath(path: string, sourcefiles: Array): boolean { + return sourcefiles.some(sourcefile => sourcefile.path === path); + } + + /** + * Checks for the given descriptor type, does there already exist a primary test json + * + * @private + * @static + * @param {ToolDescriptor.TypeEnum} descriptorType + * @param {SourceFile[]} sourcefiles + * @returns {boolean} whether or not version has a primary test json + * @memberof CodeEditorListService + */ + private static hasPrimaryTestParam(descriptorType: ToolDescriptor.TypeEnum, sourcefiles: SourceFile[]): boolean { + const pathToFind = 'test.' + descriptorType.toLowerCase() + '.json'; + return CodeEditorListService.hasFilePath(pathToFind, sourcefiles); + } + + /** + * Checks for the given descriptor type, does there already exist a primary descriptor + * + * @private + * @static + * @param {ToolDescriptor.TypeEnum} descriptorType + * @param {SourceFile[]} sourcefiles + * @returns {boolean} whether or not version has a primary descriptor + * @memberof CodeEditorListService + */ + private static hasPrimaryDescriptor(descriptorType: ToolDescriptor.TypeEnum, sourcefiles: SourceFile[]): boolean { + const pathToFind = '/Dockstore.' + descriptorType.toLowerCase(); + switch (descriptorType) { + case ToolDescriptor.TypeEnum.NFL: { + return ( + CodeEditorListService.hasFilePath(CodeEditorListService.NEXTFLOW_PATH, sourcefiles) && + CodeEditorListService.hasFilePath(CodeEditorListService.NEXTFLOW_CONFIG_PATH, sourcefiles) + ); + } + case ToolDescriptor.TypeEnum.GXFORMAT2: { + return CodeEditorListService.hasFilePath('/Dockstore.yml', sourcefiles); + } + default: { + return CodeEditorListService.hasFilePath(pathToFind, sourcefiles); + } + } + } + + /** + * This services doesn't support certain cases of descriptorTypes. + * Logs it in a consistent way. + * + * @private + * @static + * @param {ToolDescriptor.TypeEnum} descriptorType + * @memberof CodeEditorListService + */ + private static unhandledHostedWorkflowDescriptorType(descriptorType: ToolDescriptor.TypeEnum) { + console.error('Unhandled hosted workflow descriptor type: ' + descriptorType); + } +} diff --git a/src/app/shared/descriptor.service.ts b/src/app/shared/descriptor.service.ts index ea6361e779..421089f69d 100644 --- a/src/app/shared/descriptor.service.ts +++ b/src/app/shared/descriptor.service.ts @@ -35,7 +35,7 @@ export class DescriptorService { const unique = new Set(version.sourceFiles.map((sourceFile: SourceFile) => sourceFile.type)); unique.forEach((element: SourceFile.TypeEnum) => { extendedDescriptorLanguages.forEach(extendedDescriptorLanguage => { - if (extendedDescriptorLanguage.sourceFileTypeEnum.includes(element)) { + if (extendedDescriptorLanguage.descriptorFileTypes.includes(element)) { descriptorTypes.push(extendedDescriptorLanguage.toolDescriptorEnum); } }); @@ -55,7 +55,7 @@ export class DescriptorService { if (version && version.validations) { extendedDescriptorLanguages.forEach(extendedDescriptorLanguage => { const cwlValidation = version.validations.find(validation => { - return extendedDescriptorLanguage.sourceFileTypeEnum.includes(validation.type); + return extendedDescriptorLanguage.descriptorFileTypes.includes(validation.type); }); if (cwlValidation && cwlValidation.valid) { descriptorTypes.push(extendedDescriptorLanguage.toolDescriptorEnum); diff --git a/src/app/shared/entry/descriptor-language.service.ts b/src/app/shared/entry/descriptor-language.service.ts index d17ace6fa3..ca3c541e97 100644 --- a/src/app/shared/entry/descriptor-language.service.ts +++ b/src/app/shared/entry/descriptor-language.service.ts @@ -23,7 +23,7 @@ import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { EntryType } from '../enum/entry-type'; import { SessionQuery } from '../session/session.query'; -import { ToolDescriptor } from '../swagger'; +import { SourceFile, ToolDescriptor } from '../swagger'; import { Workflow } from '../swagger/model/workflow'; import { validationDescriptorPatterns } from '../validationMessages.model'; import { MetadataService } from './../swagger/api/metadata.service'; @@ -59,10 +59,10 @@ export class DescriptorLanguageService { this.filteredDescriptorLanguages$ = combined$.pipe(map(combined => this.filterLanguages(combined[0], combined[1]))); } static toolDescriptorTypeEnumToDefaultDescriptorPath(descriptorType: ToolDescriptor.TypeEnum | null): string | null { - return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguage(descriptorType).defaultDescriptorPath; + return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).defaultDescriptorPath; } - static toolDescriptorTypeEnumToExtendedDescriptorLanguage( + static toolDescriptorTypeEnumToExtendedDescriptorLanguageBean( descriptorType: ToolDescriptor.TypeEnum | null ): ExtendedDescriptorLanguageBean { const foundExtendedDescriptorLanguageFromValue = extendedDescriptorLanguages.find( @@ -71,14 +71,21 @@ export class DescriptorLanguageService { return foundExtendedDescriptorLanguageFromValue || extendedUnknownDescriptor; } + static toolDescriptorTypeEnumTotestParameterFileType(descriptorType: ToolDescriptor.TypeEnum): SourceFile.TypeEnum | null { + return this.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).testParameterFileType; + } + static workflowDescriptorTypeEnumToShortFriendlyName(workflowDescriptorTypeEnum: Workflow.DescriptorTypeEnum | null): string | null { + return this.workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean(workflowDescriptorTypeEnum).shortFriendlyName; + } + + static workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean( + descriptorType: Workflow.DescriptorTypeEnum | null + ): ExtendedDescriptorLanguageBean { const foundExtendedDescriptorLanguageFromValue = extendedDescriptorLanguages.find( - extendedDescriptorLanguage => extendedDescriptorLanguage.workflowDescriptorEnum === workflowDescriptorTypeEnum + extendedDescriptorLanguage => extendedDescriptorLanguage.workflowDescriptorEnum === descriptorType ); - if (foundExtendedDescriptorLanguageFromValue) { - return foundExtendedDescriptorLanguageFromValue.shortFriendlyName; - } - return extendedUnknownDescriptor.shortFriendlyName; + return foundExtendedDescriptorLanguageFromValue || extendedUnknownDescriptor; } update() { @@ -151,7 +158,7 @@ export class DescriptorLanguageService { * @memberof DescriptorLanguageService */ workflowDescriptorTypeEnumToPlaceholderDescriptor(descriptorType: ToolDescriptor.TypeEnum | null): string { - return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguage(descriptorType).descriptorPathPlaceholder; + return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).descriptorPathPlaceholder; } genericUnhandledTypeError(type: any): void { diff --git a/src/app/shared/file-editing.ts b/src/app/shared/file-editing.ts index d19c07cf4d..e8308633a0 100644 --- a/src/app/shared/file-editing.ts +++ b/src/app/shared/file-editing.ts @@ -57,7 +57,8 @@ export class FileEditing extends Files { sourcefile.type === SourceFile.TypeEnum.NEXTFLOWCONFIG || // DOCKSTORE-2428 - demo how to add new workflow language // sourcefile.type === SourceFile.TypeEnum.DOCKSTORESWL || - sourcefile.type === SourceFile.TypeEnum.NEXTFLOW + sourcefile.type === SourceFile.TypeEnum.NEXTFLOW || + sourcefile.type === SourceFile.TypeEnum.DOCKSTOREGXFORMAT2 ); } @@ -73,7 +74,8 @@ export class FileEditing extends Files { sourcefile.type === SourceFile.TypeEnum.CWLTESTJSON || // DOCKSTORE-2428 - demo how to add new workflow language // sourcefile.type === SourceFile.TypeEnum.SWLTESTJSON || - sourcefile.type === SourceFile.TypeEnum.NEXTFLOWTESTPARAMS + sourcefile.type === SourceFile.TypeEnum.NEXTFLOWTESTPARAMS || + sourcefile.type === SourceFile.TypeEnum.GXFORMAT2TESTFILE ); } diff --git a/src/app/shared/state/workflow.query.ts b/src/app/shared/state/workflow.query.ts index 6cd47a46fa..3da953779f 100644 --- a/src/app/shared/state/workflow.query.ts +++ b/src/app/shared/state/workflow.query.ts @@ -1,14 +1,11 @@ import { Injectable } from '@angular/core'; import { QueryEntity } from '@datorama/akita'; -import { - ExtendedDescriptorLanguageBean, - extendedDescriptorLanguages, - extendedUnknownDescriptor -} from 'app/entry/extendedDescriptorLanguage'; +import { ExtendedDescriptorLanguageBean } from 'app/entry/extendedDescriptorLanguage'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { DescriptorTypeCompatService } from '../descriptor-type-compat.service'; -import { ToolDescriptor, Workflow } from '../swagger'; +import { DescriptorLanguageService } from '../entry/descriptor-language.service'; +import { ToolDescriptor } from '../swagger'; import { BioWorkflow } from '../swagger/model/bioWorkflow'; import { Service } from '../swagger/model/service'; import { WorkflowState, WorkflowStore } from './workflow.store'; @@ -29,7 +26,7 @@ export class WorkflowQuery extends QueryEntity = this.workflow$.pipe( - map(workflow => this.workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean(workflow.descriptorType)) + map(workflow => DescriptorLanguageService.workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean(workflow.descriptorType)) ); public launchSupport$: Observable = this.extendedDescriptorLanguageBean$.pipe( map(extendedDescriptorLanguage => extendedDescriptorLanguage.workflowLaunchSupport) @@ -43,24 +40,4 @@ export class WorkflowQuery extends QueryEntity extendedDescriptorLanguage.workflowDescriptorEnum === descriptorType - ); - if (foundextendedDescriptorLanguageFromValue) { - return foundextendedDescriptorLanguageFromValue; - } - return extendedUnknownDescriptor; - } } diff --git a/src/app/workflow/register-workflow-modal/register-workflow-modal.component.ts b/src/app/workflow/register-workflow-modal/register-workflow-modal.component.ts index 434b793a1d..697cd1d75c 100644 --- a/src/app/workflow/register-workflow-modal/register-workflow-modal.component.ts +++ b/src/app/workflow/register-workflow-modal/register-workflow-modal.component.ts @@ -17,7 +17,6 @@ import { AfterViewChecked, Component, OnDestroy, OnInit, ViewChild } from '@angu import { NgForm } from '@angular/forms'; import { MatDialogRef } from '@angular/material/dialog'; import { MatRadioChange } from '@angular/material/radio'; -import { extendedDescriptorLanguages, extendedUnknownDescriptor } from 'app/entry/extendedDescriptorLanguage'; import { DescriptorLanguageService } from 'app/shared/entry/descriptor-language.service'; import { SessionQuery } from 'app/shared/session/session.query'; import { Observable, Subject } from 'rxjs'; @@ -168,13 +167,7 @@ export class RegisterWorkflowModalComponent implements OnInit, AfterViewChecked, } getWorkflowPathPlaceholder(descriptorType: Workflow.DescriptorTypeEnum): string { - const foundExtendedDescriptorLanguage = extendedDescriptorLanguages.find( - extendedDescriptorLanguage => extendedDescriptorLanguage.workflowDescriptorEnum === descriptorType - ); - if (foundExtendedDescriptorLanguage) { - return foundExtendedDescriptorLanguage.descriptorPathPlaceholder; - } - return extendedUnknownDescriptor.descriptorPathPlaceholder; + return DescriptorLanguageService.workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).descriptorPathPlaceholder; } formChanged() { @@ -241,15 +234,9 @@ export class RegisterWorkflowModalComponent implements OnInit, AfterViewChecked, * @memberof RegisterWorkflowModalComponent */ changeDescriptorType(descriptorType: Workflow.DescriptorTypeEnum): void { - const foundExtendedDescriptorLanguage = extendedDescriptorLanguages.find( - extendedDescriptorLanguage => extendedDescriptorLanguage.workflowDescriptorEnum === descriptorType - ); - if (foundExtendedDescriptorLanguage) { - this.descriptorValidationPattern = foundExtendedDescriptorLanguage.descriptorPathPattern; - } else { - this.descriptorValidationPattern = '.*'; - } - console.log(this.workflow.descriptorType); + this.descriptorValidationPattern = DescriptorLanguageService.workflowDescriptorTypeEnumToExtendedDescriptorLanguageBean( + descriptorType + ).descriptorPathPattern; this.workflowPathPlaceholder = this.getWorkflowPathPlaceholder(this.workflow.descriptorType); } diff --git a/src/app/workflow/tool-tab/tool-tab.service.ts b/src/app/workflow/tool-tab/tool-tab.service.ts index a62a767efc..2ea38eaf52 100644 --- a/src/app/workflow/tool-tab/tool-tab.service.ts +++ b/src/app/workflow/tool-tab/tool-tab.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { extendedDescriptorLanguages, extendedUnknownDescriptor } from 'app/entry/extendedDescriptorLanguage'; +import { DescriptorLanguageService } from 'app/shared/entry/descriptor-language.service'; import { ToolDescriptor } from '../../shared/swagger'; @Injectable({ @@ -16,13 +16,7 @@ export class ToolTabService { * @memberof ToolTabService */ descriptorTypeToHeaderName(descriptorType: ToolDescriptor.TypeEnum): string { - const foundExtendedDescriptorLanguage = extendedDescriptorLanguages.find( - extendedDescriptorLanguage => extendedDescriptorLanguage.toolDescriptorEnum === descriptorType - ); - if (foundExtendedDescriptorLanguage) { - return foundExtendedDescriptorLanguage.toolTab.workflowStepHeader; - } - return extendedUnknownDescriptor.toolTab.workflowStepHeader; + return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).toolTab.workflowStepHeader; } /** @@ -34,12 +28,6 @@ export class ToolTabService { * @memberof ToolTabService */ descriptorTypeToWorkflowExcerptRowHeading(descriptorType: ToolDescriptor.TypeEnum): string { - const foundExtendedDescriptorLanguage = extendedDescriptorLanguages.find( - extendedDescriptorLanguage => extendedDescriptorLanguage.toolDescriptorEnum === descriptorType - ); - if (foundExtendedDescriptorLanguage) { - return foundExtendedDescriptorLanguage.toolTab.rowIdentifier; - } - return extendedUnknownDescriptor.toolTab.rowIdentifier; + return DescriptorLanguageService.toolDescriptorTypeEnumToExtendedDescriptorLanguageBean(descriptorType).toolTab.rowIdentifier; } }