Skip to content
Open
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
49 changes: 49 additions & 0 deletions configurationapp/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions configurationapp/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>configurationapp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions configurationapp/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
2 changes: 2 additions & 0 deletions configurationapp/.settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
10 changes: 10 additions & 0 deletions configurationapp/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions configurationapp/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class ConfigurationApp {
public static void main(String[] args) {
SpringApplication.run(ConfigurationApp.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.att.data.configurations.ConfigValue;
import org.springframework.stereotype.Service;

//import javafx.util.converter.CurrencyStringConverter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Iterator;

@Service
public class ConfigurationDao {
Expand All @@ -33,16 +36,40 @@ public ConfigurationDao() {
currentConfigurations = new HashMap<>();
}

public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
return new ArrayList<>();
public List<ConfigValue> getConfigurations(String yearMonth) {
if (currentConfigurations.containsKey(yearMonth)) {
return currentConfigurations.get(yearMonth);
}
else {
return new ArrayList<>();
}
}

public void addConfiguration(String yearMonth, ConfigValue value) {
int newId = idProvider.getNextId();

if (!currentConfigurations.containsKey(yearMonth)) {
currentConfigurations.put(yearMonth,new ArrayList<>());
}
if (currentConfigurations.containsKey(yearMonth)) {
value.setConfigId(idProvider.getNextId());
currentConfigurations.get(yearMonth).add(value);
}
}

public void removeAllConfigurationsForYearMonth(String yearMonth) {
public void removeConfiguration(String yearMonth, int id) {
if (currentConfigurations.containsKey(yearMonth)) {
Iterator<ConfigValue> i = currentConfigurations.get(yearMonth).iterator();
while (i.hasNext()) {
ConfigValue item = i.next();
if (item.getConfigId() == id) {
i.remove();
}
}
}
}

public void removeAllConfigurations(String yearMonth) {
if (currentConfigurations.containsKey(yearMonth)) {
currentConfigurations.get(yearMonth).clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
Expand All @@ -17,20 +17,40 @@ public class ConfigurationController {
@Autowired
public ConfigurationController(ConfigurationDao dao) {
this.dao = dao;
this.dao.addConfiguration("012018", new ConfigValue("Test-012018-1",0));
this.dao.addConfiguration("012018", new ConfigValue("Test-012018-2",0));
this.dao.addConfiguration("012018", new ConfigValue("Test-012018-3",0));
this.dao.addConfiguration("012018", new ConfigValue("Test-012018-4",0));
this.dao.addConfiguration("012018", new ConfigValue("Test-012018-5",0));

this.dao.addConfiguration("022018", new ConfigValue("Test-202018-1",0));
this.dao.addConfiguration("022018", new ConfigValue("Test-202018-2",0));
this.dao.addConfiguration("022018", new ConfigValue("Test-202018-3",0));
this.dao.addConfiguration("022018", new ConfigValue("Test-202018-4",0));
this.dao.addConfiguration("022018", new ConfigValue("Test-202018-5",0));
}

@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET)
@ResponseBody
public List<ConfigValue> getConfigurationsForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth) {

return new ArrayList<>();
return dao.getConfigurations(yearMonth);
}

@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE)
public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {
try {
dao.removeAllConfigurations(yearMonth);
} catch (Exception ex) {

}
}

@RequestMapping(value="/{yearMonthNumber}/{id}", method=RequestMethod.DELETE)
public void deleteConfigurationForYearMonth(@PathVariable("yearMonthNumber") String yearMonth, @PathVariable("id") int id) {
try {
dao.removeConfiguration(yearMonth, id);
} catch (Exception ex) {

}
Expand All @@ -39,7 +59,8 @@ public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") St
@RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT })
public void addConfigurationForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth,
@RequestBody ConfigValue value) {

@RequestBody String name) {
dao.addConfiguration(yearMonth, new ConfigValue(name,0));
}

}
7 changes: 5 additions & 2 deletions configurationapp/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Configuration App</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="js/app.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
Expand All @@ -27,6 +27,7 @@ <h1>Welcome To The Configuration App</h1>
<tr>
<td>Configuration Id</td>
<td>Configuration Name</td>
<td>Delete</td>
</tr>
</thead>
<tbody>
Expand All @@ -35,7 +36,9 @@ <h1>Welcome To The Configuration App</h1>
</table>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
<!-- <button id="saveButton">Save Configurations</button> -->
<button id="addConfigurationItem">Add Configuration</button>
<button id="clearConfiguration">Clear Configuration</button>
</div>
</div>
<script>
Expand Down
75 changes: 69 additions & 6 deletions configurationapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
(function() {
function App() {

this.table = null;
this.curMY = "012018";
}

App.prototype.getData = function() {
$.ajax('',{
// SORRY!!! hard-coded urls!

App.prototype.getData = function(id) {
this.curMY = id;
$.ajax({
url:'/configuration/'+id, method:'GET'
}).then(function(data) {

window.app.table.clear();
window.app.table.rows.add(data);
window.app.table.draw();
})
};

App.prototype.delItem = function (id, value) {
if (confirm("Are you sure you want to delete " + value + "?")) {
$.ajax({
url:'/configuration/'+window.app.curMY+'/'+id, method:'DELETE'
}).then(function(data) {
window.app.getData(window.app.curMY);
});
}
};

App.prototype.addItem = function () {
var v = prompt("Enter the new configuration:", "");
if (v != "") {
$.ajax({
url:'/configuration/'+window.app.curMY, method:'POST',
contentType:'text/plain',
data:v
}).then(function(data) {
window.app.getData(window.app.curMY);
})
}
};

App.prototype.clearAll = function () {
if (confirm("Are you sure you want to delete all the configurations for " + this.curMY + "?")) {
$.ajax({
url:'/configuration/'+window.app.curMY, method:'DELETE'
}).then(function(data) {
window.app.getData(window.app.curMY);
})
}
};

App.prototype.init = function() {
$('#configTable').DataTable({
this.table = $('#configTable').DataTable({
scrollY: 300,
paging: false,
sorting: false,
searching: false,
info: false
info: false,
columns:[
{data:'configId'},
{data:'configName'},
{'render': function ( data, type, row ) {
return '<span onclick="window.app.delItem(' + row.configId + ', \'' + row.configName + '\');" style="color:red;cursor:pointer;"><b>X</b></span>';
}
}
]
});
$("#timePeriod").change(
function() {
window.app.getData(this.options[this.selectedIndex].value);
}
);
$("#addConfigurationItem").click(
function() {
window.app.addItem();
}
);
$("#clearConfiguration").click(
function() {
window.app.clearAll();
}
);
window.app.getData(this.curMY);
};

window.app = new App;
Expand Down
6 changes: 6 additions & 0 deletions configurationapp/target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
server.port=9000
spring.mvc.favicon.enabled=false

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions configurationapp/target/classes/static/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.controls {

}

.config-table-wrapper {

}

.content {

}
Loading