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
|
2024-07-22 01:45:08 +00:00
|
|
|
const { repoID, viewID } = this.settings;
|
|
|
|
this.localStorage = new LocalStorage(`sf-metadata-${repoID}-${viewID}`);
|
2024-06-29 09:58:27 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2024-07-22 01:45:08 +00:00
|
|
|
getViews = () => {
|
|
|
|
const repoID = this.settings['repoID'];
|
|
|
|
return this.metadataAPI.listViews(repoID);
|
|
|
|
};
|
|
|
|
|
2024-07-22 02:52:21 +00:00
|
|
|
getView = (viewId) => {
|
|
|
|
const repoID = this.settings['repoID'];
|
|
|
|
return this.metadataAPI.getView(repoID, viewId);
|
|
|
|
};
|
|
|
|
|
2024-06-29 09:58:27 +00:00
|
|
|
canModifyCell = (column) => {
|
2024-07-18 09:40:53 +00:00
|
|
|
const { editable } = column;
|
|
|
|
if (!editable) return false;
|
|
|
|
return true;
|
2024-06-29 09:58:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2024-07-18 09:40:53 +00:00
|
|
|
insertColumn = (repoId, name, type, { key, data }) => {
|
|
|
|
return this.metadataAPI.insertColumn(repoId, name, type, { key, data });
|
|
|
|
};
|
|
|
|
|
|
|
|
modifyRecord = (repoId, recordId, columnName, value) => {
|
|
|
|
return this.metadataAPI.modifyRecord(repoId, recordId, columnName, value);
|
|
|
|
};
|
|
|
|
|
|
|
|
modifyRecords = (repoId, recordsData, isCopyPaste) => {
|
|
|
|
return this.metadataAPI.modifyRecords(repoId, recordsData, isCopyPaste);
|
|
|
|
};
|
|
|
|
|
2024-07-22 01:45:08 +00:00
|
|
|
modifyView = (repoId, viewId, viewData) => {
|
|
|
|
return this.metadataAPI.modifyView(repoId, viewId, viewData);
|
|
|
|
};
|
|
|
|
|
2024-07-03 09:04:30 +00:00
|
|
|
getRowsByIds = () => {
|
|
|
|
// todo
|
|
|
|
};
|
|
|
|
|
2024-06-29 09:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Context;
|