1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-08 23:35:31 +02:00

refactor(settings): kube settings panel [EE-5504] (#9079)

This commit is contained in:
Chaim Lev-Ari 2023-06-20 11:02:39 +07:00 committed by GitHub
parent 806e1fdffa
commit 7dc6a1559f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 401 additions and 138 deletions

View file

@ -7,6 +7,7 @@ import { r2a } from '@/react-tools/react2angular';
import { withReactQuery } from '@/react-tools/withReactQuery';
import { withUIRouter } from '@/react-tools/withUIRouter';
import { ApplicationSettingsPanel } from '@/react/portainer/settings/SettingsView/ApplicationSettingsPanel';
import { KubeSettingsPanel } from '@/react/portainer/settings/SettingsView/KubeSettingsPanel';
export const settingsModule = angular
.module('portainer.app.react.components.settings', [])
@ -22,4 +23,8 @@ export const settingsModule = angular
.component(
'applicationSettingsPanel',
r2a(withReactQuery(ApplicationSettingsPanel), ['onSuccess'])
)
.component(
'kubeSettingsPanel',
r2a(withUIRouter(withReactQuery(KubeSettingsPanel)), [])
).name;

View file

@ -2,92 +2,7 @@
<application-settings-panel on-success="(handleSuccess)"></application-settings-panel>
<div class="row">
<div class="col-sm-12">
<rd-widget>
<rd-widget-header icon="svg-kube" title-text="Kubernetes settings"></rd-widget-header>
<rd-widget-body>
<form class="form-horizontal">
<!-- helm charts -->
<div class="col-sm-12 form-section-title"> Helm Repository </div>
<div>
<div class="form-group">
<span class="col-sm-12 text-muted small">
You can specify the URL to your own helm repository here. See the
<a href="https://helm.sh/docs/topics/chart_repository/" target="_blank">official documentation</a> for more details.
</span>
</div>
<div class="form-group">
<label for="helmrepository_url" class="col-sm-2 control-label text-left"> URL </label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="settings.HelmRepositoryURL" id="helmrepository_url" placeholder="https://charts.bitnami.com/bitnami" />
</div>
</div>
</div>
<!-- !helm charts -->
<!-- kube -->
<div class="col-sm-12 form-section-title"> Kubeconfig </div>
<div class="form-group">
<label for="kubeconfig_expiry" class="col-sm-2 control-label text-left"> Kubeconfig expiry </label>
<div class="col-sm-10">
<select
id="kubeconfig_expiry"
class="form-control"
ng-model="formValues.KubeconfigExpiry"
ng-options="opt.value as opt.key for opt in state.availableKubeconfigExpiryOptions"
></select>
</div>
</div>
<!-- ! kube -->
<!-- deployment options -->
<div class="col-sm-12 form-section-title"> Deployment Options </div>
<div class="form-group">
<por-switch-field
label="'Enforce code-based deployment'"
name="'toggle_hideAddWithForm'"
feature-id="enforceDeploymentOptions"
disabled="true"
checked="false"
field-class="'col-sm-12'"
label-class="'col-sm-2'"
tooltip="'Hides the \'Add with form\' buttons and prevents adding/editing of resources via forms'"
></por-switch-field>
</div>
<div class="form-group">
<por-switch-field
label="'Require a note on applications'"
name="'toggle_requireNoteOnApplications'"
feature-id="requireNoteOnApplications"
disabled="true"
checked="false"
field-class="'col-sm-12'"
label-class="'col-sm-2'"
tooltip="'BE allows entry of notes in Add/Edit application. Using this setting will enforce entry of a note in Add/Edit application (and prevent complete clearing of it in Application details).'"
></por-switch-field>
</div>
<!-- !deployment options -->
<!-- actions -->
<div class="form-group">
<div class="col-sm-12">
<button
type="button"
class="btn btn-primary btn-sm"
ng-click="saveKubernetesSettings()"
ng-disabled="state.kubeSettingsActionInProgress"
button-spinner="state.kubeSettingsActionInProgress"
data-cy="settings-saveKubeSettingsButton"
>
<span ng-hide="state.kubeSettingsActionInProgress">Save Kubernetes settings</span>
<span ng-show="state.kubeSettingsActionInProgress">Saving...</span>
</button>
</div>
</div>
<!-- !actions -->
</form>
</rd-widget-body>
</rd-widget>
</div>
</div>
<kube-settings-panel></kube-settings-panel>
<ssl-ca-file-settings></ssl-ca-file-settings>
<ssl-certificate-settings ng-show="state.showHTTPS"></ssl-certificate-settings>

View file

@ -1,7 +1,5 @@
import angular from 'angular';
import { FeatureId } from '@/react/portainer/feature-flags/enums';
angular.module('portainer.app').controller('SettingsController', [
'$scope',
'Notifications',
@ -10,40 +8,13 @@ angular.module('portainer.app').controller('SettingsController', [
function ($scope, Notifications, SettingsService, StateManager) {
$scope.updateSettings = updateSettings;
$scope.handleSuccess = handleSuccess;
$scope.requireNoteOnApplications = FeatureId.K8S_REQUIRE_NOTE_ON_APPLICATIONS;
$scope.state = {
actionInProgress: false,
availableKubeconfigExpiryOptions: [
{
key: '1 day',
value: '24h',
},
{
key: '7 days',
value: `${24 * 7}h`,
},
{
key: '30 days',
value: `${24 * 30}h`,
},
{
key: '1 year',
value: `${24 * 30 * 12}h`,
},
{
key: 'No expiry',
value: '0',
},
],
backupInProgress: false,
featureLimited: false,
showHTTPS: !window.ddExtension,
};
$scope.formValues = {
KubeconfigExpiry: undefined,
HelmRepositoryURL: undefined,
BlackListedLabels: [],
labelName: '',
labelValue: '',
@ -66,18 +37,6 @@ angular.module('portainer.app').controller('SettingsController', [
updateSettings(filteredSettingsPayload, 'Hidden container settings updated');
};
// only update the values from the kube settings widget. In future separate the api endpoints
$scope.saveKubernetesSettings = function () {
const kubeSettingsPayload = {
KubeconfigExpiry: $scope.formValues.KubeconfigExpiry,
HelmRepositoryURL: $scope.formValues.HelmRepositoryURL,
GlobalDeploymentOptions: $scope.formValues.GlobalDeploymentOptions,
};
$scope.state.kubeSettingsActionInProgress = true;
updateSettings(kubeSettingsPayload, 'Kubernetes settings updated');
};
function updateSettings(settings, successMessage = 'Settings updated') {
return SettingsService.update(settings)
.then(function success(settings) {
@ -88,7 +47,6 @@ angular.module('portainer.app').controller('SettingsController', [
Notifications.error('Failure', err, 'Unable to update settings');
})
.finally(function final() {
$scope.state.kubeSettingsActionInProgress = false;
$scope.state.actionInProgress = false;
});
}
@ -100,10 +58,6 @@ angular.module('portainer.app').controller('SettingsController', [
StateManager.updateEnableTelemetry(settings.EnableTelemetry);
$scope.formValues.BlackListedLabels = settings.BlackListedLabels;
}
// trigger an event to update the deployment options for the react based sidebar
const event = new CustomEvent('portainer:deploymentOptionsUpdated');
document.dispatchEvent(event);
}
function initView() {
@ -112,8 +66,6 @@ angular.module('portainer.app').controller('SettingsController', [
var settings = data;
$scope.settings = settings;
$scope.formValues.KubeconfigExpiry = settings.KubeconfigExpiry;
$scope.formValues.HelmRepositoryURL = settings.HelmRepositoryURL;
$scope.formValues.BlackListedLabels = settings.BlackListedLabels;
})
.catch(function error(err) {