Skip to content

Commit

Permalink
[BTRX-742] Convert submission form (#241)
Browse files Browse the repository at this point in the history
* wip infor submission form

* wip save submission data

* wip save submission data backend rework

* wip download files

* Alignments styles

* wip remove docs

* wip delete submission

* wip delete submission confirmation dialog

* wip view-edit form

* wip back link

* submission form ☺️

* removed comment

* removed old submission button

* catch save submission error

* minor

* changed to text area

* Submission Number field and Remove Column styles

* scroll to top

* redirect to project

* link redirect to project

* removed unused files

* Submissions Edit and column size fix

* Ellipsis column

* removed lines

* package-lock prior version

* Delete package-lock.json

Removed file package-lock.json

* save files if are present parts

* files are treated as diskfile object

* fixed dates, submission controller minor tweaks

* remove doc type when used
  • Loading branch information
tadeork authored Aug 21, 2019
1 parent 6d9d8ce commit c1681f2
Show file tree
Hide file tree
Showing 21 changed files with 653 additions and 512 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package org.broadinstitute.orsp

import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonParser
import grails.converters.JSON
import groovy.util.logging.Slf4j
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItem
import org.apache.commons.fileupload.disk.DiskFileItem
import org.broadinstitute.orsp.utils.IssueUtils

@Slf4j
class SubmissionController extends AuthenticatedController {

def show() {
Issue issue = queryService.findByKey(params.id)
if (issueIsForbidden(issue)) {
redirect(controller: 'Index', action: 'index')
}
Collection<Submission> submissions = queryService.getSubmissionsByProject(issue.projectKey)
Map<String, List<Submission>> groupedSubmissions = groupSubmissions(issue, submissions)
render(view: '/common/_submissionsPanel',
model: [issue : issue,
groupedSubmissions : groupedSubmissions,
attachmentsApproved: issue.attachmentsApproved()
])
def renderMainComponent() {
render(view: "/mainContainer/index", model: [params.projectKey, params.type, params.submissionId])
}

def getSubmissions() {
Expand Down Expand Up @@ -55,48 +49,73 @@ class SubmissionController extends AuthenticatedController {
}
}
SubmissionType defaultType = SubmissionType.getForLabel(params.get("type").toString()) ?: SubmissionType.Amendment.label
render(view: '/submission/submission',
model: [issue: issue,
submission: submission,
docTypes: PROJECT_DOC_TYPES,
submissionTypes: submissionTypes,
submissionNumberMaximums: submissionNumberMaximums,
defaultType: defaultType
])
render( [issue: issue,
typeLabel: issue.typeLabel,
submission: submission,
documents: submission?.documents,
docTypes: PROJECT_DOC_TYPES,
submissionTypes: submissionTypes,
submissionNumberMaximums: submissionNumberMaximums,
defaultType: defaultType
] as JSON)
}

def save() {
Issue issue = queryService.findByKey(params.projectKey)
Submission submission
if (params?.submissionId) {
submission = Submission.findById(params?.submissionId)
submission.number = Integer.parseInt(params?.submissionNumber)
submission.type = params?.submissionType
submission.comments = params?.comments
if (!submission.save(flush: true)) {
flash.message = submission.errors.allErrors.collect { it }.join("<br/>")
JsonParser parser = new JsonParser()
JsonElement jsonElement = parser.parse(request.parameterMap["submission"].toString())
JsonElement jsonFileTypes = parser.parse(request?.parameterMap["fileTypes"].toString())
JsonArray dataSubmission
JsonArray fileData

if (jsonElement.jsonArray) {
dataSubmission = jsonElement.asJsonArray
}

if (jsonFileTypes.jsonArray) {
fileData = jsonFileTypes.asJsonArray
}

List<DiskFileItem> filesItems = params?.files?.part?.fileItem.collect().flatten()
User user = getUser()

try {
Submission submission
if (params?.submissionId) {
submission = Submission.findById(params?.submissionId)
submission.comments = dataSubmission[0].comments.value
submission.type = dataSubmission[0].type.value
} else {
submission = getJson(Submission.class, dataSubmission[0])
submission.createDate = new Date()
submission.author = getUser()?.displayName
submission.documents = new ArrayList<StorageDocument>()
}
} else {
submission = new Submission(
projectKey: params.projectKey,
number: Integer.parseInt(params?.submissionNumber),
author: getUser()?.displayName,
type: params?.submissionType,
comments: params.comments,
createDate: new Date(),
documents: new ArrayList<StorageDocument>())
if (!filesItems.isEmpty()) {
filesItems.forEach{
StorageDocument submissionDoc = storageProviderService.saveFileItem(
(String) user.displayName,
(String) user.userName,
(String) submission.projectKey,
(String) fileData.find { data -> data.name.value == it.fileName }.fileType.value,
it)
submission.documents.add(submissionDoc)
fileData.remove(fileData.findIndexOf{ data -> data.name.value == it.fileName })
}
}

if (!submission.save(flush: true)) {
flash.message = submission.errors.allErrors.collect { it }.join("<br/>")
response.status = 500
render([error: submission.errors.allErrors] as JSON)
}

response.status = 201
render([message: submission] as JSON)

} catch (Exception e) {
log.error("There was an error trying to save the submission: " + e.message)
response.status = 500
render([error: e.message] as JSON)
}
def number = params?.submissionNumber ?: 0 // Helpful in the error case
render(view: '/submission/submission',
model: [issue : issue,
submission: submission,
minNumber : number,
docTypes : PROJECT_DOC_TYPES,
submissionTypes: getSubmissionTypesForIssueType(issue.getType())])
}

def delete() {
Expand All @@ -111,66 +130,36 @@ class SubmissionController extends AuthenticatedController {
StorageDocument doc = StorageDocument.findById(it)
storageProviderService.removeStorageDocument(doc, getUser()?.displayName)
}
flash.message = message
}
redirect(controller: 'project', action: 'main', params: [projectKey: params.projectKey, tab: "submissions"])
}

def addFile() {
Issue issue = queryService.findByKey(params.projectKey)
Submission submission = Submission.findById(params.submissionId)
if (submission) {
DiskFileItem file = params?.files?.part?.fileItem
if (file) {
StorageDocument document = storageProviderService.saveFileItem(
(String) getUser()?.displayName,
(String) getUser()?.userName,
(String) params?.projectKey,
(String) params?.type,
file
)
if (document) {
submission?.documents?.add(document)
persistenceService.saveEvent(params.projectKey, getUser()?.displayName, "Added Document to Submission: " + document?.fileName, EventType.CHANGE)
}
submission.save(flush: true)
flash.message = "Successfully uploaded file"
} else {
flash.error = "Please select a file to upload"
}
if (submission.hasErrors()) {
response.status = 500
render([error: submission.getErrors() ] as JSON)
} else {
flash.error = "Unable to save file for unknown/unsaved submission"
response.status = 200
render([message: 'Submission was deleted'] as JSON)
}
render(view: '/submission/submission',
model: [issue : issue,
submission: submission,
minNumber : submission.number,
docTypes : PROJECT_DOC_TYPES,
submissionTypes: getSubmissionTypesForIssueType(issue.getType())])
}

def removeFile() {
def issue = Issue.findByProjectKey(params?.projectKey)
def submission = Submission.findById(params?.submissionId)
def document = StorageDocument.findByUuid(params?.uuid)
def message = "Removed Document from Submission: " + document?.fileName
submission?.getDocuments()?.remove(document)
submission?.save(flush: true)
if (document) {
storageProviderService.removeStorageDocument(document, getUser()?.getDisplayName())
}
if (StorageDocument.findByUuid(params?.uuid)?.id) {
flash.error = "Unable to delete file"
} else {
persistenceService.saveEvent(params.projectKey, getUser()?.displayName, message, EventType.CHANGE)
flash.message = message
response.status = 500
render([error: "Unable to delete file"] as JSON)
}
render(view: '/submission/submission',
model: [issue : issue,
submission: submission,
minNumber : submission.number,
docTypes : PROJECT_DOC_TYPES,
submissionTypes: getSubmissionTypesForIssueType(issue.getType())])

response.status = 200
render (['message': 'document deleted'] as JSON)
}

private static getJson(Class type, Object json) {
Gson gson = new Gson()
gson.fromJson(gson.toJson(json), type)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ class UrlMappings {
'/api/comments/save'(controller: 'comments', action: 'saveNewComment', method: 'POST')
'/api/comments/list'(controller: 'comments', action: 'getComments', method: 'GET')
'/api/history'(controller: 'history', action: 'list', method: 'GET')

'/api/submissions'(controller: 'submission', action: 'show', method: 'GET')
'/api/submissions'(controller: 'submission', action: 'delete', method: 'DELETE')
'/api/submissions/display'(controller: 'submission', action: 'getSubmissions', method: 'GET')
'/api/submissions/add-new'(controller: 'submission', action: 'index')
'/api/submissions/info'(controller: 'submission', action: 'index', method: 'GET')
'/submissions/add-new'(controller: 'submission', action: 'renderMainComponent', method: 'GET')
'/api/submissions/add-new-old'(controller: 'submission', action: 'index', method: 'GET')
'/api/submissions/save-new'(controller: 'submission', action: 'save', method: 'POST')
'/api/submissions/add-new'(controller: 'submission', action: 'save', method: 'POST')
'/api/submission/remove-file'(controller: 'submission', action: 'removeFile', method: 'DELETE')

'/api/data-use/new-restriction'(controller: 'dataUse', action: 'create')
'/api/data-use/restriction'(controller: 'dataUse', action: 'findRestriction')
'/api/consent/export'(controller: 'dataUse', action: 'exportConsent', method: 'POST')
Expand Down
97 changes: 0 additions & 97 deletions grails-app/views/common/_submissionsPanel.gsp

This file was deleted.

Loading

0 comments on commit c1681f2

Please sign in to comment.