RED-6786, made saving faster.

This commit is contained in:
George 2023-05-26 17:52:00 +03:00
parent edafd45e5c
commit b80486b702
4 changed files with 15 additions and 17 deletions

View File

@ -55,6 +55,7 @@ export class DictionaryScreenComponent implements OnInit {
null,
true,
DICTIONARY_TO_ENTRY_TYPE_MAP[this.type],
false,
);
await this._loadEntries();
} catch (e) {

View File

@ -1,7 +1,7 @@
<ngx-monaco-editor
(init)="onCodeEditorInit($event)"
(ngModelChange)="_editorTextChanged$.next($event)"
(paste)="onPaste()"
(paste)="onPaste($event)"
*ngIf="!showDiffEditor"
[(ngModel)]="value"
[options]="editorOptions"

View File

@ -77,6 +77,12 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
this._sub$.unsubscribe();
}
onPaste(event: ClipboardEvent) {
if ((event.target as HTMLTextAreaElement).ariaRoleDescription === 'editor') {
this._loadingService.start();
}
}
ngOnChanges(changes: SimpleChanges) {
if (changes.diffEditorText) {
this._diffEditor?.getOriginalEditor().setValue(this.diffEditorText);
@ -141,10 +147,6 @@ export class EditorComponent implements OnInit, OnChanges, OnDestroy {
this._editorTextChanged$.next(this.value);
}
onPaste() {
this._loadingService.start();
}
private _defineThemes(): void {
for (const theme of this._editorThemeService.themes) {
(window as any).monaco.editor.defineTheme(theme, this._editorThemeService.configurations[theme]);

View File

@ -103,23 +103,17 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
dossierId: string,
showToast = true,
dictionaryEntryType = DictionaryEntryTypes.ENTRY,
removeCurrent = true,
) {
const entriesToAdd: Array<string> = [];
const initialEntriesSet = new Set(initialEntries);
let hasInvalidRows = false;
let hasNewEntries = false;
for (let i = 0; i < entries.length; i++) {
const entry = entries.at(i);
if (!entry.trim()) {
if (!entry.trim() || initialEntriesSet.has(entry)) {
continue;
}
if (entry.length < MIN_WORD_LENGTH) {
hasInvalidRows = true;
}
if (!hasNewEntries && !initialEntriesSet.has(entry)) {
hasNewEntries = true;
}
hasInvalidRows ||= entry.length < MIN_WORD_LENGTH;
entriesToAdd.push(entry);
}
if (hasInvalidRows) {
@ -141,8 +135,8 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
if (deletedEntries.length) {
await this._deleteEntries(deletedEntries, dossierTemplateId, type, dictionaryEntryType, dossierId);
}
if (hasNewEntries) {
await this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId);
if (entriesToAdd.length) {
await this._addEntries(entriesToAdd, dossierTemplateId, type, dictionaryEntryType, dossierId, removeCurrent);
}
if (showToast) {
@ -264,11 +258,12 @@ export class DictionaryService extends EntitiesService<IDictionary, Dictionary>
type: string,
dictionaryEntryType: DictionaryEntryType,
dossierId: string,
removeCurrent = true,
) {
const queryParams: List<QueryParam> = [
{ key: 'dossierId', value: dossierId },
{ key: 'dictionaryEntryType', value: dictionaryEntryType },
{ key: 'removeCurrent', value: true },
{ key: 'removeCurrent', value: removeCurrent },
];
const url = `${this._defaultModelPath}/${type}/${dossierTemplateId}`;
return firstValueFrom(this._post(entries, url, queryParams));