Skip to content

Commit f40b09c

Browse files
committed
feat: replaced search bar with descriptive block for selection.
1 parent 8a6ca7a commit f40b09c

File tree

3 files changed

+135
-241
lines changed

3 files changed

+135
-241
lines changed

src/main.ts

Lines changed: 40 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import templateContent from "./template.html?raw";
22
import * as FilePondLib from "filepond";
33
import { FilePond, FilePondOptions } from "filepond";
44
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";
75
import customCSS from './style.css?inline';
86

97
const ATTRIBUTES: string[] = ["base-url"];
@@ -23,7 +21,6 @@ class MappingInputProvider extends HTMLElement {
2321

2422
selectedMappingId: string | null = null;
2523
selectedMappingType: string | null = null;
26-
2724
messageDisplayed: boolean | null = null;
2825
// --- Helper methods
2926
addCssContent(css: string): void {
@@ -48,7 +45,6 @@ class MappingInputProvider extends HTMLElement {
4845
// Create Shadow DOM
4946
this.shadowRoot = this.attachShadow({ mode: "open" });
5047
this.addCssContent(filepondCSS);
51-
this.addCssContent(typeaheadCSS);
5248
this.addCssContent(customCSS);
5349

5450
// Apply HTML Template to shadow DOM
@@ -97,36 +93,20 @@ class MappingInputProvider extends HTMLElement {
9793
this.testingFileChooser = FilePondLib.create(filepondElement, options);
9894
}
9995

100-
//Box of detailed contents like title , description
96+
//Box of detailed contents like image, description of mapping
10197
const mappingIdsEndpoint = this.baseUrl.toString() + "api/v1/mappingAdministration/";
10298
let optionsContainer: HTMLElement = <HTMLInputElement>(
10399
this.shadowRoot.getElementById('options-container')
104100
);
105-
optionsContainer.addEventListener("click", (event) => {
106-
const selectedButton = event.target as HTMLElement;
107-
console.log(selectedButton);
108-
// Remove the "selected" class from all buttons
109-
const buttons = optionsContainer.querySelectorAll(".selection-button");
110-
// console.log(buttons);
111-
buttons.forEach((button) => {
112-
button.classList.remove("selected-id");
113-
114-
});
115-
// Add the "selected" class to the clicked button
116-
selectedButton.classList.add("selected-id");
101+
// Remove any existing event listeners before adding a new one
102+
optionsContainer.removeEventListener("click", this.handleButtonClick.bind(this));
117103

118-
// Get the selected mapping ID from the button's ID
119-
const selectedMappingId = selectedButton.id.replace("mapping-button-", "");
120-
this.selectedMappingId = selectedMappingId;
121-
122-
// const selectedType=selectedButton
123-
console.log(selectedButton);
124-
});
104+
// Add the event listener
105+
optionsContainer.addEventListener("click", this.handleButtonClick.bind(this));
125106

126107
fetch(mappingIdsEndpoint).then(response => response.json())
127108
.then((mappingIdsData: MappingItem[]) => {
128109
const mappingIds = mappingIdsData.map((item: MappingItem) => ({
129-
130110
id: item.mappingId,
131111
title: item.title,
132112
description: item.description,
@@ -135,63 +115,39 @@ class MappingInputProvider extends HTMLElement {
135115
optionsContainer.innerHTML = '';
136116
mappingIds.forEach(mapping => {
137117
const division = document.createElement("div")
138-
// const button = document.createElement("button");
139-
// button.classList.add("xyz");
140-
division.classList.add("xyz");
141-
// button.setAttribute("data-test", "start-basics");
142-
// button.id = `${mapping.id}`;
143-
// button.innerText = "Select";
144-
145-
//<span class="selected-type section-type">Type : ${mapping.type}</span>
146-
// <span class="home-price section-heading"> ${mapping.title}</span>
118+
division.classList.add("cards");
147119
division.innerHTML = `
120+
<!-- Commenting out the image section -->
121+
<!--
148122
<img class="mapping-image" src="${this.getImageByType(mapping.type)}" alt="Mapping Image" />
149-
150-
123+
-->
124+
<h3>${mapping.title}</h3>
151125
<span class="home-text10 section-description">
152126
<br>
153127
<span style="display:inline-block; overflow: auto; height: 124px;">
154128
${mapping.description}
155129
</span>
156-
<span></span>
157130
</span>
158131
<button class ="selection-button " id="mapping-button-${mapping.id}" >Select</button>
159-
160-
161132
`;
162-
163133
const button = division.querySelector(`#mapping-button-${mapping.id}`);
164-
165134
if (button) {
166135
button.addEventListener("click", () => {
167136
this.selectedMappingId = mapping.id;
168-
169-
console.log(this.selectedMappingId);
170137
if (!this.messageDisplayed) {
171138
const fileInput = this.shadowRoot.querySelector("#fileUpload");
172-
173139
const messageElement = document.createElement("div");
174-
// messageElement.style.display = "none";
175140
messageElement.innerText = "Please upload file and then click on map document to extract metadata";
176141
messageElement.style.marginBottom = "10px"; // Add some bottom margin for spacing
177142
messageElement.classList.add("message");
178143
if (fileInput != null && fileInput.parentNode != null) {
179144
fileInput.parentNode.insertBefore(messageElement, fileInput);
180145
}
181146
this.messageDisplayed = true;
182-
183147
}
184-
185-
// this.displayMessage("Please upload file and then click on map document to extract metadata");
186-
// this.executeMapping(selectedMappingId);
187-
const selectedMappingType = mapping.type;
188-
console.log(selectedMappingType);
189-
190-
191148
});
192149
}
193150
optionsContainer.appendChild(division);
194-
195151
})
196152
}).catch(error => {
197153
console.error('Error while fetch Mapping Ids' + error)
@@ -203,7 +159,6 @@ class MappingInputProvider extends HTMLElement {
203159
* Invoked each time the custom element is disconnected from the document's DOM.
204160
*/
205161
disconnectedCallback(): void {
206-
return;
207162
}
208163

209164
/**
@@ -238,9 +193,6 @@ class MappingInputProvider extends HTMLElement {
238193
async executeMapping(download: boolean = false): Promise<any> {
239194
document.body.style.cursor = 'wait';
240195
const selectedMappingId = this.selectedMappingId;
241-
// const selectedValue = inputElement?.value;
242-
// console.log('Selected Value ' +selectedValue)
243-
// const selectedMappingId = selectedValue?.split("-")[0].trim();
244196
if (selectedMappingId && this.testingFileChooser != null) {
245197
const uploadedFile = this.testingFileChooser.getFile();
246198
if (uploadedFile != null) {
@@ -291,17 +243,43 @@ class MappingInputProvider extends HTMLElement {
291243
URL.revokeObjectURL(element.href);
292244
}
293245

246+
/**
247+
* In case if you want to show images according the the mappingType eg: SEM,TEM etc yu can use this method
248+
*/
294249
getImageByType(mappingType: string): string {
295250
if (mappingType.includes("GEMMA")) {
296-
return "https://th.bing.com/th/id/R.13af2c708c50701c5c418f39f1032c4a?rik=Bhi%2fy8GZ%2fC%2b1%2bg&riu=http%3a%2f%2flogos.textgiraffe.com%2flogos%2flogo-name%2fGemma-designstyle-pastel-m.png&ehk=oiRKyC5Jg2VKEybuGyH%2f8q4l73rWTBZpvXw7hP69AOk%3d&risl=&pid=ImgRaw&r=0";
251+
// Assuming gemma.png is in the assets/images folder
252+
return "/images/gemma.png";
297253
} else if (mappingType.includes("SEM")) {
298-
return "https://th.bing.com/th/id/R.aaebd43a8dc60519d02c93699d67fa33?rik=c9P%2bsFde%2bGc8gg&riu=http%3a%2f%2fwww.benspaintsupply.com%2fwp-content%2fuploads%2f2011%2f10%2fSEM-Logo.jpg&ehk=n3cCc0XCRDKt0XFslLWIafoPO6zFEMc91UZQJA6hxuA%3d&risl=&pid=ImgRaw&r=0";
254+
// Assuming sem.png is in the assets/images folder
255+
return "/images/tem.png";
299256
} else if (mappingType.includes("TEM")) {
300-
return "https://en.tem.ch/wp-content/uploads/sites/2/2019/08/TEM_Logo_Ohne_Claim.jpg";
257+
// Assuming tem.png is in the assets/images folder
258+
return "/images/tem.png";
301259
} else {
302-
return "https://th.bing.com/th/id/OIP.dDFaFWAAhofP-4yOMUOsCwHaD5?pid=ImgDet&rs=1";
260+
// Default image path when no mapping type matches
261+
return "/images/other.png";
303262
}
304263
}
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+
}
305283
}
306284

307285
// Custom Elements:

src/style.css

Lines changed: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
input {
2-
padding: 0.625rem;
3-
font-size: 0.875rem;
4-
border: 1px solid #ccc;
5-
border-radius: 0.25rem;
6-
width: 23.625rem;
7-
}
8-
91
#fileUpload {
102
padding: 0.625rem;
113
width: auto;
@@ -42,33 +34,106 @@ button:hover {
4234
transform: translateY(-0.125rem);
4335
}
4436

45-
.mapping-container {
46-
max-width: 37.5rem;
47-
margin: 0 auto;
37+
.home-text08 {
38+
font-size: 2rem;
39+
}
40+
41+
.home-text09 {
42+
font-size: 1.125rem;
43+
}
44+
45+
.message {
46+
background-color: #eaf0b0;
47+
align-content: center;
4848
text-align: center;
49+
color: #333;
50+
padding: 0.625rem 1.25rem;
51+
margin-bottom: 0.625rem;
52+
margin-left: 1.5625rem;
53+
margin-right: 1.5625rem;
54+
font-size: 1rem;
55+
font-weight: bold;
56+
border-radius: 0.3125rem;
57+
animation: fade-in 0.3s ease-in-out;
4958
}
5059

51-
.mapping-title {
52-
font-size: 2rem;
53-
margin-bottom: 1.25rem;
60+
.selection-button.selected-id {
61+
/* Add your selected button styles here */
62+
background-color: rgb(137, 202, 84);
63+
color: #fff;
5464
}
5565

56-
.mapping-input-container {
66+
.mapping-options {
5767
display: flex;
68+
flex-direction: column;
5869
align-items: center;
59-
max-width: 25rem;
60-
margin: 0 auto;
61-
background-color: #fff;
62-
border-radius: 3.125rem;
63-
padding: 0.625rem 1.25rem;
64-
box-shadow: 0 0.125rem 0.3125rem rgba(0, 0, 0, 0.3);
65-
width: fit-content;
70+
padding: 1.25rem;
6671
}
6772

68-
.mapping-input {
69-
flex: 1;
70-
border: none;
71-
outline: none;
72-
font-size: 1.125rem;
73+
.container-wrapper {
74+
display: flex;
75+
justify-content: center;
76+
width: 100%;
77+
overflow-x: auto;
78+
align-self: center;
79+
padding: 1.25rem;
80+
}
81+
82+
.options-container {
83+
display: flex;
84+
flex-wrap: nowrap;
85+
justify-content: center;
86+
overflow-x: auto;
87+
padding-bottom: 0.625rem;
88+
}
89+
90+
.cards {
91+
flex: 0 0 calc(25% - 1.25rem);
92+
display: flex;
93+
flex-wrap: wrap;
94+
flex-direction: column;
95+
align-items: center;
96+
justify-content: center;
97+
text-align: center;
7398
padding: 0.625rem;
99+
box-sizing: border-box;
100+
border: 1px solid #ccc;
101+
margin: 0.625rem;
102+
overflow: hidden;
103+
position: relative;
104+
min-width: 12.5rem;
105+
/* Added minimum width for better mobile view */
106+
background-color: #eef3f4;
107+
/* Add your desired background color here */
108+
}
109+
110+
.cards img {
111+
max-width: 6.25rem;
112+
margin-bottom: 0.625rem;
113+
}
114+
115+
.cards h2 {
116+
margin-bottom: 0.625rem;
117+
white-space: normal;
118+
overflow-wrap: break-word;
119+
cursor: pointer;
120+
width: 100%;
121+
background-color: #c49898;
122+
color: #333;
123+
padding: 0.3125rem;
124+
border-radius: 0.3125rem;
125+
}
126+
127+
.cards div {
128+
text-align: center;
129+
white-space: normal;
130+
}
131+
132+
.home-heading-container {
133+
text-align: center;
134+
}
135+
136+
.section-heading {
137+
/* background-color: #c52222; */
138+
font-size: large;
74139
}

0 commit comments

Comments
 (0)