Skip to content

Commit

Permalink
Merge branch 'master' into Start_page_design&CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBuzdin authored Sep 4, 2018
2 parents 377efd9 + 89a048e commit 90afc5b
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 64 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: java
install: true
sudo: false
script: mvn clean test
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ public List<EventDto> getAllAuthorEvents() {
.map(e -> new EventDto(e.getName(), e.getDescription(), e.getDate(), e.getTime(), e.getId(), e.getAgenda()))
.collect(Collectors.toList());
}
}


@POST
@Path("/delete/{id}")
@RolesAllowed({"USER", "ADMIN"})
public void deleteEvent(@PathParam("id") Long id) throws IllegalArgumentException {
eventStore.deleteEventById(id);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ public Optional<Event> getEventById(Long id) {
.getResultStream()
.findFirst();
}

public List<Event> getAuthorEvents(User user) {
return em.createQuery("select e from Event e where e.author=:user", Event.class)
.setParameter("user", user)
.getResultList();
}

public int deleteEventById(Long id){
return em.createQuery("delete from Event e where e.id=:id",Event.class)
.setParameter("id",id)
.executeUpdate();
}
}
44 changes: 0 additions & 44 deletions src/main/webapp/app/javascript/event_logic.js

This file was deleted.

78 changes: 59 additions & 19 deletions src/main/webapp/app/jsp/add-event.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,30 @@
function getDataFromField() {
var name = document.getElementById("name");
data["name"] = name.value;
var eventdate = document.getElementById("datepicker");
data["date"] = eventdate.value;
data["name"] = (name.value).trim();
if(name === "" || name === " ") {
return;
}
var description = document.getElementById("description");
data["description"] = description.value;
data["description"] = (description.value).trim();
if(description === "" || description === " ") {
return;
}
var agenda = document.getElementById("agenda");
data["agenda"] = agenda.value;
data["agenda"] = (agenda.value).trim();
if(agenda === "" || agenda === " ") {
return;
}
var eventdate = document.getElementById("datepicker");
data["date"] = eventdate.value;
if((eventdate.value) === "") {
return;
}
var eventtime=document.getElementById("timepicker");
data["time"] = eventtime.value;
data["time"] = (eventtime.value).trim();
if((eventtime.value) === "" || (eventtime.value) === " ") {
return;
}
if (id) {
data["id"] = id;
Expand All @@ -65,30 +80,55 @@
getEventDataFromDB();
document.getElementById("add").classList.add("w3-hide");
document.getElementById("edit").classList.remove("w3-hide");
document.getElementById("update").classList.remove("w3-hide")
document.getElementById("update").classList.remove("w3-hide");
document.getElementById("save").classList.add("w3-hide")
}
else {
document.getElementById("add").classList.remove("w3-hide");
document.getElementById("edit").classList.add("w3-hide");
document.getElementById("update").classList.add("w3-hide")
document.getElementById("save").classList.remove("w3-hide")
document.getElementById("update").classList.add("w3-hide");
document.getElementById("save").classList.remove("w3-hide");
}
}
function saveDataToDB() {
getDataFromField();
fetch("<c:url value='/api/event/save'/>", {
"method": "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}, body: JSON.stringify(data)
}).then(function (response) {
location.href = "<c:url value='/app/jsp/start.jsp'/>";
});
if(data.name == "" || data.name == " ") {
alert("Please input Event Name");
return;
} else {
if (data.description == "" || data.description == " ") {
alert("Please input Event Description");
return;
} else {
if (data.agenda == "" || data.agenda == " ") {
alert("Please input Event Agenda");
return;
} else {
// if (data.date == "" || data.date == " ") {
if (data.date == "") {
alert("Please input Event Date");
return;
} else {
if (data.time == "" || data.time == " ") {
alert("Please input Event Time");
return;
}
}
}
}
}
fetch("<c:url value='/api/event/save'/>", {
"method": "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}, body: JSON.stringify(data)
}).then(function (response) {
location.href = "<c:url value='/app/jsp/start.jsp'/>";
});
}
function updateData() {
Expand Down
15 changes: 15 additions & 0 deletions src/main/webapp/app/jsp/my-events.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<p>
<button onclick="goToEditPage('{{eventID}}')" id="goToEdit">Edit</button>
<button onclick="deleteEvent('{{eventID}}'),window.location.reload()" id="delete">Delete</button>
<button onclick="goToCreatePoolPage()" id="createPoolButton">Create Pool</button>

</p>
Expand Down Expand Up @@ -61,6 +62,20 @@
location.href = "<c:url value='/app/jsp/add-event.jsp?id='/>" + x;
}
function deleteEvent(x) {
fetch("<c:url value='/api/event/delete/'/>" + x, {
"method": "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
}).then(function (response) {
if (response.status === 200) {
location.reload();
}
})
}
class EventList {
constructor(events) {
this.eventList = events
Expand Down

0 comments on commit 90afc5b

Please sign in to comment.