@@ -2,19 +2,26 @@ import templateContent from "./template.html?raw";
22import * as FilePondLib from "filepond" ;
33import { FilePond , FilePondOptions } from "filepond" ;
44import filepondCSS from "filepond/dist/filepond.min.css?inline" ;
5- import typeahead from "typeahead-standalone" ;
6- import typeaheadCSS from "typeahead-standalone/dist/basic.css?inline" ;
75import customCSS from './style.css?inline' ;
86
97const ATTRIBUTES : string [ ] = [ "base-url" ] ;
8+ interface MappingItem {
9+ mappingId : string ;
10+ title : string ;
11+ description ?: string ;
12+ mappingType : string ;
13+ name : string ;
14+ }
1015class MappingInputProvider extends HTMLElement {
1116 shadowRoot : ShadowRoot ;
1217 private testingFileChooser : FilePond | null = null ;
1318 // --- Attribute accessible from the HTML tag:
1419 baseUrl : URL = new URL ( "http://localhost:8090/" ) ;
1520 // ---
1621
17-
22+ selectedMappingId : string | null = null ;
23+ selectedMappingType : string | null = null ;
24+ messageDisplayed : boolean | null = null ;
1825 // --- Helper methods
1926 addCssContent ( css : string ) : void {
2027 let styleElem : HTMLStyleElement = document . createElement ( "style" ) ;
@@ -38,7 +45,6 @@ class MappingInputProvider extends HTMLElement {
3845 // Create Shadow DOM
3946 this . shadowRoot = this . attachShadow ( { mode : "open" } ) ;
4047 this . addCssContent ( filepondCSS ) ;
41- this . addCssContent ( typeaheadCSS ) ;
4248 this . addCssContent ( customCSS ) ;
4349
4450 // Apply HTML Template to shadow DOM
@@ -86,43 +92,73 @@ class MappingInputProvider extends HTMLElement {
8692 options . maxFiles = 1 ;
8793 this . testingFileChooser = FilePondLib . create ( filepondElement , options ) ;
8894 }
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' )
91100 ) ;
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 ;
107147 }
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+
119156 }
120157
121158 /**
122159 * Invoked each time the custom element is disconnected from the document's DOM.
123160 */
124161 disconnectedCallback ( ) : void {
125- return ;
126162 }
127163
128164 /**
@@ -156,12 +192,8 @@ class MappingInputProvider extends HTMLElement {
156192 executeMapping ( ) : Promise < any > ;
157193 async executeMapping ( download : boolean = false ) : Promise < any > {
158194 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 ) {
165197 const uploadedFile = this . testingFileChooser . getFile ( ) ;
166198 if ( uploadedFile != null ) {
167199 const execUrl = this . baseUrl . toString ( ) + "api/v1/mappingExecution/" + selectedMappingId ;
@@ -210,6 +242,44 @@ class MappingInputProvider extends HTMLElement {
210242 this . shadowRoot . removeChild ( element ) ;
211243 URL . revokeObjectURL ( element . href ) ;
212244 }
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+ }
213283}
214284
215285// Custom Elements:
0 commit comments