Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xvitcoder.angularspringapp</groupId>
<artifactId>AngularSpringApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>AngularSpringApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xvitcoder.angularspringapp</groupId>
<artifactId>AngularSpringApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>AngularSpringApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>

</dependencies>
<build>
<finalName>AngularSpringApp</finalName>
</build>

</dependencies>
<build>
<finalName>AngularSpringApp</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.xvitcoder.angualrspringapp.beans;

public class RailwayStation {


private Long id;

private String name;

private Train train;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Train getTrain() {
return train;
}

public void setTrain(Train train) {
this.train = train;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.xvitcoder.angualrspringapp.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xvitcoder.angualrspringapp.beans.RailwayStation;
import com.xvitcoder.angualrspringapp.service.RailwayStationServiceImpl;

@Controller
@RequestMapping("/railwaystations")
public class RailwayStationController {

@Autowired
private RailwayStationServiceImpl railwayStationsService;

@RequestMapping("railwaystationlist.json")
public @ResponseBody List<RailwayStation> getRailwayStationList() {
return railwayStationsService.getAllRailwayStations();
}

@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody void addRailwayStation(@RequestBody RailwayStation railwayStation) {
railwayStationsService.addRailwayStation(railwayStation);
}

@RequestMapping(value = "/update", method = RequestMethod.PUT)
public @ResponseBody void updateRailwayStation(@RequestBody RailwayStation railwayStation) {
railwayStationsService.updateRailwayStation(railwayStation);
}

@RequestMapping(value = "/remove/{id}", method = RequestMethod.DELETE)
public @ResponseBody void removeRailwayStation(@PathVariable("id") Long id) {
railwayStationsService.deleteRailwayStationById(id);
}

@RequestMapping(value = "/removeAll", method = RequestMethod.DELETE)
public @ResponseBody void removeAllRailwayStations() {
railwayStationsService.deleteAll();
}

@RequestMapping("/layout")
public String getRailwayStationPartialPage(ModelMap modelMap) {
return "railwaystations/layout";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.xvitcoder.angualrspringapp.service;

import com.xvitcoder.angualrspringapp.beans.RailwayStation;

import java.util.List;


public interface RailwayStationService {

public List<RailwayStation> getAllRailwayStations();

public RailwayStation getRailwayStationById(Long id);

public void addRailwayStation(RailwayStation RailwayStation);

public void deleteRailwayStationById(Long id);

public void deleteAll();

public void updateRailwayStation(RailwayStation RailwayStation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.xvitcoder.angualrspringapp.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.xvitcoder.angualrspringapp.beans.RailwayStation;


@Service("RailwayStationService")
public class RailwayStationServiceImpl implements RailwayStationService {

private static List<RailwayStation> rsList = new ArrayList<RailwayStation>();
private static Long id = 0L;

public RailwayStation getRailwayStationById(Long id) {

return findRailwayStationById(id);
}

private RailwayStation findRailwayStationById(Long id) {
for (RailwayStation rs : rsList) {
if (rs.getId() == id) {
return rs;
}
}

return null;
}

public List<RailwayStation> getAllRailwayStations() {
return rsList;
}


public void addRailwayStation(RailwayStation railwayStation) {
railwayStation.setId(++ id);
rsList.add(railwayStation);

}

public void deleteRailwayStationById(Long id) {
RailwayStation found = findRailwayStationById(id);
if (found != null) {
rsList.remove(found);
id--;
}

}

public void updateRailwayStation(RailwayStation railwayStation) {
RailwayStation found = findRailwayStationById(railwayStation.getId());
if (found != null) {
rsList.remove(found);
rsList.add(railwayStation);
}
}

@Override
public void deleteAll() {
rsList.clear();
id = 0L;
}
}
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ul class="menu">
<li><a href="#/cars">Cars</a></li>
<li><a href="#/trains">Trains</a></li>
<li><a href="#/railwaystations">Railway Station</a></li>
</ul>
<hr class="" />
<div ng-view></div>
Expand All @@ -21,6 +22,7 @@
<script src="resources/js/lib/angular/angular.js"></script>
<script src="resources/js/app.js"></script>
<script src="resources/js/services.js"></script>
<script src="resources/js/controllers/RailwayStationController.js"></script>
<script src="resources/js/controllers/CarController.js"></script>
<script src="resources/js/controllers/TrainController.js"></script>
<script src="resources/js/filters.js"></script>
Expand Down
86 changes: 86 additions & 0 deletions src/main/webapp/WEB-INF/html/railwaystations/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<div class="alert alert-error" ng-show="error">{{errorMessage}}</div>
<form class="form-horizontal">

<div class="control-group">
<label class="control-label" for="rs_name">Railway Station Name</label>

<div class="controls">
<input type="text" id="rs_name" ng-model="rs.name"
placeholder="Railway Name" required min="2">
</div>
</div>


<div class="control-group">
<label class="control-label" for="train_name">Train Name</label>

<div class="controls">
<input type="text" id="train_name" ng-model="rs.train.name"
placeholder="Train Name" required min="2">
</div>
</div>
<div class="control-group">
<label class="control-label" for="train_speed">Speed</label>

<div class="controls">


<input class="span3" type="text" id="train_speed"
ng-model="rs.train.speed" placeholder="Speed" required min="1">
<span class="add-on">km/h</span>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox"> <input type="checkbox"
ng-model="rs.train.diesel"> Is Diesel
</label>
</div>
<hr />
<div class="controls">
<button type="button" class="btn btn-primary"
ng-disabled="!rs.name || !rs.train.speed" ng-hide="editMode"
ng-click="addNewRailwayStation(rs)">Add Railway Station</button>

<button type="button" class="btn btn-primary"
ng-disabled="!rs.train.name || !rs.train.speed" ng-show="editMode"
ng-click="updateRailwayStation(rs)">Save Railway Station</button>
<button type="button" class="btn" ng-click="resetRailwayStationForm()">Reset</button>
</div>
</div>
</form>
<hr />
<h3>Railway Stations List</h3>
<div class="alert alert-info" ng-show="railwaystations.length == 0">No Railway Stations found</div>
<table class="table table-bordered table-striped" ng-show="railwaystations.length > 0">
<thead>
<tr>
<th style="text-align: center; width: 25px;">Id</th>
<th style="text-align: center;">Name</th>
<!--
<th style="text-align: center;">Speed</th>
<th style="text-align: center;">Diesel</th>
-->
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in railwaystations | orderBy:predicate">
<td style="text-align: center;">{{item.id}}</td>
<td>{{item.name}}</td>


<!-- <td>{{train.speed}}</td>
<td style="text-align: center; width: 20px;"><span
ng-show="train.diesel" class="icon-ok"></span></td> -->

<td style="width: 100px; text-align: center;">
<button class="btn btn-mini btn-danger"
ng-click="removeRailwayStation(item.id)">Remove</button>
<button class="btn btn-mini btn-success" ng-click="editRailwayStation(item)">Edit</button>
</td>
</tr>
</tbody>
</table>
<button class="btn btn-danger" ng-show="railwaystations.length > 1"
ng-click="removeAllRailwayStations()">Remove All stations</button>
3 changes: 2 additions & 1 deletion src/main/webapp/WEB-INF/html/trains/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<div class="controls">


<input class="span3" type="text" id="inputSpeed" ng-model="train.speed" placeholder="Speed" required min="1">
<span class="add-on">km/h</span>
</div>
Expand Down Expand Up @@ -60,4 +61,4 @@ <h3>Trains List</h3>
</tr>
</tbody>
</table>
<button class="btn btn-danger" ng-show="trains.length > 1" ng-click="removeAllTrains()">Remove All Cars</button>
<button class="btn btn-danger" ng-show="trains.length > 1" ng-click="removeAllTrains()">Remove All Trains</button>
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/webapp-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ App.config(['$routeProvider', function ($routeProvider) {
templateUrl: 'trains/layout',
controller: TrainController
});

$routeProvider.when('/railwaystations', {
templateUrl: 'railwaystations/layout',
controller: RailwayStationController
});

$routeProvider.otherwise({redirectTo: '/cars'});
}]);
Loading