recalculate data on edit and on delete

This commit is contained in:
Dan Percic 2021-06-24 17:16:40 +03:00
parent def0d17121
commit e3f5beb509
2 changed files with 14 additions and 15 deletions

View File

@ -12,6 +12,13 @@ import { TypeValueWrapper } from '../../../../models/file/type-value.wrapper';
import { TranslateService } from '@ngx-translate/core';
import { LoadingService } from '../../../../services/loading.service';
const toChartConfig = (dict: TypeValueWrapper): DoughnutChartConfig => ({
value: dict.entries ? dict.entries.length : 0,
color: dict.hexColor,
label: dict.label,
key: dict.type
});
@Component({
selector: 'redaction-dictionary-listing-screen',
templateUrl: './dictionary-listing-screen.component.html',
@ -61,6 +68,7 @@ export class DictionaryListingScreenComponent
this._loadingService.start();
await this._appStateService.loadDictionaryData();
this._loadDictionaryData(false);
this._calculateData();
this._loadingService.stop();
}
);
@ -76,6 +84,7 @@ export class DictionaryListingScreenComponent
this._loadingService.start();
await this._appStateService.loadDictionaryData();
this._loadDictionaryData(false);
this._calculateData();
this._loadingService.stop();
}
}
@ -117,17 +126,8 @@ export class DictionaryListingScreenComponent
}
private _calculateData(): void {
this.chartData = this.allEntities.map(dict => this._toChartConfig(dict));
this.chartData = this.allEntities.map(dict => toChartConfig(dict));
this.chartData.sort((a, b) => (a.label < b.label ? -1 : 1));
this._loadingService.stop();
}
private _toChartConfig(dict: TypeValueWrapper): DoughnutChartConfig {
return {
value: dict.entries ? dict.entries.length : 0,
color: dict.hexColor,
label: dict.label,
key: dict.type
};
}
}

View File

@ -162,14 +162,13 @@ export class DictionaryManagerComponent implements OnChanges, OnInit {
}
private _applySearchDecorations() {
this._searchDecorations = this._codeEditor?.deltaDecorations(this._searchDecorations, []);
this._searchDecorations =
this._codeEditor?.deltaDecorations(this._searchDecorations, []) || [];
const decorations = this.findMatches.map(match => this._getSearchDecoration(match));
this._searchDecorations = this._codeEditor?.deltaDecorations(
this._searchDecorations,
decorations
);
this._searchDecorations =
this._codeEditor?.deltaDecorations(this._searchDecorations, decorations) || [];
}
private _getMatches(text: string): FindMatch[] {