fix: update private labeling (#2048)

This commit is contained in:
Max Peintner 2021-07-21 10:42:36 +02:00 committed by GitHub
parent 17fb40b55d
commit 6e32bb9fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 42 deletions

View File

@ -259,7 +259,7 @@
</cnsl-info-section>
</ng-container>
<mat-slide-toggle class="toggle" color="primary" ngDefaultControl [disabled]="serviceType == PolicyComponentServiceType.MGMT && (['label_policy.watermark'] | hasFeature | async) == false"
[(ngModel)]="previewData.disableWatermark" (change)="saveWatermark()">
[(ngModel)]="previewData.disableWatermark" (change)="savePolicy()">
{{'POLICY.DATA.DISABLEWATERMARK' | translate}}
</mat-slide-toggle>
</div>

View File

@ -354,8 +354,6 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
this.authService.canUseFeature(['label_policy.private_label']).pipe(take(1)).subscribe((canUse) => {
this.getPreviewData().then(data => {
console.log('preview', data);
if (data.policy) {
this.previewData = data.policy;
this.loading = false;
@ -371,8 +369,6 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
});
this.getData().then(data => {
console.log('data', data);
if (data.policy) {
this.data = data.policy;
this.loading = false;
@ -506,7 +502,6 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
private loadAsset(imagekey: string, url: string): Promise<any> {
return this.assetService.load(`${url}`, this.org.id).then(data => {
console.log(data);
const objectURL = URL.createObjectURL(data);
this.images[imagekey] = this.sanitizer.bypassSecurityTrustUrl(objectURL);
this.refreshPreview.emit();
@ -529,6 +524,18 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
}
public savePolicy(): Promise<any> {
const reloadPolicy = () => {
setTimeout(() => {
this.loadingImages = true;
this.getData().then(data => {
if (data.policy) {
this.data = data.policy;
this.loadImages();
}
});
}, 500);
};
switch (this.serviceType) {
case PolicyComponentServiceType.MGMT:
if ((this.previewData as LabelPolicy.AsObject).isDefault) {
@ -537,6 +544,8 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
return (this.service as ManagementService).addCustomLabelPolicy(req0).then(() => {
this.toast.showInfo('POLICY.TOAST.SET', true);
reloadPolicy();
}).catch((error: HttpErrorResponse) => {
this.toast.showError(error);
});
@ -546,6 +555,8 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
return (this.service as ManagementService).updateCustomLabelPolicy(req1).then(() => {
this.toast.showInfo('POLICY.TOAST.SET', true);
reloadPolicy();
}).catch(error => {
this.toast.showError(error);
});
@ -554,6 +565,7 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
const req = new UpdateLabelPolicyRequest();
this.overwriteValues(req);
return (this.service as AdminService).updateLabelPolicy(req).then(() => {
reloadPolicy();
this.toast.showInfo('POLICY.TOAST.SET', true);
}).catch(error => {
this.toast.showError(error);
@ -561,42 +573,6 @@ export class PrivateLabelingPolicyComponent implements OnDestroy {
}
}
public saveWatermark(): void {
switch (this.serviceType) {
case PolicyComponentServiceType.MGMT:
if ((this.previewData as LabelPolicy.AsObject).isDefault) {
const req0 = new AddCustomLabelPolicyRequest();
req0.setDisableWatermark(this.previewData.disableWatermark);
(this.service as ManagementService).addCustomLabelPolicy(req0).then(() => {
this.toast.showInfo('POLICY.TOAST.SET', true);
}).catch((error: HttpErrorResponse) => {
this.toast.showError(error);
});
} else {
const req1 = new UpdateCustomLabelPolicyRequest();
req1.setDisableWatermark(this.previewData.disableWatermark);
(this.service as ManagementService).updateCustomLabelPolicy(req1).then(() => {
this.toast.showInfo('POLICY.TOAST.SET', true);
}).catch(error => {
this.toast.showError(error);
});
}
break;
case PolicyComponentServiceType.ADMIN:
const req = new UpdateLabelPolicyRequest();
req.setDisableWatermark(this.data.disableWatermark);
(this.service as AdminService).updateLabelPolicy(req).then(() => {
this.toast.showInfo('POLICY.TOAST.SET', true);
}).catch(error => {
this.toast.showError(error);
});
break;
}
}
public get isDefault(): boolean {
if (this.previewData && this.serviceType === PolicyComponentServiceType.MGMT) {
return (this.previewData as LabelPolicy.AsObject).isDefault;