Adjust the size of an event in the Angular Full Calendar with Chronofy, while utilizing constraints to control the drag and drop functionality

I'm currently in the process of developing an availability calendar for scheduling meetings during open times.

If a time slot is unavailable, users should not be able to place an event there.

While I have successfully implemented this feature, I am facing an issue with resizing events to adjust their duration.

The system only allows me to resize events when I remove the constraint property, but this also permits dragging events into unavailable slots.

To achieve this functionality, I make two API calls - one to retrieve availability data from Chronofy and another to fetch scheduled events for the selected period.

I combine these arrays and populate the Full Calendar events using the configuration options to display all events.

This code is purely a proof of concept, so it may not be very polished.

    this.setEventSources([
    ...available_periods.available_periods.map((ap: any) => {
      ap.groupId = 1;
      ap.display = 'inverse-background';
      return ap;
    }), 
    ...res.events.events.map((e: any) => {
      e.id = e.event_id,
      e.display ='auto';
      e.className = 'tester';
      e.editable = true;
      e.durationEditable = true;
      e.startEditable = true;
      e.constraint = 1;
      return e;
    })]);

This function simply sets the event property on the Full Calendar options based on the provided array.

Note the display setting for the first array which represents available periods. The inverse-background option is used to differentiate between available and unavailable slots by displaying them as blank or greyed out respectively.

A groupId is assigned to group events together as per documentation requirements.

In the second array containing booked events, a constraint is set to prevent overlaps when dragging events with a groupId of 1.

While this functions correctly, I am struggling to enable event resizing/extending with this constraint in place.

If anyone could offer guidance or assistance on how to resolve this issue, I would greatly appreciate it.

Thank you

Answer №1

There are a couple of approaches to address this issue:

Solution 1

If an event is scheduled within a time period, include that period in the list of "available periods." Although it may not appear available to users due to the overlapping event, it will enable you to move and resize the event within that timeframe, as long as it doesn't spill into an unavailable section.

Example data:

var events = [ 
{ "event_id": 1, "title": "Test 1", "start": "2024-01-05 09:00", "end": "2024-01-05 11:00"}, 
{ "event_id": 1, "title": "Test 2", "start": "2024-01-06 11:00", "end": "2024-01-06 12:30"}, 
{ "event_id": 1, "title": "Test 3", "start": "2024-01-02 10:00", "end": "2024-01-03 11:00"}, 
{ "event_id": 1, "title": "Test 4", "start": "2024-01-04 10:00", "end": "2024-01-04 11:10"}, ]; 
var available_periods = [ 
{ "start": "2024-01-01 09:00", "end": "2024-01-01 12:00" }, 
{ "start": "2024-01-02 10:00", "end": "2024-01-03 11:00"}, 
{ "start": "2024-01-04 09:00", "end": "2024-01-04 12:00" }, 
{ "start": "2024-01-05 09:00", "end": "2024-01-05 13:00"}, 
{ "start": "2024-01-06 11:00", "end": "2024-01-06 12:30"}, 
{ "start": "2024-01-06 13:00", "end": "2024-01-06 17:00" }]; 

Live demo: https://codepen.io/ADyson82/pen/dyrVOdV

Solution 2

Instead of using inverse-background events for availability indication, consider using regular background events during the unavailable times. Configure the calendar so that users cannot manipulate events over these background elements. Any slot without a background or booked event is considered available.

Note: For regularly occurring unavailability patterns, utilize the businessHours setting efficiently and establish it as the event constraint.

Sample data:

var events = [ 
{ "event_id": 1, "title": "Test 1", "start": "2024-01-05 09:00", "end": "2024-01-05 11:00"}, 
{ "event_id": 1, "title": "Test 2", "start": "2024-01-06 11:00", "end": "2024-01-06 12:30"}, 
{ "event_id": 1, "title": "Test 3", "start": "2024-01-02 10:00", "end": "2024-01-03 11:00"}, 
{ "event_id": 1, "title": "Test 4", "start": "2024-01-04 10:00", "end": "2024-01-04 11:10"}, ]; 
var unavailable_periods = [ 
{ "start": "2023-12-31 00:00", "end": "2024-01-01 00:00" }, 
{ "start": "2024-01-01 12:00", "end": "2024-01-02 00:00"}, 
{ "start": "2024-01-02 09:00", "end": "2024-01-03 10:00"}, 
{ "start": "2024-01-03 11:00", "end": "2024-01-04 00:00" }, 
{ "start": "2024-01-04 12:00", "end": "2024-01-05 00:00" }, 
{ "start": "2024-01-05 13:00", "end": "2024-01-06 00:00"}, 
{ "start": "2024-01-06 09:00", "end": "2024-01-06 11:00"}, 
{ "start": "2024-01-06 12:30", "end": "2024-01-06 13:00" }, 
{ "start": "2024-01-06 17:00", "end": "2024-01-07 00:00" }]; 

Code modifications:

unavailable_periods.map

ap.display = 'background'; 

(variable name change and switch from "inverse-background" to "background")

and

events.map((e) => { 
e.id = e.event_id, 
e.display ='auto'; 
e.className = 'tester'; 
e.editable = true; 
e.durationEditable = true; 
e.startEditable = true; 
return e; }) 

(removal of eventConstraint property)

Additional option:

eventOverlap: function (stillEvent, movingEvent) { return stillEvent.display != "background"; }, 

Live demo: https://codepen.io/ADyson82/pen/dyrZOXp

Please note that the examples provided above are written in regular JavaScript, as I am unfamiliar with Angular. However, the core principles remain the same, and minor syntax adjustments may be necessary to make it compatible with Angular.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

TypeORM find query is returning a data type that does not match the defined entity type

In my infrastructure module, I am using the code snippet below: import { Student } from "core" import { Repository } from "./Repository" import { Database } from "../../db" export class UserRepository<Student> extends Re ...

Using jQuery to toggle visibility based on scroll position

Recently, I received a web template equipped with a jQuery library called sticky, which essentially makes the navigation "stick" to the top of the page as you scroll. Now, my goal is to integrate a logo into the navigation once it reaches its final positio ...

Developing a unified input element containing numerous fields

After @grateful answered this question, I wanted to elaborate in case it could benefit others... In my project, there's a page called rsetup.php which has some PHP code to access a MySQL database for filling the HTML content of the page. This HTML ge ...

Create a versatile multi-autocomplete-chips input in Angular 9 using FormArray and encounter the issue: ERROR TypeError: control.registerOnChange is not a

Current Situation Table component - a table with buttons to create or edit rows. Clicking on any of these buttons will open the same Dialog component containing an input field. The input field is a reusable multi-autocomplete-chips component. If the user ...

Can Angular 4 support the use of a "template reference variable"?

Trying to understand how to utilize a template reference variable within a .pug template. For instance: div(#var) results in an error: compiler.es5.js:1694 Uncaught Error: Template parse errors: There is no directive with "exportAs" set to "#var" (" ... ...

The server's response contained a MIME type of "application/octet-stream" that did not include JavaScript. Module scripts in HTML are subject to strict MIME type checking

Here is the structure of my project: node_modules server.js public: glsl: fragment.glsl vertex.glsl index.html main.js img.jpg style.css I have set up a simple server to serve a three.js animation in server.js const express = require('expre ...

Multiple jQuery load() requests are being triggered by calling it from within the ajaxComplete() callback

I've been stuck on this issue for quite some time now. To troubleshoot, I suggest using Firebug to inspect the AJAX requests. It seems that they are multiplying with each click of the next and previous buttons, causing the page to load slowly: You ca ...

Design a clear button for MUI autocomplete feature

I'm currently working on a project where I need to implement a button that clears the MUI autocomplete value and removes the data from the UI. Although I've managed to delete the data from the UI with the code provided, the onChange value remain ...

Can HTML5 be used to store IDs in PHP chat applications?

I'm in the process of developing a chat application with PHP. Everything is functioning properly, but I have encountered a potential loophole. I am implementing AJAX to fetch chat data as the user scrolls, similar to platforms like Facebook and Twitte ...

PassportJS ensuring secure authentication across all routes

Currently, I am implementing passportJS to secure my API Endpoints within an Express application. So far, the following code is functioning properly. app.get("/route1", passport.authenticate('basic', { session: false }), (req, res) => { ...

The menu field remains open even after clicking on the menu

I have encountered an issue with my code. Here is a DEMO that I created on jsfiddle.net Currently, when you click on the red div, the menu opens. However, if you click on the menu items, the menu area does not close. What do I need to do in order to clo ...

Testing in Angular using the getByRole query functionality is successful only when the hidden: true option is utilized

Currently experimenting with a new library, I'm facing difficulties accessing elements based on their ARIA role. My setup includes angular 10.0.6, jest 26.2.1, along with jest-preset-angular 8.2.1 and @testing-library/angular 10.0.1. Following instru ...

Transferring PHP array data to JavaScript using echo

I'm currently in the process of working on a project that requires extracting data from a database and converting it into a JavaScript array. This array will be used to dynamically update a graph. Below is the PHP code I have written to retrieve the ...

How can I retrieve a list of downloads utilizing the Chrome.downloads api?

I have developed an extension that needs to display all the downloads from the user's downloads folder on a webpage instead of opening the download folder directly. Below is the code I have implemented: window.onload = function(){ var maxNumOfEn ...

Track your status with jQuery technology

I have a link: <a href="/test/number/3/phone/0">33df</a> Is there a way to determine if the words 'number' and 'phone' are present in this link? I am looking for a function similar to: check('number', ' ...

sort by the last element in the array

I have implemented an angular table that is organized by an array. The structure is such that the second level depends on the first level, and the third level depends on the second, and so forth. For instance: A is the parent of B, B is the parent of C. ...

Upon clicking the save button, the FormArray does not trigger the display of any mat error

When I click on the save button outside of the form, I want to display a mat error. However, the error is not getting displayed. I have tried using this.form.markAsDirty() and this.form.markASTouched(), but none of them seem to work. <form [formGroup ...

Methods to verify if an array contains a particular string within a PUG template

I'm currently working with NodeJS using Express and the PUG view engine. My goal is to determine whether an array includes a specific string. I've experimented with JavaScript's built-in methods like: array.includes(str) array.indexOf(str) ...

Error: The file or directory specified at ' ode_modules@fullcalendarcommon' does not exist

While attempting to build or serve my Angular project, I encountered the following error: 'An unhandled exception occurred: ENOENT: no such file or directory, lstat '\node_modules@fullcalendar\common' See "\AppData\ ...

Tips for regularly retrieving information from a psql table

I have a scenario where I am retrieving data from a psql table and converting it into a JSON array to be used for displaying a time series chart using JavaScript. The data that is passed needs to be in the form of an array. Since the data in the table get ...