Skip to content

Commit f954482

Browse files
committed
Provide install and help commands for fields plugin
Closes gh-1291
1 parent f3d12f9 commit f954482

File tree

21 files changed

+173
-10
lines changed

21 files changed

+173
-10
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Fields
2+
3+
Fields plugin provides customizable form-field rendering based on overrideable GSP template.
4+
5+
```
6+
$ grace fields:install
7+
```
8+
9+
Happy coding~~ 👨🏻‍💻
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import grails.plugin.formfields.FieldsGrailsPlugin
2+
3+
namespace 'fields'
4+
description "Print Help infromation for Fields", "grace fields:help"
5+
visible false
6+
7+
URL url = FieldsGrailsPlugin.getResource('/META-INF/HELP')
8+
9+
consoleLogger.addStatus "HELP"
10+
11+
consoleLogger.log url.text
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.nio.file.*
2+
import java.util.zip.ZipEntry
3+
import java.util.zip.ZipInputStream
4+
import grails.plugin.formfields.FieldsGrailsPlugin
5+
6+
namespace 'fields'
7+
description "Install Fields", "grace fields:install"
8+
visible false
9+
10+
URL url = FieldsGrailsPlugin.getResource('/META-INF/templates/_fields')
11+
File projectDir = executionContext.baseDir
12+
File viewsDir = new File(projectDir, 'app/views')
13+
File jarFile = new File(new URI(url.file.takeBefore('!')))
14+
15+
use(FileCategory) {
16+
jarFile.unzip(viewsDir, 'META-INF/templates/')
17+
}
18+
19+
consoleLogger.addStatus "Copying the default templates to 'app/views'"
20+
21+
22+
class FileCategory {
23+
24+
def static unzip(File zipFile, File distDir, String path) {
25+
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))
26+
ZipEntry entry
27+
28+
while (entry = zis.nextEntry) {
29+
String fileName = entry.name
30+
if (!fileName.startsWith(path)) {
31+
continue
32+
}
33+
File file = new File(distDir, fileName - path)
34+
if (fileName.endsWith('/')) {
35+
if (file.isFile()) {
36+
file.delete()
37+
}
38+
file.mkdirs()
39+
}
40+
else {
41+
Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING)
42+
}
43+
}
44+
45+
zis.closeEntry()
46+
zis.close()
47+
}
48+
49+
}

grace-plugin-fields/src/main/templates/_fields/_list.gsp

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<g:formatBoolean boolean="${value}"/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="custom-control-inline custom-control custom-switch">
2+
<g:checkBox class="custom-control-input" id="${property}" name="${property}" value="${value}" />
3+
<label class="custom-control-label" for="${property}">&nbsp;</label>
4+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<g:formatDate date="${value}" format="yyyy-MM-dd HH:mm"/>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<g:formatDate date="${value}" format="yyyy-MM-dd HH:mm"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="hstack gap-3">
2+
<g:datePicker name="${property}" value="${value ?: new Date()}"
3+
precision="${attrs.precision}"
4+
cssClasses="[year: 'form-select w-20', 'month': 'form-select w-20', 'day': 'form-select w-20', 'hour': 'form-select w-20', 'minute': 'form-select w-20']"
5+
noSelection="['':'-Choose-']"/>
6+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<g:if test="${type in [Boolean, null]}">
2+
<g:formatBoolean boolean="${value}"/>
3+
</g:if>
4+
<g:elseif test="${type in [Calendar, Date, java.sql.Date, java.sql.Time]}">
5+
<g:formatDate date="${value}" format="yyyy-MM-dd HH:mm"/>
6+
</g:elseif>
7+
<g:else>
8+
<g:fieldValue bean="${bean}" field="${property}"/>
9+
</g:else>

0 commit comments

Comments
 (0)