Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sympy-parsing-workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang committed Oct 17, 2024
2 parents e6da81e + 9e33a8b commit 086c47b
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { computed, ref } from 'vue';
import { exportProjectAsFile } from '@/services/project';
import { AcceptedExtensions } from '@/types/common';
import { MenuItem } from 'primevue/menuitem';
import useAuthStore from '@/stores/auth';
const props = defineProps<{ project: Project | null }>();
Expand All @@ -26,8 +27,8 @@ const { isShareDialogVisible, isRemoveDialogVisible, isProjectConfigDialogVisibl
const isCopying = ref(false);
const menu = ref();
const renameMenuItem = {
label: 'Edit project details',
const editDetailsMenuItem = {
label: 'Edit details',
icon: 'pi pi-pencil',
command: () => {
isProjectConfigDialogVisible.value = true;
Expand All @@ -41,14 +42,14 @@ const shareMenuItem = {
}
};
const removeMenuItem = {
label: 'Remove',
label: 'Delete',
icon: 'pi pi-trash',
command: () => {
isRemoveDialogVisible.value = true;
}
};
const copyMenuItem = {
label: 'Copy this project',
label: 'Copy',
icon: 'pi pi-clone',
command: async () => {
if (props.project) {
Expand Down Expand Up @@ -80,19 +81,20 @@ const downloadMenuItem = {
}
};
const separatorMenuItem = { separator: true };
const projectMenuItems = computed(() => {
const items: MenuItem[] = [];
if (props.project?.publicProject || props.project?.userPermission === 'creator') {
items.push(copyMenuItem);
items.push(downloadMenuItem);
}
if (props.project?.userPermission === 'creator') {
items.push(renameMenuItem, shareMenuItem, separatorMenuItem, removeMenuItem);
// Basic access to public and reader project
const items: MenuItem[] = [copyMenuItem, downloadMenuItem];
// Creator/Editor of the project
if (['creator', 'writer'].includes(props.project?.userPermission ?? '')) {
items.push(editDetailsMenuItem, shareMenuItem);
}
if (props.project?.userPermission === 'writer') {
items.push(renameMenuItem);
// Creator of the project, or an admin
if (props.project?.userPermission === 'creator' || useAuthStore().isAdmin) {
items.push(removeMenuItem);
}
return items;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const userMenuItems = ref([
command: () => {
router.push(RoutePath.UserAdmin);
},
visible: auth.user?.roles.some((r) => r.name === 'ADMIN')
visible: auth.isAdmin
},
{
label: 'Logout',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<template>
<div id="adobe-dc-view" />
<div :id="id" />
</template>

<script setup lang="ts">
import { ref, watch, onMounted } from 'vue';
import API from '@/api/api';
import { v4 as uuidv4 } from 'uuid';
const props = defineProps<{
pdfLink?: string;
title: string;
filePromise?: Promise<ArrayBuffer | null>;
}>();
const id = uuidv4();
const adobeDCView = ref();
const adobeApis = ref();
const isAdobePdfApiReady = ref(false);
Expand Down Expand Up @@ -49,7 +52,7 @@ watch(isAdobePdfApiReady, () => {
// eslint-disable-line
new window.AdobeDC.View({
clientId: apiKey,
divId: 'adobe-dc-view'
divId: id
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<TabView v-if="pdfs?.length" class="container">
<TabPanel :header="pdf.name" v-for="pdf in pdfs" :key="pdf.name">
<tera-pdf-embed v-if="pdf.isPdf" :pdf-link="pdf.data" :title="pdf.name || ''" />
<tera-text-editor v-else :initial-text="pdf.data" />
</TabPanel>
</TabView>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import TabView from 'primevue/tabview';
import TabPanel from 'primevue/tabpanel';
import TeraPdfEmbed from '@/components/widgets/tera-pdf-embed.vue';
import TeraTextEditor from '@/components/documents/tera-text-editor.vue';
import type { DocumentAsset } from '@/types/Types';
interface PdfData {
document: DocumentAsset;
data: string;
isPdf: boolean;
name: string;
}
const props = defineProps<{
pdfs: PdfData[];
}>();
const pdfs = ref<PdfData[]>(props.pdfs);
</script>
<style scoped>
.container {
display: flex;
flex-direction: column;
flex: 1;
}
:deep(.p-tabview) {
display: flex;
flex-direction: column;
flex: 1;
}
:deep(.p-tabview-panels) {
display: flex;
flex-direction: column;
flex: 1;
}
:deep(.p-tabview-panel) {
flex: 1;
}
:deep(.p-tabview-header) {
max-width: 150px;
}
:deep(.p-tabview-title) {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
hide-dropdown
>
<template #sidebar>
<tera-slider-panel
v-if="pdfData.length"
v-model:is-open="isPdfSidebarOpen"
content-width="700px"
header="Document Viewer"
>
<template #content>
<tera-drilldown-section :is-loading="isFetchingPDF">
<tera-pdf-panel :pdfs="pdfData" />
</tera-drilldown-section>
</template>
</tera-slider-panel>

<tera-slider-panel
v-model:is-open="isSidebarOpen"
content-width="360px"
Expand Down Expand Up @@ -174,7 +187,14 @@ import TeraColumnarPanel from '@/components/widgets/tera-columnar-panel.vue';
import Button from 'primevue/button';
import TeraInputText from '@/components/widgets/tera-input-text.vue';
import { getInterventionPoliciesForModel, getModel } from '@/services/model';
import { AssetType, Intervention, InterventionPolicy, Model, type TaskResponse } from '@/types/Types';
import {
AssetType,
Intervention,
InterventionPolicy,
Model,
type TaskResponse,
type DocumentAsset
} from '@/types/Types';
import { logger } from '@/utils/logger';
import TeraProgressSpinner from '@/components/widgets/tera-progress-spinner.vue';
import { useConfirm } from 'primevue/useconfirm';
Expand All @@ -198,6 +218,8 @@ import VegaChart from '@/components/widgets/VegaChart.vue';
import TeraSaveAssetModal from '@/components/project/tera-save-asset-modal.vue';
import { useProjects } from '@/composables/project';
import { interventionPolicyFromDocument } from '@/services/goLLM';
import { downloadDocumentAsset, getDocumentAsset, getDocumentFileAsText } from '@/services/document-assets';
import TeraPdfPanel from '@/components/widgets/tera-pdf-panel.vue';
import TeraInterventionCard from './tera-intervention-card.vue';
import {
InterventionPolicyOperation,
Expand Down Expand Up @@ -234,6 +256,10 @@ const newBlankInterventionPolicy = ref({
interventions: [blankIntervention]
});
const isPdfSidebarOpen = ref(true);
const isFetchingPDF = ref(false);
const pdfData = ref<{ document: DocumentAsset; data: string; isPdf: boolean; name: string }[]>([]);
const showSaveModal = ref(false);
const showCreatePolicyModal = ref(false);
const isSidebarOpen = ref(true);
Expand Down Expand Up @@ -569,6 +595,29 @@ onMounted(() => {
} else {
initialize();
}
if (documentIds.value.length) {
isFetchingPDF.value = true;
documentIds.value.forEach(async (id) => {
const document = await getDocumentAsset(id);
const name: string = document?.name ?? '';
const filename = document?.fileNames?.[0];
const isPdf = !!document?.fileNames?.[0]?.endsWith('.pdf');
if (document?.id && filename) {
let data: string | null;
if (isPdf) {
data = await downloadDocumentAsset(document.id, filename);
} else {
data = await getDocumentFileAsText(document.id, filename);
}
if (data !== null) {
pdfData.value.push({ document, data, isPdf, name });
}
}
});
}
isFetchingPDF.value = false;
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
hide-dropdown
>
<template #sidebar>
<tera-slider-panel
v-if="pdfData.length"
v-model:is-open="isDocViewerOpen"
header="Document Viewer"
content-width="700px"
>
<template #content>
<tera-drilldown-section :is-loading="isFetchingPDF">
<tera-pdf-panel :pdfs="pdfData" />
</tera-drilldown-section>
</template>
</tera-slider-panel>
<tera-slider-panel
class="input-config"
v-model:is-open="isSidebarOpen"
Expand Down Expand Up @@ -212,6 +224,7 @@ import TeraModelDiagram from '@/components/model/petrinet/tera-model-diagram.vue
import TeraObservables from '@/components/model/model-parts/tera-observables.vue';
import TeraInitialTable from '@/components/model/petrinet/tera-initial-table.vue';
import TeraParameterTable from '@/components/model/petrinet/tera-parameter-table.vue';
import { downloadDocumentAsset, getDocumentAsset, getDocumentFileAsText } from '@/services/document-assets';
import {
emptyMiraModel,
generateModelDatasetConfigurationContext,
Expand Down Expand Up @@ -246,14 +259,15 @@ import TeraToggleableInput from '@/components/widgets/tera-toggleable-input.vue'
import { saveCodeToState } from '@/services/notebook';
import TeraSaveAssetModal from '@/components/project/tera-save-asset-modal.vue';
import { useProjects } from '@/composables/project';
import TeraModelConfigurationItem from './tera-model-configuration-item.vue';
import TeraPdfPanel from '@/components/widgets/tera-pdf-panel.vue';
import {
blankModelConfig,
isModelConfigsEqual,
isModelConfigValuesEqual,
ModelConfigOperation,
ModelConfigOperationState
} from './model-config-operation';
import TeraModelConfigurationItem from './tera-model-configuration-item.vue';
enum ConfigTabs {
Wizard = 'Wizard',
Expand All @@ -264,6 +278,11 @@ const props = defineProps<{
node: WorkflowNode<ModelConfigOperationState>;
}>();
const isFetchingPDF = ref(false);
const isDocViewerOpen = ref(true);
const pdfData = ref<{ document: any; data: string; isPdf: boolean; name: string }[]>([]);
const isSidebarOpen = ref(true);
const isEditingDescription = ref(false);
const newDescription = ref('');
Expand Down Expand Up @@ -707,6 +726,29 @@ onMounted(() => {
selectedOutputId.value = props.node.active;
initialize(true);
}
if (documentIds.value.length) {
isFetchingPDF.value = true;
documentIds.value.forEach(async (id) => {
const document = await getDocumentAsset(id);
const name: string = document?.name ?? '';
const filename = document?.fileNames?.[0];
const isPdf = !!document?.fileNames?.[0]?.endsWith('.pdf');
if (document?.id && filename) {
let data: string | null;
if (isPdf) {
data = await downloadDocumentAsset(document.id, filename);
} else {
data = await getDocumentFileAsText(document.id, filename);
}
if (data !== null) {
pdfData.value.push({ document, data, isPdf, name });
}
}
});
}
isFetchingPDF.value = false;
});
watch(
Expand Down Expand Up @@ -860,4 +902,11 @@ button.start-edit {
.executed-code {
white-space: pre-wrap;
}
:deep(.content-wrapper) {
& > section {
& > main {
overflow: hidden;
}
}
}
</style>
11 changes: 6 additions & 5 deletions packages/client/hmi-client/src/page/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@
</section>
<section class="projects">
<div v-if="!isLoadingProjects && isEmpty(searchedAndFilterProjects)" class="no-projects">
<Vue3Lottie :animationData="EmptySeed" :height="200" :width="200"></Vue3Lottie>
<!--
<img src="@assets/svg/seed.svg" alt="" />
-->
<Vue3Lottie :animationData="EmptySeed" :height="200" :width="200" />
<template v-if="tab.title === TabTitles.MyProjects">
<p class="mt-4">
Get started by creating a
Expand Down Expand Up @@ -232,7 +229,11 @@ const viewOptions = ref([
const myFilteredSortedProjects = computed(() => {
const projects = useProjects().allProjects.value;
if (!projects) return [];
const myProjects = projects.filter(({ userPermission }) => ['creator', 'writer'].includes(userPermission ?? ''));
const myProjects = projects.filter(
({ userPermission, publicProject }) =>
// I can edit the project, or I can view the project and it's not public
['creator', 'writer'].includes(userPermission ?? '') || (userPermission === 'reader' && !publicProject)
);
return filterAndSortProjects(myProjects);
});
Expand Down
Loading

0 comments on commit 086c47b

Please sign in to comment.