mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-31 06:34:40 +00:00
add_deleted_tags_and_lang (#7150)
* add_deleted_tags_and_lang * update * update --------- Co-authored-by: zheng.shen <zheng.shen@seafile.com>
This commit is contained in:
@@ -44,7 +44,7 @@ const LibSettingsDialog = ({ repoID, currentRepoInfo, toggleDialog, tab }) => {
|
||||
const { encrypted, is_admin } = currentRepoInfo;
|
||||
const { enableMetadataManagement } = window.app.pageOptions;
|
||||
const { enableFaceRecognition, updateEnableFaceRecognition } = useMetadata();
|
||||
const { enableMetadata, updateEnableMetadata, enableTags, updateEnableTags } = useMetadataStatus();
|
||||
const { enableMetadata, updateEnableMetadata, enableTags, tagsLang, updateEnableTags } = useMetadataStatus();
|
||||
const enableHistorySetting = is_admin; // repo owner, admin of the department which the repo belongs to, and ...
|
||||
const enableAutoDelSetting = is_admin && enableRepoAutoDel;
|
||||
const enableExtendedPropertiesSetting = !encrypted && is_admin && enableMetadataManagement;
|
||||
@@ -139,6 +139,7 @@ const LibSettingsDialog = ({ repoID, currentRepoInfo, toggleDialog, tab }) => {
|
||||
<LibMetadataTagsStatusSettingPanel
|
||||
repoID={repoID}
|
||||
value={enableTags}
|
||||
lang={tagsLang}
|
||||
submit={updateEnableTags}
|
||||
toggleDialog={toggleDialog}
|
||||
/>
|
||||
|
@@ -16,6 +16,7 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi
|
||||
const [isLoading, setLoading] = useState(true);
|
||||
const [enableMetadata, setEnableMetadata] = useState(false);
|
||||
const [enableTags, setEnableTags] = useState(false);
|
||||
const [tagsLang, setTagsLang] = useState(null);
|
||||
const [isBeingBuilt, setIsBeingBuilt] = useState(false);
|
||||
|
||||
const cancelMetadataURL = useCallback(() => {
|
||||
@@ -36,11 +37,12 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi
|
||||
return;
|
||||
}
|
||||
metadataAPI.getMetadataStatus(repoID).then(res => {
|
||||
const { enabled: enableMetadata, tags_enabled: enableTags } = res.data;
|
||||
const { enabled: enableMetadata, tags_enabled: enableTags, tags_lang: tagsLang } = res.data;
|
||||
if (!enableMetadata) {
|
||||
cancelMetadataURL();
|
||||
}
|
||||
setEnableTags(enableTags);
|
||||
setTagsLang(tagsLang);
|
||||
setEnableMetadata(enableMetadata);
|
||||
setLoading(false);
|
||||
}).catch(error => {
|
||||
@@ -62,14 +64,15 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi
|
||||
setEnableMetadata(newValue);
|
||||
}, [enableMetadata, cancelMetadataURL]);
|
||||
|
||||
const updateEnableTags = useCallback((newValue) => {
|
||||
if (newValue === enableTags) return;
|
||||
const updateEnableTags = useCallback((newValue, lang = 'en') => {
|
||||
if (newValue === enableTags && lang === tagsLang) return;
|
||||
if (!newValue) {
|
||||
cancelMetadataURL();
|
||||
hideMetadataView && hideMetadataView();
|
||||
}
|
||||
setEnableTags(newValue);
|
||||
}, [enableTags, cancelMetadataURL, hideMetadataView]);
|
||||
setTagsLang(lang);
|
||||
}, [enableTags, tagsLang, cancelMetadataURL, hideMetadataView]);
|
||||
|
||||
return (
|
||||
<EnableMetadataContext.Provider
|
||||
@@ -80,6 +83,7 @@ export const MetadataStatusProvider = ({ repoID, currentRepoInfo, hideMetadataVi
|
||||
updateEnableMetadata,
|
||||
setIsBeingBuilt,
|
||||
enableTags,
|
||||
tagsLang,
|
||||
updateEnableTags,
|
||||
}}
|
||||
>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
.tags-language-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tags-language-container .tags-language-selector {
|
||||
width: 200px;
|
||||
margin-top: 10px;
|
||||
margin-left: 10px;
|
||||
}
|
@@ -8,11 +8,24 @@ import tagsAPI from '../../../../tag/api';
|
||||
import toaster from '../../../../components/toast';
|
||||
import { Utils } from '../../../../utils/utils';
|
||||
import TurnOffConfirmDialog from './turn-off-confirm';
|
||||
import { SeahubSelect } from '../../../../components/common/select';
|
||||
|
||||
// import './index.css';
|
||||
import './index.css';
|
||||
|
||||
const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggle, submit }) => {
|
||||
const langOptions = [
|
||||
{
|
||||
value: 'zh-cn',
|
||||
label: '简体中文'
|
||||
},
|
||||
{
|
||||
value: 'en',
|
||||
label: 'English'
|
||||
}
|
||||
];
|
||||
|
||||
const MetadataTagsStatusDialog = ({ value: oldValue, lang: oldLang, repoID, toggleDialog: toggle, submit }) => {
|
||||
const [value, setValue] = useState(oldValue);
|
||||
const [lang, setLang] = useState({ value: oldLang || 'en', label: langOptions.find(item => item.value === oldLang).label });
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [showTurnOffConfirmDialog, setShowTurnOffConfirmDialog] = useState(false);
|
||||
|
||||
@@ -26,15 +39,15 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
tagsAPI.openTags(repoID).then(res => {
|
||||
submit(true);
|
||||
tagsAPI.openTags(repoID, lang.value).then(res => {
|
||||
submit(true, lang.value);
|
||||
toggle();
|
||||
}).catch(error => {
|
||||
const errorMsg = Utils.getErrorMsg(error);
|
||||
toaster.danger(errorMsg);
|
||||
setSubmitting(false);
|
||||
});
|
||||
}, [repoID, submit, toggle, value]);
|
||||
}, [lang, repoID, submit, toggle, value]);
|
||||
|
||||
const turnOffConfirmToggle = useCallback(() => {
|
||||
setShowTurnOffConfirmDialog(!showTurnOffConfirmDialog);
|
||||
@@ -58,6 +71,10 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl
|
||||
setValue(nextValue);
|
||||
}, [value]);
|
||||
|
||||
const onSelectChange = (option) => {
|
||||
setLang(option);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{!showTurnOffConfirmDialog && (
|
||||
@@ -75,10 +92,21 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl
|
||||
<p className="tip m-0">
|
||||
{gettext('Enable tags to add tags to files and search files by tags.')}
|
||||
</p>
|
||||
{value && (
|
||||
<div className="tags-language-container">
|
||||
<span>{gettext('Tags language:')}</span>
|
||||
<SeahubSelect
|
||||
className='tags-language-selector'
|
||||
value={lang || { value: 'en', label: 'English' }}
|
||||
options={langOptions}
|
||||
onChange={onSelectChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={onToggle}>{gettext('Cancel')}</Button>
|
||||
<Button color="primary" disabled={oldValue === value || submitting} onClick={onSubmit}>{gettext('Submit')}</Button>
|
||||
<Button color="primary" disabled={(oldValue === value && oldLang === lang.value) || submitting} onClick={onSubmit}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</>
|
||||
)}
|
||||
|
@@ -49,9 +49,12 @@ class TagsManagerAPI {
|
||||
return this.req.get(url);
|
||||
};
|
||||
|
||||
openTags = (repoID) => {
|
||||
openTags = (repoID, lang) => {
|
||||
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/tags-status/';
|
||||
return this.req.put(url);
|
||||
const params = {
|
||||
lang: lang,
|
||||
};
|
||||
return this.req.put(url, params);
|
||||
};
|
||||
|
||||
closeTags = (repoID) => {
|
||||
|
@@ -2,6 +2,7 @@ import logging
|
||||
import os.path
|
||||
|
||||
from pysearpc import SearpcError
|
||||
from seahub.repo_metadata.models import RepoMetadata
|
||||
from seaserv import seafile_api
|
||||
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
@@ -161,6 +162,13 @@ class ImageTags(APIView):
|
||||
error_msg = 'Library %s not found.' % repo_id
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
try:
|
||||
record = RepoMetadata.objects.filter(repo_id=repo_id).first()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
permission = check_folder_permission(request, repo_id, os.path.dirname(path))
|
||||
if not permission:
|
||||
error_msg = 'Permission denied.'
|
||||
@@ -182,7 +190,8 @@ class ImageTags(APIView):
|
||||
|
||||
params = {
|
||||
'path': path,
|
||||
'download_token': token
|
||||
'download_token': token,
|
||||
'lang': record.tags_lang if record and record.tags_enabled else None
|
||||
}
|
||||
|
||||
try:
|
||||
|
@@ -62,6 +62,7 @@ class MetadataManage(APIView):
|
||||
return Response({
|
||||
'enabled': is_enabled,
|
||||
'tags_enabled': is_tags_enabled,
|
||||
'tags_lang': record.tags_lang,
|
||||
})
|
||||
|
||||
def put(self, request, repo_id):
|
||||
@@ -1245,6 +1246,11 @@ class MetadataTagsStatusManage(APIView):
|
||||
throttle_classes = (UserRateThrottle,)
|
||||
|
||||
def put(self, request, repo_id):
|
||||
lang = request.data.get('lang')
|
||||
if not lang:
|
||||
error_msg = 'lang invalid.'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
# resource check
|
||||
repo = seafile_api.get_repo(repo_id)
|
||||
if not repo:
|
||||
@@ -1260,15 +1266,19 @@ class MetadataTagsStatusManage(APIView):
|
||||
error_msg = f'The metadata module is not enabled for repo {repo_id}.'
|
||||
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
|
||||
|
||||
old_tags_enabled = metadata.tags_enabled
|
||||
|
||||
try:
|
||||
metadata.tags_enabled = True
|
||||
metadata.save()
|
||||
metadata.tags_enabled = True
|
||||
metadata.tags_lang = lang
|
||||
metadata.save()
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal Server Error')
|
||||
|
||||
metadata_server_api = MetadataServerAPI(repo_id, request.user.username)
|
||||
init_tags(metadata_server_api)
|
||||
if not old_tags_enabled:
|
||||
metadata_server_api = MetadataServerAPI(repo_id, request.user.username)
|
||||
init_tags(metadata_server_api)
|
||||
|
||||
return Response({'success': True})
|
||||
|
||||
@@ -1300,6 +1310,7 @@ class MetadataTagsStatusManage(APIView):
|
||||
|
||||
try:
|
||||
record.tags_enabled = False
|
||||
record.tags_lang = None
|
||||
record.save()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
@@ -65,6 +65,7 @@ class RepoMetadata(models.Model):
|
||||
from_commit = models.CharField(max_length=40)
|
||||
to_commit = models.CharField(max_length=40)
|
||||
tags_enabled = models.BooleanField(db_index=True)
|
||||
tags_lang = models.CharField(max_length=36)
|
||||
last_face_cluster_time = models.DateTimeField(db_index=True, blank=True, null=True)
|
||||
|
||||
objects = RepoMetadataManager()
|
||||
|
Reference in New Issue
Block a user