Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1167 feat implement new code asset type in back end #1735

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
});
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@
AcceptedTypes.TXT,
AcceptedTypes.MD,
AcceptedTypes.PY,
AcceptedTypes.JS,
AcceptedTypes.M,
AcceptedTypes.R,
AcceptedTypes.JL
]"
Expand All @@ -195,8 +193,6 @@
AcceptedExtensions.TXT,
AcceptedExtensions.MD,
AcceptedExtensions.PY,
AcceptedExtensions.M,
AcceptedExtensions.JS,
AcceptedExtensions.R,
AcceptedExtensions.JL
]"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
:project="project"
@asset-loaded="emit('asset-loaded')"
/>
<!-- DVINCE TODO

<code-editor
v-else-if="pageType === AssetType.CODE"
v-else-if="pageType === AssetType.Code"
:initial-code="code"
@vue:mounted="
emit('asset-loaded');
openNextCodeFile();
openCode();
"
/>-->
/>
<code-editor
v-else-if="pageType === AssetType.Artifacts && !assetName?.endsWith('.pdf')"
:initial-code="code"
Expand Down Expand Up @@ -65,12 +65,12 @@
</template>

<script setup lang="ts">
import { ref, Ref, computed } from 'vue';
import { ref, computed } from 'vue';
import { ProjectPages, IProject } from '@/types/Project';
import { useRouter } from 'vue-router';
import { RouteName } from '@/router/routes';
import { isEmpty } from 'lodash';
import { CodeRequest, Tab } from '@/types/common';
import { Tab } from '@/types/common';
import Button from 'primevue/button';
import TeraDocument from '@/components/documents/tera-document.vue';
import TeraDataset from '@/components/dataset/tera-dataset.vue';
Expand All @@ -83,6 +83,7 @@ import { getArtifactArrayBuffer, getArtifactFileAsText } from '@/services/artifa
import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue';
import useResourceStore from '@/stores/resources';
import { AssetType } from '@/types/Types';
import { getCodeFileAsText } from '@/services/code';

const props = defineProps<{
project: IProject;
Expand All @@ -100,11 +101,9 @@ const router = useRouter();

const code = ref<string>();

const queuedCodeRequests: Ref<CodeRequest[]> = ref([]);

const assetName = computed<string>(() => {
if (props.pageType === ProjectPages.OVERVIEW) return 'Overview';
// dvince TODO if (props.pageType === ProjectAssetTypes.CODE) return 'New File';

const assets = resourceStore.activeProjectAssets;

/**
Expand All @@ -115,8 +114,9 @@ const assetName = computed<string>(() => {
*/
if (assets) {
const asset: any = assets[props.pageType as string].find((d: any) => d.id === props.assetId);
return asset.name ?? 'n/a';
if (asset.name) return asset.name;
}
if (props.pageType === AssetType.Code) return 'New File';
return 'n/a';
});

Expand All @@ -130,23 +130,10 @@ const openOverview = () => {
params: { pageType: ProjectPages.OVERVIEW, assetId: undefined }
});
};
async function openCode(codeRequests: CodeRequest[]) {
queuedCodeRequests.value = codeRequests;
await openNextCodeFile();
}

async function openNextCodeFile() {
if (queuedCodeRequests.value.length > 0) {
const currentRequest: CodeRequest | undefined = queuedCodeRequests.value.pop();

if (!currentRequest) return;

code.value = currentRequest.code;
await router.push({
name: RouteName.ProjectRoute,
params: currentRequest.asset
});
}
async function openCode() {
const res: string | null = await getCodeFileAsText(props.assetId!, assetName.value!);
if (!res) return;
code.value = res;
}

function getPDFBytes(): Promise<ArrayBuffer | null> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ function endDrag() {
const optionsMenu = ref();
const optionsMenuItems = ref([
{
/* DVINCE TODO key: ProjectAssetTypes.CODE,
key: AssetType.Code,
label: 'Code editor',
command() {
emit('open-asset', {
assetName: 'New file',
pageType: ProjectAssetTypes.CODE,
pageType: AssetType.Code,
assetId: undefined
});
} */
}
},
{
key: AssetType.Models,
Expand Down
14 changes: 7 additions & 7 deletions packages/client/hmi-client/src/page/project/tera-project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ const overviewResource = {
pageType: ProjectPages.OVERVIEW,
assetId: ''
};
// const codeResource = {
// pageType: ProjectAssetTypes.CODE,
// assetId: ''
// };

const codeResource = {
pageType: AssetType.Code,
assetId: ''
};

const adjustTabsProjectChange = () => {
const pageType = openedAssetRoute.value.pageType;
Expand Down Expand Up @@ -344,11 +345,10 @@ const adjustTabs = () => {

// If new code or overview
if (!tabExist && !assetId) {
// DVINCE TODO
/* if (pageType === ProjectAssetTypes.CODE) {
if (pageType === AssetType.Code) {
tabStore.addTab(projectId, codeResource);
openAsset();
} else */ if (pageType === ProjectPages.OVERVIEW) {
} else if (pageType === ProjectPages.OVERVIEW) {
tabStore.addTab(projectId, overviewResource);
openAsset(0);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/hmi-client/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const RouteMetadata: {
[RouteName.ProjectRoute]: { displayName: 'Project summary', icon: IconAccount32 },
[RouteName.CodeRoute]: {
displayName: 'Code',
icon: IconCode32
// dvince TODO projectAsset: ProjectAssetTypes.CODE
icon: IconCode32,
projectAsset: AssetType.Code
},
[RouteName.ProvenanceRoute]: { displayName: 'Provenance', icon: IconFlow32 },
[RouteName.HomeRoute]: { displayName: 'Home', icon: 'pi pi-home' },
Expand Down
Loading