Merge pull request #5278 from tsiegleauq/tinymce-in-settings-page

Manual change detection for config list
This commit is contained in:
Emanuel Schütze 2020-03-25 15:21:41 +01:00 committed by GitHub
commit 19af02a315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -325,14 +325,6 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit, OnDes
this.sendUpdate(ev.target.getContent()); this.sendUpdate(ev.target.getContent());
} }
}); });
editor.on('Remove', ev => {
// Do not save empty values on remove. This prevents losing the value on e.g.
// fast navigation, when the editor is not fully loaded. Then the content is empty
// and would trigger an update with empty data.
if (ev.target.getContent() && ev.target.getContent() !== this.translatedValue) {
this.sendUpdate(ev.target.getContent());
}
});
} }
}; };
} }

View File

@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
@ -31,7 +31,8 @@ export interface ConfigItem {
@Component({ @Component({
selector: 'os-config-list', selector: 'os-config-list',
templateUrl: './config-list.component.html', templateUrl: './config-list.component.html',
styleUrls: ['./config-list.component.scss'] styleUrls: ['./config-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class ConfigListComponent extends BaseComponent implements CanComponentDeactivate, OnInit, OnDestroy { export class ConfigListComponent extends BaseComponent implements CanComponentDeactivate, OnInit, OnDestroy {
public configGroup: ConfigGroup; public configGroup: ConfigGroup;
@ -51,6 +52,7 @@ export class ConfigListComponent extends BaseComponent implements CanComponentDe
public constructor( public constructor(
protected titleService: Title, protected titleService: Title,
protected translate: TranslateService, protected translate: TranslateService,
private cd: ChangeDetectorRef,
private repo: ConfigRepositoryService, private repo: ConfigRepositoryService,
private route: ActivatedRoute, private route: ActivatedRoute,
private promptDialog: PromptService private promptDialog: PromptService
@ -70,6 +72,7 @@ export class ConfigListComponent extends BaseComponent implements CanComponentDe
const groupName = this.translate.instant(configGroup.name); const groupName = this.translate.instant(configGroup.name);
super.setTitle(`${settings} - ${groupName}`); super.setTitle(`${settings} - ${groupName}`);
this.configGroup = configGroup; this.configGroup = configGroup;
this.cd.markForCheck();
} }
}); });
}); });
@ -89,16 +92,20 @@ export class ConfigListComponent extends BaseComponent implements CanComponentDe
} else { } else {
this.configItems[index] = { key, value }; this.configItems[index] = { key, value };
} }
this.cd.markForCheck();
} }
/** /**
* Saves every field in this config-group. * Saves every field in this config-group.
*/ */
public saveAll(): void { public saveAll(): void {
this.cd.detach();
this.repo.bulkUpdate(this.configItems).then(result => { this.repo.bulkUpdate(this.configItems).then(result => {
this.errors = result.errors; this.errors = result.errors;
if (Object.keys(result.errors).length === 0) { if (Object.keys(result.errors).length === 0) {
this.configItems = []; this.configItems = [];
this.cd.reattach();
this.cd.markForCheck();
} }
}); });
} }