!2698 功能:在文件管理器中,直接打开历史版本

pull/2719/MERGE
黄诗津 4 months ago committed by ChenX
parent e7d423520f
commit f73ce9ecf4

@ -1,11 +1,14 @@
import { Button, Checkbox, HTMLTable } from "@blueprintjs/core";
import { Button, Checkbox, HTMLTable, Intent } from "@blueprintjs/core";
import { observable } from "mobx";
import { observer } from "mobx-react";
import React from "react";
import { app } from "../../ApplicationServices/Application";
import { StoreageKeys } from "../../Common/StoreageKeys";
import { FileServer } from "../../DatabaseServices/FileServer";
import { userConfig } from "../../Editor/UserConfig";
import { BoardModalType } from "../../UI/Components/Board/BoardModalType";
import { ModalState } from "../../UI/Components/Modal/ModalInterface";
import { AppToaster } from "../../UI/Components/Toaster";
import { userConfigStore } from "../../UI/Store/UserConfigStore";
import { HistoryProp } from "./OperLogsModal";
@ -95,6 +98,12 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
_LastOper = "";
_Data = this.props.data;
@observable _CanOpen: boolean = false;
constructor(props)
{
super(props);
if (this.props.newFileId)
this._CanOpen = true;
}
render()
{
@ -109,7 +118,13 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
label="只显示能还原记录"
style={{ position: 'absolute', right: "10px", fontSize: "12px", top: "15px" }}
checked={this._CanOpen}
onClick={(e) => { this._Index = 0, this._LastOper = "", this._CanOpen = !this._CanOpen; e.currentTarget.blur(); }}
onClick={(e) =>
{
this._Index = 0;
this._LastOper = "";
this._CanOpen = !this._CanOpen;
e.currentTarget.blur();
}}
/>
</th>
</tr>
@ -125,6 +140,7 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
_AllDataList = () =>
{
let count = 0;
return (
<>
{
@ -134,6 +150,11 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
if (this._LastOper === "打开")
return;
this._LastOper = d.oper_type_name;
if (d.oper_type_name === "修改")
count++;
if (this.props.newFileId && count > 5) return;
return <tr key={d.oper_date}>
<td>{d.oper_type_name}</td>
<td
@ -160,13 +181,16 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
_CanOpenDataList = () =>
{
let count = 0;
return (
<>
{
this._Data.map(d =>
this._Data.map((d, i) =>
{
if (d.oper_type_name !== "新建" && d.oper_type_name !== "修改") return;
if (!this._HasHistoryFile(d.oper_type_name, d.oper_date, this.props.files[this._Index])) return;
count++;
if (this.props.newFileId && count > 5) return;
return <tr>
<td>{d.oper_type_name}</td>
<td
@ -188,10 +212,8 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
text="打开"
onClick={(e) =>
{
this.props.OnClickOpenFile(this.props.userName, this.props.fileId, this.props.files, e.currentTarget.value);
if (this.props.isNotToaster)
app.Editor.ModalManage.m_PromisRes({ Status: ModalState.Ok });
app.Editor.ModalManage.Destory();
let index = e.currentTarget.value;
this.handleOpen(index);
}}
/>
</td>
@ -201,6 +223,43 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
</>
);
};
handleOpen = async (index: number) =>
{
const { fileId, newFileId, files, userName } = this.props;
let status: boolean = true;
if (newFileId)
{
let server = FileServer.GetInstance();
if (fileId != newFileId)
{
server._CurrentFilePath = "";
server.m_CurFileId = newFileId;
let info = await server.GetFileInfo(newFileId);
server.CurrentFileMd5 = info.code;
if (info.name)
server.currentFileInfo.name = info.name;
localStorage.setItem(StoreageKeys.LastOpenFileId, info.file_id || "");
}
status = await this.props.OnClickOpenFile(userName, newFileId, files, index);
}
else
{
status = await this.props.OnClickOpenFile(userName, fileId, files, index);
}
if (!status)
{
AppToaster.show({
message: "打开图纸失败,请尝试打开其他历史记录图纸",
timeout: 3000,
intent: Intent.DANGER,
});
return;
}
if (this.props.isNotToaster)
app.Editor.ModalManage.m_PromisRes({ Status: ModalState.Ok });
app.Editor.ModalManage.Destory();
};
_ButtonEl(name: string, oper_date: string, file_date: string): React.ReactElement<any>
{
@ -210,12 +269,10 @@ export class OpenHistoryList extends React.Component<HistoryProp, {}>
className="histroyBtn"
value={this._Index++}
text="打开"
onClick={(e) =>
onClick={async (e) =>
{
this.props.OnClickOpenFile(this.props.userName, this.props.fileId, this.props.files, e.currentTarget.value);
if (this.props.isNotToaster)
app.Editor.ModalManage.m_PromisRes({ Status: ModalState.Ok });
app.Editor.ModalManage.Destory();
let index = e.currentTarget.value;
this.handleOpen(index);
}}
/>
);

@ -8,6 +8,7 @@ import { inflateBase64 } from "../../Common/inflate";
import { CADFiler } from "../../DatabaseServices/CADFiler";
import { FileServer } from "../../DatabaseServices/FileServer";
import { Command } from "../../Editor/CommandMachine";
import { AppConfirm } from "../../UI/Components/Common/Confirm";
import { ModalState } from "../../UI/Components/Modal/ModalInterface";
import { AppToaster } from "../../UI/Components/Toaster";
import { ParseTime } from "./OpenHistory";
@ -22,12 +23,29 @@ export const HistoryToaster = Toaster.create({
export class OperLogs implements Command
{
constructor(private _IsOpenFile: boolean = true) { }
constructor(private _IsOpenFile: boolean = true, private fileId?: string, private fileName?: string) { }
async exec()
{
let fid = FileServer.GetInstance().m_CurFileId;
if (!fid)
if (this.fileId)
{
if (!app.Saved)
{
let status = await AppConfirm.show({
message: "您当前图纸还未保存,是否放弃保存?",
confirmButtonText: "放弃保存",
intent: Intent.DANGER
});
if (!status)
{
AppToaster.dismiss("openfile");
return;//如果不肯放弃保存,那么终止本次文件打开
}
}
}
else if (!fid)
{
AppToaster.show({
message: "该文件为新键文件,未保存",
@ -37,11 +55,13 @@ export class OperLogs implements Command
return;
}
let cur_fid = this.fileId ?? fid;
let userName = localStorage.getItem(StoreageKeys.UserName);
let curUserFileHistoryRes: Response;//当前用户操作历史(备份服务器)
try
{
curUserFileHistoryRes = await fetch(`${FileHistoryUrl}?user=${userName}&fileId=${fid}`);
curUserFileHistoryRes = await fetch(`${FileHistoryUrl}?user=${userName}&fileId=${cur_fid}`);
if (curUserFileHistoryRes.status !== 200) return;
} catch (error)
{
@ -55,7 +75,7 @@ export class OperLogs implements Command
let allFiles = await curUserFileHistoryRes.json() as string[];
let operLogsRes = await PostJson(SignUrl.operLogs, { obj_type: 1, obj_value: fid });//服务端操作历史
let operLogsRes = await PostJson(SignUrl.operLogs, { obj_type: 1, obj_value: cur_fid });//服务端操作历史
if (operLogsRes.err_code !== RequestStatus.Ok) return;
let userNames: Set<string> = new Set;
@ -65,7 +85,7 @@ export class OperLogs implements Command
if (user === userName || userNames.has(user)) continue;
userNames.add(date.oper_user);
let res = await fetch(`${FileHistoryUrl}?user=${date.oper_user}&fileId=${fid}`);
let res = await fetch(`${FileHistoryUrl}?user=${date.oper_user}&fileId=${cur_fid}`);
if (res.status !== 200) continue;
let files = await res.json() as string[];
@ -84,15 +104,18 @@ export class OperLogs implements Command
{
app.Editor.ModalManage.RenderModal(OperLogsModal, {
fileId: fid,
newFileId: this.fileId,
userName: userName,
files: allFiles,
data: data,
fileName: this.fileName,
OnClickOpenFile: this.OnClickOpenFile,
isNotToaster: true,
});
let Rm = await app.Editor.ModalManage.Wait();
if (Rm.Status !== ModalState.Ok) return;
}
if (this.fileId) return true;
let time = allFiles.length === 0 ? 5000 : 10000; //窗口持续时间
@ -113,19 +136,28 @@ export class OperLogs implements Command
timeout: time + 500,
intent: Intent.NONE,
});
return true;
}
//打开历史保存的文件图纸
private async OnClickOpenFile(userName: string, fileId: string, files: string[], number: number)
{
let fileName = files[number];
let url = FileHistoryFilesUrl + encodeURIComponent(userName + "//" + fileId + "//" + fileName);
let cadf = await FetchFile1(url + ".cad");
app.OpenFile(cadf);
try
{
let fileName = files[number];
let url = FileHistoryFilesUrl + encodeURIComponent(userName + "//" + fileId + "//" + fileName);
let cadf = await FetchFile1(url + ".cad");
app.OpenFile(cadf);
return true;
}
catch
{
return false;
}
}
}
async function FetchFile1(url: string): Promise<CADFiler>
export async function FetchFile1(url: string): Promise<CADFiler>
{
let res = await fetch(url);
let binaryData = await res.text();

@ -17,11 +17,13 @@ export interface HistoryProp
userName: string,
files: string[], //保存记录
data: OperInfo[],
fileName?: string;
isNotToaster?: boolean,
isOpenFile?: boolean,
time?: number,
Toaster?: IToaster;
OnClickOpenFile: (userName: string, fileId: string, files: string[], number: number) => void;
newFileId?: string;//右键打开历史记录时文件id
OnClickOpenFile: (userName: string, fileId: string, files: string[], number: number) => Promise<boolean>;
}
@observer
@ -42,6 +44,9 @@ export class OperLogsModal extends React.Component<HistoryProp, {}>
onClick={() => { app.Editor.ModalManage.Destory(); }}
/>
</div>
<div style={{ padding: "0 10px", height: "25px", lineHeight: "25px", fontSize: "15px" }}>
: {this.props.fileName}
</div>
<div style={{ padding: "0 10px", height: "35px", lineHeight: "35px", fontWeight: "bold", fontSize: "16px" }}>
7
</div>
@ -53,6 +58,7 @@ export class OperLogsModal extends React.Component<HistoryProp, {}>
fileId={this.props.fileId}
userName={this.props.userName}
files={this.props.files}
newFileId={this.props.newFileId}
data={this.props.data}
OnClickOpenFile={this.props.OnClickOpenFile}
isNotToaster={this.props.isNotToaster}

@ -233,6 +233,15 @@ export class FileServer extends Singleton
intent: status ? Intent.SUCCESS : Intent.DANGER
}, 'openfile');
if (!status)
{
AppToaster.show({
message: "可尝试右键文件打开历史版本!",
timeout: 5000,
intent: Intent.WARNING
}, 'openhistroy');
}
if (userConfig.openHistoryList)
{
let operLogs = new OperLogs();

@ -3,6 +3,7 @@ import { IObservableValue } from 'mobx';
import { inject, observer } from 'mobx-react';
import * as React from 'react';
import { ExportDataModal } from '../../../Add-on/ExportData';
import { OperLogs } from '../../../Add-on/File/OperLog';
import { InsertDocument } from '../../../Add-on/Insert';
import { app } from '../../../ApplicationServices/Application';
import { CommandNames } from '../../../Common/CommandNames';
@ -37,7 +38,8 @@ export interface IFileListProps
@inject('store')
@observer
export class FileList extends React.Component<IFileListProps, {}> {
export class FileList extends React.Component<IFileListProps, {}>
{
handleOpenFile = async (file: IFileInfo) =>
{
this.props.store.m_FileManageOpen = false;
@ -205,6 +207,18 @@ export class FileList extends React.Component<IFileListProps, {}> {
this.ShareRender(data.file_id);
}}
/>
<MenuItem
icon="history"
text="打开历史版本"
disabled={this.props.selectIds.size != 1}
onClick={async () =>
{
let operLogs = new OperLogs(false, data.file_id, data.name);
let isSuccess = await operLogs.exec();
if (isSuccess)
this.props.store.m_FileManageOpen = false;
}}
/>
<MenuItem
icon="trash"
text="删除"

Loading…
Cancel
Save