The Grails 3 Versioned Files plugin adds support to attach files to domain models. It was intially inspired by great attachmentable plugin which at the time was limited to grails 2. Main difference is with this plugin you can attach files and manage their versions.
Add the dependency in build.gradle
:
dependencies {
...
compile 'tools.blocks:grails3-versioned-files-plugin:{project-version}'
...
You only need to set these properties in application.yml or application.groovy:
annexable:
repositoryPath: /home/user_name/annexable_docs
bucket: test
userName: user_name
To enable Annexable interface you have two options, static property:
Book.groovy
package com.mycompany
class Book {
static annexable = true
....
}
or implement Annexable interface:
Book.groovy
package com.mycompany
class Book implements Annexable {
....
}
From now you can use your domains as files container.
All controllers are enhanced by this trait. Methods added:
Method | Description |
---|---|
findAnnex |
Allows to find annexes by part of the name of file and bucket |
uploadAnnex |
Allows to upload file as new Annex object or new version of existing one |
attachAnnex |
Allows to attach existing Annex object to your domain object |
detachAnnex |
Allows to detach previously attached Annex from your domain object |
showAnnex |
Same as downloadAnnex method but with changed headers |
downloadAnnex |
Allows to download file (if no version is set then the latest one will be used) |
Contains same methods as these added by AnnexableControllerTrait
. It can be used instead of enhanced controllers methods.
Namespace of AnnexableTagLib is annexable
. It use boostrap, jquery and font-awesome (not included).
annexesDomainPanel
Panel for use with domain model. Contains full set of operations, with search for attach. Can be treated as an example or can be used as complete solution. Example of usage in gsp:
Property | Description |
---|---|
bean |
Domain model to use with |
controller |
Controller name to handle requests (if not set |
name |
Name of HTML element (if not set |
bucket |
Name of bucket (if not set |
<annexable:annexesDomainPanel bean="${testAnnex}" controller="testAnnex" name="annexes" bucket="testBucket"/>
upload
Tag for upload file. File can uploaded as new version of existing Annex or brand new Annex. It can be also linked with existing domain model if specified.
Property | Description |
---|---|
bean |
Domain model to use with (if set new Annex will be linked with model) |
controller |
Controller name to handle requests (if not set |
bucket |
Name of bucket (if not set |
uploadAnnexId |
Identity of Annex object (if not set new Annex will be created) |
<annexable:upload bean="${testAnnex}" controller="testAnnex" uploadAnnexId=1 bucket="testBucket"/>
download
Tag for downloading file with particular version. Tag displays versions of the Annex.
Property | Description |
---|---|
annex |
Annex domain model to download |
controller |
Controller name to handle requests (if not set |
<annexable:download bean="${testAnnex}" controller="testAnnex" />
show
Tag to display file content. It’s implemented as iFrame, so iframeId must be specified and points to existing HTML element.
Property | Description |
---|---|
annexId |
Id of existing Annex object |
controller |
Controller name to handle requests (if not set |
iframeId |
Id property of HTML iFrame element (must be set and exists) |
<annexable:show annexId=1 controller="testAnnex" iframeId="showIFrame"/>
attach
Tag for attaching Annex to domain model.
Property | Description |
---|---|
bean |
Domain model to attach to |
annexId |
Id of existing Annex object |
controller |
Controller name to handle requests (if not set |
fileName |
Name of the file to attach (optional, just for display on button) |
<annexable:attach bean="${testAnnex}" annexId=1 controller="testAnnex" fileName="test annex.png" />
detach
Tag for detach Annex from domain model.
Property | Description |
---|---|
bean |
Domain model to detach from |
annexId |
Id of existing Annex object |
controller |
Controller name to handle requests (if not set |
<annexable:detach bean="${testAnnex}" annexId=1 controller="testAnnex" />
-
0.1.0
-
First release with complete set of methods, controller enhance trait, service and files operations helper.
-
-
0.1.1:
-
Created by
andEdited by
fields handling
-
-
0.2.1:
-
Move to Grails 3.2.11
-
Package rename
-
New tag
-
Redirect after upload based on params
-
-
0.2.2:
-
Allow multiple annexesMiniDomainPanel tag (one per bucket)
-
Fixes related to application contextPath
-
-
0.2.3:
-
Flash message added to controller trait
-