Can download labels.

This commit is contained in:
Haifeng Luo 2022-05-08 19:58:57 +08:00
parent 8a398775b8
commit a98947eda5
6 changed files with 36 additions and 7 deletions

View File

@ -3,6 +3,8 @@ import {DownOutlined, DeleteOutlined, UpOutlined} from '@ant-design/icons';
import {Button, Col, Input, InputNumber, Row, Table, Tooltip} from 'antd';
import * as Setting from "./Setting";
import i18next from "i18next";
import FileSaver from "file-saver";
import XLSX from "xlsx";
class LabelTable extends React.Component {
constructor(props) {
@ -61,6 +63,22 @@ class LabelTable extends React.Component {
this.updateTable(table);
}
downloadLabels() {
let data = [];
this.props.table.forEach((label, i) => {
let row = {};
row[0] = label.timestamp;
row[1] = label.text;
data.push(row);
});
let sheet = XLSX.utils.json_to_sheet(data, {skipHeader: true});
const blob = Setting.sheet2blob(sheet, "labels");
const fileName = `labels-${this.props.video.name}-${this.props.table.length}.xlsx`;
FileSaver.saveAs(blob, fileName);
}
renderTable(table) {
const columns = [
{
@ -78,11 +96,10 @@ class LabelTable extends React.Component {
{index + 1}
</Button>
)
return (index + 1);
}
},
{
title: i18next.t("video:Timestamp (second)"),
title: i18next.t("video:Timestamp (s)"),
dataIndex: 'timestamp',
key: 'timestamp',
width: '120px',
@ -147,8 +164,8 @@ class LabelTable extends React.Component {
{this.props.title}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.addRow(table)}>{i18next.t("general:Add")}</Button>
{
this.props.wordset === undefined ? null : (
<Button style={{marginLeft: "5px", marginRight: "5px"}} size="small" onClick={() => Setting.downloadXlsx(this.props.wordset)}>{i18next.t("general:Download")}</Button>
this.props.table.length === 0 ? null : (
<Button style={{marginLeft: "5px", marginRight: "5px"}} size="small" onClick={() => this.downloadLabels()}>{i18next.t("general:Download")}</Button>
)
}
</div>

View File

@ -264,7 +264,7 @@ export function getLabelTags(labels) {
res.push(
<Tooltip placement="top" title={getShortText(JSON.stringify(label.text), 500)}>
<Tag color={"processing"}>
{`${label.timestamp}: ${label.text}`}
{`${label.timestamp}: ${label.text !== "" ? label.text : "(Empty)"}`}
</Tag>
</Tooltip>
);

View File

@ -171,6 +171,7 @@ class VideoEditPage extends React.Component {
title={i18next.t("video:Labels")}
table={this.state.video.labels}
currentTime={this.state.currentTime}
video={this.state.video}
player={this.state.player}
screen={this.state.screen}
videoObj={this.state.videoObj}

View File

@ -123,6 +123,15 @@ class VideoListPage extends React.Component {
return Setting.getLabelTags(text);
}
},
{
title: i18next.t("video:Label count"),
dataIndex: 'labelCount',
key: 'labelCount',
width: '110px',
render: (text, record, index) => {
return record.labels.length;
}
},
{
title: i18next.t("general:Action"),
dataIndex: 'action',

View File

@ -37,9 +37,10 @@
"Cover": "Cover",
"Current time (second)": "Current time (second)",
"Edit Video": "Edit Video",
"Label count": "Label count",
"Labels": "Labels",
"Text": "Text",
"Timestamp (second)": "Timestamp (s)",
"Timestamp (s)": "Timestamp (s)",
"Video": "Video",
"Video ID": "Video ID"
},

View File

@ -37,9 +37,10 @@
"Cover": "封面图片",
"Current time (second)": "当前时间(秒)",
"Edit Video": "编辑视频",
"Label count": "标签数量",
"Labels": "标签",
"Text": "文本",
"Timestamp (second)": "时间戳(秒)",
"Timestamp (s)": "时间戳(秒)",
"Video": "视频",
"Video ID": "视频ID"
},