2023-10-19 11:45:50 +00:00
|
|
|
import { parseAccessControlFormData } from '@/react/portainer/access-control/utils';
|
|
|
|
import { ResourceControlOwnership } from '@/react/portainer/access-control/types';
|
|
|
|
import { UserId } from '@/portainer/users/types';
|
|
|
|
import { getDefaultImageConfig } from '@/react/portainer/registries/utils/getImageConfig';
|
|
|
|
|
2024-06-10 18:54:31 +00:00
|
|
|
import { ContainerDetailsResponse } from '../../queries/useContainer';
|
2023-10-19 11:45:50 +00:00
|
|
|
|
|
|
|
import { toViewModel as toPortsMappingViewModel } from './PortsMappingField.viewModel';
|
|
|
|
import { Values } from './BaseForm';
|
|
|
|
|
|
|
|
export function toViewModel(
|
2024-06-10 18:54:31 +00:00
|
|
|
config: ContainerDetailsResponse,
|
2024-02-14 22:50:20 +00:00
|
|
|
isPureAdmin: boolean,
|
2023-10-19 11:45:50 +00:00
|
|
|
currentUserId: UserId,
|
|
|
|
nodeName: string,
|
|
|
|
image: Values['image'],
|
|
|
|
enableWebhook: boolean
|
|
|
|
): Values {
|
|
|
|
// accessControl shouldn't be copied to new container
|
|
|
|
|
2024-02-14 22:50:20 +00:00
|
|
|
const accessControl = parseAccessControlFormData(isPureAdmin, currentUserId);
|
2023-10-19 11:45:50 +00:00
|
|
|
|
|
|
|
if (config.Portainer?.ResourceControl?.Public) {
|
|
|
|
accessControl.ownership = ResourceControlOwnership.PUBLIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
accessControl,
|
|
|
|
name: config.Name ? config.Name.replace('/', '') : '',
|
|
|
|
alwaysPull: true,
|
|
|
|
autoRemove: config.HostConfig?.AutoRemove || false,
|
|
|
|
ports: toPortsMappingViewModel(config.HostConfig?.PortBindings || {}),
|
|
|
|
publishAllPorts: config.HostConfig?.PublishAllPorts || false,
|
|
|
|
nodeName,
|
|
|
|
image,
|
|
|
|
enableWebhook,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getDefaultViewModel(
|
2024-02-14 22:50:20 +00:00
|
|
|
isPureAdmin: boolean,
|
2023-10-19 11:45:50 +00:00
|
|
|
currentUserId: UserId,
|
|
|
|
nodeName: string
|
|
|
|
): Values {
|
2024-02-14 22:50:20 +00:00
|
|
|
const accessControl = parseAccessControlFormData(isPureAdmin, currentUserId);
|
2023-10-19 11:45:50 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
nodeName,
|
|
|
|
enableWebhook: false,
|
|
|
|
image: getDefaultImageConfig(),
|
|
|
|
accessControl,
|
|
|
|
name: '',
|
|
|
|
alwaysPull: true,
|
|
|
|
autoRemove: false,
|
|
|
|
ports: [],
|
|
|
|
publishAllPorts: false,
|
|
|
|
};
|
|
|
|
}
|