Changeset 290
- Timestamp:
- Jan 22, 2010, 5:29:24 PM (15 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AssetDetailedController.groovy
r286 r290 14 14 static allowedMethods = [delete:'POST', save:'POST', update:'POST', saveCopy:'POST'] 15 15 16 def overview = { 17 } 18 19 @Secured(['ROLE_Manager','ROLE_AppAdmin']) 16 20 def importAssetTree = { 17 21 } 18 def overview = { 19 } 20 22 23 @Secured(['ROLE_Manager','ROLE_AppAdmin']) 21 24 def importAssetTreeSave = { 22 25 def result = csvService.importAssetTree(request) -
trunk/grails-app/i18n/messages.properties
r287 r290 1 1 asset.tree.import.success=Asset tree imported. 2 asset.tree.import.failure=Could not create asset tree from supplied file .2 asset.tree.import.failure=Could not create asset tree from supplied file, failed on line {0}. 3 3 asset.tree.import.file.over.max.size=Supplied file is greater than max size of {0} Mbytes. 4 4 asset.tree.import.file.not.supplied=No file supplied. … … 22 22 person.personGroups.help=Groups may be assigned to tasks and \ 23 23 may also provide a record of persons qualified or trained in a specific area. \ 24 Use Ctrl or Shift to select multiple groups. \ 25 Groups provide no application authorisations. 24 Groups provide no application authorisations. 26 25 person.loginName=Login Name 27 26 person.loginName.help=This is the id or name that the person will use to login to the application. -
trunk/grails-app/services/AssetSubItemService.groovy
r285 r290 22 22 23 23 def save(params) { 24 Asset .withTransaction { status ->24 AssetSubItem.withTransaction { status -> 25 25 def result = [:] 26 26 -
trunk/grails-app/services/CreateDataService.groovy
r276 r290 156 156 saveAndTest(authInstance) 157 157 158 // #3 158 159 authInstance = new Authority(description:"Application User, all application users need this base role to allow login.", 159 160 authority:"ROLE_AppUser") -
trunk/grails-app/services/CsvService.groovy
r287 r290 16 16 */ 17 17 def importAssetTree(request) { 18 def result = [:] 19 20 def megaByteMultiplier = 1000 * 1000 21 def fileMaxSize = 10 * megaByteMultiplier //Mb 22 23 def multiPartFile = request.getFile('file') 24 25 InputStreamReader sr = new InputStreamReader(multiPartFile.inputStream) 26 CSVReader reader = new CSVReader(sr) 27 28 def fail = { Map m -> 29 //status.setRollbackOnly() 30 reader.close() 31 result.error = [ code: m.code, args: m.args ] 32 return result 33 } 34 35 if(!multiPartFile || multiPartFile.isEmpty()) 36 return fail(code: "asset.tree.import.file.not.supplied") 37 38 if (multiPartFile.getSize() > fileMaxSize) 39 return fail(code: "asset.tree.import.file.over.max.size", args: [fileMaxSize/megaByteMultiplier]) 40 41 def line = reader.readNext() 42 def lineNumber = 1 43 44 def header = ["Site", "Section", "Asset", "Sub Asset", "Functional Assembly", "Sub Assembly Group"] 45 46 if(line != header) 47 return fail(code: "asset.tree.import.no.header") 48 49 log.info "Import checks passed, start processing asset file." 50 51 // Prepare the first body line. 52 line = reader.readNext() 53 lineNumber ++ 54 55 while(line) { 56 def lineSize = line.size() 57 // log.info lineNumber+ "(" + lineSize + ")" + " : " + line 58 59 if(line[0]) { 60 if( !Site.findByName(line[0]) ) 61 new Site(name: line[0]).save() 62 } 63 18 Asset.withTransaction { status -> 19 def result = [:] 20 21 def megaByteMultiplier = 1000 * 1000 22 def fileMaxSize = 10 * megaByteMultiplier //Mb 23 24 def multiPartFile = request.getFile('file') 25 26 InputStreamReader sr = new InputStreamReader(multiPartFile.inputStream) 27 CSVReader reader = new CSVReader(sr) 28 29 def fail = { Map m -> 30 status.setRollbackOnly() 31 reader.close() 32 result.error = [ code: m.code, args: m.args ] 33 return result 34 } 35 36 if(!multiPartFile || multiPartFile.isEmpty()) 37 return fail(code: "asset.tree.import.file.not.supplied") 38 39 if (multiPartFile.getSize() > fileMaxSize) 40 return fail(code: "asset.tree.import.file.over.max.size", args: [fileMaxSize/megaByteMultiplier]) 41 42 def line = reader.readNext() 43 def lineNumber = 1 44 45 def header = ["Site", "Section", "Asset", "Sub Asset", "Functional Assembly", "Sub Assembly Group"] 46 47 if(line != header) 48 return fail(code: "asset.tree.import.no.header") 49 50 log.info "Import checks passed, start processing asset file." 51 52 // Prepare the first body line. 64 53 line = reader.readNext() 65 54 lineNumber ++ 66 } //while(line) 67 68 // Success. 69 reader.close() 70 return result 71 55 56 def siteInstance 57 def sectionInstance 58 def assetInstance 59 60 while(line) { 61 def lineSize = line.size() 62 // log.info lineNumber+ "(" + lineSize + ")" + " : " + line 63 64 if(line[0]) { 65 if( !Site.findByName(line[0]) ) 66 siteInstance = new Site(name: line[0]) 67 if(!siteInstance.save()) 68 return fail(code: "asset.tree.import.failure", args: [lineNumber]) 69 } 70 else continue 71 72 if(line[1]) { 73 if( !Section.findByName(line[1]) ) 74 sectionInstance = new Section(name: line[1], 75 site: siteInstance) 76 if(!sectionInstance.save()) 77 return fail(code: "asset.tree.import.failure", args: [lineNumber]) 78 } 79 else continue 80 81 if(line[2]) { 82 if( !Asset.findByName(line[2]) ) 83 assetInstance = new Asset(name: line[2], 84 section: sectionInstance) 85 if(!sectionInstance.save()) 86 return fail(code: "asset.tree.import.failure", args: [lineNumber]) 87 } 88 else continue 89 90 line = reader.readNext() 91 lineNumber ++ 92 } //while(line) 93 94 // Success. 95 reader.close() 96 return result 97 98 } //end withTransaction 72 99 } // end importAssetTree() 73 100 -
trunk/grails-app/taglib/CustomTagLib.groovy
r286 r290 36 36 def isChecked, ht, wd, style, html 37 37 38 def displayFields = attrs.displayFields 39 40 def displayValue = " " 41 38 42 // sets the style to override height and/or width if either of them 39 43 // is specified, else the default from the CSS is taken … … 54 58 from.each { obj -> 55 59 60 displayValue = " " 61 62 if( displayFields?.contains("id") ) { 63 displayValue += obj.id + " - " 64 } 65 66 if(displayFields?.contains("name")) { 67 displayValue += obj.name 68 } 69 else displayValue += obj 70 56 71 // if we wanted to select the checkbox using a click anywhere on the label (also hover effect) 57 72 // but grails does not recognize index suffix in the name as an array: … … 61 76 isChecked = (value?.contains(obj."${attrs.optionKey}"))? true: false 62 77 63 out << "<li>" << checkBox(name:cname, value:obj."${attrs.optionKey}", checked: isChecked) << " ${obj.id} - ${obj.name}"<< "</li>"78 out << "<li>" << checkBox(name:cname, value:obj."${attrs.optionKey}", checked: isChecked) << displayValue << "</li>" 64 79 } 65 80 -
trunk/grails-app/views/assetDetailed/edit.gsp
r286 r290 88 88 from="${AssetSubItem.list()}" 89 89 value="${assetInstance?.assetSubItems.collect{it.id}}" 90 optionKey="id"/> 90 optionKey="id" 91 displayFields="['id', 'name']"/> 91 92 92 93 </td>
Note: See TracChangeset
for help on using the changeset viewer.