34
34
</ ul >
35
35
</ div >
36
36
37
- < section class ="mx-5 ">
38
- < div class ="message-header ">
37
+ < section class ="mx-5 message is-dark ">
38
+ < div class ="message-header is-flex ">
39
39
< p >
40
40
{{ object.name }}
41
41
| {{ object.size|filesizeformat }}
42
42
| < a class ="has-text-white " href ="{{ object.get_raw_url }}?as_attachment=1 "> < i class ="fas fa-download "> </ i > </ a >
43
43
< br >
44
44
< span style ="font-size: 10px; "> {{ object.path }}</ span >
45
45
</ p >
46
+ < div >
47
+ < button class ="button previous-btn is-dark " disabled > < i class ="fas fa-arrow-up mr-2 "> </ i > Previous</ button >
48
+ < button class ="button next-btn is-dark " disabled > < i class ="fas fa-arrow-down mr-2 "> </ i > Next</ button >
49
+ </ div >
46
50
</ div >
47
51
< div id ="editor " style ="min-height:730px; border: lightgrey 1px solid; "> {{ file_content }}</ div >
48
52
</ section >
69
73
function removeAllMarkers ( ) {
70
74
let session = editor . getSession ( ) ;
71
75
let markers = session . getMarkers ( ) ;
72
- for ( const [ key , value ] of Object . entries ( markers ) ) {
73
- session . removeMarker ( value . id ) ;
74
- }
76
+ for ( const [ key , value ] of Object . entries ( markers ) ) {
77
+ session . removeMarker ( value . id ) ;
78
+ }
75
79
}
76
80
77
81
// Range(startRow, startColumn, endRow, endColumn)
81
85
let annotations = [ ] ;
82
86
removeAllMarkers ( ) ;
83
87
84
- detected_data . forEach ( function ( $el ) {
88
+ detected_data . forEach ( function ( $el ) {
85
89
// Indexes a 0-based in ace.js
86
90
let start_row = $el . start_line - 1 ;
87
91
let start_column = 0 ;
88
92
let end_row = $el . end_line - 1 ;
89
93
let end_column = 10000 ;
90
94
91
95
let range = new Range ( start_row , start_column , end_row , end_column ) ;
92
- editor . session . addMarker ( range , 'ace-marker' , 'line' ) ; // "fullLine" also available
96
+ editor . session . addMarker ( range , 'ace-marker' , 'line' ) ; // "fullLine" also available
93
97
94
98
annotations . push ( {
95
99
row : start_row ,
102
106
editor . getSession ( ) . setAnnotations ( annotations ) ;
103
107
}
104
108
105
- const $selectionButtons = getAll ( '.tabs a' ) ;
109
+ let scrollPositionIndex = 0 ;
110
+ const selectionButtons = getAll ( '.tabs a' ) ;
111
+ const previousBtn = document . querySelector ( '.previous-btn' ) ;
112
+ const nextBtn = document . querySelector ( '.next-btn' ) ;
106
113
107
114
let detected_values = JSON . parse ( document . querySelector ( "#detected_values" ) . textContent ) ;
115
+ let detected_data ;
108
116
109
- if ( $selectionButtons . length > 0 ) {
110
- $selectionButtons . forEach ( function ( $el ) {
111
- $el . addEventListener ( 'click' , function ( ) {
117
+ if ( selectionButtons . length > 0 ) {
118
+ selectionButtons . forEach ( function ( $el ) {
119
+ $el . addEventListener ( 'click' , function ( ) {
120
+ removeAllMarkers ( ) ;
112
121
let active_li = document . querySelector ( "li.is-active" ) ;
113
122
if ( active_li ) active_li . classList . remove ( "is-active" ) ;
114
- $el . parentElement . classList . add ( "is-active" ) ;
115
123
124
+ $el . parentElement . classList . add ( "is-active" ) ;
116
125
let type = $el . getAttribute ( "data-type" ) ;
117
- let detected_data = detected_values [ type ] ;
118
- if ( detected_data ) {
126
+ detected_data = detected_values [ type ] ;
127
+
128
+ if ( detected_data . length ) {
129
+ scrollPositionIndex = 0 ;
119
130
setDetectedValues ( detected_data ) ;
120
- }
121
- else {
122
- removeAllMarkers ( ) ;
123
- editor . getSession ( ) . setAnnotations ( [ ] ) ;
131
+ editor . renderer . scrollToLine ( detected_data [ 0 ] . start_line - 1 ) ;
132
+ previousBtn . disabled = true ;
133
+ nextBtn . disabled = ( detected_data . length - 1 == 0 ) ;
134
+ } else {
135
+ scrollPositionIndex = 0 ;
136
+ editor . renderer . scrollToLine ( 0 ) ;
137
+ previousBtn . disabled = true ;
138
+ nextBtn . disabled = true ;
124
139
}
125
140
} ) ;
126
141
} ) ;
127
142
}
143
+
144
+ nextBtn . addEventListener ( 'click' , function ( ) {
145
+ if ( scrollPositionIndex >= detected_data . length - 1 ) return false ;
146
+ scrollPositionIndex ++ ;
147
+ editor . renderer . scrollToLine ( detected_data [ scrollPositionIndex ] . start_line - 1 ) ;
148
+ nextBtn . disabled = ( scrollPositionIndex == detected_data . length - 1 ) ;
149
+ previousBtn . disabled = false ;
150
+ } )
151
+
152
+ previousBtn . addEventListener ( 'click' , function ( ) {
153
+ if ( scrollPositionIndex <= 0 ) return false ;
154
+ scrollPositionIndex -- ;
155
+ editor . renderer . scrollToLine ( detected_data [ scrollPositionIndex ] . start_line - 1 ) ;
156
+ previousBtn . disabled = ( scrollPositionIndex == 0 ) ;
157
+ nextBtn . disabled = false ;
158
+ } )
128
159
</ script >
129
160
{% endblock %}
0 commit comments