2020-10-02 13:56:46 +00:00
|
|
|
import FileSaver from "file-saver";
|
|
|
|
|
|
|
|
import { ClientRepresentation } from "./clients/models/client-model";
|
2020-10-08 11:38:25 +00:00
|
|
|
import { ProviderRepresentation } from "./context/server-info/server-info";
|
2020-08-31 18:26:25 +00:00
|
|
|
|
2020-09-01 14:51:59 +00:00
|
|
|
export const sortProvider = (
|
|
|
|
a: [string, ProviderRepresentation],
|
|
|
|
b: [string, ProviderRepresentation]
|
|
|
|
) => {
|
2020-08-31 18:26:25 +00:00
|
|
|
let s1, s2;
|
|
|
|
if (a[1].order != b[1].order) {
|
|
|
|
s1 = b[1].order;
|
|
|
|
s2 = a[1].order;
|
2020-09-01 14:51:59 +00:00
|
|
|
} else {
|
2020-08-31 18:26:25 +00:00
|
|
|
s1 = a[0];
|
|
|
|
s2 = b[0];
|
2020-09-01 14:51:59 +00:00
|
|
|
}
|
2020-08-31 18:26:25 +00:00
|
|
|
if (s1 < s2) {
|
|
|
|
return -1;
|
|
|
|
} else if (s1 > s2) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
2020-10-02 13:56:46 +00:00
|
|
|
|
|
|
|
export const exportClient = (client: ClientRepresentation): void => {
|
|
|
|
const clientCopy = JSON.parse(JSON.stringify(client));
|
|
|
|
delete clientCopy.id;
|
|
|
|
|
|
|
|
if (clientCopy.protocolMappers) {
|
|
|
|
for (let i = 0; i < clientCopy.protocolMappers.length; i++) {
|
|
|
|
delete clientCopy.protocolMappers[i].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSaver.saveAs(
|
|
|
|
new Blob([JSON.stringify(clientCopy, null, 2)], {
|
|
|
|
type: "application/json",
|
|
|
|
}),
|
|
|
|
clientCopy.clientId + ".json"
|
|
|
|
);
|
|
|
|
};
|
2020-10-20 20:47:23 +00:00
|
|
|
|
|
|
|
export const convertToFormValues = (
|
|
|
|
obj: any,
|
|
|
|
prefix: string,
|
|
|
|
setValue: (name: string, value: any) => void
|
|
|
|
) => {
|
|
|
|
return Object.keys(obj).map((key) => {
|
|
|
|
const newKey = key.replace(/\./g, "_");
|
|
|
|
setValue(prefix + "." + newKey, obj[key]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const convertFormValuesToObject = (obj: any) => {
|
|
|
|
const keyValues = Object.keys(obj).map((key) => {
|
|
|
|
const newKey = key.replace(/_/g, ".");
|
|
|
|
return { [newKey]: obj[key] };
|
|
|
|
});
|
|
|
|
return Object.assign({}, ...keyValues);
|
|
|
|
};
|