2024-06-29 09:58:27 +00:00
|
|
|
import metadataAPI from '../api';
|
|
|
|
import { UserService, LocalStorage } from './_basic';
|
2024-07-11 09:45:30 +00:00
|
|
|
import EventBus from '../../components/common/event-bus';
|
2024-07-03 09:04:30 +00:00
|
|
|
import { username } from '../../utils/constants';
|
2024-06-29 09:58:27 +00:00
|
|
|
|
|
|
|
class Context {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.settings = {};
|
|
|
|
this.metadataAPI = null;
|
|
|
|
this.localStorage = null;
|
|
|
|
this.userService = null;
|
|
|
|
this.eventBus = null;
|
|
|
|
this.hasInit = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async init({ otherSettings }) {
|
|
|
|
if (this.hasInit) return;
|
|
|
|
|
|
|
|
// init settings
|
|
|
|
this.settings = otherSettings || {};
|
|
|
|
|
|
|
|
// init metadataAPI
|
|
|
|
const { mediaUrl } = this.settings;
|
|
|
|
this.metadataAPI = metadataAPI;
|
|
|
|
|
|
|
|
// init localStorage
|
|
|
|
const { repoID } = this.settings;
|
|
|
|
this.localStorage = new LocalStorage(`sf-metadata-${repoID}`);
|
|
|
|
|
|
|
|
// init userService
|
|
|
|
this.userService = new UserService({ mediaUrl, api: this.metadataAPI.listUserInfo });
|
|
|
|
|
|
|
|
const eventBus = new EventBus();
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
|
|
|
|
this.hasInit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy = () => {
|
|
|
|
this.settings = {};
|
|
|
|
this.metadataAPI = null;
|
|
|
|
this.localStorage = null;
|
|
|
|
this.userService = null;
|
|
|
|
this.eventBus = null;
|
|
|
|
this.hasInit = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
getSetting = (key) => {
|
|
|
|
if (this.settings[key] === false) return this.settings[key];
|
|
|
|
return this.settings[key] || '';
|
|
|
|
};
|
|
|
|
|
|
|
|
setSetting = (key, value) => {
|
|
|
|
this.settings[key] = value;
|
|
|
|
};
|
|
|
|
|
2024-07-03 09:04:30 +00:00
|
|
|
getUsername = () => {
|
|
|
|
return username;
|
|
|
|
};
|
|
|
|
|
|
|
|
// collaborators
|
|
|
|
getCollaborators = () => {
|
|
|
|
const repoID = this.settings['repoID'];
|
|
|
|
return this.metadataAPI.getCollaborators(repoID);
|
|
|
|
};
|
|
|
|
|
2024-06-29 09:58:27 +00:00
|
|
|
// metadata
|
2024-07-03 09:04:30 +00:00
|
|
|
getMetadata = (params) => {
|
|
|
|
const repoID = this.settings['repoID'];
|
|
|
|
return this.metadataAPI.getMetadata(repoID, params);
|
2024-06-29 09:58:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
canModifyCell = (column) => {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
canModifyRow = (row) => {
|
2024-07-05 09:41:34 +00:00
|
|
|
return true;
|
2024-06-29 09:58:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
getPermission = () => {
|
|
|
|
return 'rw';
|
|
|
|
};
|
|
|
|
|
|
|
|
getCollaboratorsFromCache = () => {
|
|
|
|
//
|
|
|
|
};
|
2024-07-03 09:04:30 +00:00
|
|
|
|
|
|
|
restoreRows = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
|
|
|
updateRows = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
|
|
|
lockRowViaButton = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
|
|
|
updateRowViaButton = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
|
|
|
getRowsByIds = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
2024-06-29 09:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Context;
|