diff --git a/packages/client/hmi-client/src/components/extracting/tera-drag-n-drop-importer.vue b/packages/client/hmi-client/src/components/extracting/tera-drag-n-drop-importer.vue index f371378697..3c4dff3e8b 100644 --- a/packages/client/hmi-client/src/components/extracting/tera-drag-n-drop-importer.vue +++ b/packages/client/hmi-client/src/components/extracting/tera-drag-n-drop-importer.vue @@ -85,8 +85,6 @@ const props = defineProps({ AcceptedTypes.TXT, AcceptedTypes.MD, AcceptedTypes.PY, - AcceptedTypes.M, - AcceptedTypes.JS, AcceptedTypes.R, AcceptedTypes.JL ].every((v) => value.includes(v)) @@ -101,8 +99,6 @@ const props = defineProps({ AcceptedExtensions.TXT, AcceptedExtensions.MD, AcceptedExtensions.PY, - AcceptedExtensions.M, - AcceptedExtensions.JS, AcceptedExtensions.R, AcceptedExtensions.JL ].every((v) => value.includes(v)) diff --git a/packages/client/hmi-client/src/components/widgets/tera-import-github-file.vue b/packages/client/hmi-client/src/components/widgets/tera-import-github-file.vue index 933437fac3..910770be18 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-import-github-file.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-import-github-file.vue @@ -192,6 +192,7 @@ import { createNewDatasetFromGithubFile } from '@/services/dataset'; import { createNewArtifactFromGithubFile } from '@/services/artifact'; import { extractPDF } from '@/services/models/extractions'; import useAuthStore from '@/stores/auth'; +import { uploadCodeToProjectFromGithub } from '@/services/code'; const props = defineProps<{ urlString: string; @@ -362,8 +363,14 @@ async function importDocumentFiles(githubFiles: GithubFile[]) { * @param githubFiles The code files to open */ async function openCodeFiles(githubFiles: GithubFile[]) { - // For now just throw to the document path as they're all artifacts - await importDocumentFiles(githubFiles); + githubFiles.forEach(async (githubFile) => { + await uploadCodeToProjectFromGithub( + repoOwnerAndName.value, + githubFile.path, + props.project?.id ?? '', + githubFile.htmlUrl + ); + }); } diff --git a/packages/client/hmi-client/src/components/widgets/tera-tab-group.vue b/packages/client/hmi-client/src/components/widgets/tera-tab-group.vue index e57c9a48c7..446d2138e8 100644 --- a/packages/client/hmi-client/src/components/widgets/tera-tab-group.vue +++ b/packages/client/hmi-client/src/components/widgets/tera-tab-group.vue @@ -60,7 +60,6 @@ const loadingTabIndex = ref(); const getTabName = (tab: Tab) => { if (tab.assetName) return tab.assetName; if (tab.pageType === ProjectPages.OVERVIEW) return 'Overview'; - // DVINCE TODO if (tab.pageType === AssetType.CODE) return 'New File'; const assets = resourceStore.activeProjectAssets; if (assets) { @@ -71,6 +70,9 @@ const getTabName = (tab: Tab) => { // https://github.com/DARPA-ASKEM/data-service/issues/299 return (tab.pageType === AssetType.Publications ? asset?.title : asset?.name) ?? 'n/a'; } + + if (tab.pageType === AssetType.Code) return 'New File'; + return 'n/a'; }; diff --git a/packages/client/hmi-client/src/page/project/components/tera-project-overview.vue b/packages/client/hmi-client/src/page/project/components/tera-project-overview.vue index dcd8bb9855..f3c4bd48e6 100644 --- a/packages/client/hmi-client/src/page/project/components/tera-project-overview.vue +++ b/packages/client/hmi-client/src/page/project/components/tera-project-overview.vue @@ -184,8 +184,6 @@ AcceptedTypes.TXT, AcceptedTypes.MD, AcceptedTypes.PY, - AcceptedTypes.JS, - AcceptedTypes.M, AcceptedTypes.R, AcceptedTypes.JL ]" @@ -195,8 +193,6 @@ AcceptedExtensions.TXT, AcceptedExtensions.MD, AcceptedExtensions.PY, - AcceptedExtensions.M, - AcceptedExtensions.JS, AcceptedExtensions.R, AcceptedExtensions.JL ]" @@ -283,6 +279,7 @@ import TeraMultiSelectModal from '@/components/widgets/tera-multi-select-modal.v import { useTabStore } from '@/stores/tabs'; import { extractPDF } from '@/services/models/extractions'; import useAuthStore from '@/stores/auth'; +import { uploadCodeToProject } from '@/services/code'; const props = defineProps<{ project: IProject; @@ -351,40 +348,77 @@ const assets = computed(() => { async function processFiles(files: File[], csvDescription: string) { return files.map(async (file) => { - if (file.type === AcceptedTypes.CSV) { - const addedCSV: CsvAsset | null = await createNewDatasetFromCSV( - progress, - file, - auth.name ?? '', - props.project.id, - csvDescription - ); - - if (addedCSV !== null) { - const text: string = addedCSV?.csv?.join('\r\n') ?? ''; - const images = []; - - return { file, error: false, response: { text, images } }; - } - return { file, error: true, response: { text: '', images: [] } }; + switch (file.type) { + case AcceptedTypes.CSV: + return processDataset(file, csvDescription); + case AcceptedTypes.PDF: + case AcceptedTypes.TXT: + case AcceptedTypes.MD: + return processArtifact(file); + case AcceptedTypes.PY: + case AcceptedTypes.R: + case AcceptedTypes.JL: + return processCode(file); + default: + return { file, error: true, response: { text: '', images: [] } }; } - - // This is pdf, txt, md files - const artifact: Artifact | null = await uploadArtifactToProject( - progress, - file, - props.project.username ?? '', - props.project.id, - '' - ); - if (artifact && file.name.toLowerCase().endsWith('.pdf')) { - extractPDF(artifact); - return { file, error: false, response: { text: '', images: [] } }; - } - return { file, error: true, response: { text: '', images: [] } }; }); } +/** + * Process a python, R or Julia file into a code asset + * @param file + */ +async function processCode(file: File) { + // This is pdf, txt, md files + await uploadCodeToProject(props.project.id, file, progress); + + return { file, error: true, response: { text: '', images: [] } }; +} + +/** + * Process a pdf, txt, md file into an artifact + * @param file + */ +async function processArtifact(file: File) { + // This is pdf, txt, md files + const artifact: Artifact | null = await uploadArtifactToProject( + progress, + file, + props.project.username ?? '', + props.project.id, + '' + ); + if (artifact && file.name.toLowerCase().endsWith('.pdf')) { + await extractPDF(artifact); + return { file, error: false, response: { text: '', images: [] } }; + } + return { file, error: true, response: { text: '', images: [] } }; +} + +/** + * Process a csv file into a dataset + * @param file + * @param description + */ +async function processDataset(file: File, description: string) { + const addedCSV: CsvAsset | null = await createNewDatasetFromCSV( + progress, + file, + auth.name ?? '', + props.project.id, + description + ); + + if (addedCSV !== null) { + const text: string = addedCSV?.csv?.join('\r\n') ?? ''; + const images = []; + + return { file, error: false, response: { text, images } }; + } + return { file, error: true, response: { text: '', images: [] } }; +} + const onRowSelect = (selectedRows) => { // show multi select modal when there are selectedRows otherwise hide showMultiSelect.value = selectedRows.length !== 0; diff --git a/packages/client/hmi-client/src/page/project/components/tera-project-page.vue b/packages/client/hmi-client/src/page/project/components/tera-project-page.vue index 3b2f76eeb4..dc66c04cd0 100644 --- a/packages/client/hmi-client/src/page/project/components/tera-project-page.vue +++ b/packages/client/hmi-client/src/page/project/components/tera-project-page.vue @@ -5,15 +5,15 @@ :project="project" @asset-loaded="emit('asset-loaded')" /> - + />