1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 12:25:22 +02:00

refactor(app): backport technical changes (#4679)

* refactor(app): backport technical changes

* refactor(app): remove EE only features

* feat(app): small review changes to match EE codebase layout on some files

Co-authored-by: xAt0mZ <baron_l@epitech.eu>
This commit is contained in:
Alice Groux 2021-02-26 16:50:33 +01:00 committed by GitHub
parent 158bdae10e
commit ccf6babc02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 951 additions and 976 deletions

View file

@ -79,6 +79,7 @@
ng-model="ctrl.state.volumeSize"
placeholder="20"
ng-min="0"
min="0"
ng-change="ctrl.onChangeSize()"
required
/>
@ -100,11 +101,11 @@
</div>
<div class="form-inline">
<div class="small text-warning" style="margin-top: 5px;" ng-show="ctrl.state.volumeSizeError || kubernetesVolumeUpdateForm.size.$invalid">
<div class="small text-warning" style="margin-top: 5px;" ng-show="ctrl.state.errors.volumeSize || kubernetesVolumeUpdateForm.size.$invalid">
<div ng-messages="kubernetesVolumeUpdateForm.size.$error">
<p ng-message="required"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> This field is required.</p>
</div>
<p ng-show="ctrl.state.volumeSizeError && !kubernetesVolumeUpdateForm.size.$invalid"
<p ng-show="ctrl.state.errors.volumeSize && !kubernetesVolumeUpdateForm.size.$invalid"
><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> The new size must be greater than the actual size.</p
>
</div>

View file

@ -64,18 +64,17 @@ class KubernetesVolumeController {
onChangeSize() {
if (this.state.volumeSize) {
const size = filesizeParser(this.state.volumeSize + this.state.volumeSizeUnit);
const size = filesizeParser(this.state.volumeSize + this.state.volumeSizeUnit, { base: 10 });
if (this.state.oldVolumeSize > size) {
this.state.volumeSizeError = true;
this.state.errors.volumeSize = true;
} else {
this.volume.PersistentVolumeClaim.Storage = size;
this.state.volumeSizeError = false;
this.state.errors.volumeSize = false;
}
}
}
sizeIsValid() {
return !this.state.volumeSizeError && this.state.oldVolumeSize !== this.volume.PersistentVolumeClaim.Storage;
return !this.state.errors.volumeSize && this.state.volumeSize && this.state.oldVolumeSize !== filesizeParser(this.state.volumeSize + this.state.volumeSizeUnit, { base: 10 });
}
/**
@ -84,7 +83,7 @@ class KubernetesVolumeController {
async updateVolumeAsync(redeploy) {
try {
this.volume.PersistentVolumeClaim.Storage = this.state.volumeSize + this.state.volumeSizeUnit.charAt(0) + 'i';
this.volume.PersistentVolumeClaim.Storage = this.state.volumeSize + this.state.volumeSizeUnit.charAt(0);
await this.KubernetesPersistentVolumeClaimService.patch(this.oldVolume.PersistentVolumeClaim, this.volume.PersistentVolumeClaim);
this.Notifications.success('Volume successfully updated');
@ -126,9 +125,9 @@ class KubernetesVolumeController {
volume.Applications = KubernetesVolumeHelper.getUsingApplications(volume, applications);
this.volume = volume;
this.oldVolume = angular.copy(volume);
this.state.volumeSize = parseInt(volume.PersistentVolumeClaim.Storage.slice(0, -2));
this.state.volumeSize = parseInt(volume.PersistentVolumeClaim.Storage.slice(0, -2), 10);
this.state.volumeSizeUnit = volume.PersistentVolumeClaim.Storage.slice(-2);
this.state.oldVolumeSize = filesizeParser(volume.PersistentVolumeClaim.Storage);
this.state.oldVolumeSize = filesizeParser(volume.PersistentVolumeClaim.Storage, { base: 10 });
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to retrieve volume');
}
@ -179,9 +178,11 @@ class KubernetesVolumeController {
increaseSize: false,
volumeSize: 0,
volumeSizeUnit: 'GB',
volumeSizeError: false,
volumeSharedAccessPolicy: '',
volumeSharedAccessPolicyTooltip: '',
errors: {
volumeSize: false,
},
};
this.state.activeTab = this.LocalStorage.getActiveTab('volume');

View file

@ -1,9 +1,10 @@
require('../../templates/advancedDeploymentPanel.html');
import * as _ from 'lodash-es';
import _ from 'lodash-es';
import filesizeParser from 'filesize-parser';
import angular from 'angular';
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
import KubernetesResourceQuotaHelper from 'Kubernetes/helpers/resourceQuotaHelper';
function buildStorages(storages, volumes) {
_.forEach(storages, (s) => {
@ -15,28 +16,9 @@ function buildStorages(storages, volumes) {
}
function computeSize(volumes) {
let hasT,
hasG,
hasM = false;
const size = _.sumBy(volumes, (v) => {
const storage = v.PersistentVolumeClaim.Storage;
if (!hasT && _.endsWith(storage, 'TB')) {
hasT = true;
} else if (!hasG && _.endsWith(storage, 'GB')) {
hasG = true;
} else if (!hasM && _.endsWith(storage, 'MB')) {
hasM = true;
}
return filesizeParser(storage, { base: 10 });
});
if (hasT) {
return size / 1000 / 1000 / 1000 / 1000 + 'TB';
} else if (hasG) {
return size / 1000 / 1000 / 1000 + 'GB';
} else if (hasM) {
return size / 1000 / 1000 + 'MB';
}
return size;
const size = _.sumBy(volumes, (v) => filesizeParser(v.PersistentVolumeClaim.Storage, { base: 10 }));
const format = KubernetesResourceQuotaHelper.formatBytes(size);
return `${format.Size}${format.SizeUnit}`;
}
class KubernetesVolumesController {