waibu-db 1.1.19 → 1.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bajo/intl/en-US.json +3 -0
- package/bajo/intl/id.json +3 -0
- package/bajoTemplate/partial/crud/_add-attachment.html +3 -0
- package/bajoTemplate/partial/crud/_details-attachment.html +3 -0
- package/bajoTemplate/partial/crud/_edit-attachment.html +43 -0
- package/bajoTemplate/partial/crud/_list-attachment.html +9 -0
- package/bajoTemplate/partial/crud/add-handler.html +3 -0
- package/bajoTemplate/partial/crud/details-handler.html +5 -1
- package/bajoTemplate/partial/crud/edit-handler.html +3 -0
- package/lib/crud/details-handler.js +4 -1
- package/lib/crud/edit-handler.js +28 -13
- package/lib/crud/helper/attachment-handler.js +7 -0
- package/package.json +1 -1
- package/plugin/method/get-schema-ext.js +3 -0
package/bajo/intl/en-US.json
CHANGED
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"clonePrevious": "Clone previous",
|
|
30
30
|
"actionPermanentlyDisabled%s": "Sorry, action '%s' is permanently disabled at database level. For more information, please contact your Admin immediately, thank you!",
|
|
31
31
|
"dbModels": "Database Models",
|
|
32
|
+
"checkAll": "Check All",
|
|
33
|
+
"uncheckAll": "Uncheck All",
|
|
34
|
+
"attachment": "Attachment",
|
|
32
35
|
"op": {
|
|
33
36
|
"equals": "Equals",
|
|
34
37
|
"notEquals": "Not Equals",
|
package/bajo/intl/id.json
CHANGED
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"clonePrevious": "Duplikasi sebelumnya",
|
|
30
30
|
"actionPermanentlyDisabled%s": "Sorry, action '%s' is permanently disabled at database level. For more information, please contact your Admin immediately, thank you!",
|
|
31
31
|
"dbModels": "Model Database",
|
|
32
|
+
"checkAll": "Cek Semua",
|
|
33
|
+
"uncheckAll": "Uncheck Semua",
|
|
34
|
+
"attachment": "Attachment",
|
|
32
35
|
"op": {
|
|
33
36
|
"equals": "Sama Dengan",
|
|
34
37
|
"notEquals": "Tidak Sama Dengan",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<c:fieldset id="attachment" t:legend="attachment" grid-gutter="3"
|
|
2
|
+
x-data="{
|
|
3
|
+
selected: [],
|
|
4
|
+
checkAll (check = true) {
|
|
5
|
+
if (!check) {
|
|
6
|
+
this.selected = []
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
const all = document.querySelectorAll('#attachment input[type=checkbox]')
|
|
10
|
+
this.selected = _.map(all, item => item.value)
|
|
11
|
+
},
|
|
12
|
+
toggleBtn () {
|
|
13
|
+
const el = this.$refs.removeatt
|
|
14
|
+
if (this.selected.length > 0) el.classList.remove('disabled')
|
|
15
|
+
else el.classList.add('disabled')
|
|
16
|
+
},
|
|
17
|
+
remove () {
|
|
18
|
+
this.$refs.action.value = 'removeatt'
|
|
19
|
+
this.$refs.value.value = JSON.stringify(this.selected)
|
|
20
|
+
document.getElementById('main-form').submit()
|
|
21
|
+
}
|
|
22
|
+
}"
|
|
23
|
+
x-init="$watch('selected', val => toggleBtn())"
|
|
24
|
+
<%= schema.view.card === false ? '' : 'card' %>
|
|
25
|
+
>
|
|
26
|
+
<input x-ref="action" type="hidden" name="_action" />
|
|
27
|
+
<input x-ref="value" type="hidden" name="_value" />
|
|
28
|
+
<c:grid-col col="12">
|
|
29
|
+
<c:grid-row gutter="3">
|
|
30
|
+
<c:grid-col col="8-md 12-sm">
|
|
31
|
+
<c:form-file name="file" multiple no-label <%= _.isString(schema.view.attachment) ? ('accept="' + schema.view.attachment + '"') : '' %> />
|
|
32
|
+
</c:grid-col>
|
|
33
|
+
<c:grid-col col="4-md 12-sm" flex="align-items:center">
|
|
34
|
+
<c:btn-group margin="end-2">
|
|
35
|
+
<c:btn size="sm" color="secondary-outline" t:content="checkAll" @click="checkAll()"/>
|
|
36
|
+
<c:btn size="sm" color="secondary-outline" t:content="uncheckAll" @click="checkAll(false)"/>
|
|
37
|
+
</c:btn-group>
|
|
38
|
+
<c:btn margin="end-2" size="sm" class="disabled" x-ref="removeatt" color="danger-outline" t:content="Remove" @click="remove()"/>
|
|
39
|
+
</c:grid-col>
|
|
40
|
+
</c:grid-row>
|
|
41
|
+
</c:grid-col>
|
|
42
|
+
<!-- include waibuDb.partial:/crud/_list-attachment.html -->
|
|
43
|
+
</c:fieldset>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<% for (const att of attachments) { %>
|
|
2
|
+
<c:grid-col col="4-lg 6-md">
|
|
3
|
+
<% if (attr.readonly) { %>
|
|
4
|
+
<a href="<%= decodeURI(att.url) %>" target="_blank"><%= att.fileName %></a>
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<c:form-check x-model="selected" value="<%= att.fullPath %>" label="<a href='<%= att.url %>' target='_blank'><%= att.fileName %></a>" />
|
|
7
|
+
<% } %>
|
|
8
|
+
</c:grid-col>
|
|
9
|
+
<% } %>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<c:wdb-form id="main-form" method="POST" enctype="multipart/form-data">
|
|
2
|
+
<% if (schema.view.attachment) { %>
|
|
3
|
+
<!-- include waibuDb.partial:/crud/_add-attachment.html -->
|
|
4
|
+
<% } %>
|
|
2
5
|
<!-- include waibuDb.partial:/crud/_add-btns.html -->
|
|
3
6
|
</c:wdb-form>
|
|
4
7
|
<!-- include waibuDb.partial:/crud/_addons.html -->
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
<c:wdb-form tag="div" id="main-form"
|
|
1
|
+
<c:wdb-form tag="div" id="main-form">
|
|
2
|
+
<% if (schema.view.attachment) { %>
|
|
3
|
+
<!-- include waibuDb.partial:/crud/_details-attachment.html -->
|
|
4
|
+
<% } %>
|
|
5
|
+
</c:wdb-form>
|
|
2
6
|
<!-- include waibuDb.partial:/crud/_details-btns.html -->
|
|
3
7
|
<!-- include waibuDb.partial:/crud/_addons.html -->
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<c:wdb-form id="main-form" method="POST" enctype="multipart/form-data">
|
|
2
|
+
<% if (schema.view.attachment) { %>
|
|
3
|
+
<!-- include waibuDb.partial:/crud/_edit-attachment.html -->
|
|
4
|
+
<% } %>
|
|
2
5
|
<!-- include waibuDb.partial:/crud/_edit-btns.html -->
|
|
3
6
|
</c:wdb-form>
|
|
4
7
|
<!-- include waibuDb.partial:/crud/_addons.html -->
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import attachmentHandler from './helper/attachment-handler.js'
|
|
2
|
+
|
|
1
3
|
async function detailsHandler ({ req, reply, model, params = {}, id, template, addOnsHandler, templateDisabled = 'waibuDb.template:/disabled.html' } = {}) {
|
|
2
4
|
const { pascalCase } = this.app.bajo
|
|
3
5
|
const { recordGet, getSchemaExt } = this.app.waibuDb
|
|
@@ -12,7 +14,8 @@ async function detailsHandler ({ req, reply, model, params = {}, id, template, a
|
|
|
12
14
|
const resp = await recordGet({ model, req, id, options })
|
|
13
15
|
const form = resp.data
|
|
14
16
|
const addOns = addOnsHandler ? await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: resp, schema }) : undefined
|
|
15
|
-
|
|
17
|
+
const attachments = await attachmentHandler.call(this, { schema, id })
|
|
18
|
+
merge(params, { form, schema, addOns, attachments })
|
|
16
19
|
return reply.view(template, params)
|
|
17
20
|
}
|
|
18
21
|
|
package/lib/crud/edit-handler.js
CHANGED
|
@@ -1,33 +1,48 @@
|
|
|
1
|
+
import attachmentHandler from './helper/attachment-handler.js'
|
|
2
|
+
|
|
1
3
|
async function editHandler ({ req, reply, model, id, params = {}, template, addOnsHandler, templateDisabled = 'waibuDb.template:/disabled.html' } = {}) {
|
|
2
|
-
const { pascalCase } = this.app.bajo
|
|
4
|
+
const { pascalCase, getPluginDataDir } = this.app.bajo
|
|
3
5
|
const { recordUpdate, recordGet, getSchemaExt } = this.app.waibuDb
|
|
4
6
|
const { buildUrl } = this.app.waibuMpa
|
|
5
|
-
const {
|
|
7
|
+
const { fs } = this.lib
|
|
8
|
+
const { merge, defaultsDeep, isEmpty, omit } = this.lib._
|
|
6
9
|
const options = {}
|
|
10
|
+
let error
|
|
11
|
+
let resp
|
|
12
|
+
let form
|
|
7
13
|
model = model ?? pascalCase(req.params.model)
|
|
8
14
|
const { schema } = await getSchemaExt(model, 'edit', options, { params })
|
|
9
15
|
if (schema.disabled.includes('update')) return reply.view(templateDisabled, { action: 'edit' })
|
|
10
16
|
// req.query.attachment = true
|
|
11
17
|
options.fields = schema.view.fields
|
|
12
|
-
let error
|
|
13
|
-
let resp
|
|
14
|
-
let form
|
|
15
18
|
id = id ?? req.params.id ?? req.query.id
|
|
16
19
|
if (req.method === 'GET') {
|
|
17
20
|
const old = await recordGet({ model, req, id, options })
|
|
18
21
|
form = defaultsDeep(req.body, old.data)
|
|
19
22
|
} else {
|
|
20
|
-
form = req.body
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
form = omit(req.body, ['_action', '_value'])
|
|
24
|
+
if (req.body._action === 'removeatt' && !isEmpty(req.body._value)) {
|
|
25
|
+
const root = `${getPluginDataDir('dobo')}/attachment`
|
|
26
|
+
for (const item of req.body._value) {
|
|
27
|
+
try {
|
|
28
|
+
const file = `${root}/${item}`
|
|
29
|
+
await fs.unlink(file)
|
|
30
|
+
} catch (err) {}
|
|
31
|
+
}
|
|
32
|
+
if (req && req.flash) req.flash('notify', req.t('attachmentRemoved'))
|
|
33
|
+
} else {
|
|
34
|
+
try {
|
|
35
|
+
resp = await recordUpdate({ model, req, id, reply, options })
|
|
36
|
+
form = resp.data
|
|
37
|
+
return reply.redirectTo(buildUrl({ url: req.url, base: req.params.base ?? req.query.base ?? 'list', params: { page: 1 }, exclude: ['id'] }))
|
|
38
|
+
} catch (err) {
|
|
39
|
+
error = err
|
|
40
|
+
}
|
|
27
41
|
}
|
|
28
42
|
}
|
|
29
43
|
const addOns = addOnsHandler ? await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: resp, schema, error }) : undefined
|
|
30
|
-
|
|
44
|
+
const attachments = await attachmentHandler.call(this, { schema, id })
|
|
45
|
+
merge(params, { form, schema, error, addOns, attachments })
|
|
31
46
|
return reply.view(template, params)
|
|
32
47
|
}
|
|
33
48
|
|
package/package.json
CHANGED
|
@@ -19,11 +19,14 @@ function getCommons (action, schema, ext, opts = {}) {
|
|
|
19
19
|
const disabled = get(ext, `view.${action}.disabled`, get(ext, 'common.disabled', []))
|
|
20
20
|
const x = defaultsDeep(get(ext, `view.${action}.x`), get(ext, 'common.x', {}))
|
|
21
21
|
const aggregate = get(ext, `view.${action}.stat.aggregate`, get(ext, 'common.stat.aggregate', []))
|
|
22
|
+
let attachment = get(ext, `view.${action}.attachment`, get(ext, 'common.attachment', false))
|
|
23
|
+
if (!schema.attachment || action === 'list') attachment = false
|
|
22
24
|
hidden.push('siteId', ...schema.hidden, ...(opts.hidden ?? []))
|
|
23
25
|
hidden = uniq(hidden)
|
|
24
26
|
pull(hidden, ...forceVisible)
|
|
25
27
|
const allFields = without(map(schema.properties, 'name'), ...hidden)
|
|
26
28
|
const forFields = get(ext, `view.${action}.fields`, get(ext, 'common.fields', allFields))
|
|
29
|
+
set(schema, 'view.attachment', attachment)
|
|
27
30
|
set(schema, 'view.calcFields', calcFields)
|
|
28
31
|
set(schema, 'view.noEscape', noEscape)
|
|
29
32
|
set(schema, 'view.widget', widget)
|