mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 00:09:40 +02:00
feat(custom-templates): hide variables [EE-2602] (#7068)
This commit is contained in:
parent
f39775752d
commit
97a880e6c1
13 changed files with 48 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { buildOption } from '@/portainer/components/BoxSelector';
|
import { buildOption } from '@/portainer/components/BoxSelector';
|
||||||
import { AccessControlFormData } from '@/portainer/components/accessControlForm/porAccessControlFormModel';
|
import { AccessControlFormData } from '@/portainer/components/accessControlForm/porAccessControlFormModel';
|
||||||
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
|
|
||||||
class KubeCreateCustomTemplateViewController {
|
class KubeCreateCustomTemplateViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
@ -13,6 +14,7 @@ class KubeCreateCustomTemplateViewController {
|
||||||
];
|
];
|
||||||
|
|
||||||
this.templates = null;
|
this.templates = null;
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
method: 'editor',
|
method: 'editor',
|
||||||
|
@ -53,6 +55,10 @@ class KubeCreateCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTemplate(templateStr) {
|
parseTemplate(templateStr) {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const variables = getTemplateVariables(templateStr);
|
const variables = getTemplateVariables(templateStr);
|
||||||
|
|
||||||
const isValid = !!variables;
|
const isValid = !!variables;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
</file-upload-form>
|
</file-upload-form>
|
||||||
|
|
||||||
<custom-templates-variables-definition-field
|
<custom-templates-variables-definition-field
|
||||||
|
ng-if="$ctrl.isTemplateVariablesEnabled"
|
||||||
value="$ctrl.formValues.Variables"
|
value="$ctrl.formValues.Variables"
|
||||||
on-change="($ctrl.onVariablesChange)"
|
on-change="($ctrl.onVariablesChange)"
|
||||||
is-variables-names-from-parent="$ctrl.state.method === 'editor'"
|
is-variables-names-from-parent="$ctrl.state.method === 'editor'"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { ResourceControlViewModel } from '@/portainer/access-control/models/ResourceControlViewModel';
|
import { ResourceControlViewModel } from '@/portainer/access-control/models/ResourceControlViewModel';
|
||||||
import { AccessControlFormData } from '@/portainer/components/accessControlForm/porAccessControlFormModel';
|
import { AccessControlFormData } from '@/portainer/components/accessControlForm/porAccessControlFormModel';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
|
||||||
class KubeEditCustomTemplateViewController {
|
class KubeEditCustomTemplateViewController {
|
||||||
|
@ -7,6 +8,8 @@ class KubeEditCustomTemplateViewController {
|
||||||
constructor($async, $state, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
constructor($async, $state, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
||||||
Object.assign(this, { $async, $state, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
Object.assign(this, { $async, $state, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
||||||
|
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.formValues = null;
|
this.formValues = null;
|
||||||
this.state = {
|
this.state = {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
|
@ -60,6 +63,10 @@ class KubeEditCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTemplate(templateStr) {
|
parseTemplate(templateStr) {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const variables = getTemplateVariables(templateStr);
|
const variables = getTemplateVariables(templateStr);
|
||||||
|
|
||||||
const isValid = !!variables;
|
const isValid = !!variables;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
</web-editor-form>
|
</web-editor-form>
|
||||||
|
|
||||||
<custom-templates-variables-definition-field
|
<custom-templates-variables-definition-field
|
||||||
|
ng-if="$ctrl.isTemplateVariablesEnabled"
|
||||||
value="$ctrl.formValues.Variables"
|
value="$ctrl.formValues.Variables"
|
||||||
on-change="($ctrl.onVariablesChange)"
|
on-change="($ctrl.onVariablesChange)"
|
||||||
is-variables-names-from-parent="true"
|
is-variables-names-from-parent="true"
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
></custom-template-selector>
|
></custom-template-selector>
|
||||||
|
|
||||||
<custom-templates-variables-field
|
<custom-templates-variables-field
|
||||||
ng-if="ctrl.state.template"
|
ng-if="$ctrl.isTemplateVariablesEnabled && ctrl.state.template"
|
||||||
definitions="ctrl.state.template.Variables"
|
definitions="ctrl.state.template.Variables"
|
||||||
value="ctrl.formValues.Variables"
|
value="ctrl.formValues.Variables"
|
||||||
on-change="(ctrl.onChangeTemplateVariables)"
|
on-change="(ctrl.onChangeTemplateVariables)"
|
||||||
|
|
|
@ -7,6 +7,7 @@ import PortainerError from '@/portainer/error';
|
||||||
import { KubernetesDeployManifestTypes, KubernetesDeployBuildMethods, KubernetesDeployRequestMethods, RepositoryMechanismTypes } from 'Kubernetes/models/deploy';
|
import { KubernetesDeployManifestTypes, KubernetesDeployBuildMethods, KubernetesDeployRequestMethods, RepositoryMechanismTypes } from 'Kubernetes/models/deploy';
|
||||||
import { buildOption } from '@/portainer/components/BoxSelector';
|
import { buildOption } from '@/portainer/components/BoxSelector';
|
||||||
import { renderTemplate } from '@/react/portainer/custom-templates/components/utils';
|
import { renderTemplate } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
|
|
||||||
class KubernetesDeployController {
|
class KubernetesDeployController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
@ -23,6 +24,8 @@ class KubernetesDeployController {
|
||||||
this.CustomTemplateService = CustomTemplateService;
|
this.CustomTemplateService = CustomTemplateService;
|
||||||
this.DeployMethod = 'manifest';
|
this.DeployMethod = 'manifest';
|
||||||
|
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.deployOptions = [
|
this.deployOptions = [
|
||||||
buildOption('method_kubernetes', 'fa fa-cubes', 'Kubernetes', 'Kubernetes manifest format', KubernetesDeployManifestTypes.KUBERNETES),
|
buildOption('method_kubernetes', 'fa fa-cubes', 'Kubernetes', 'Kubernetes manifest format', KubernetesDeployManifestTypes.KUBERNETES),
|
||||||
buildOption('method_compose', 'fab fa-docker', 'Compose', 'docker-compose format', KubernetesDeployManifestTypes.COMPOSE),
|
buildOption('method_compose', 'fab fa-docker', 'Compose', 'docker-compose format', KubernetesDeployManifestTypes.COMPOSE),
|
||||||
|
@ -83,6 +86,10 @@ class KubernetesDeployController {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTemplate() {
|
renderTemplate() {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const rendered = renderTemplate(this.state.templateContent, this.formValues.Variables, this.state.template.Variables);
|
const rendered = renderTemplate(this.state.templateContent, this.formValues.Variables, this.state.template.Variables);
|
||||||
this.onChangeFormValues({ EditorContent: rendered });
|
this.onChangeFormValues({ EditorContent: rendered });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Edition, FeatureId, FeatureState } from './enums';
|
import { Edition, FeatureId, FeatureState } from './enums';
|
||||||
|
|
||||||
|
export const isBE = process.env.PORTAINER_EDITION === 'BE';
|
||||||
interface ServiceState {
|
interface ServiceState {
|
||||||
currentEdition: Edition;
|
currentEdition: Edition;
|
||||||
features: Record<FeatureId, Edition>;
|
features: Record<FeatureId, Edition>;
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<custom-templates-variables-definition-field
|
<custom-templates-variables-definition-field
|
||||||
|
ng-if="$ctrl.isTemplateVariablesEnabled"
|
||||||
value="$ctrl.formValues.Variables"
|
value="$ctrl.formValues.Variables"
|
||||||
on-change="($ctrl.onVariablesChange)"
|
on-change="($ctrl.onVariablesChange)"
|
||||||
is-variables-names-from-parent="$ctrl.state.Method === 'editor'"
|
is-variables-names-from-parent="$ctrl.state.Method === 'editor'"
|
||||||
|
|
|
@ -2,6 +2,7 @@ import _ from 'lodash';
|
||||||
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
||||||
import { TEMPLATE_NAME_VALIDATION_REGEX } from '@/constants';
|
import { TEMPLATE_NAME_VALIDATION_REGEX } from '@/constants';
|
||||||
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
|
|
||||||
class CreateCustomTemplateViewController {
|
class CreateCustomTemplateViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
@ -20,6 +21,8 @@ class CreateCustomTemplateViewController {
|
||||||
StateManager,
|
StateManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.formValues = {
|
this.formValues = {
|
||||||
Title: '',
|
Title: '',
|
||||||
FileContent: '',
|
FileContent: '',
|
||||||
|
@ -176,6 +179,10 @@ class CreateCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTemplate(templateStr) {
|
parseTemplate(templateStr) {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const variables = getTemplateVariables(templateStr);
|
const variables = getTemplateVariables(templateStr);
|
||||||
|
|
||||||
const isValid = !!variables;
|
const isValid = !!variables;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
>
|
>
|
||||||
<advanced-form>
|
<advanced-form>
|
||||||
<custom-templates-variables-field
|
<custom-templates-variables-field
|
||||||
|
ng-if="$ctrl.isTemplateVariablesEnabled"
|
||||||
definitions="$ctrl.state.selectedTemplate.Variables"
|
definitions="$ctrl.state.selectedTemplate.Variables"
|
||||||
value="$ctrl.formValues.variables"
|
value="$ctrl.formValues.variables"
|
||||||
on-change="($ctrl.onChangeTemplateVariables)"
|
on-change="($ctrl.onChangeTemplateVariables)"
|
||||||
|
|
|
@ -2,6 +2,7 @@ import _ from 'lodash-es';
|
||||||
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
||||||
import { TEMPLATE_NAME_VALIDATION_REGEX } from '@/constants';
|
import { TEMPLATE_NAME_VALIDATION_REGEX } from '@/constants';
|
||||||
import { renderTemplate } from '@/react/portainer/custom-templates/components/utils';
|
import { renderTemplate } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
|
|
||||||
class CustomTemplatesViewController {
|
class CustomTemplatesViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
@ -34,6 +35,8 @@ class CustomTemplatesViewController {
|
||||||
this.StateManager = StateManager;
|
this.StateManager = StateManager;
|
||||||
this.StackService = StackService;
|
this.StackService = StackService;
|
||||||
|
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.DOCKER_STANDALONE = 'DOCKER_STANDALONE';
|
this.DOCKER_STANDALONE = 'DOCKER_STANDALONE';
|
||||||
this.DOCKER_SWARM_MODE = 'DOCKER_SWARM_MODE';
|
this.DOCKER_SWARM_MODE = 'DOCKER_SWARM_MODE';
|
||||||
|
|
||||||
|
@ -119,6 +122,10 @@ class CustomTemplatesViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTemplate() {
|
renderTemplate() {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const fileContent = renderTemplate(this.state.templateContent, this.formValues.variables, this.state.selectedTemplate.Variables);
|
const fileContent = renderTemplate(this.state.templateContent, this.formValues.variables, this.state.selectedTemplate.Variables);
|
||||||
this.onChangeFormValues({ fileContent });
|
this.onChangeFormValues({ fileContent });
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<custom-templates-variables-definition-field
|
<custom-templates-variables-definition-field
|
||||||
|
ng-if="$ctrl.isTemplateVariablesEnabled"
|
||||||
value="$ctrl.formValues.Variables"
|
value="$ctrl.formValues.Variables"
|
||||||
on-change="($ctrl.onVariablesChange)"
|
on-change="($ctrl.onVariablesChange)"
|
||||||
is-variables-names-from-parent="true"
|
is-variables-names-from-parent="true"
|
||||||
|
|
|
@ -3,12 +3,15 @@ import { ResourceControlViewModel } from '@/portainer/access-control/models/Reso
|
||||||
|
|
||||||
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
|
||||||
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
import { getTemplateVariables, intersectVariables } from '@/react/portainer/custom-templates/components/utils';
|
||||||
|
import { isBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
|
|
||||||
class EditCustomTemplateViewController {
|
class EditCustomTemplateViewController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
constructor($async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService) {
|
||||||
Object.assign(this, { $async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
Object.assign(this, { $async, $state, $window, ModalService, Authentication, CustomTemplateService, FormValidator, Notifications, ResourceControlService });
|
||||||
|
|
||||||
|
this.isTemplateVariablesEnabled = isBE;
|
||||||
|
|
||||||
this.formValues = null;
|
this.formValues = null;
|
||||||
this.state = {
|
this.state = {
|
||||||
formValidationError: '',
|
formValidationError: '',
|
||||||
|
@ -127,6 +130,10 @@ class EditCustomTemplateViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTemplate(templateStr) {
|
parseTemplate(templateStr) {
|
||||||
|
if (!this.isTemplateVariablesEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const variables = getTemplateVariables(templateStr);
|
const variables = getTemplateVariables(templateStr);
|
||||||
|
|
||||||
const isValid = !!variables;
|
const isValid = !!variables;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue