messages for dict, smarter update and corner case fixes, sorted entries
This commit is contained in:
parent
d1974cdde0
commit
7c348c31ad
@ -10,6 +10,7 @@ import { reference } from '../../../utils/functions';
|
|||||||
import { debounce } from '../../../utils/debounce';
|
import { debounce } from '../../../utils/debounce';
|
||||||
import { NotificationService, NotificationType } from '../../../notification/notification.service';
|
import { NotificationService, NotificationType } from '../../../notification/notification.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
declare var ace;
|
declare var ace;
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ export class DictionaryOverviewScreenComponent {
|
|||||||
|
|
||||||
private _initialize() {
|
private _initialize() {
|
||||||
this._dictionaryControllerService.getDictionaryForType(this.dictionary.type).subscribe((data) => {
|
this._dictionaryControllerService.getDictionaryForType(this.dictionary.type).subscribe((data) => {
|
||||||
this.initialDictionaryEntries = data.entries;
|
this.initialDictionaryEntries = data.entries.sort((str1, str2) => str1.localeCompare(str2, undefined, { sensitivity: 'accent' }));
|
||||||
this.revert();
|
this.revert();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -155,36 +156,43 @@ export class DictionaryOverviewScreenComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hasChanges() {
|
get hasChanges() {
|
||||||
return this.changedLines.length > 0 || this.currentDictionaryEntries.length !== this.initialDictionaryEntries.length;
|
return this.activeEditMarkers.length > 0 || this.currentDictionaryEntries.length < this.initialDictionaryEntries.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveEntries() {
|
async saveEntries() {
|
||||||
let entriesToAdd = [];
|
let entriesToAdd = [];
|
||||||
const entriesToDelete = [];
|
|
||||||
this.currentDictionaryEntries.forEach((currentEntry) => {
|
this.currentDictionaryEntries.forEach((currentEntry) => {
|
||||||
if (this.initialDictionaryEntries.indexOf(currentEntry) < 0) {
|
|
||||||
entriesToAdd.push(currentEntry);
|
entriesToAdd.push(currentEntry);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.initialDictionaryEntries.forEach((initialEntry) => {
|
|
||||||
if (this.currentDictionaryEntries.indexOf(initialEntry) < 0) {
|
|
||||||
entriesToDelete.push(initialEntry);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove empty lines
|
// remove empty lines
|
||||||
entriesToAdd = entriesToAdd.filter((e) => e && e.trim().length > 0).map((e) => e.trim());
|
entriesToAdd = entriesToAdd.filter((e) => e && e.trim().length > 0).map((e) => e.trim());
|
||||||
|
|
||||||
const invalidRowsExist = entriesToAdd.filter((e) => e.length < DictionaryOverviewScreenComponent.MIN_WORD_LENGTH);
|
const invalidRowsExist = entriesToAdd.filter((e) => e.length < DictionaryOverviewScreenComponent.MIN_WORD_LENGTH);
|
||||||
|
|
||||||
if (invalidRowsExist.length === 0) {
|
if (invalidRowsExist.length === 0) {
|
||||||
|
// can add at least 1
|
||||||
|
let obs: Observable<any>;
|
||||||
if (entriesToAdd.length > 0) {
|
if (entriesToAdd.length > 0) {
|
||||||
await this._dictionaryControllerService.addEntry(entriesToAdd, this.dictionary.type).toPromise();
|
obs = this._dictionaryControllerService.addEntry(entriesToAdd, this.dictionary.type, true);
|
||||||
}
|
} else {
|
||||||
if (entriesToDelete.length > 0) {
|
obs = this._dictionaryControllerService.deleteEntries(this.initialDictionaryEntries, this.dictionary.type);
|
||||||
await this._dictionaryControllerService.deleteEntries(entriesToDelete, this.dictionary.type).toPromise();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obs.subscribe(
|
||||||
|
() => {
|
||||||
this._initialize();
|
this._initialize();
|
||||||
|
this._notificationService.showToastNotification(
|
||||||
|
this._translateService.instant('dictionary-overview.success.generic'),
|
||||||
|
null,
|
||||||
|
NotificationType.SUCCESS
|
||||||
|
);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this._notificationService.showToastNotification(
|
||||||
|
this._translateService.instant('dictionary-overview.error.generic'),
|
||||||
|
null,
|
||||||
|
NotificationType.ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this._notificationService.showToastNotification(
|
this._notificationService.showToastNotification(
|
||||||
this._translateService.instant('dictionary-overview.error.entries-to-short'),
|
this._translateService.instant('dictionary-overview.error.entries-to-short'),
|
||||||
|
|||||||
@ -500,7 +500,11 @@
|
|||||||
},
|
},
|
||||||
"dictionary-overview": {
|
"dictionary-overview": {
|
||||||
"error": {
|
"error": {
|
||||||
"entries-to-short": "Some entries of the dictionary are below the minimum length of 2. These are highlighted with red!"
|
"entries-to-short": "Some entries of the dictionary are below the minimum length of 2. These are highlighted with red!",
|
||||||
|
"generic": "Something went wrong... Dictionary update failed!"
|
||||||
|
},
|
||||||
|
"success": {
|
||||||
|
"generic": "Dictionary updated!"
|
||||||
},
|
},
|
||||||
"search": "Search...",
|
"search": "Search...",
|
||||||
"save-changes": "Save Changes",
|
"save-changes": "Save Changes",
|
||||||
|
|||||||
@ -60,13 +60,14 @@ export class DictionaryControllerService {
|
|||||||
* None
|
* None
|
||||||
* @param body entries
|
* @param body entries
|
||||||
* @param type type
|
* @param type type
|
||||||
|
* @param removeCurrent removeCurrent
|
||||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||||
* @param reportProgress flag to report request and response progress.
|
* @param reportProgress flag to report request and response progress.
|
||||||
*/
|
*/
|
||||||
public addEntry(body: Array<string>, type: string, observe?: 'body', reportProgress?: boolean): Observable<any>;
|
public addEntry(body: Array<string>, type: string, removeCurrent?: boolean, observe?: 'body', reportProgress?: boolean): Observable<any>;
|
||||||
public addEntry(body: Array<string>, type: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
|
public addEntry(body: Array<string>, type: string, removeCurrent?: boolean, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
|
||||||
public addEntry(body: Array<string>, type: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
|
public addEntry(body: Array<string>, type: string, removeCurrent?: boolean, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
|
||||||
public addEntry(body: Array<string>, type: string, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
|
public addEntry(body: Array<string>, type: string, removeCurrent?: boolean, observe: any = 'body', reportProgress: boolean = false): Observable<any> {
|
||||||
if (body === null || body === undefined) {
|
if (body === null || body === undefined) {
|
||||||
throw new Error('Required parameter body was null or undefined when calling addEntry.');
|
throw new Error('Required parameter body was null or undefined when calling addEntry.');
|
||||||
}
|
}
|
||||||
@ -75,6 +76,11 @@ export class DictionaryControllerService {
|
|||||||
throw new Error('Required parameter type was null or undefined when calling addEntry.');
|
throw new Error('Required parameter type was null or undefined when calling addEntry.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let queryParameters = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() });
|
||||||
|
if (removeCurrent !== undefined && removeCurrent !== null) {
|
||||||
|
queryParameters = queryParameters.set('removeCurrent', <any>removeCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
let headers = this.defaultHeaders;
|
let headers = this.defaultHeaders;
|
||||||
|
|
||||||
// authentication (RED-OAUTH) required
|
// authentication (RED-OAUTH) required
|
||||||
@ -99,6 +105,7 @@ export class DictionaryControllerService {
|
|||||||
|
|
||||||
return this.httpClient.request<any>('post', `${this.basePath}/dictionary/${encodeURIComponent(String(type))}`, {
|
return this.httpClient.request<any>('post', `${this.basePath}/dictionary/${encodeURIComponent(String(type))}`, {
|
||||||
body: body,
|
body: body,
|
||||||
|
params: queryParameters,
|
||||||
withCredentials: this.configuration.withCredentials,
|
withCredentials: this.configuration.withCredentials,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
observe: observe,
|
observe: observe,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user