@@ -2,19 +2,26 @@ import templateContent from "./template.html?raw";
2
2
import * as FilePondLib from "filepond" ;
3
3
import { FilePond , FilePondOptions } from "filepond" ;
4
4
import filepondCSS from "filepond/dist/filepond.min.css?inline" ;
5
- import typeahead from "typeahead-standalone" ;
6
- import typeaheadCSS from "typeahead-standalone/dist/basic.css?inline" ;
7
5
import customCSS from './style.css?inline' ;
8
6
9
7
const ATTRIBUTES : string [ ] = [ "base-url" ] ;
8
+ interface MappingItem {
9
+ mappingId : string ;
10
+ title : string ;
11
+ description ?: string ;
12
+ mappingType : string ;
13
+ name : string ;
14
+ }
10
15
class MappingInputProvider extends HTMLElement {
11
16
shadowRoot : ShadowRoot ;
12
17
private testingFileChooser : FilePond | null = null ;
13
18
// --- Attribute accessible from the HTML tag:
14
19
baseUrl : URL = new URL ( "http://localhost:8090/" ) ;
15
20
// ---
16
21
17
-
22
+ selectedMappingId : string | null = null ;
23
+ selectedMappingType : string | null = null ;
24
+ messageDisplayed : boolean | null = null ;
18
25
// --- Helper methods
19
26
addCssContent ( css : string ) : void {
20
27
let styleElem : HTMLStyleElement = document . createElement ( "style" ) ;
@@ -38,7 +45,6 @@ class MappingInputProvider extends HTMLElement {
38
45
// Create Shadow DOM
39
46
this . shadowRoot = this . attachShadow ( { mode : "open" } ) ;
40
47
this . addCssContent ( filepondCSS ) ;
41
- this . addCssContent ( typeaheadCSS ) ;
42
48
this . addCssContent ( customCSS ) ;
43
49
44
50
// Apply HTML Template to shadow DOM
@@ -86,43 +92,73 @@ class MappingInputProvider extends HTMLElement {
86
92
options . maxFiles = 1 ;
87
93
this . testingFileChooser = FilePondLib . create ( filepondElement , options ) ;
88
94
}
89
- let inputElement : HTMLInputElement = < HTMLInputElement > (
90
- this . shadowRoot . getElementById ( "mappingchooser" )
95
+
96
+ //Box of detailed contents like image, description of mapping
97
+ const mappingIdsEndpoint = this . baseUrl . toString ( ) + "api/v1/mappingAdministration/" ;
98
+ let optionsContainer : HTMLElement = < HTMLInputElement > (
99
+ this . shadowRoot . getElementById ( 'options-container' )
91
100
) ;
92
- if ( inputElement != null ) {
93
- typeahead ( {
94
- input : inputElement ,
95
- minLength : - 1 ,
96
- highlight : true ,
97
- source : {
98
- prefetch : {
99
- url : this . baseUrl . toString ( ) + "api/v1/mappingAdministration/" ,
100
- done : false ,
101
- } ,
102
- identifier : "name" ,
103
- transform : ( data ) => {
104
- for ( let item of data ) {
105
- if ( typeof item == "object" ) {
106
- item . name = item . title ? `${ item . mappingId } - ${ item . title } ` : item . mappingId ;
101
+ // Remove any existing event listeners before adding a new one
102
+ optionsContainer . removeEventListener ( "click" , this . handleButtonClick . bind ( this ) ) ;
103
+
104
+ // Add the event listener
105
+ optionsContainer . addEventListener ( "click" , this . handleButtonClick . bind ( this ) ) ;
106
+
107
+ fetch ( mappingIdsEndpoint ) . then ( response => response . json ( ) )
108
+ . then ( ( mappingIdsData : MappingItem [ ] ) => {
109
+ const mappingIds = mappingIdsData . map ( ( item : MappingItem ) => ( {
110
+ id : item . mappingId ,
111
+ title : item . title ,
112
+ description : item . description ,
113
+ type : item . mappingType
114
+ } ) ) ;
115
+ optionsContainer . innerHTML = '' ;
116
+ mappingIds . forEach ( mapping => {
117
+ const division = document . createElement ( "div" )
118
+ division . classList . add ( "cards" ) ;
119
+ division . innerHTML = `
120
+ <!-- Commenting out the image section -->
121
+ <!--
122
+ <img class="mapping-image" src="${ this . getImageByType ( mapping . type ) } " alt="Mapping Image" />
123
+ -->
124
+ <h3>${ mapping . title } </h3>
125
+ <span class="home-text10 section-description">
126
+ <br>
127
+ <span style="display:inline-block; overflow: auto; height: 124px;">
128
+ ${ mapping . description }
129
+ </span>
130
+ </span>
131
+ <button class ="selection-button " id="mapping-button-${ mapping . id } " >Select</button>
132
+ ` ;
133
+ const button = division . querySelector ( `#mapping-button-${ mapping . id } ` ) ;
134
+ if ( button ) {
135
+ button . addEventListener ( "click" , ( ) => {
136
+ this . selectedMappingId = mapping . id ;
137
+ if ( ! this . messageDisplayed ) {
138
+ const fileInput = this . shadowRoot . querySelector ( "#fileUpload" ) ;
139
+ const messageElement = document . createElement ( "div" ) ;
140
+ messageElement . innerText = "Please upload file and then click on map document to extract metadata" ;
141
+ messageElement . style . marginBottom = "10px" ; // Add some bottom margin for spacing
142
+ messageElement . classList . add ( "message" ) ;
143
+ if ( fileInput != null && fileInput . parentNode != null ) {
144
+ fileInput . parentNode . insertBefore ( messageElement , fileInput ) ;
145
+ }
146
+ this . messageDisplayed = true ;
107
147
}
108
- }
109
- return data
110
- } ,
111
- dataTokens : [ "description" ] ,
112
- identity : ( suggestion ) => `${ suggestion . mappingId } ${ suggestion . title } `
113
- } ,
114
- preventSubmit : true ,
115
- } ) ;
116
- } else {
117
- console . error ( "Could not find element for mapping selector (typeahead)." ) ;
118
- }
148
+ } ) ;
149
+ }
150
+ optionsContainer . appendChild ( division ) ;
151
+ } )
152
+ } ) . catch ( error => {
153
+ console . error ( 'Error while fetch Mapping Ids' + error )
154
+ } )
155
+
119
156
}
120
157
121
158
/**
122
159
* Invoked each time the custom element is disconnected from the document's DOM.
123
160
*/
124
161
disconnectedCallback ( ) : void {
125
- return ;
126
162
}
127
163
128
164
/**
@@ -156,12 +192,8 @@ class MappingInputProvider extends HTMLElement {
156
192
executeMapping ( ) : Promise < any > ;
157
193
async executeMapping ( download : boolean = false ) : Promise < any > {
158
194
document . body . style . cursor = 'wait' ;
159
- let inputElement : HTMLInputElement = < HTMLInputElement > (
160
- this . shadowRoot . getElementById ( "mappingchooser" )
161
- ) ;
162
- const selectedValue = inputElement ?. value ;
163
- const selectedMappingId = selectedValue ?. split ( "-" ) [ 0 ] . trim ( ) ;
164
- if ( this . testingFileChooser != null ) {
195
+ const selectedMappingId = this . selectedMappingId ;
196
+ if ( selectedMappingId && this . testingFileChooser != null ) {
165
197
const uploadedFile = this . testingFileChooser . getFile ( ) ;
166
198
if ( uploadedFile != null ) {
167
199
const execUrl = this . baseUrl . toString ( ) + "api/v1/mappingExecution/" + selectedMappingId ;
@@ -210,6 +242,44 @@ class MappingInputProvider extends HTMLElement {
210
242
this . shadowRoot . removeChild ( element ) ;
211
243
URL . revokeObjectURL ( element . href ) ;
212
244
}
245
+
246
+ /**
247
+ * In case if you want to show images according the the mappingType eg: SEM,TEM etc yu can use this method
248
+ */
249
+ getImageByType ( mappingType : string ) : string {
250
+ if ( mappingType . includes ( "GEMMA" ) ) {
251
+ // Assuming gemma.png is in the assets/images folder
252
+ return "/images/gemma.png" ;
253
+ } else if ( mappingType . includes ( "SEM" ) ) {
254
+ // Assuming sem.png is in the assets/images folder
255
+ return "/images/tem.png" ;
256
+ } else if ( mappingType . includes ( "TEM" ) ) {
257
+ // Assuming tem.png is in the assets/images folder
258
+ return "/images/tem.png" ;
259
+ } else {
260
+ // Default image path when no mapping type matches
261
+ return "/images/other.png" ;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * We have used this method to capture mapping id which is later used to execute mapping
267
+ */
268
+ private handleButtonClick ( event : Event ) {
269
+ const selectedButton = event . target as HTMLElement ;
270
+ console . log ( selectedButton ) ;
271
+ // Remove the "selected" class from all buttons
272
+ const buttons = this . shadowRoot . querySelectorAll ( ".selection-button" ) ;
273
+ buttons . forEach ( ( button ) => {
274
+ button . classList . remove ( "selected-id" ) ;
275
+ } ) ;
276
+ // Add the "selected" class to the clicked button
277
+ selectedButton . classList . add ( "selected-id" ) ;
278
+
279
+ // Get the selected mapping ID from the button's ID
280
+ const selectedMappingId = selectedButton . id . replace ( "mapping-button-" , "" ) ;
281
+ this . selectedMappingId = selectedMappingId ;
282
+ }
213
283
}
214
284
215
285
// Custom Elements:
0 commit comments