Skip to content

Commit c51ccf2

Browse files
Feature/entry number for display and navigation (#1215)
* initial commit for goto entry * Add entry number to Entry card * Remove unneeded import * clear goto after valid move * Add function to check if filtering and sorting is on. Add implementation ng-disabled to back, forward and goto elements * Added controller model to imnput element to track current enrty index * Change input tool tip message * Remove unused binding to ui element * Min and Max validation properties were inadvertently removed. dc-entry entry-index="$ctrl.entryIndex() removed on rebase, adding back * reset input value on blur; hide control on filter This change adds a ng-blur handler that resets the value of the numeric input to the current entry index. This fixes the input having a sticky invalid state/red box when the user clicks a button or loses focus on the input. Additionally, we hide the controls when the filter is active, instead of disabling. Co-authored-by: Chris Hirt <chris@hirtfamily.net>
1 parent 3468c99 commit c51ccf2

7 files changed

Lines changed: 55 additions & 4 deletions

File tree

src/angular-app/bellows/core/offline/editor-data.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ export class EditorDataService {
269269
return index;
270270
}
271271

272+
// find entry id from index number, used to goto and display editor record
273+
getIdInFilteredList = (index: number): string => {
274+
let list = this.filteredEntries;
275+
let id: string;
276+
if(index > 0 && index <= list.length){
277+
let entry = list[index-1];
278+
id = entry.id;
279+
}
280+
return id;
281+
}
282+
272283
sortEntries = (shouldResetVisibleEntriesList: boolean): angular.IPromise<any> => {
273284
const startTime = performance.now();
274285
return this.configService.getEditorConfig().then(config => {

src/angular-app/languageforge/lexicon/core/lexicon-editor-data.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class LexiconEditorDataService {
1717
removeEntryFromLists = this.editorDataService.removeEntryFromLists;
1818
addEntryToEntryList = this.editorDataService.addEntryToEntryList;
1919
getIndexInList = this.editorDataService.getIndexInList;
20+
getIdInFilteredList = this.editorDataService.getIdInFilteredList;
2021
showInitialEntries = this.editorDataService.showInitialEntries;
2122
showMoreEntries = this.editorDataService.showMoreEntries;
2223
sortEntries = this.editorDataService.sortEntries;

src/angular-app/languageforge/lexicon/editor/_editor.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,3 +827,20 @@ dc-entry .card {
827827
form.submitted .ng-invalid {
828828
border: 1px solid #f00;
829829
}
830+
831+
// remove up/down arrows for goto Entry
832+
.gotoEntry {
833+
width: 60px;
834+
&::-webkit-inner-spin-button{ display: none; }
835+
-moz-appearance:textfield;
836+
}
837+
838+
.gotoEntry.ng-invalid {
839+
border: 3px solid #f00;
840+
}
841+
842+
.gotoEntry:focus.ng-invalid {
843+
background-color: #fff;
844+
outline: none;
845+
border: 3px solid #f00;
846+
}

src/angular-app/languageforge/lexicon/editor/editor-entry.view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<dc-rendered config="$ctrl.lecConfig.entry" global-config="$ctrl.lecConfig"
117117
model="$ctrl.currentEntry" option-lists="$ctrl.lecOptionLists"></dc-rendered>
118118
</div>
119-
<dc-entry config="$ctrl.lecConfig.entry" model="$ctrl.currentEntry" control="$ctrl.control"></dc-entry>
119+
<dc-entry config="$ctrl.lecConfig.entry" model="$ctrl.currentEntry" control="$ctrl.control" entry-index="$ctrl.entryIndex()"></dc-entry>
120120
</div>
121121
</div>
122122
</div>

src/angular-app/languageforge/lexicon/editor/editor.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
<span class="d-none d-md-inline-block">List</span></a>
1212
</div>
1313
<div class="float-right" data-ng-show="$ctrl.isAtEditorEntry()">
14-
<div class="btn-group">
14+
<div class="btn-group" ng-form="validateGoto" ng-hide="$ctrl.entryListModifiers.filterActive()">
1515
<button class="btn btn-std" data-ng-click="$ctrl.skipToEntry(-1)" ng-disabled="!$ctrl.canSkipToEntry(-1)">
1616
<span class="fa fa-arrow-left"></span> <span class="d-none d-lg-inline-block">Previous</span>
1717
</button>
18+
<input type="number" id="goto" name="goto" class="gotoEntry" title="Enter a number and press Enter to go to that entry"
19+
data-ng-min="1" data-ng-max="$ctrl.filteredEntries.length === 0 ? 1 : $ctrl.filteredEntries.length" data-ng-model="item.value" data-ng-value="$ctrl.currentIndex.index" data-ng-blur="item.value = $ctrl.currentIndex.index" data-on-enter="$ctrl.gotoToEntry(item.value, validateGoto.goto.$valid)"></input>
1820
<button class="btn btn-std" data-ng-click="$ctrl.skipToEntry(1)" ng-disabled="!$ctrl.canSkipToEntry(1)">
1921
<span class="d-none d-lg-inline-block">Next</span> <span class="fa fa-arrow-right"></span>
2022
</button>

src/angular-app/languageforge/lexicon/editor/editor.component.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export class LexiconEditorController implements angular.IController {
4949

5050
lastSavedDate = new Date();
5151
currentEntry: LexEntry = new LexEntry();
52+
53+
currentIndex = {
54+
index: -1
55+
}
56+
5257
commentContext = {
5358
contextGuid: ''
5459
};
@@ -469,6 +474,20 @@ export class LexiconEditorController implements angular.IController {
469474
this.goToEntry(id);
470475
}
471476

477+
gotoToEntry(index: number, isValid: boolean) {
478+
if (isValid) {
479+
let id = this.editorService.getIdInFilteredList(Number(index));
480+
this.editEntryAndScroll(id);
481+
}
482+
}
483+
484+
entryIndex(): number {
485+
let id = this.currentEntry.id;
486+
let index = this.editorService.getIndexInList(id, this.entries)
487+
this.currentIndex.index = index + 1;
488+
return this.currentIndex.index;
489+
}
490+
472491
canSkipToEntry(distance: number): boolean {
473492
const i = this.editorService.getIndexInList(this.currentEntry.id, this.visibleEntries) + distance;
474493
return i >= 0 && i < this.visibleEntries.length;

src/angular-app/languageforge/lexicon/editor/field/dc-entry.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {LexEntry} from '../../shared/model/lex-entry.model';
66
import {LexSense} from '../../shared/model/lex-sense.model';
77
import {LexConfigFieldList} from '../../shared/model/lexicon-config.model';
88
import {FieldControl} from './field-control.model';
9-
109
export class FieldEntryController implements angular.IController {
1110
model: LexEntry;
1211
config: LexConfigFieldList;
1312
control: FieldControl;
13+
entryIndex: number;
1414

1515
contextGuid: string = '';
1616
fieldName: string = 'entry';
@@ -83,7 +83,8 @@ export const FieldEntryComponent: angular.IComponentOptions = {
8383
bindings: {
8484
model: '=',
8585
config: '<',
86-
control: '<'
86+
control: '<',
87+
entryIndex: '<'
8788
},
8889
controller: FieldEntryController,
8990
templateUrl: '/angular-app/languageforge/lexicon/editor/field/dc-entry.component.html'

0 commit comments

Comments
 (0)