Skip to content
Snippets Groups Projects
Commit cd681f39 authored by wiepke's avatar wiepke
Browse files

costum elements start. file storage update

parent c0c497d3
No related branches found
No related tags found
No related merge requests found
Showing with 288 additions and 68 deletions
......@@ -48,4 +48,12 @@ public class FileManagementDAO {
connect.close();
return result;
}
void deleteMetaOfFile(String fileLocation){
connect.connect();
String mysqlRequest =
"DELETE FROM `largefilestorage` WHERE filelocation=?";
connect.issueInsertOrDeleteStatement(mysqlRequest, fileLocation);
connect.close();
}
}
......@@ -21,6 +21,9 @@ import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
......@@ -148,25 +151,6 @@ public class FileManagementService {
return fileName;
}
public void downloadPDF(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=" + "testPDF.pdf");
try {
File f = new File("C://New folder//itext_Test.pdf");
FileInputStream fis = new FileInputStream(f);
DataOutputStream os = new DataOutputStream(response.getOutputStream());
response.setHeader("Content-Length", String.valueOf(f.length()));
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) >= 0) {
os.write(buffer, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}
}
static File getPDFFile(String fileLocation) {
return new File(folderName + fileLocation);
}
......@@ -174,4 +158,15 @@ public class FileManagementService {
Map<String, String> getListOfFiles(User user, Project project){
return fileManagementDAO.getListOfFiles(user, project);
}
void deleteFile(String fileLocation){
try{
Path path = Paths.get("."+File.separator+folderName+File.separator+fileLocation);
Files.delete(path);
}catch(Exception e){
}
fileManagementDAO.deleteMetaOfFile(fileLocation);
}
}
\ No newline at end of file
......@@ -75,4 +75,13 @@ public class fileManagementView {
Project project = projectDAO.getProjectByName(projectName);
return fileManagementService.getListOfFiles(user, project);
}
@POST
@Path("/delete/fileLocation/{fileLocation}")
@Produces("application/json")
public Response deleteFile(@Context HttpServletRequest req,@PathParam("fileLocation") String fileLocation) throws IOException {
fileManagementService.deleteFile(fileLocation);
//Respond that everything worked out
return Response.ok("Data deletion successfull").build();
}
}
customElements.define('fl-upload',
class extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
let fileForm = document.createElement('form');
fileForm.id = "uploadForm";
let fileBtn = document.createElement('input');
fileBtn.innerText = "Suche Datei";
fileBtn.type = "file";
let uploadBtn = document.createElement('button');
uploadBtn.addEventListener('click', function () {
uploadForm(this.getAttribute('data-projectName'));
});
uploadBtn.className = "btn btn-primary";
fileForm.appendChild(fileBtn);
fileForm.appendChild(uploadBtn);
shadowRoot.appendChild(fileForm);
}
}
);
$(document).ready(function () {
errorHandler(null);
$('#uploadSubmit').on('click', function (event) {
event.preventDefault();
uploadForm($('#projectName').html().trim());
});
listFilesOfGroup($('#projectName').html().trim());
});
function errorHandler(error) {
switch (error) {
case "upload":
$('#errorUpload').show();
break;
case "deletion":
$('#errorDeletion').show();
break;
default:
$('#successUpload').hide();
$('#errorUpload').hide();
$('#fileDeleted').hide();
$('#errorDeletion').hide();
}
}
function uploadForm(projectName) {
document.getElementById('loader').className = "loader";
let data = new FormData($('#uploadForm')[0]);
$.ajax({
url: "../rest/fileStorage/presentation/projectName/" + projectName,
data: data,
dataType: "text",
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success: function (data) {
$('#successUpload').show();
document.getElementById('loader').className = "loader-inactive";
},
error: function (data) {
errorHandler("upload");
document.getElementById('loader').className = "loader-inactive";
}
});
}
function listFilesOfGroup(projectName) {
$.ajax({
url: "../rest/fileStorage/listOfFiles/projectName/" + projectName,
type: 'GET',
success: function (response) {
let tmplObject = [];
let count = 1;
for (let key in response) {
if (response.hasOwnProperty(key))
tmplObject.push({
fileCount: count,
fileLocation: key,
fileName: response[key]
});
count++;
}
$('#listOfFilesTemplate').tmpl(tmplObject).appendTo('#listOfFiles');
prepareDeletion();
},
error: function (a) {
}
});
}
function prepareDeletion() {
let linksForDeletion = $('.deleteFile');
linksForDeletion.each(function () {
$(this).on('click', function () {
$.ajax({
url: "../rest/fileStorage/delete/fileLocation/" + $(this).attr('name'),
method: 'POST',
dataType: "text",
type: 'POST',
success: function () {
$('#fileDeleted').show();
},
error: function () {
errorHandler("deletion");
}
});
});
});
}
\ No newline at end of file
......@@ -15,7 +15,7 @@
<jsp:include page="../taglibs/omniDependencies.jsp">
<jsp:param name="hierarchy" value="1"/>
</jsp:include>
<script src="js/upload-File.js"></script>
<script src="../taglibs/js/fileStorage.js" defer></script>
</head>
<body>
<div class="loader-inactive" id="loader">
......@@ -31,22 +31,51 @@
<!-- this is what we are here for -->
<ul id="listOfFiles">
<script id="listOfFilesTemplate" type="text/x-jQuery-tmpl">
<li>
<a id="${fileCount}" href="../rest/fileStorage/download/fileLocation/${fileLocation}">${fileName}</a>
<a name="${fileLocation}" class="deleteFile" style="cursor: pointer;"><i class="fa fa-trash" aria-hidden="true"></i></a>
</li>
</script>
</ul>
<form id="uploadForm" method="POST" enctype="multipart/form-data">
<p>Select a file: <input type="file" name="file" size="45" accept=".pdf, .pptx"/></p>
<label>Select a file: <input type="file" name="file" size="45" accept=".pdf, .pptx"/></label>
<button id="uploadSubmit" class="btn btn-primary">Upload File</button>
</form>
<!--works just with chrome -.- <script>
let XUploadPrototype = Object.create(HTMLElement.prototype);
XUploadPrototype.createdCallback = function(){
let shadow = this.createShadowRoot();
let fileForm = document.createElement('form');
fileForm.id = "uploadForm";
let fileBtn = document.createElement('input');
fileBtn.innerText = "Suche Datei";
fileBtn.type = "file";
let uploadBtn = document.createElement('button');
uploadBtn.addEventListener('click', function(){
uploadForm(this.getAttribute('data-projectName'));
});
uploadBtn.className = "btn btn-primary";
fileForm.appendChild(fileBtn);
fileForm.appendChild(uploadBtn);
shadow.appendChild(fileForm);
};
let XUploadElements = document.registerElement('x-upload',
{prototype: XUploadPrototype});
</script>-->
<fl-upload data-projectName="CheckThisOut"></fl-upload>
<div id="successUpload" class="alert alert-success">Die Datei wurde erfolgreich gespeichert.</div>
<div id="errorUpload" class="alert alert-warning">Ein Fehler ist beim Upload der Datei aufgetreten.</div>
<div id="fileDeleted" class="alert alert-success">Die Datei wurde erfolgreich gelöscht.</div>
<div id="errorDeletion" class="alert alert-warning">Ein Fehler ist aufgetreten beim Löschen der Datei.</div>
<!-- this is what we are here for -->
<ol id="listOfFiles">
<script id="listOfFilesTemplate" type="text/x-jQuery-tmpl">
<li><a id="${fileCount}" href="../rest/fileStorage/download/fileLocation/${fileLocation}">${fileName}</a></li>
</script>
</ol>
<div class="col span_chat span_l_of_3 right">
<chat:chatWindow orientation="right" scope="project"/>
<chat:chatWindow orientation="right" scope="group"/>
<a id="groupView" style="cursor:pointer;">Gruppenansicht</a>
</div>
<div class="row">
......
let userEmail;
let projectName;
$(document).ready(function () {
userEmail = $('#userEmail').html().trim();
projectName = $('#projectName').html().trim();
errorHandler(null);
$('#uploadSubmit').on('click', function(event){
event.preventDefault();
uploadForm();
});
listFilesOfGroup();
});
function errorHandler(error) {
......@@ -17,9 +15,14 @@ function errorHandler(error) {
case "upload":
$('#errorUpload').show();
break;
case "deletion":
$('#errorDeletion').show();
break;
default:
$('#successUpload').hide();
$('#errorUpload').hide();
$('#fileDeleted').hide();
$('#errorDeletion').hide();
}
}
......@@ -63,9 +66,30 @@ function listFilesOfGroup(){
count++;
}
$('#listOfFilesTemplate').tmpl(tmplObject).appendTo('#listOfFiles');
prepareDeletion();
},
error: function(a){
}
});
}
function prepareDeletion(){
let linksForDeletion = $('.deleteFile');
linksForDeletion.each(function(){
$(this).on('click', function(){
$.ajax({
url: "../rest/fileStorage/delete/fileLocation/"+$(this).attr('name'),
method: 'POST',
dataType: "text",
type: 'POST',
success: function(){
$('#fileDeleted').show();
},
error: function(){
errorHandler("deletion");
}
});
});
});
}
\ No newline at end of file
......@@ -31,6 +31,7 @@
<link rel="stylesheet" href="<%=new TagUtilities().hierarchyToString(hierarchyLevel)%>libs/css/Sidebar-Menu.css">
<script src="<%=new TagUtilities().hierarchyToString(hierarchyLevel)%>taglibs/js/utility.js"></script>
<script src="<%=new TagUtilities().hierarchyToString(hierarchyLevel)%>taglibs/js/footer.js"></script>
<script src="<%=new TagUtilities().hierarchyToString(hierarchyLevel)%>taglibs/js/fileStorage.js"></script>
<!--<link rel=\"stylesheet\" href=\"" + hierarchyToString(hierarchyLevel) + "project/css/all.css\">-->
<!--<link rel=\"stylesheet\" href=\"" + hierarchyToString(hierarchyLevel) + "project/css/style.css\" type=\"text/css\">-->
<link rel="stylesheet" href="<%=new TagUtilities().hierarchyToString(hierarchyLevel)%>libs/tagsinput/jquery.tagsinput.min.css">
......
......@@ -7,47 +7,78 @@
String projectName = tu.getParamterFromQuery("projectName", request);
Phase phase = tu.getPhase(projectName);
%>
<div class="loader-inactive" id="loader">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
</div>
<div class="col span_timeline timeline span_s_of_2">
<!--begin timeLine -->
<ul>
<% if (phase != null) {%>
<% if (phase == Phase.GroupFormation) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon ">Entwurfsphase</li>
<li class="icon inactive">Feedbackphase</li>
<li class="icon inactive">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.DossierFeedback) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon">Feedbackphase</li>
<li class="icon inactive">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Execution) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon closed">Feedbackphase</li>
<li class="icon">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Assessment) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon closed">Feedbackphase</li>
<li class="icon closed">Reflextionsphase</li>
<li class="icon">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Projectfinished) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed\">Entwurfsphase</li>
<li class="feedback icon closed\">Feedbackphase</li>
<li class="icon closed">Reflextionsphase</li>
<li class="icon closed">Assessment</li>
<li class="icon">Noten</li>
<%}%>
<% if (phase == Phase.GroupFormation) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon ">Entwurfsphase</li>
<li class="icon inactive">Feedbackphase</li>
<li class="icon inactive">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.DossierFeedback) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon">Feedbackphase</li>
<li class="icon inactive">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Execution) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon closed">Feedbackphase</li>
<li class="icon">Reflextionsphase</li>
<li class="icon inactive">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Assessment) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed">Entwurfsphase</li>
<li class="feedback icon closed">Feedbackphase</li>
<li class="icon closed">Reflextionsphase</li>
<li class="icon">Assessment</li>
<li class="icon inactive">Noten</li>
<%} else if (phase == Phase.Projectfinished) {%>
<li class="neutral icon closed">Projektinitialisierung</li>
<li class="draft icon closed\">Entwurfsphase</li>
<li class="feedback icon closed\">Feedbackphase</li>
<li class="icon closed">Reflextionsphase</li>
<li class="icon closed">Assessment</li>
<li class="icon">Noten</li>
<%}%>
<%}%>
</ul>
<!-- end timeLine-->
<!--begin data deletion, up- and download-->
<div style="margin-top:50px;"></div>
<h4>Ergebnisse</h4>
<ul id="listOfFiles">
<script id="listOfFilesTemplate" type="text/x-jQuery-tmpl">
<li>
<a id="${fileCount}" href="../rest/fileStorage/download/fileLocation/${fileLocation}">${fileName}</a>
<a name="${fileLocation}" class="deleteFile" style="cursor: pointer;"><i class="fa fa-trash" aria-hidden="true"></i></a>
</li>
</script>
</ul>
<form id="uploadForm" method="POST" enctype="multipart/form-data">
<label>Select a file: <input type="file" name="file" size="45" accept=".pdf, .pptx"/></label>
<button id="uploadSubmit" class="btn btn-primary">Upload File</button>
</form>
<div id="successUpload" class="alert alert-success">Die Datei wurde erfolgreich gespeichert.</div>
<div id="errorUpload" class="alert alert-warning">Ein Fehler ist beim Upload der Datei aufgetreten.</div>
<div id="fileDeleted" class="alert alert-success">Die Datei wurde erfolgreich gelöscht.</div>
<div id="errorDeletion" class="alert alert-warning">Ein Fehler ist aufgetreten beim Löschen der Datei.</div>
<!--end data deletion, up- and download-->
</div>
<%!
......
......@@ -38,6 +38,8 @@ CREATE TABLE `categoriesselected` (
`categorySelected` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='NOT IMPLEMENTED';
--user with userName in project projectName gets quantitative feedback from fromPeer.
--This feedback ranges between 1 and 5 for the categories dossier, eJournal and research.
CREATE TABLE `contributionrating` (
`projectName` varchar(200) NOT NULL,
`userName` varchar(100) NOT NULL,
......@@ -45,8 +47,12 @@ CREATE TABLE `contributionrating` (
`dossier` int(11) NOT NULL,
`eJournal` int(11) NOT NULL,
`research` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='TODO @Axel plz comment';
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Holds the quantitative peer assessment regarding the uploads.';
--user with userEmail uploads a file for project projectName
--This file is saved locally in TomCat-Folder (for example C:\dev\apache-tomcat-7.0.88-windows-x64\apache-tomcat-7.0.88\bin\userFilesFLTrail)
-- with name fileLocation. The original fileName is saved in DB.
--fileRole indicates the purpose of the file (for example PRESENTATION or DOSSIER)
CREATE TABLE `largefilestorage` (
`id` int(11) NOT NULL,
`userEmail` varchar(255) CHARACTER SET utf8 NOT NULL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment