Working with Multiple Resources Types
Posted: Tue Mar 26, 2013 1:49 pm
With a few modifications, you can provide your users with a simple tool that lets them decide what values to use for the column headers on the Schedule view.
Before you make any changes to your file, back it up. Do not proceed until you have done this!
NOTE: The modifications described in this article affect both the Schedule and Grid view similarly (a column on the Schedule view is equivalent to a row on the Grid view). For clarity, I'll refer only to the Schedule view.
Section I: Dynamic column headers
1. Create a value list for each type of resource. For example:
Rooms
Teachers
Levels
2. Create another value list whose values are the actual names of the above value lists. We'll call this one "ResourceTypes".
3. Create a global text field in the CalendarInterface table called "ResourceTypeGlob".
4. Place the "ResourceTypeGlob" field on the Settings panel in the sidebar on the Calendar layout, format it as radio buttons, and assign it the "ResourceTypes" value list. Set up an "OnObjectModify" script trigger on that field to run the "Run Resource Filter" script. (see attached image)
5. Somewhere toward the beginning of the "Upon Opening" script, add a Set Field step to assign the CalendarInterface::ResourceTypeGlob field a default value of one of the value list names (we'll use "Rooms" for this example).
6. In the "Load Resources" script, you'll see that the first script step populates the $sc_Resources variable by the following calculation:
ValueListItems ( Get ( FileName ) ; "Resources" )
Change it to this:
ValueListItems ( Get ( FileName ) ; CalendarInterface::ResourceTypeGlob )
This tells the script to populate the column headers on the Schedule view with the value list that the user has selected.
7. In the "Load Filtered Resources" script, replace this step:
Set Variable [$$sc_ResourceList; Value:CalendarInterface::FilterGlob_3]
With these two steps:
Set Variable [$sc_Resources; Value:ValueListItems ( Get ( FileName ) ; CalendarInterface::ResourceTypeGlob )]
Set Variable [$$sc_ResourceList; Value:FilterValues ( $sc_Resources ; CalendarInterface::FilterGlob_3 )]
Section II: Data Entry
1. Open an event in the Event Details popup window, go into layout mode, and go to one of the unused tabs. Draw a field object and associate it with the Resource field. Format the field as radio buttons and assign it one of your resource-type value lists (Rooms). Then repeat that process for each of your other resource-type value lists (Teachers and Levels). So you'll end up with three instances of the Resource field, each associated with a different value list. Label each instance accordingly, and name the tab you're on "Resources". (see attached image)
2. If the Resource field still appears on the "Main Info" tab of your Event Details layout as an edit box or drop-down list, you should remove it to avoid confusion, because from now on the Resource field will contain a list of return-separated values.
3. If in your solution you are storing different resource types in separate fields and you would like to involve them all in rendering events on the Schedule view, simply set the Resource field to auto-enter by calculation the following*:
List ( YourTable::Room ; YourTable::Teacher ; YourTable::Level )
*Where Room, Teacher and Level are separate data fields in your events table.
Be sure to uncheck the "Do not replace existing…" box in the Options dialog.
3a. If you use this "separate fields" scenario, there is one more set of scripting modifications you'll need to make in order to use drag-and-drop to move events between resources on the Schedule view. Drag-and-drop will appear to work at this point (the event will move to the correct new column because the Resource field will have been updated), but don't be fooled. The actual data fields (Room, Teacher and Level) will not have been updated. To fix this problem, open the "Create Edit Delete Event…" script and look within the If [not IsEmpty ($sc_Resource)] nest, immediately following the "This set field includes support for multiple resources…" comment. Disable the "Set Field By Name" step and add three new "Set Field" steps here to update the Room, Teacher and Level fields directly, and wrap each in an If [] statement to determine whether the value associated with the target column appears in the value list that is associated with that field. You can copy the calculation code from the original "Set Field By Name" step, and you only need to change the field that is referenced in the first line (r = YourTable::Room, r = YourTable::Teacher and r = YourTable::Level).
Section III: Filtering
1. To enable filtering based on your multiple value lists, go to the Filters > Resources tab panel in the sidebar and associate the FilterGlob_3 field with the "Rooms" value list.
2. Duplicate that field object and associate the copy with the "Teachers" value list, and then do the same for "Levels". So you'll end up with three instances of the FilterGlob_3 field, each associated with a different value list. Label each instance accordingly.
3. Format these field objects as checkboxes (or popup-menus, if the lists are too long), and resize them as necessary.
Section IV: Going further...
With lots of resources you may only want to see those that are actually used in the found set of events. To restrict the resources this way (in both the column headers on schedule view and in the check boxes for the different resource-type filters) make these additional changes:
1. Create three new text fields in the CalendarInterface table: "vl_1", "vl_2" and "vl_3", and one new global number field called "FilterResourcesGlob".
2. Create three new value lists called "Rooms Filtered", "Teachers Filtered" and "Levels Filtered". Set them up to "Use values from field" from CalendarInterface::vl_1, CalendarInterface::vl_2 and CalendarInterface::vl_3, respectively. Use these new value lists for the filter-field check boxes.
3. Edit the "Load Resources" script so it looks like this:
Here's the code you'll need to set that $all_resources variable:
4. Make a toggle switch using the "FilterResourcesGlob" global number field on the "Settings" panel so your users can turn this feature on and off.
That's it! Enjoy!
Before you make any changes to your file, back it up. Do not proceed until you have done this!
NOTE: The modifications described in this article affect both the Schedule and Grid view similarly (a column on the Schedule view is equivalent to a row on the Grid view). For clarity, I'll refer only to the Schedule view.
Section I: Dynamic column headers
1. Create a value list for each type of resource. For example:
Rooms
Teachers
Levels
2. Create another value list whose values are the actual names of the above value lists. We'll call this one "ResourceTypes".
3. Create a global text field in the CalendarInterface table called "ResourceTypeGlob".
4. Place the "ResourceTypeGlob" field on the Settings panel in the sidebar on the Calendar layout, format it as radio buttons, and assign it the "ResourceTypes" value list. Set up an "OnObjectModify" script trigger on that field to run the "Run Resource Filter" script. (see attached image)
5. Somewhere toward the beginning of the "Upon Opening" script, add a Set Field step to assign the CalendarInterface::ResourceTypeGlob field a default value of one of the value list names (we'll use "Rooms" for this example).
6. In the "Load Resources" script, you'll see that the first script step populates the $sc_Resources variable by the following calculation:
ValueListItems ( Get ( FileName ) ; "Resources" )
Change it to this:
ValueListItems ( Get ( FileName ) ; CalendarInterface::ResourceTypeGlob )
This tells the script to populate the column headers on the Schedule view with the value list that the user has selected.
7. In the "Load Filtered Resources" script, replace this step:
Set Variable [$$sc_ResourceList; Value:CalendarInterface::FilterGlob_3]
With these two steps:
Set Variable [$sc_Resources; Value:ValueListItems ( Get ( FileName ) ; CalendarInterface::ResourceTypeGlob )]
Set Variable [$$sc_ResourceList; Value:FilterValues ( $sc_Resources ; CalendarInterface::FilterGlob_3 )]
Section II: Data Entry
1. Open an event in the Event Details popup window, go into layout mode, and go to one of the unused tabs. Draw a field object and associate it with the Resource field. Format the field as radio buttons and assign it one of your resource-type value lists (Rooms). Then repeat that process for each of your other resource-type value lists (Teachers and Levels). So you'll end up with three instances of the Resource field, each associated with a different value list. Label each instance accordingly, and name the tab you're on "Resources". (see attached image)
2. If the Resource field still appears on the "Main Info" tab of your Event Details layout as an edit box or drop-down list, you should remove it to avoid confusion, because from now on the Resource field will contain a list of return-separated values.
3. If in your solution you are storing different resource types in separate fields and you would like to involve them all in rendering events on the Schedule view, simply set the Resource field to auto-enter by calculation the following*:
List ( YourTable::Room ; YourTable::Teacher ; YourTable::Level )
*Where Room, Teacher and Level are separate data fields in your events table.
Be sure to uncheck the "Do not replace existing…" box in the Options dialog.
3a. If you use this "separate fields" scenario, there is one more set of scripting modifications you'll need to make in order to use drag-and-drop to move events between resources on the Schedule view. Drag-and-drop will appear to work at this point (the event will move to the correct new column because the Resource field will have been updated), but don't be fooled. The actual data fields (Room, Teacher and Level) will not have been updated. To fix this problem, open the "Create Edit Delete Event…" script and look within the If [not IsEmpty ($sc_Resource)] nest, immediately following the "This set field includes support for multiple resources…" comment. Disable the "Set Field By Name" step and add three new "Set Field" steps here to update the Room, Teacher and Level fields directly, and wrap each in an If [] statement to determine whether the value associated with the target column appears in the value list that is associated with that field. You can copy the calculation code from the original "Set Field By Name" step, and you only need to change the field that is referenced in the first line (r = YourTable::Room, r = YourTable::Teacher and r = YourTable::Level).
Section III: Filtering
1. To enable filtering based on your multiple value lists, go to the Filters > Resources tab panel in the sidebar and associate the FilterGlob_3 field with the "Rooms" value list.
2. Duplicate that field object and associate the copy with the "Teachers" value list, and then do the same for "Levels". So you'll end up with three instances of the FilterGlob_3 field, each associated with a different value list. Label each instance accordingly.
3. Format these field objects as checkboxes (or popup-menus, if the lists are too long), and resize them as necessary.
Section IV: Going further...
With lots of resources you may only want to see those that are actually used in the found set of events. To restrict the resources this way (in both the column headers on schedule view and in the check boxes for the different resource-type filters) make these additional changes:
1. Create three new text fields in the CalendarInterface table: "vl_1", "vl_2" and "vl_3", and one new global number field called "FilterResourcesGlob".
2. Create three new value lists called "Rooms Filtered", "Teachers Filtered" and "Levels Filtered". Set them up to "Use values from field" from CalendarInterface::vl_1, CalendarInterface::vl_2 and CalendarInterface::vl_3, respectively. Use these new value lists for the filter-field check boxes.
3. Edit the "Load Resources" script so it looks like this:
Here's the code you'll need to set that $all_resources variable:
- Code: Select all
ExecuteSQL (
"SELECT \"Resource\" FROM \"SampleEvents\" where \"zscTimestampStartCalcNum\" Between " & $start & " and " & $end &
"Union
SELECT \"Resource\" FROM \"SampleEvents\" where \"zscTimestampEndCalcNum\" Between " & $start & " and " & $end &
"Union
SELECT \"Resource\" FROM \"SampleEvents\" where \"zscTimestampStartCalcNum\" < " & $start & " and \"zscTimestampEndCalcNum\" > " & $end ; "!~!" ; "¶" )
4. Make a toggle switch using the "FilterResourcesGlob" global number field on the "Settings" panel so your users can turn this feature on and off.
That's it! Enjoy!