Skip to content

Commit

Permalink
feat: added actions for git detail
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 18, 2024
1 parent 0f09257 commit 121feb8
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 375 deletions.
21 changes: 3 additions & 18 deletions src/components/file/FileActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { sendEvent } from '@/admin/umeng';
import { downloadData } from '@/utils';
const props = defineProps<{
ns: ListStoreNamespace,
activeId: string,
ns: ListStoreNamespace;
activeId: string;
}>();
// i18n
Expand Down Expand Up @@ -60,19 +60,6 @@ const onClickExport = async () => {
:tooltip="t('components.file.actions.tooltip.fileEditorActions')"
/>
<cl-nav-action-item>
<cl-fa-icon-button
:icon="['fa', 'robot']"
:tooltip="
systemInfo.edition !== 'global.edition.community'
? t('components.file.actions.tooltip.createWithAi')
: t('components.file.actions.tooltip.createWithAiDisabled')
"
type="primary"
id="create-with-ai-btn"
class-name="create-with-ai-btn"
:disabled="systemInfo.edition === 'global.edition.community'"
@click="onOpenCreateWithAi"
/>
<cl-fa-icon-button
:icon="['fa', 'upload']"
:tooltip="t('components.file.actions.tooltip.uploadFiles')"
Expand All @@ -93,9 +80,7 @@ const onClickExport = async () => {
/>
<cl-fa-icon-button
:icon="['fa', 'cog']"
:tooltip="
t('components.file.actions.tooltip.fileEditorSettings')
"
:tooltip="t('components.file.actions.tooltip.fileEditorSettings')"
type="info"
id="open-settings-btn"
class-name="open-settings-btn"
Expand Down
179 changes: 179 additions & 0 deletions src/components/file/UploadFilesDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { useStore } from 'vuex';
import { ElMessage } from 'element-plus';
import { useI18n } from 'vue-i18n';
import { sendEvent } from '@/admin/umeng';
import { getOSPathSeparator } from '@/utils';
import { useRoute } from 'vue-router';
import { FILE_UPLOAD_MODE_DIR } from '@/constants';
import FileUpload from '@/components/file/FileUpload.vue';
const props = defineProps<{
ns: ListStoreNamespace;
activeDialogKey?: DialogKey;
activeId: string;
form: BaseModel;
services: FileServices<BaseModel>;
}>();
// i18n
const { t } = useI18n();
// route
const route = useRoute();
// store
const store = useStore();
const fileUploadRef = ref<typeof FileUpload>();
const mode = ref<FileUploadMode>(FILE_UPLOAD_MODE_DIR);
const files = ref<FileWithPath[]>([]);
const fileUploadVisible = computed(
() => props.activeDialogKey === 'uploadFiles'
);
const name = computed(() => props.form?.name);
const confirmLoading = ref<boolean>(false);
const confirmDisabled = computed<boolean>(() => !files.value.length);
const isDetail = computed<boolean>(() => !!props.activeId);
const { listRootDir, saveFilesBinary } = props.services;
const id = computed<string>(() => {
const { activeId, form } = props;
if (isDetail.value) {
return activeId;
} else {
return form?._id as string;
}
});
const hasMultiDir = computed<boolean>(() => {
if (!files.value) return false;
const set = new Set<string>();
for (const f of files.value) {
const lv1 = f?.path?.split(getOSPathSeparator())[0] as string;
if (!set.has(lv1)) {
set.add(lv1);
}
if (set.size > 1) {
return true;
}
}
return false;
});
const uploadInfo = computed(() => {
const info = {
fileCount: files.value.length,
filePaths: files.value.map(f => f.path || f.name),
} as FileUploadInfo;
if (mode.value === FILE_UPLOAD_MODE_DIR) {
const f = files.value[0];
info.dirName = f?.path?.split(getOSPathSeparator())[0];
}
return info;
});
const getFilePath = (f: FileWithPath): string => {
const path = f.path;
if (!path) return f.name;
if (hasMultiDir.value) {
return path;
} else {
return path
.split(getOSPathSeparator())
.filter((_: any, i: number) => i > 0)
.join(getOSPathSeparator());
}
};
const uploadFiles = async () => {
if (!files.value) return;
await saveFilesBinary(
id.value,
files.value.map((f: FileWithPath) => {
return { path: getFilePath(f) as string, file: f as File };
})
);
await listRootDir(id.value);
};
const onUploadClose = () => {
const { ns } = props;
store.commit(`${ns}/hideDialog`);
};
const onUploadConfirm = async () => {
const { ns } = props;
confirmLoading.value = true;
try {
sendEvent('click_spider_detail_actions_upload_confirm', {
mode: mode.value,
});
await uploadFiles();
await ElMessage.success(t('common.message.success.upload'));
} catch (e: any) {
await ElMessage.error(e);
} finally {
confirmLoading.value = false;
store.commit(`${ns}/hideDialog`);
}
};
const onModeChange = (value: FileUploadMode) => {
mode.value = value;
};
const onFilesChange = (fileList: FileWithPath[]) => {
if (!fileList.length) return;
files.value = fileList;
sendEvent('click_spider_detail_actions_files_change');
};
const title = computed(() => {
return (
t('components.file.upload.title') + (name.value ? ` - ${name.value}` : '')
);
});
watch(fileUploadVisible, () => {
if (!fileUploadVisible.value) {
files.value = [];
}
});
watch(mode, () => {
files.value = [];
});
onBeforeUnmount(() => {
const { ns } = props;
store.commit(`${ns}/hideDialog`);
});
</script>

<template>
<cl-dialog
:visible="fileUploadVisible"
:title="title"
:confirm-loading="confirmLoading"
:confirm-disabled="confirmDisabled"
@close="onUploadClose"
@confirm="onUploadConfirm"
>
<cl-file-upload
ref="fileUploadRef"
:mode="mode"
:upload-info="uploadInfo"
@mode-change="onModeChange"
@files-change="onFilesChange"
/>
</cl-dialog>
</template>

<style lang="scss" scoped></style>
23 changes: 23 additions & 0 deletions src/components/file/UploadGitFilesDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { useStore } from 'vuex';
import useGitService from '@/services/git/gitService';
import useGitDetail from '@/views/git/detail/useGitDetail';
// store
const ns = 'git';
const store = useStore();
const { git: state } = store.state as RootStoreState;
const { activeId } = useGitDetail();
</script>

<template>
<cl-upload-files-dialog
:ns="ns"
:active-dialog-key="state.activeDialogKey"
:active-id="activeId"
:form="state.form"
:services="useGitService(store)"
/>
</template>

<style lang="scss" scoped></style>
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import FileEditorNavTabsShowMoreContextMenu from './file/FileEditorNavTabsShowMo
import FileEditorSettingsDialog from './file/FileEditorSettingsDialog.vue';
import FileTab from './file/FileTab.vue';
import FileUpload from './file/FileUpload.vue';
import UploadFilesDialog from './file/UploadFilesDialog.vue';
import FilterCondition from './filter/FilterCondition.vue';
import FilterConditionList from './filter/FilterConditionList.vue';
import FilterInput from './filter/FilterInput.vue';
Expand Down Expand Up @@ -188,6 +189,7 @@ export {
FileEditorSettingsDialog as ClFileEditorSettingsDialog,
FileTab as ClFileTab,
FileUpload as ClFileUpload,
UploadFilesDialog as ClUploadFilesDialog,
FilterCondition as ClFilterCondition,
FilterConditionList as ClFilterConditionList,
FilterInput as ClFilterInput,
Expand Down
Loading

0 comments on commit 121feb8

Please sign in to comment.