RED-6786, made saving faster.

This commit is contained in:
George 2023-05-26 17:52:00 +03:00
parent 3e4f6026f9
commit 8fb36e1d31
4 changed files with 13 additions and 15 deletions

View File

@ -58,6 +58,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,8 +77,10 @@ export class EditorComponent implements OnInit, OnChanges {
return this.currentEntries.length;
}
onPaste() {
this._loadingService.start();
onPaste(event: ClipboardEvent) {
if ((event.target as HTMLTextAreaElement).ariaRoleDescription === 'editor') {
this._loadingService.start();
}
}
ngOnChanges(changes: SimpleChanges) {

View File

@ -94,23 +94,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) {
@ -132,8 +126,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) {
@ -241,11 +235,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));