From 467250286326bcb1a202e44c6b4b5cebdc259b34 Mon Sep 17 00:00:00 2001 From: chenshihai Date: Wed, 1 Nov 2023 10:34:59 +0800 Subject: [PATCH] #4852 --- options/locale/locale_en-US.ini | 1 + options/locale/locale_zh-CN.ini | 1 + public/self/dataset_preview.js | 14 ++++++++++++++ templates/repo/datasets/dirs/dir_preview.tmpl | 9 +++++++++ 4 files changed, 25 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4f1ff4384a..19bb44a6e8 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -868,6 +868,7 @@ file_list=File list file_not_support_preview=File does not support preview please_select_file_preview=Please select a file for preview see_more=See more +query_timeout_tips=The server is processing it. Drink a glass of water and come back to take a look~ show_dataset= Dataset edit_dataset= Edit Dataset diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 37e1fb99c7..4b9143c5bc 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -868,6 +868,7 @@ file_list=文件列表 file_not_support_preview=文件暂不支持预览 please_select_file_preview=请选择文件进行预览 see_more=查看更多 +query_timeout_tips=服务器正在处理,喝杯水回来再看看~ reference_dataset_fail=关联数据集失败,请稍后再试。 cancel_reference_dataset_fail=取消关联数据集失败,请稍后再试。 diff --git a/public/self/dataset_preview.js b/public/self/dataset_preview.js index 60ef7fdd76..506523d816 100644 --- a/public/self/dataset_preview.js +++ b/public/self/dataset_preview.js @@ -1,5 +1,6 @@ (function () { function DatasetPreview() { + this.ajaxTimeOut = 1000 * 60; this.datasetData = DATASET_DATA; this.supportImgReg = /(\.jpg|\.jpeg|\.png|\.gif|\.bmp)$/i; this.supportTxtReg = /(\.txt|\.xml|\.html|\.json|\.py|\.sh|\.md|\.csv|\.log|\.js|\.css|\.ipynb)$/i; @@ -50,6 +51,11 @@ this.getPathChildren(); }; + DatasetPreview.prototype.showGetPathChildrenTimeout = function () { + $('#myCanvas_div .tabpannel.ui.form .query-timeout').show(); + $('#filelist').hide(); + } + DatasetPreview.prototype.getPathChildrenMore = function () { var self = this; var lastDir = this.data.filePath[this.data.filePath.length - 1]; @@ -60,6 +66,7 @@ type: "get", url: `/api/v1/attachments/get_dir`, dataType: "json", + timeout: this.ajaxTimeOut, data: { _csrf: this.datasetData.csrf, uuid: this.datasetData.uuid, @@ -94,6 +101,9 @@ error: function (err) { $('#myCanvas_div .tabpannel.ui.form').removeClass('loading'); console.log(err); + if (err.statusText == 'timeout') { + self.showGetPathChildrenTimeout(); + } } }); } @@ -114,6 +124,7 @@ type: "get", url: `/api/v1/attachments/get_dir`, dataType: "json", + timeout: this.ajaxTimeOut, data: { _csrf: this.datasetData.csrf, uuid: this.datasetData.uuid, @@ -141,6 +152,9 @@ error: function (err) { $('#myCanvas_div .tabpannel.ui.form').removeClass('loading'); console.log(err); + if (err.statusText == 'timeout') { + self.showGetPathChildrenTimeout(); + } } }); } diff --git a/templates/repo/datasets/dirs/dir_preview.tmpl b/templates/repo/datasets/dirs/dir_preview.tmpl index c7e3c9cb08..50e335bfee 100644 --- a/templates/repo/datasets/dirs/dir_preview.tmpl +++ b/templates/repo/datasets/dirs/dir_preview.tmpl @@ -50,6 +50,14 @@ #filelist .file-item.active { color: #0366d6; } + .query-timeout { + height: 100%; + display: flex; + align-items: center; + justify-content: center; + padding: 0 20px; + text-align: center; + }