diff --git a/src/main/java/com/metaweb/gridworks/GridworksServlet.java b/src/main/java/com/metaweb/gridworks/GridworksServlet.java index 47eb4a186..f5d92322c 100644 --- a/src/main/java/com/metaweb/gridworks/GridworksServlet.java +++ b/src/main/java/com/metaweb/gridworks/GridworksServlet.java @@ -19,6 +19,7 @@ import com.metaweb.gridworks.commands.edit.DoTextTransformCommand; import com.metaweb.gridworks.commands.edit.FacetBasedEditCommand; import com.metaweb.gridworks.commands.edit.JoinMultiValueCellsCommand; import com.metaweb.gridworks.commands.edit.RemoveColumnCommand; +import com.metaweb.gridworks.commands.edit.DeleteProjectCommand; import com.metaweb.gridworks.commands.edit.SaveProtographCommand; import com.metaweb.gridworks.commands.edit.SplitMultiValueCellsCommand; import com.metaweb.gridworks.commands.edit.UndoRedoCommand; @@ -58,6 +59,8 @@ public class GridworksServlet extends HttpServlet { _commands.put("get-project-metadata", new GetProjectMetadataCommand()); _commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand()); + + _commands.put("delete-project", new DeleteProjectCommand()); _commands.put("get-models", new GetModelsCommand()); _commands.put("get-rows", new GetRowsCommand()); diff --git a/src/main/java/com/metaweb/gridworks/ProjectManager.java b/src/main/java/com/metaweb/gridworks/ProjectManager.java index e209a29bd..a710b4ee5 100644 --- a/src/main/java/com/metaweb/gridworks/ProjectManager.java +++ b/src/main/java/com/metaweb/gridworks/ProjectManager.java @@ -307,4 +307,16 @@ public class ProjectManager implements Serializable { } } } + + public boolean deleteProject(Project project) { + File file = new File(_dir, project.id + ".project"); + if (file.exists()) { + _projects.remove(project.id); + _projectsMetadata.remove(project.id); + boolean result = file.delete(); + save(); + return result; + } + return false; + } } diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/DeleteProjectCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/DeleteProjectCommand.java new file mode 100644 index 000000000..045a8254c --- /dev/null +++ b/src/main/java/com/metaweb/gridworks/commands/edit/DeleteProjectCommand.java @@ -0,0 +1,26 @@ +package com.metaweb.gridworks.commands.edit; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.metaweb.gridworks.ProjectManager; +import com.metaweb.gridworks.commands.Command; + +public class DeleteProjectCommand extends Command { + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + try { + boolean result = ProjectManager.singleton.deleteProject(getProject(request)); + + respond(response, "{ \"code\" : " + (result ? "\"ok\"" : "\"error\"") + " }"); + + } catch (Exception e) { + respondException(response, e); + } + } +} diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 00afb05a5..f6ce84ff0 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -1 +1 @@ - Gridworks

New Project

Create a new project by uploading a tab-separated value or comma-separated value file.

Project Name:
Project Password:
optional, not protected, so use some password you don't care to reveal
Upload File:
Skip: initial data rows
Load up to: data rows
\ No newline at end of file + Gridworks

New Project

Create a new project by uploading a tab-separated value or comma-separated value file.

Project Name:
Project Password:
optional, not protected, so use some password you don't care to reveal
Upload File:
Skip: initial data rows
Load up to: data rows
\ No newline at end of file diff --git a/src/main/webapp/project.html b/src/main/webapp/project.html index d79051395..49b5071a1 100644 --- a/src/main/webapp/project.html +++ b/src/main/webapp/project.html @@ -1 +1 @@ - Gridworks
starting up ...
\ No newline at end of file + Gridworks
starting up ...
\ No newline at end of file diff --git a/src/main/webapp/scripts/index.js b/src/main/webapp/scripts/index.js index b80e31e27..fa249d422 100644 --- a/src/main/webapp/scripts/index.js +++ b/src/main/webapp/scripts/index.js @@ -45,19 +45,36 @@ function renderProjects(data) { $('

').text("Projects").appendTo(container); - var table = $('
last modified
') - .attr("cellspacing", "5") - .appendTo(container)[0]; + var table = $('
last modified
').attr("cellspacing", "5")[0]; for (var i = 0; i < projects.length; i++) { var project = projects[i]; var tr = table.insertRow(table.rows.length); var td0 = tr.insertCell(0); var td1 = tr.insertCell(1); + var td2 = tr.insertCell(2); $('').text(project.name).attr("href", "/project.html?project=" + project.id).appendTo(td0); $('').text(formatDate(project.date)).appendTo(td1); + $('').attr("title","Delete this project").attr("href","").html("").click(function() { + if (window.confirm("Are you sure you want to delete this project?")) { + $.ajax({ + type: "POST", + url: "/command/delete-project", + data: { "project" : project.id }, + dataType: "json", + success: function (data) { + if (data && typeof data['code'] != 'undefined' && data.code == "ok") { + window.location.reload() + } + } + }); + } + return false; + }).appendTo(td2); } + + $(table).appendTo(container); } }