DocSpace-client/web/ASC.Web.Client/src/store/SettingsSetupStore.js

208 lines
4.7 KiB
JavaScript
Raw Normal View History

import api from "@appserver/common/api";
2021-02-15 19:43:07 +00:00
import { makeAutoObservable } from "mobx";
const { Filter } = api;
class SettingsSetupStore {
common = {
whiteLabel: {
logoSizes: [],
logoText: null,
logoUrls: [],
},
};
security = {
accessRight: {
options: [],
users: [],
admins: [],
owner: {},
filter: Filter.getDefault(),
},
};
integration = {
consumers: [],
selectedConsumer: {},
};
constructor() {
makeAutoObservable(this);
}
setOptions = (options) => {
2021-02-15 19:43:07 +00:00
this.security.accessRight.options = options;
};
2021-02-15 19:43:07 +00:00
setUsers = (users) => {
2021-02-15 19:43:07 +00:00
this.security.accessRight.users = users;
};
2021-02-15 19:43:07 +00:00
setAdmins = (admins) => {
2021-02-15 19:43:07 +00:00
this.security.accessRight.admins = admins;
};
2021-02-15 19:43:07 +00:00
setOwner = (owner) => {
2021-02-15 19:43:07 +00:00
this.security.accessRight.owner = owner;
};
2021-02-15 19:43:07 +00:00
setFilter = (filter) => {
2021-02-15 19:43:07 +00:00
this.security.accessRight.filter = filter;
};
2021-02-15 19:43:07 +00:00
setLogoText = (text) => {
2021-02-15 19:43:07 +00:00
this.common.whiteLabel.logoText = text;
};
2021-02-15 19:43:07 +00:00
setLogoSizes = (sizes) => {
2021-02-15 19:43:07 +00:00
this.common.whiteLabel.logoSizes = sizes;
};
2021-02-15 19:43:07 +00:00
setLogoUrls = (urls) => {
2021-02-15 19:43:07 +00:00
this.common.whiteLabel.logoUrls = urls;
};
2021-02-15 19:43:07 +00:00
setConsumers = (consumers) => {
2021-02-15 19:43:07 +00:00
this.integration.consumers = consumers;
};
2021-02-15 19:43:07 +00:00
setSelectedConsumer = (selectedConsumerName) => {
this.integration.selectedConsumer =
this.integration.consumers.find((c) => c.name === selectedConsumerName) ||
{};
};
2021-02-15 19:43:07 +00:00
changeAdmins = async (userIds, productId, isAdmin, filter) => {
let filterData = filter && filter.clone();
if (!filterData) {
filterData = Filter.getDefault();
}
const requests = userIds.map((userId) =>
api.people.changeProductAdmin(userId, productId, isAdmin)
);
await Promise.all(requests);
const admins = await api.people.getListAdmins(filterData);
filterData.total = admins.total;
this.setAdmins(admins.items);
this.setFilter(filterData);
};
getPortalOwner = async (userId) => {
const owner = await api.people.getUserById(userId);
this.setOwner(owner);
};
fetchPeople = async (filter) => {
let filterData = filter && filter.clone();
if (!filterData) {
filterData = Filter.getDefault();
}
const admins = await api.people.getListAdmins(filterData);
filterData.total = admins.total;
this.setAdmins(admins.items);
this.setFilter(filterData);
};
getUpdateListAdmin = async (filter) => {
let filterData = filter && filter.clone();
if (!filterData) {
filterData = Filter.getDefault();
}
const admins = await api.people.getListAdmins(filterData);
filterData.total = admins.total;
this.setAdmins(admins.items);
this.setFilter(filterData);
};
getWhiteLabelLogoText = async () => {
const res = await api.settings.getLogoText();
this.setLogoText(res);
};
getWhiteLabelLogoSizes = async () => {
const res = await api.settings.getLogoSizes();
this.setLogoSizes(res);
};
getWhiteLabelLogoUrls = async () => {
const res = await api.settings.getLogoUrls();
this.setLogoUrls(Object.values(res));
};
setLanguageAndTime = async (lng, timeZoneID) => {
const res = await api.settings.setLanguageAndTime(lng, timeZoneID);
console.log("setLanguageAndTime", res);
if (res) this.setLanguageAndTime({ lng, timeZoneID });
2021-02-15 19:43:07 +00:00
};
setGreetingTitle = async (greetingTitle) => {
const res = await api.settings.setGreetingSettings(greetingTitle);
console.log("res", res);
2021-03-22 08:57:08 +00:00
if (res) this.setGreetingSettings(greetingTitle);
2021-02-15 19:43:07 +00:00
};
setCurrentShema = async (id) => {
return api.settings.setCurrentShema(id);
};
setCustomShema = async (
userCaption,
usersCaption,
groupCaption,
groupsCaption,
userPostCaption,
regDateCaption,
groupHeadCaption,
guestCaption,
guestsCaption
) => {
//debugger;
return api.settings.setCustomShema(
userCaption,
usersCaption,
groupCaption,
groupsCaption,
userPostCaption,
regDateCaption,
groupHeadCaption,
guestCaption,
guestsCaption
);
};
2021-02-15 19:43:07 +00:00
restoreGreetingTitle = async () => {
const res = await api.settings.restoreGreetingSettings();
if (res) this.setGreetingSettings(res.Content);
};
getConsumers = async () => {
const res = await api.settings.getConsumersList();
this.setConsumers(res);
};
updateConsumerProps = async (newProps) => {
const res = await api.settings.updateConsumerProps(newProps);
console.log("updateConsumerProps", res);
2021-02-15 19:43:07 +00:00
await this.getConsumers();
};
2021-03-17 15:33:05 +00:00
changePassword = (userId, hash, key) => {
return api.people.changePassword(userId, hash, key);
};
2021-03-22 17:56:53 +00:00
sendOwnerChange = (id) => {
return api.settings.sendOwnerChange(id);
};
2021-02-15 19:43:07 +00:00
}
export default SettingsSetupStore;