Skip to content

Commit

Permalink
25 display version number in web pages and sample client (#29)
Browse files Browse the repository at this point in the history
* Displaying version client page

* Displaying version in index page
# Conflicts:
#	objectmorph-app/src/main/resources/public/client.html

* Rebase rectification + home link
  • Loading branch information
mohamed-ennahdi authored Dec 23, 2024
1 parent 33038eb commit 170c0b3
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 83 deletions.
20 changes: 18 additions & 2 deletions objectmorph-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>objectmorph-app</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<name>objectmorph-app</name>
<description>Demo project for Spring Boot</description>
Expand All @@ -17,7 +17,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -54,7 +53,24 @@
<imageName>docker.io/ennahdi/${project.artifactId}:${project.version}</imageName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.mohamedennahdi.objectmorph.app.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -18,6 +20,9 @@ public class ObjectmorphController {

ObjectmorphService objectmorphService;

@Value("${spring.application.version}")
private String applicationVersion;

public ObjectmorphController(ObjectmorphService objectmorphService) {
this.objectmorphService = objectmorphService;
}
Expand All @@ -35,4 +40,15 @@ public ObjectmorphController(ObjectmorphService objectmorphService) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@CrossOrigin(origins = "*")
@GetMapping( value = "/version" )
public ResponseEntity<String> version() {
try {
return new ResponseEntity<>(applicationVersion, HttpStatus.OK);
} catch (Exception e) {
log.error("Error in ObjectmorphController", e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
8 changes: 7 additions & 1 deletion objectmorph-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
spring:
application:
name: "objectmorph-app"
name: "@project.name@"
version: "@project.version@"
description: "@project.description@"
groupId: "@project.groupId@"
artifactId: "@project.artifactId@"
logging:
level:
root: INFO
pattern:
console: "[%level] %d{yyyy-MM-dd HH:mm:ss} - %logger{1.} - %msg%n"
server:
max-http-request-header-size: 65000
128 changes: 66 additions & 62 deletions objectmorph-app/src/main/resources/public/client.html
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Objectmorph-Sample-Client</title>
</head>
<body>
<h1>Objectmorph Sample Client</h1>
<h3>
This page executes client side code.
</h3>
<h4>
<i>Executable locally.</i>
</h4>
<div align="center" >
<textarea id="notepad" placeholder="drag and drop Java source code files here" cols="64" rows="16"></textarea>
</div>
</body>
<script>
var notepad = document.getElementById('notepad');
var files = [];
function dropfile(file) {
var reader = new FileReader();
reader.onload = function(e) {
files.push(encodeURIComponent(e.target.result));
};
reader.readAsText(file, "UTF-8");
}
<head>
<meta charset="UTF-8">
<title>Objectmorph-Sample-Client</title>
<script type="text/javascript" src="version.js" ></script>
</head>
<body onload="getVersion()" >
<a href = "/" >Home</a>
<h1>Objectmorph Sample Client</h1>
<h3>This page executes client side code.</h3>
<h4>
<i>Executable locally.</i>
</h4>
<div align="center">
<textarea id="notepad" placeholder="drag and drop Java source code files here" cols="64" rows="16" ></textarea>
</div>
</body>
<footer >
<div align="right" >
<p align="right" >
Version: <b><label id="paragraphVersion" ></label></b>
</p>
</div>
</footer>
<script>
var notepad = document.getElementById('notepad');
var files = [];
function dropfile(file) {
var reader = new FileReader();
reader.onload = function(e) {
files.push(encodeURIComponent(e.target.result));
};
reader.readAsText(file, "UTF-8");
}

notepad.ondrop = function(e) {
e.preventDefault();
e.dataTransfer.setData("text/plain","data set in dragstart");
for (const file of e.dataTransfer.files) {
if (!file.name.includes(".java")) {
continue;
notepad.ondrop = function(e) {
e.preventDefault();
e.dataTransfer.setData("text/plain","data set in dragstart");
for (const file of e.dataTransfer.files) {
if (!file.name.includes(".java")) {
continue;
}
dropfile(file);
}
dropfile(file);
}
setTimeout(() => {
UserAction(files);
}, 250);
files = [];
};
setTimeout(() => {
UserAction(files);
}, 250);
files = [];
};

function UserAction(file) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
const winUrl = URL.createObjectURL(
new Blob([this.responseText], { type: "text/html" })
);

const win = window.open(
winUrl,
"win",
`width=512,height=512`
);
}
};
var url = location.protocol + '//' + location.host + "/html";
xhttp.open("POST", url, true);
var data = new FormData();
data.append('sourceCode', file);
xhttp.send(data);
}
</script>
function UserAction(file) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
console.log(this.responseText);
const winUrl = URL.createObjectURL(new Blob([this.responseText], { type: "text/html" }));
const win = window.open(winUrl, "win", `width=512,height=512`);
} else {
alert('Error: ' + this.status + " " + this.responseText);
}
};
}
var url = location.protocol + '//' + location.host + "/html";
xhttp.open("POST", url, true);
var data = new FormData();
data.append('sourceCode', file);
xhttp.send(data);
}
</script>
</html>
44 changes: 26 additions & 18 deletions objectmorph-app/src/main/resources/public/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to ObjectMorph Application</title>
</head>
<body>
<h1>ObjectMorph application</h1>
<div>
<p>
The HTML endpoint: <a href="/html" >HTML Renderer</a>.
</p>
<p>
The Swagger page <a href="/swagger-ui/index.html" >here</a>.
</p>
<p>
Access to the sample client <a href="/client.html" >here</a>.
</p>
</div>
</body>
<head>
<meta charset="UTF-8">
<title>Welcome to ObjectMorph Application</title>
<script type="text/javascript" src="version.js"></script>
</head>
<body onload="getVersion()" >
<h1>ObjectMorph application <i>(Beta version)</i></h1>
<div>
<p>
The HTML endpoint: <a href="/html">HTML Renderer</a>.
</p>
<p>
The Swagger page <a href="/swagger-ui/index.html">here</a>.
</p>
<p>
Access to the sample client <a href="/client.html">here</a>.
</p>
</div>
</body>
<footer>
<div align="right">
<p align="right">
Version: <b><label id="paragraphVersion"></label></b>
</p>
</div>
</footer>
</html>
15 changes: 15 additions & 0 deletions objectmorph-app/src/main/resources/public/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function getVersion() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
document.getElementById("paragraphVersion").outerText = this.responseText;
} else {
alert('Error: ' + this.status + " " + this.responseText);
}
}
};
var url = location.protocol + '//' + location.host + "/version";
xhttp.open("GET", url, true);
xhttp.send(null);
}

0 comments on commit 170c0b3

Please sign in to comment.