mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
optimize code and structure
This commit is contained in:
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import toaster from '../../components/toast';
|
||||
import seahubManageAPI from './seahub-manage-api';
|
||||
import seahubMetadataAPI from './seahub-metadata-api';
|
||||
|
||||
const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
@@ -48,11 +48,11 @@ class MetadataManageView extends React.Component {
|
||||
};
|
||||
|
||||
onClick = () => {
|
||||
seahubManageAPI.getMetadataManagementEnabledStatus(this.props.repoID).then((res) => {
|
||||
seahubMetadataAPI.getMetadataManagementEnabledStatus(this.props.repoID).then((res) => {
|
||||
if (res.data.enabled){
|
||||
this.viewMetadata();
|
||||
} else if (confirm(gettext('Enable-Metadata-Manage?'))){
|
||||
seahubManageAPI.enableMetadataManagement(this.props.repoID).then((res) => {
|
||||
seahubMetadataAPI.enableMetadataManagement(this.props.repoID).then((res) => {
|
||||
this.viewMetadata();
|
||||
}).catch((error) => {
|
||||
let errMessage = Utils.getErrorMsg(error);
|
||||
|
@@ -2,7 +2,7 @@ import axios from 'axios';
|
||||
import cookie from 'react-cookies';
|
||||
import { siteRoot } from '../../utils/constants';
|
||||
|
||||
class SeahubManageAPI {
|
||||
class SeahubMetadataAPI {
|
||||
init({ server, username, password, token }) {
|
||||
this.server = server;
|
||||
this.username = username;
|
||||
@@ -50,7 +50,7 @@ class SeahubManageAPI {
|
||||
|
||||
enableMetadataManagement(repoID) {
|
||||
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/';
|
||||
return this.req.post(url);
|
||||
return this.req.put(url);
|
||||
}
|
||||
|
||||
disableMetadataManagement(repoID) {
|
||||
@@ -91,8 +91,8 @@ class SeahubManageAPI {
|
||||
}
|
||||
}
|
||||
|
||||
const seahubManageAPI = new SeahubManageAPI();
|
||||
const seahubMetadataAPI = new SeahubMetadataAPI();
|
||||
const xcsrfHeaders = cookie.load('sfcsrftoken');
|
||||
seahubManageAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
|
||||
seahubMetadataAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
|
||||
|
||||
export default seahubManageAPI;
|
||||
export default seahubMetadataAPI;
|
Reference in New Issue
Block a user