Skip to content

Commit 0530f1b

Browse files
committed
initial react integration
1 parent 3fceaa4 commit 0530f1b

File tree

13 files changed

+26364
-20
lines changed

13 files changed

+26364
-20
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ hs_err_pid*
1515
.project
1616
.settings/
1717
target/
18-
src/main/resources/config/application.properties
18+
src/main/resources/config/application.properties
19+
node/
20+
src/main/resources/static/node_modules/

pom.xml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,49 @@
4343

4444

4545
<build>
46-
<plugins>
47-
<plugin>
48-
<groupId>org.springframework.boot</groupId>
49-
<artifactId>spring-boot-maven-plugin</artifactId>
50-
</plugin>
51-
</plugins>
46+
<pluginManagement>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-maven-plugin</artifactId>
51+
</plugin>
52+
<plugin>
53+
<groupId>com.github.eirslett</groupId>
54+
<artifactId>frontend-maven-plugin</artifactId>
55+
<version>0.0.24</version>
56+
<configuration>
57+
<workingDirectory>src/main/resources/static</workingDirectory>
58+
</configuration>
59+
<executions>
60+
<execution>
61+
<id>install node and npm</id>
62+
<goals>
63+
<goal>install-node-and-npm</goal>
64+
</goals>
65+
<configuration>
66+
<nodeVersion>v0.10.33</nodeVersion>
67+
<npmVersion>1.3.8</npmVersion>
68+
</configuration>
69+
</execution>
70+
<execution>
71+
<id>npm install</id>
72+
<goals>
73+
<goal>npm</goal>
74+
</goals>
75+
<configuration>
76+
<arguments>install</arguments>
77+
</configuration>
78+
</execution>
79+
<execution>
80+
<id>webpack build</id>
81+
<goals>
82+
<goal>webpack</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
</plugins>
88+
</pluginManagement>
5289
</build>
5390

5491
</project>

src/main/java/com/shadowaterservices/thehub/controllers/AppController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AppController {
1414

1515
@RequestMapping("/")
1616
public ModelAndView index() {
17-
ModelAndView mav = new ModelAndView("users");
17+
ModelAndView mav = new ModelAndView("index");
1818
mav.addObject("users", userRepository.findAll());
1919
return mav;
2020
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
define(function() {
2+
'use strict';
3+
4+
/* Convert a single or array of resources into "URI1\nURI2\nURI3..." */
5+
return {
6+
read: function(str /*, opts */) {
7+
return str.split('\n');
8+
},
9+
write: function(obj /*, opts */) {
10+
// If this is an Array, extract the self URI and then join using a newline
11+
if (obj instanceof Array) {
12+
return obj.map(function(resource) {
13+
return resource._links.self.href;
14+
}).join('\n');
15+
} else { // otherwise, just return the self URI
16+
return obj._links.self.href;
17+
}
18+
}
19+
};
20+
21+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
define(function(require) {
2+
'use strict';
3+
4+
var interceptor = require('rest/interceptor');
5+
6+
return interceptor({
7+
request: function (request /*, config, meta */) {
8+
/* If the URI is a URI Template per RFC 6570 (http://tools.ietf.org/html/rfc6570), trim out the template part */
9+
if (request.path.indexOf('{') === -1) {
10+
return request;
11+
} else {
12+
request.path = request.path.split('{')[0];
13+
return request;
14+
}
15+
}
16+
});
17+
18+
});

src/main/resources/static/app.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
const client = require('./client');
5+
6+
class App extends React.Component {
7+
8+
constructor(props) {
9+
super(props);
10+
this.state = {users: []};
11+
}
12+
13+
componentDidMount() {
14+
client({method: 'GET', path: '/api/users'}).done(response => {
15+
this.setState({users: response.entity._embedded.users});
16+
});
17+
}
18+
19+
render() {
20+
return (
21+
<UserList users={this.state.users}/>
22+
)
23+
}
24+
}
25+
26+
class UserList extends React.Component{
27+
render() {
28+
var users = this.props.users.map(user =>
29+
<User key={user._links.self.href} user={user}/>
30+
);
31+
return (
32+
<table>
33+
<tr>
34+
<th>First Name</th>
35+
<th>Last Name</th>
36+
</tr>
37+
{users}
38+
</table>
39+
)
40+
}
41+
}
42+
43+
class User extends React.Component{
44+
render() {
45+
return (
46+
<tr>
47+
<td>{this.props.user.firstName}</td>
48+
<td>{this.props.user.lastName}</td>
49+
</tr>
50+
)
51+
}
52+
}
53+
54+
React.render(
55+
<App />,
56+
document.getElementById('react')
57+
)
58+

0 commit comments

Comments
 (0)