saltcorn / fullcalendar

Calendar plugin based on FullCalendar
MIT License
0 stars 4 forks source link

how to create a join field? #8

Open kevin8181 opened 2 years ago

kevin8181 commented 2 years ago

@glutamate how do I make the color field show options for join fields? like if someone had a table of event types, and each one had a color field, and the events are children of the event types

glutamate commented 2 years ago

Exactly this scenario done in the new gantt chart @kevin8181

First, make the array of field names the user can choose the color field from. I start with an array of all the color fields on the associated table: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L35-L37

then loop through the key fields: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L38-L39

get the parent table, its fields, and append all color fields to the array of options, a string with a dot separating the key field from the field on the joined table: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L44-L46

cfg form field as normal: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L138-L145

in the run method, figure out if it is a join field i.e. has a dot: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L230

if yes, add a join field to the joinFields argument to getJoinedRows: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L231-L234

key in joinFields object is the variable name in the fetched rows, ref is the key field name and target is the name of the field on the join table which will hold the data.

used here https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L238

The use of the color variable here was very idiosyncratic according to the underlying library, hopefully you don't have to create the CSS classes as I do. to retrieve the color you still have to keep track of its name though like this: https://github.com/saltcorn/svelte-gantt/blob/c70268d16e0043ec8bf357720cafea732b6a1f95/index.js#L292-L293

glutamate commented 2 years ago

for more examples of getJoinedRows and its joinFields argument, see this test file https://github.com/saltcorn/saltcorn/blob/master/packages/saltcorn-data/tests/table.test.ts

kevin8181 commented 2 years ago

maybe there should be a function for this? like pass a table, array of data types, parent depth, child depth, and get the values back? seems like something used often enough to make a standardized system

either way I'll give this a try

Lulubel commented 2 years ago

Hello. I agree Full calendar should use the joined fields. I have a table "_actions" with all the informations about a project, like the title ; and a table "_dates" with a join field "action" on _actions (relation type: one action to many dates). I use the view Calendar on the _dates table. I would like the title show on the calendar but the extension only propose the _dates fields for "Event title field". (Sorry for my english). Thanks for your answer. Aurélie