How to set event color for individual events in FullCalendar eventSources or eventSourceSuccess - fullcalendar

I'm using eventSources with FullCalendar 5.
Each event source returns a different type of event which is then colored differently. One source will return three different types of events, an object with three arrays wrapped, rather than having the source parse the same date range 3 times and return one array each time. Each of the three event types should be colored differently.
The eventSources entry currently looks like this:
{
// Reservation types
url: '/reservations',
method: 'POST',
color: '#ffd5d5',
textColor: 'black',
eventClassNames: ['cal__reservations'],
},
the return is:
{
"type 1": [
{ "title": "type 1 title",
"start": "2022-05-02",
"end": "2022-05-02"}
},
"type 2": [
{ "title": "type 2 title",
"start": "2022-05-04",
"end": "2022-05-02"}
},
"type 3": [
{ "title": "type 3 title",
"start": "2022-05-24",
"end": "2022-05-24"}
}
}
I would like to parse this return so that each type is assigned a different color, but it seems that eventSources is expecting a single array from eventSourceSuccess and that the event color is still statically defined within eventSources for each source as a whole.
Is there any way in eventSources or in eventSourceSuccess to conditionally assign a color to each event, individually?

Related

How to use Phabricator datasource type custom field's "datasource.parameters" property?

I find the type in the doc Custom field,but I don't know how to use it.
The property datasource.parameters receives an array and you can use it to pass your own settings of the field. For instance, a custom field would look like this in the JSON format:
"custom-field": {
"name": "Custom Field",
"type": "datasource",
"caption": "Choose a cool source",
"datasource.class": "MyCustomDatasource",
"datasource.parameters": ["my_custom_setting": "1"]
"limit": 1,
"required": false,
"subtypes": ["my_form"]
}
And in your datasource class you can access them using getParameter():
MyCustomDatasource.php
public function loadResults() {
...
$param_value = $this->getParameter('my_custom_setting');
\\ now you can do anything with the value
}

How do I get a list of all properties in a JSON document?

I have a dynamic JSON document but for the sake of this question, imagine it resembles the following:
{
"name": "Jungle Gym",
"age": 25,
"favorite_color": "#ffa500",
"gender": "male",
"location": {
"city": "Seattle",
"state": "WA",
"citystate": "Seattle, WA"
},
"pets": [
{
"type": "dog",
"name": "Foo",
"food": [
"chicken",
"beef",
"fish"
]
},
{
"type": "cat",
"name": "Bar"
}
]
}
How do I get a list of all property names in the document? I can get the top level property names ("name", "age", "favorite_color", "gender", "location", "pets") but I need to get all property names down to "location.state" or "pets.food" and, if the properties / objects exist, even deeper.
I started using the following:
var model = JsonConvert.DeserializeObject<JObject>(json);
foreach (JProperty property in model.Properties())
{
if (property.Value.Type == JTokenType.Object)
{
foreach (var tmp in property.Children())
{
Console.WriteLine(tmp.SelectToken().);
}
}
}
but cannot seem to navigate into the objects beyond the top level to get the next level of properties (location properties, e.g.). Ideally, I'd like the list of derived property names to include the full path to the property, e.g., location.city, location.state, etc., instead of just the property name, e.g. city, state.
How can I get a list of all properties in a JSON document with potentially various levels of nesting?
In order to get all the keys in Json string (all levels), you could use Descendants and Path properties to fetch the details.
var data = JObject.Parse(jsonString);
var result = data.Descendants()
.OfType<JProperty>()
.Select(f=>Regex.Replace(f.Path,#"\[[0-9]\]",string.Empty))
.Distinct();
Please note the Regex is used to replace all the indices that might result due to pets list.
Output,

Firebase data structure - Keeping duplicated data up-to-date

I created a flatted data structure. When pushing duplicated data whats the accepted pattern for keeping that data up-to-date. Here the data for the groups info is duplicated into the users-groups and the groups tree.
{
"users": ..
"users-groups": ..
"groups": ..
}
When creating a group for a user two updates takes place:
First: push to /groups/group_key
{
"name": "Test Group",
"image: "/testimage.jpg"
}
Second: push to /users-groups/user_uid/group_key
{
"orderNum: 0,
"info": {
"name": "Test Group",
"image: "/testimage.jpg"
}
}
Should keeping this data in the user-groups up-to-date be a job for the client or should a server handle this?
The data in the groups tree will always be the newest and the changes should propagate down to all the users that are members of that group.
Is there any tutorials or reference material for this problem?
note: i'm using this structure because a user can be a member of multiple groups and I don't think it would be a good idea to make possibly several ref.once's to get the data from the /groups/ directly.
You can use multi path update. Just observe reference with function and update all other informations
db.ref("").update({
'/users/dedd': info,
'/users/cdcd': info2
})
You should not have data saved duplicated. Instead you should save reference to group.
Your data should look like this.
{
"users": {
"userkey1": {
"data": {
"name": "",
"firstname": ""
},
"groups": {
"groupkey1": true // true or orderNum value
}
}
},
"groups": {
"groupkey1": {
"data": {
"name": "Test Group",
"image": "/testimage.jpg",
"other": "data"
},
"users": {
"userkey1": true
}
}
}
}
You can easily check if user is in group by checking if value at any of these positions is true.
users/userkey1/groups/groupkey1 or groups/groupkey1/users/userkey1.
When you create new group you save in under groups/newgroupkey position and you updated groups under users node by only setting newgroupkey to true.
So you do not duplicate your data.
For more information about structuring your data check the following link.
https://firebase.google.com/docs/database/android/structure-data

How to create GTM data layer variable with complex array

In Google Tag Manager a pre-defined variable type of "Data Layer Variable" exists with an input for the variable name. In a standard single level of key/value pairs this is easy.
var dataLayer = [{"mykey":"myvalue"}];
Given that data layer you'd just use mykey as your variable to input into GTM. However, if you use the CEDDL spec (http://www.w3.org/2013/12/ceddl-201312.pdf) structure you end up with a deeply nested array:
dataLayer = [
{
"product": [
{
"category": {
"primaryCategory": "Auto Loans"
},
"productInfo": {
"productID": "1",
"productName": "PurchaseLoan",
"description": "Auto finance loan"
},
"security": [
"Analytics",
"Personalization",
"Recommendations"
]
}
]
}
]
So the real question is: how do I access the value of "productName" in the above example?
In standard Javascript you might access it like so:
dataLayer[1].product[0].productInfo.productName
or
dataLayer.1.product.1.productInfo.productName
... but neither of these options work (with or without dataLayer.1 as the first node).
This is the UI to enter the variable name:
When you define your DataLayer variable in GTM, you don't need to specify "dataLayer" in the variable name, ie. it should just be:
product.0.productInfo.productName

how to sort events in full calendar with json property irrespective srart time and duration?

I want to sort events with my json property called "displayOrder". but not on start time.
I have applied eventOrder:"displayOrder" still not sorting based on given input
this means event one should appear first.
here is json
{
"title": "Event two",
"start": "2015-10-01T10:30:00-05:00",
"end": "2015-10-02T17:30:00-05:00",
"displayOrder":"2",
"bookingsAvailable":true,
"description":"We can add description in JSON"
},
{
"title": "Event one",
"start": "2015-10-01T11:30:00-05:00",
"end": "2015-10-01T17:30:00-05:00",
"displayOrder":"1"
}
check image
You will requrie to modify compareSlotSegs(seg1, seg2) inside fullcalendar.js
function compareSlotSegs(seg1, seg2) {
return seg1.originalStart - seg2.originalStart || // earlier start time goes first
(seg2.originalEnd - seg2.originalStart) - (seg1.originalEnd - seg1.originalStart) ||
(seg1.event.displayOrder|| '').localeCompare(seg2.event.displayOrder);
}
compareSegs: function(seg1, seg2) {
return compareByFieldSpecs(seg1.event, seg2.event, this.view.eventOrderSpecs)|| // events with display order
seg1.displayOrder -seg2.displayOrder || // earlier events go first
seg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first
seg2.event.allDay - seg1.event.allDay // tie? put all-day events first (booleans cast to 0/1)
}

Resources