Skip to content

Commit 6746c21

Browse files
committed
add HTML stuff
1 parent 85eb0d9 commit 6746c21

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-17
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
hs_err_pid*
66

77
target/**
8-
vscode/**
9-
metals/**
10-
bsp/**
11-
bloop/**
8+
project/**
9+
.vscode/**
10+
.metals/**
11+
.bsp/**
12+
.bloop/**

index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
<head>
44
<title>Scala.js</title>
5+
<link rel="stylesheet" href="style.css">
56
</head>
67

78
<body>
8-
<input type="text" id="txtname" placeholder="Enter your name" value="User"></input>
9-
<div id="status">Hello</div>
9+
<b>Step 1 - Generate the decision matrix content</b>
10+
<br/>
11+
<textarea id="textarea_decmat"
12+
placeholder="Enter and copy & paste the decision matrix content here"
13+
rows="10" cols="50">
14+
0.3 0.4 0.5 0.6 0.7
15+
0.2 0.3 0.4 0.5 0.6
16+
0.1 0.2 0.3 0.4 0.5
17+
</textarea>
18+
<br/>
19+
<input id="btn_generate_decmat" type="button" value="Generate">
20+
<div id = "div_decmat_output">..</div>
1021
</body>
1122

1223

13-
<script src="./target/scala-3.5.2/mcdm-fastopt.js"></script>
24+
<script src="./target/scala-3.6.4/mcdm-fastopt.js"></script>
1425

15-
</html>
26+
</html>

src/main/scala/Main.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1+
package org.expr.mcdm
2+
13
import org.scalajs.dom
24
import org.scalajs.dom.HTMLInputElement
35
import org.scalajs.dom.HTMLDivElement
6+
import org.scalajs.dom.HTMLButtonElement
7+
import org.scalajs.dom.HTMLTextAreaElement
8+
import org.w3c.dom.html.HTMLUListElement
49

510

611
val document = dom.document
712
val window = dom.window
8-
val status: HTMLDivElement = document.getElementById("status").asInstanceOf[HTMLDivElement]
9-
10-
def status(msg: String): Unit =
11-
status.textContent = msg
1213

14+
def registerEvents(): Unit =
15+
val input: HTMLInputElement = document.getElementById("btn_generate_decmat").asInstanceOf[HTMLInputElement]
16+
window.console.log("We are in registerEvents")
17+
input.onclick = (e: dom.Event) =>
18+
window.console.log("Button clicked")
19+
val decmatoutput: HTMLDivElement = document.getElementById("div_decmat_output").asInstanceOf[HTMLDivElement]
20+
val textarea : HTMLTextAreaElement = document.getElementById("textarea_decmat").asInstanceOf[HTMLTextAreaElement]
21+
val textcontent = textarea.value
22+
decmatoutput.innerHTML = ""
23+
decmatoutput.appendChild(HtmlUtils.makeTable(HtmlUtils.parseTextToTable(textcontent)))
1324
@main def hello(): Unit =
14-
val txtname = document.getElementById("txtname").asInstanceOf[HTMLInputElement]
15-
txtname.oninput = (e: dom.Event) => {
16-
status("Hello, " + txtname.value)
17-
}
18-
status("Ready")
25+
window.console.log("Hello, world!")
26+
registerEvents()
27+
window.console.log("Registered events")
1928

2029

src/main/scala/htmlutils.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.expr.mcdm
2+
3+
import org.scalajs.dom
4+
import org.scalajs.dom.HTMLInputElement
5+
import org.scalajs.dom.HTMLDivElement
6+
7+
object HtmlUtils:
8+
val document = dom.document
9+
val window = dom.window
10+
11+
def makeTable(a: Mat): dom.HTMLTableElement =
12+
val table = document.createElement("table").asInstanceOf[dom.HTMLTableElement]
13+
a.foreach(row =>
14+
val tr = document.createElement("tr").asInstanceOf[dom.HTMLTableRowElement]
15+
row.foreach(cell =>
16+
val td = document.createElement("td").asInstanceOf[dom.HTMLTableCellElement]
17+
td.className = "matrixcell"
18+
td.textContent = cell.toString
19+
tr.appendChild(td)
20+
)
21+
table.appendChild(tr)
22+
)
23+
table
24+
25+
def parseTextToTable(text: String): Mat =
26+
text.split("\n").map(row => row.split(" ").map(cell => cell.toDouble))

style.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.matrixcell {
2+
height: 20px;
3+
border: 1px solid black;
4+
text-align: center;
5+
font-size: 16px;
6+
font-weight: bold;
7+
color: black;
8+
background-color: white;
9+
}
10+
11+
input[type="button"] {
12+
height: 30px;
13+
background-color: #4CAF50;
14+
color: white;
15+
font-size: 16px;
16+
font-weight: bold;
17+
border: none;
18+
}

0 commit comments

Comments
 (0)