Skip to content

Commit

Permalink
Download of blank template
Browse files Browse the repository at this point in the history
  • Loading branch information
maurercw committed Feb 12, 2015
1 parent d8f23da commit 99d32cd
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@

<body>
<wicket:extend>
<div><wicket:message key="importExport.page.description" /></div>

<div wicket:id="wizard">[wizard will be placed here]</div>
<div>
<div><wicket:message key="importExport.step1.heading" /></div>
<div><wicket:message key="importExport.step1.description" /></div>
<div>
<a wicket:id="downloadBlankTemplate" wicket:message="title:importExport.step1.button.blankTemplate">
<wicket:message key="importExport.step1.button.blankTemplate" />
</a>
<!--<a wicket:id="downloadFullGradebook" wicket:message="title:importExport.step1.button.fullGradebook">-->
<!--<wicket:message key="importExport.step1.button.fullGradebook" />-->
<!--</a>-->
</div>
</div>

<div>
<div><wicket:message key="importExport.step2.heading" /></div>
<div><wicket:message key="importExport.step2.description" /></div>
</div>
<div>
<div><wicket:message key="importExport.step3.heading" /></div>
<div><wicket:message key="importExport.step3.description" /></div>
</div>

</wicket:extend>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,26 +1,86 @@
package org.sakaiproject.gradebookng.tool.pages;


import org.apache.log4j.Logger;
import org.sakaiproject.gradebookng.tool.panels.GradeImportUploadStep;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.link.DownloadLink;
import org.apache.wicket.markup.html.link.ResourceLink;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.request.resource.ByteArrayResource;
import org.apache.wicket.util.time.Duration;
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.user.api.User;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
* Import Export page
*
*
* @author Steve Swinsburg ([email protected])
*
*/
public class ImportExportPage extends BasePage {

private static final long serialVersionUID = 1L;

private static final Logger log = Logger.getLogger(ImportExportPage.class);



public ImportExportPage() {
add(new GradeImportUploadStep("wizard"));

//get list of assignments. this allows us to build the columns and then fetch the grades for each student for each assignment from the map
final List<Assignment> assignments = this.businessService.getGradebookAssignments();
final List<User> users = this.businessService.getGradeableUsers();

add(new DownloadLink("downloadBlankTemplate", new LoadableDetachableModel<File>() {

@Override
protected File load() {
File tempFile;
try {
//TODO - add the site name to the file?
tempFile = File.createTempFile("gradebookTemplate", ".csv");
// FileOutputStream fos = new FileOutputStream();
FileWriter fw = new FileWriter(tempFile);
//Create csv header
List<String> header = new ArrayList<String>();
header.add("studentId");
header.add("studentName");

for (Assignment assignment : assignments) {
header.add(assignment.getName());
}
String headerStr = StringUtils.join(header, ",");
fw.append(headerStr + "\n");

List<String> line = new ArrayList<String>();

for (User user : users) {
line.add(wrapText(user.getEid()));
line.add(wrapText(user.getSortName()));
String lineStr = StringUtils.join(line, ",");
fw.append(lineStr + "\n");
}


fw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return tempFile;
// return new File(new ByteArrayResource("", null));
}
}).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true));




}

private String wrapText(String input) {
return "\"" + input + "\"";
}


Expand Down

0 comments on commit 99d32cd

Please sign in to comment.