diff --git a/es/components/extraFile/commit/index.d.ts b/es/components/extraFile/commit/index.d.ts index 0cb3eca37..5014e556b 100644 --- a/es/components/extraFile/commit/index.d.ts +++ b/es/components/extraFile/commit/index.d.ts @@ -6,5 +6,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps< block: boolean; type: string; executeText: string; + buttonProps: {}; }>) => import("react").ReactElement>; export default _default; diff --git a/es/components/extraFile/commit/index.js b/es/components/extraFile/commit/index.js index 241e8d852..ed4d0fa4b 100644 --- a/es/components/extraFile/commit/index.js +++ b/es/components/extraFile/commit/index.js @@ -24,6 +24,7 @@ export default OakComponent({ block: false, type: 'primary', executeText: '', + buttonProps: {}, }, methods: { getEfIds() { @@ -32,7 +33,7 @@ export default OakComponent({ assert(efPaths); if (oakFullpath) { const ids = efPaths.map((path) => { - const path2 = path ? `${oakFullpath}.path` : oakFullpath; + const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; const data = this.features.runningTree.getFreshValue(path2); if (data) { return data.map(ele => ele.id); @@ -42,7 +43,22 @@ export default OakComponent({ } return []; }, - upload() { + async upload() { + const ids = this.getEfIds(); + const promises = []; + ids.forEach((id) => { + const fileState = this.features.extraFile2.getFileState(id); + if (fileState) { + const { state } = fileState; + if (['local', 'failed'].includes(state)) { + promises.push(this.features.extraFile2.upload(id)); + } + } + }); + if (promises.length > 0) { + await Promise.all(promises); + } } - } + }, + features: ['extraFile2'], }); diff --git a/es/components/extraFile/commit/web.d.ts b/es/components/extraFile/commit/web.d.ts index 628cad9b6..e7e7ad279 100644 --- a/es/components/extraFile/commit/web.d.ts +++ b/es/components/extraFile/commit/web.d.ts @@ -8,6 +8,7 @@ export default function render(props: WebComponentProps Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/es/components/extraFile/commit/web.js b/es/components/extraFile/commit/web.js index 7bc5ae56f..0ceaa2b59 100644 --- a/es/components/extraFile/commit/web.js +++ b/es/components/extraFile/commit/web.js @@ -1,7 +1,7 @@ import { jsx as _jsx } from "react/jsx-runtime"; import { Button } from 'antd-mobile'; export default function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state)); let text = executeText || t('common::action.confirm'); @@ -24,5 +24,5 @@ export default function render(props) { else { await upload(); } - }, children: text })); + }, ...buttonProps, children: text })); } diff --git a/es/components/extraFile/commit/web.pc.d.ts b/es/components/extraFile/commit/web.pc.d.ts index 33488bc23..136a413eb 100644 --- a/es/components/extraFile/commit/web.pc.d.ts +++ b/es/components/extraFile/commit/web.pc.d.ts @@ -8,6 +8,7 @@ export default function render(props: WebComponentProps Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/es/components/extraFile/commit/web.pc.js b/es/components/extraFile/commit/web.pc.js index 5c23f90fa..cf185fb00 100644 --- a/es/components/extraFile/commit/web.pc.js +++ b/es/components/extraFile/commit/web.pc.js @@ -1,7 +1,7 @@ import { jsx as _jsx } from "react/jsx-runtime"; import { Button } from 'antd'; export default function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps = {} } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); let text = executeText || t('common::action.confirm'); @@ -24,5 +24,5 @@ export default function render(props) { else { await upload(); } - }, children: text })); + }, ...buttonProps, children: text })); } diff --git a/es/features/extraFile2.js b/es/features/extraFile2.js index 53c44e343..76ca54d7b 100644 --- a/es/features/extraFile2.js +++ b/es/features/extraFile2.js @@ -4,6 +4,7 @@ import { bytesToSize, getFileURL } from '../utils/extraFile'; import { assert } from 'oak-domain/lib/utils/assert'; import { getCos } from '../utils/cos'; import { unset } from 'oak-domain/lib/utils/lodash'; +import { generateNewIdAsync } from 'oak-domain'; export class ExtraFile2 extends Feature { cache; application; @@ -62,9 +63,19 @@ export class ExtraFile2 extends Feature { item.state = 'uploading'; item.percentage = 0; const up = new Upload(); - const cos = getCos(origin); try { + const cos = getCos(extraFile.origin); await cos.upload(extraFile, up.uploadFile, file); + await this.cache.exec('operate', { + entity: 'extraFile', + operation: { + id: await generateNewIdAsync(), + action: 'update', + data: { + uploadState: 'success', + }, + }, + }); item.state = 'uploaded'; item.percentage = undefined; this.publish(); diff --git a/lib/components/extraFile/commit/index.d.ts b/lib/components/extraFile/commit/index.d.ts index 0cb3eca37..5014e556b 100644 --- a/lib/components/extraFile/commit/index.d.ts +++ b/lib/components/extraFile/commit/index.d.ts @@ -6,5 +6,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps< block: boolean; type: string; executeText: string; + buttonProps: {}; }>) => import("react").ReactElement>; export default _default; diff --git a/lib/components/extraFile/commit/index.js b/lib/components/extraFile/commit/index.js index f4128b694..a90e6eef6 100644 --- a/lib/components/extraFile/commit/index.js +++ b/lib/components/extraFile/commit/index.js @@ -27,6 +27,7 @@ exports.default = OakComponent({ block: false, type: 'primary', executeText: '', + buttonProps: {}, }, methods: { getEfIds() { @@ -35,7 +36,7 @@ exports.default = OakComponent({ (0, assert_1.default)(efPaths); if (oakFullpath) { const ids = efPaths.map((path) => { - const path2 = path ? `${oakFullpath}.path` : oakFullpath; + const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; const data = this.features.runningTree.getFreshValue(path2); if (data) { return data.map(ele => ele.id); @@ -45,7 +46,22 @@ exports.default = OakComponent({ } return []; }, - upload() { + async upload() { + const ids = this.getEfIds(); + const promises = []; + ids.forEach((id) => { + const fileState = this.features.extraFile2.getFileState(id); + if (fileState) { + const { state } = fileState; + if (['local', 'failed'].includes(state)) { + promises.push(this.features.extraFile2.upload(id)); + } + } + }); + if (promises.length > 0) { + await Promise.all(promises); + } } - } + }, + features: ['extraFile2'], }); diff --git a/lib/components/extraFile/commit/web.d.ts b/lib/components/extraFile/commit/web.d.ts index 628cad9b6..e7e7ad279 100644 --- a/lib/components/extraFile/commit/web.d.ts +++ b/lib/components/extraFile/commit/web.d.ts @@ -8,6 +8,7 @@ export default function render(props: WebComponentProps Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/extraFile/commit/web.js b/lib/components/extraFile/commit/web.js index 0ceea7c17..bf5d034c1 100644 --- a/lib/components/extraFile/commit/web.js +++ b/lib/components/extraFile/commit/web.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const antd_mobile_1 = require("antd-mobile"); function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state)); let text = executeText || t('common::action.confirm'); @@ -26,6 +26,6 @@ function render(props) { else { await upload(); } - }, children: text })); + }, ...buttonProps, children: text })); } exports.default = render; diff --git a/lib/components/extraFile/commit/web.pc.d.ts b/lib/components/extraFile/commit/web.pc.d.ts index 33488bc23..136a413eb 100644 --- a/lib/components/extraFile/commit/web.pc.d.ts +++ b/lib/components/extraFile/commit/web.pc.d.ts @@ -8,6 +8,7 @@ export default function render(props: WebComponentProps Promise; }>): import("react/jsx-runtime").JSX.Element; diff --git a/lib/components/extraFile/commit/web.pc.js b/lib/components/extraFile/commit/web.pc.js index aa5ad2b8d..1d8147ed0 100644 --- a/lib/components/extraFile/commit/web.pc.js +++ b/lib/components/extraFile/commit/web.pc.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const antd_1 = require("antd"); function render(props) { - const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText } = props.data; + const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, buttonProps = {} } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); let text = executeText || t('common::action.confirm'); @@ -26,6 +26,6 @@ function render(props) { else { await upload(); } - }, children: text })); + }, ...buttonProps, children: text })); } exports.default = render; diff --git a/lib/features/extraFile2.js b/lib/features/extraFile2.js index 3e64b5f51..a0ddd4422 100644 --- a/lib/features/extraFile2.js +++ b/lib/features/extraFile2.js @@ -7,6 +7,7 @@ const extraFile_1 = require("../utils/extraFile"); const assert_1 = require("oak-domain/lib/utils/assert"); const cos_1 = require("../utils/cos"); const lodash_1 = require("oak-domain/lib/utils/lodash"); +const oak_domain_1 = require("oak-domain"); class ExtraFile2 extends oak_frontend_base_1.Feature { cache; application; @@ -65,9 +66,19 @@ class ExtraFile2 extends oak_frontend_base_1.Feature { item.state = 'uploading'; item.percentage = 0; const up = new upload_1.Upload(); - const cos = (0, cos_1.getCos)(origin); try { + const cos = (0, cos_1.getCos)(extraFile.origin); await cos.upload(extraFile, up.uploadFile, file); + await this.cache.exec('operate', { + entity: 'extraFile', + operation: { + id: await (0, oak_domain_1.generateNewIdAsync)(), + action: 'update', + data: { + uploadState: 'success', + }, + }, + }); item.state = 'uploaded'; item.percentage = undefined; this.publish(); diff --git a/src/components/extraFile/commit/index.ts b/src/components/extraFile/commit/index.ts index 1941a864b..5e492dd16 100644 --- a/src/components/extraFile/commit/index.ts +++ b/src/components/extraFile/commit/index.ts @@ -31,6 +31,7 @@ export default OakComponent({ block: false, type: 'primary', executeText: '', + buttonProps: {}, }, methods: { getEfIds() { @@ -40,7 +41,7 @@ export default OakComponent({ if (oakFullpath) { const ids = efPaths.map( (path) => { - const path2 = path ? `${oakFullpath}.path` : oakFullpath; + const path2 = path ? `${oakFullpath}.${path}` : oakFullpath; const data = this.features.runningTree.getFreshValue(path2); if (data) { return (data as EntityDict['extraFile']['OpSchema'][]).map( @@ -55,8 +56,26 @@ export default OakComponent({ } return []; }, - upload() { + async upload() { + const ids = this.getEfIds(); + + const promises: Promise[] = []; + ids.forEach( + (id) => { + const fileState = this.features.extraFile2.getFileState(id); + if (fileState) { + const { state } = fileState; + if (['local', 'failed'].includes(state)) { + promises.push(this.features.extraFile2.upload(id)); + } + } + } + ); + if (promises.length > 0) { + await Promise.all(promises); + } } - } + }, + features: ['extraFile2'], }); \ No newline at end of file diff --git a/src/components/extraFile/commit/web.pc.tsx b/src/components/extraFile/commit/web.pc.tsx index da6376eaf..42a910bf8 100644 --- a/src/components/extraFile/commit/web.pc.tsx +++ b/src/components/extraFile/commit/web.pc.tsx @@ -10,11 +10,12 @@ export default function render(props: WebComponentProps Promise }>) { const { state, oakExecutable, oakExecuting, oakDirty, - size, block, type, executeText } = props.data; + size, block, type, executeText, buttonProps = {} } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable !== true && ['uploaded'].includes(state)); @@ -46,6 +47,7 @@ export default function render(props: WebComponentProps {text} diff --git a/src/components/extraFile/commit/web.tsx b/src/components/extraFile/commit/web.tsx index 19aae65e2..b1abcf996 100644 --- a/src/components/extraFile/commit/web.tsx +++ b/src/components/extraFile/commit/web.tsx @@ -10,11 +10,12 @@ export default function render(props: WebComponentProps Promise }>) { const { state, oakExecutable, oakExecuting, oakDirty, - size, block, type, executeText } = props.data; + size, block, type, executeText, buttonProps } = props.data; const { t, upload, execute } = props.methods; const disabled = oakExecuting || ['uploading'].includes(state) || (oakExecutable === false && ['uploaded'].includes(state)); @@ -46,6 +47,7 @@ export default function render(props: WebComponentProps {text} diff --git a/src/features/extraFile2.ts b/src/features/extraFile2.ts index f4306466d..9d08508c3 100644 --- a/src/features/extraFile2.ts +++ b/src/features/extraFile2.ts @@ -13,6 +13,7 @@ import { assert } from 'oak-domain/lib/utils/assert'; import { getCos } from '../utils/cos'; import { OpSchema } from '../oak-app-domain/ExtraFile/Schema'; import { unset } from 'oak-domain/lib/utils/lodash'; +import { generateNewIdAsync } from 'oak-domain'; export type FileState = 'local' | 'uploading' | 'uploaded' | 'failed'; @@ -94,13 +95,23 @@ export class ExtraFile2< item.percentage = 0; const up = new Upload(); - const cos = getCos(origin); try { + const cos = getCos(extraFile.origin!); await cos.upload( extraFile as OpSchema, up.uploadFile, file ); + await this.cache.exec('operate', { + entity: 'extraFile', + operation: { + id: await generateNewIdAsync(), + action: 'update', + data: { + uploadState: 'success', + }, + } as ED['extraFile']['Operation'], + }); item.state = 'uploaded'; item.percentage = undefined; this.publish();