Add Search bar for the language Editor and fixed some minor bugs on it

This commit is contained in:
George Kalampokis 2020-02-28 12:58:42 +02:00
parent 1254cabbf1
commit 687390e3b9
3 changed files with 55 additions and 8 deletions

View File

@ -1,6 +1,12 @@
<div *ngIf="parseFinished" class="language-editor" [style.height]="(keys.length * rowHeight) + 'px'">
<form (ngSubmit)="updateLang()" [formGroup]="formGroup">
<div class="row">
<div class="search-bar">
<input class="search-text" mat-input #search placeholder="{{ 'DASHBOARD.SEARCH' | translate }}">
<button mat-button type="button" (click)="findKeys(search)">
<mat-icon>search</mat-icon>
</button>
</div>
<mat-card class="col-md-8 offset-md-2 sticky">
<mat-card-title><div [innerHTML]="currentLang"></div></mat-card-title>
<mat-card-content>

View File

@ -18,7 +18,25 @@
.sticky {
position: fixed;
left: 200px;
right: 150px;
right: 200px;
width: 50%;
}
.search-bar {
padding-top: inherit !important;
bottom: auto !important;
width: 260px !important;
top: 100px;
position: fixed;
right: 10px;
background-color: white;
border: 1px solid rgb(218, 218, 218);
border-radius: 6px;
padding-left: 10px;
}
.search-text {
border: 0px solid rgb(218, 218, 218);
border-radius: 6px;
}
}

View File

@ -16,6 +16,7 @@ export class LanguageEditorComponent extends BaseComponent implements OnInit, On
readonly rowHeight = 100;
readonly maxElements = 12;
allkeys = [];
keys = [];
visibleKeys = [];
startIndex = 0;
@ -56,8 +57,13 @@ export class LanguageEditorComponent extends BaseComponent implements OnInit, On
const langObj = JSON.parse(fr.result as string);
this.convertObjectToForm(langObj, '', this.formGroup);
this.currentLang = this.language.getCurrentLanguageName();
this.keys.length = 0;
for (const key of this.allkeys) {
this.keys.push(key);
}
this.visibleKeys = this.keys.slice(this.startIndex, this.endIndex);
this.parseFinished = true;
};
fr.readAsText(blob);
}
@ -71,7 +77,7 @@ export class LanguageEditorComponent extends BaseComponent implements OnInit, On
continue;
} else {
form.addControl(prop, this.formBuilder.control(obj[prop]));
this.keys.push(key);
this.allkeys.push(key);
}
}
return;
@ -103,13 +109,30 @@ onCallbackError(error: any) {
refreshFn = (ev: Event) => {
this.startIndex = Math.floor((ev.srcElement as HTMLDocument).scrollingElement.scrollTop / this.rowHeight);
this.endIndex = this.startIndex + this.maxElements;
const tempKeys = this.keys.slice(this.startIndex, this.endIndex);
this.visibleKeys.length = 0;
for (const key of tempKeys) {
this.visibleKeys.push(key);
if ((ev.srcElement as HTMLDocument).scrollingElement !== undefined) {
this.startIndex = Math.floor((ev.srcElement as HTMLDocument).scrollingElement.scrollTop / this.rowHeight);
this.endIndex = this.startIndex + this.maxElements;
const tempKeys = this.keys.slice(this.startIndex, this.endIndex);
this.visibleKeys.length = 0;
for (const key of tempKeys) {
this.visibleKeys.push(key);
}
}
}
findKeys(ev: any) {
let tempKeys = [];
if (ev.value === "") {
tempKeys = this.allkeys;
} else {
tempKeys = this.allkeys.filter((key) => (this.formGroup.get(key).value as string).includes(ev.value));
window.scrollTo({top: 0});
}
this.keys.length = 0;
for (const key of tempKeys) {
this.keys.push(key);
}
this.visibleKeys = this.keys.slice(this.startIndex, this.endIndex);
}
}