Skip to content

Commit

Permalink
Retoracao - Marlon
Browse files Browse the repository at this point in the history
  • Loading branch information
mucapaz committed Feb 7, 2015
1 parent 3e84e1b commit e2f78db
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
48 changes: 30 additions & 18 deletions grails-app/controllers/rgms/member/MemberController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MemberController {
redirect(action: "list", params: params)
}



def list = {

params.max = Math.min(params.max ? params.int('max') : 10, 100)
Expand All @@ -28,6 +30,8 @@ class MemberController {
[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
}



def create = {
def member = new Member(params)
def user = new User(params)
Expand All @@ -42,10 +46,15 @@ class MemberController {
[userMemberInstanceList: [memberInstance: member, userInstance: user]]
}

def renderCreateMember(){
render(view: "create", model: [userMemberInstanceList: [memberInstance: memberInstance, userInstance: userInstance]])
return
}

def save = {
//#if($Auth)
if (!grailsApplication.config.grails.mail.username) {
// throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured'))
// throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured'))
}
//#end

Expand All @@ -62,8 +71,7 @@ class MemberController {
userInstance.passwordChangeRequiredOnNextLogon = true

if (!memberInstance.save(flush: true)) {
render(view: "create", model: [userMemberInstanceList: [memberInstance: memberInstance, userInstance: userInstance]])
return
renderCreateMember()
}

userInstance.author = memberInstance;
Expand All @@ -72,8 +80,7 @@ class MemberController {
println it
}
memberInstance.delete(flush: true)
render(view: "create", model: [userMemberInstanceList: [memberInstance: memberInstance, userInstance: userInstance]])
return
renderCreateMember()

This comment has been minimized.

Copy link
@mjuliagfl

mjuliagfl Feb 9, 2015

Boa refatoração

}

def email = memberInstance.email
Expand All @@ -87,15 +94,15 @@ class MemberController {
flash.message = message(code: 'default.created.message', args: [message(code: 'member.label', default: 'Member'), memberInstance.id])
redirect(action: "show", id: memberInstance.id)
}

def search = {
def userMemberList = []
if(params.name){
def members = Member.findAllByName(params.name)

generateMemberList(userMemberList,members)
}

[userMemberInstanceList: userMemberList, memberInstanceTotal: Member.count()]
}

Expand Down Expand Up @@ -186,21 +193,22 @@ class MemberController {
redirect(action: "show", id: memberInstance.id)
}

def redirectNotFound(){
flash.message = message(code: 'default.not.found.message', args: [message(code: 'member.label', default: 'Member'), params.id])
redirect(action: "list")
}

def delete = {
Member.class
Member.deleteAll();
Member.dele
def memberInstance = Member.get(params.id)
def userInstance = User.findByAuthor(memberInstance)
if (!memberInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'member.label', default: 'Member'), params.id])
redirect(action: "list")
if(!isMemberInstance(memberInstance)) {
return
}

if (!userInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'member.label', default: 'Member'), params.id])
redirect(action: "list")
redirectNotFound()
return
}

Expand Down Expand Up @@ -237,11 +245,17 @@ class MemberController {
memberInstance.save()
}



def isMemberInstance(memberInstance){
if (!memberInstance) {
redirectNotFound()
}
}

def Get_MemberInstance() {
def memberInstance = Member.get(params.id)
if (!memberInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'member.label', default: 'Member'), params.id])
redirect(action: "list")
if(!isMemberInstance(memberInstance)) {
return
}
def user = User.findByAuthor(memberInstance)
Expand All @@ -268,6 +282,4 @@ class MemberController {
userMemberList.add([member: i])
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class ResearchLineController {
if(member.getName() == params.member)
{
lista.add(researchline.getName())


}
}
[researchLineInstanceList: lista]
Expand Down Expand Up @@ -179,19 +177,22 @@ class ResearchLineController {
researchLineInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
[message(code: 'researchLine.label', default: 'ResearchLine')] as Object[],
message(code: 'default.warningwhileedting.message'))
render(view: "edit", model: [researchLineInstance: researchLineInstance])
return false
render()
}
}
return true
}

def renderEdit(){
render(view: "edit", model: [researchLineInstance: researchLineInstance])
return false
}

def editPublications(researchLineInstance) {
for (p in researchLineInstance?.publications) {
p.researchLine = null;
if (!p.save(flush: true)) {
render(view: "edit", model: [researchLineInstance: researchLineInstance])
return false
renderEdit()
}
}
true
Expand Down
32 changes: 15 additions & 17 deletions grails-app/controllers/rgms/researchProject/FunderController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,19 @@ class FunderController {
redirect(action: "show", id: funderInstance.id)
}

def show(Long id) {
def funderInstance = Funder.get(id)
if (!funderInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'funder.label', default: 'Funder'), id])
redirect(action: "list")
return
}
def getFunderInstance(Long id){
def funderInstance = Funder.get(id)
if (!funderInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'funder.label', default: 'Funder'), id])
redirect(action: "list")
return
}

[funderInstance: funderInstance]
}

def edit(Long id) {
def funderInstance = Funder.get(id)
if (!funderInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'funder.label', default: 'Funder'), id])
redirect(action: "list")
return
}

[funderInstance: funderInstance]
def show(Long id) {
getFunderInstance(id)
}

def update(Long id, Long version) {
Expand Down Expand Up @@ -82,6 +75,10 @@ class FunderController {
redirect(action: "show", id: funderInstance.id)
}

def edit(Long id) {
getFunderInstance(id)
}

def delete(Long id) {
def funderInstance = Funder.get(id)
if (!funderInstance) {
Expand All @@ -101,4 +98,5 @@ class FunderController {
}
}
}
//#end
//#end

1 comment on commit e2f78db

@mjuliagfl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boa sacada em getfunderinstance, evitou duplicação de código

Please sign in to comment.