Comments (7)
I think I understand the text of this issue, but not the title. Can you elaborate on this one?
from express-admin.
Yes. Basically I have a situation where I need to be able to seet a TINYINT column = 1 to say "This has been deleted", but a deletedAt field (Like Rails or Sequelize use) would be a great option too. I'd imagine having both is ideal, but I understand they're two separate things, and since deletedAt is the standard today, I believe it's the most needed one.
I'll give an example I have working and I'm trying to adapt it to Express Admin:
"categories": {
"slug": "categories",
"table": {
"name": "categories",
"pk": "id",
"verbose": "Categories"
},
"columns": [
{
"name": "id",
"verbose": "id",
"control": {
"text": true
},
"type": "int(11)",
"allowNull": true,
"defaultValue": null,
"listview": {
"show": false
},
"editview": {
"show": true
}
},
{
"name": "name",
"verbose": "Name",
"control": {
"text": true
},
"type": "varchar(255)",
"allowNull": false,
"defaultValue": null,
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "deleted",
"verbose": "deleted",
"control": {
"text": true
},
"type": "tinyint(1)",
"allowNull": false,
"defaultValue": "0",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "createdAt",
"verbose": "createdAt",
"control": {
"text": true
},
"type": "datetime",
"allowNull": false,
"defaultValue": "0000-00-00 00:00:00",
"listview": {
"show": true
},
"editview": {
"show": true
}
},
{
"name": "updatedAt",
"verbose": "updatedAt",
"control": {
"text": true
},
"type": "datetime",
"allowNull": false,
"defaultValue": "0000-00-00 00:00:00",
"listview": {
"show": true
},
"editview": {
"show": true
}
}
],
"mainview": {
"show": true
},
"listview": {
"order": {},
"page": 25
},
"editview": {
"readonly": false
}
}
from express-admin.
If you want to set fields containing application generated values (like created_at, deleted_at, generated guid for id and so on), you should use the events
There is no API for this, so you should take a look at the examples and here
The workflow is as follows:
1 add a breakpoint at the top of the event (write debugger;)
2 run the admin with --debug-brk flag
3 use node-inspector to see what you have in the args var
Basically this isn't an event either but rather just a function called right before/after the database is updated. So you can use that to set things on your own.
These pre/save callback are very flexible, in fact you can write in them whatever you want to. It requires a bit knowledge about the admin args though. Also this event code is part of your project's configuration, and it's completely out of the admin's core code.
Let me know if I'm missing something.
from express-admin.
@simov the Events are pretty great, I didn't think about using them like this.
We're still left with the deletion issue. How should we go about listing only WHERE deletedAt IS NULL
or WHERE deleted=0
?
from express-admin.
Apparently we need more events not just pre/post save. Actually this was the initial idea, but the pre/post save were the most urgent. I think this can go in the next release.
Essentially you'll have to modify the query for the list view, but yeah currently it's not possible. I think I can have it these days, you can watch the project to get notifications when I'm pushing stuff.
from express-admin.
So the workflow is as usual using the debugger heavily to get an idea what's in args
. The example is very well commented.
You need to write tests for your events, and execute them each time you install new version of express-admin (just in case)
In short: inside the preSave event I'm tricking the admin to think that it updates a record instead of removing it.
Inside the preList event first I'm checking if the user actually insist on showing the soft deleted records by using the filter widget (I thought it might be useful to see only the soft deleted records + you can filter by deleted_at
also)
Next I'm modifying the generated query for the listview by adding some conditions to it, also to the query partials that are used for creating the pagination query after that.
I'm closing this, let me know if there is anything else.
from express-admin.
@ellahn I just updated the events documentation
The examples are for deleting and then selecting inside the listview
The second one is a bit simplified, also you can try it out from the examples repository
from express-admin.
Related Issues (20)
- nsp security issues HOT 1
- Store comma seperated values for a single column.
- Passing parameters to /add in order to prevalue fields
- mysql insert operation not working in -v (development, no login) mode HOT 1
- Time is not shown correctlly for mysql db HOT 1
- Unhandled exception when paginating empty resultsets
- Ajax call not working
- Error creating entry with many to many relationship
- crashes under Firefox Quantum 62.0 (64-bit) under OSX
- Support for postgres data type json? HOT 4
- ERROR! Could not find `pg` or `pg.js` module HOT 1
- Can this be used with hapijs? HOT 1
- PG setup via connection string
- Datepicker saving timezone with timestamp HOT 1
- Empty one to Many HOT 4
- Filter in tables throw internal server error HOT 1
- Password authentication fails for Postgres (11) connections HOT 4
- Flash of unstyled content HOT 3
- how to configure server using nodemon HOT 1
- what is mean for this error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-admin.