Skip to content

Commit

Permalink
fix 对象添加重置按钮, 重置对象时,将字段也重置. 重置:将db中的当前对象信息、字段信息全部清理掉. #6537
Browse files Browse the repository at this point in the history
  • Loading branch information
baozhoutao committed Mar 21, 2024
1 parent 5bda246 commit e243f8a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* @Author: [email protected]
* @Date: 2022-03-29 20:33:44
* @LastEditors: [email protected]
* @LastEditTime: 2024-03-21 10:45:57
* @Description:
*/
module.exports = {
resetVisible: function (object_name, record_id, permission, data) {
if(Meteor.settings.public.enable_saas){
return false;
}
var record = data && data.record;
return record && record.is_system && record.is_customize && record.created;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: reset
amis_schema: |-
{
"type": "service",
"body": [
{
"type": "button",
"label": "重置",
"id": "u:delete_object",
"onEvent": {
"click": {
"actions": [
{
"actionType": "dialog",
"dialog": {
"type": "dialog",
"title": "重置对象: ${record.label}",
"body": [
{
"type": "tpl",
"tpl": "<div>\n<div style=\"text-align: left;\">重置一个自定义对象进行以下操作:</div>\n<ul>\n<li style=\"text-align: left;\">删除自定义的对象</li>\n<li style=\"text-align: left;\">删除自定义对象的字段</li>\n</ul>\n</div>",
"inline": true,
"id": "u:6d0819fc0bda"
}
],
"id": "u:b5c0f98dc113",
"closeOnEsc": false,
"closeOnOutside": false,
"showCloseButton": true,
"data": {
"&": "$$",
"recordId": "${recordId}"
},
"onEvent": {
"confirm": {
"weight": 0,
"actions": [
{
"componentId": "",
"args": {
"api": {
"url": "/service/api/~database-objects/reset",
"method": "post",
"data": {
"objectName": "${record.name}"
}
},
"messages": {}
},
"actionType": "ajax"
},
{
"actionType": "custom",
"script": "window.location.reload();"
}
]
}
}
}
}
],
"weight": 0
}
}
}
],
"regions": [
"body"
],
"data": {
},
"bodyClassName": "p-0",
"id": "u:46d1821365fc"
}
is_enable: true
label: 重置
'on': record_only_more
type: amis_button
visible: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
* @Author: [email protected]
* @Date: 2023-04-21 16:25:07
* @LastEditors: [email protected]
* @LastEditTime: 2023-05-18 09:26:18
* @LastEditTime: 2024-03-21 11:58:43
* @Description:
*/
var packageServiceName = '~database-objects'

const { getObject } = require('@steedos/objectql');

const sleep = async (ms) => new Promise(resolve => setTimeout(resolve, ms));

function isPatternTrigger(data){
const {listenTo} = data;
if(listenTo === '*'){
Expand Down Expand Up @@ -36,7 +41,19 @@ module.exports = {
* Actions
*/
actions: {

resetObject: {
rest: {
method: "POST",
path: "/reset"
},
async handler(ctx) {
const { objectName } = ctx.params;
await getObject('objects').directDelete({filters: ['name','=', objectName]});
await getObject('object_fields').directDelete({filters: ['object','=', objectName]});
await sleep(2 * 1000)
return true;
}
}
},

/**
Expand Down

0 comments on commit e243f8a

Please sign in to comment.