આ માર્ગદર્શિકા મીટિંગ રૂમ બુક કરવા માટેનું કૅલેન્ડર બનાવે છે: દરેક રૂમ માટે એક હરોળવાળી ટાઇમલાઇન, ડ્રૅગ કરીને ગોઠવી શકાય તેવાં બુકિંગ, એક રૂમને બે વાર બુક થતો અટકાવતો નિયમ, અને કોઈ પણ કૅલેન્ડરમાં બુકિંગ ઉમેરતી ફાઇલ. તે @needless-ui/angular નું શેડ્યૂલર વાપરે છે, જે આખા Needless UI ની જેમ MIT લાઇસન્સ હેઠળ છે, તેથી રિસોર્સ ટાઇમલાઇન કોઈ પણ ઍપ માટે મફત છે.

રૂમ અને બુકિંગ

રૂમ એ રિસોર્સ છે: એક id, એક title, અને બાકીનું બધું data માં. બુકિંગ એ સાદા ISO સમયવાળી ઇવેન્ટ છે, જેમ કે 2026-10-23T09:00, અને તેમના રૂમનો id resource માં હોય છે. એક બુકિંગમાં યાદી તરીકે અનેક રૂમ કે લોકો હોઈ શકે છે.

દરેક રૂમ માટે એક હરોળ

બંનેને view="timeline" સાથે nui-scheduler ને પાસ કરો. dayStart અને dayEnd દિવસને રૂમ ખુલ્લા હોય તે કલાકો પૂરતો રાખે છે, snapMinutes બુકિંગને 15 મિનિટના સ્ટેપમાં ખસેડે છે, અને businessHours રૂમ બંધ હોય તે સમય ઝાંખો કરે છે. nuiSchedulerResource દરેક હરોળનું હેડર દોરે છે.

booking.html
<nui-scheduler
[events]="bookings()"
[resources]="rooms"
view="timeline"
dayStart="8"
dayEnd="19"
snapMinutes="15"
[businessHours]="hours"
editable
selectable
[allow]="free"
(slotSelect)="book($event)"
(eventChange)="move($event)"
(rangeChange)="range.set($event)"
>
<ng-template nuiSchedulerResource let-room>{{ room.title }}</ng-template>
</nui-scheduler>
<button nuiButton type="button" (click)="download()">Add to calendar</button>

બુક કરો અને ખસેડો

શેડ્યૂલર તમારો ડેટા જાતે ક્યારેય બદલતું નથી: લોકો જે કરે છે તે જણાવે છે. રૂમની હરોળ પર ડ્રૅગ કરવાથી સમય પસંદ થાય છે, અને slotSelect તેને રૂમ સાથે જણાવે છે. બુકિંગ કે તેનો છેડો ડ્રૅગ કરવાથી eventChange તેનો નવો સમય જણાવે છે, અને તે બીજા રૂમમાં ગયું હોય તો નવો રૂમ પણ. સિગ્નલ અપડેટ કરો, એટલે ટાઇમલાઇન પણ બદલાઈ જાય છે.

booking.ts
import { Component, signal } from '@angular/core';
import { NuiButton } from '@needless-ui/angular/button';
import {
NuiScheduler,
type NuiSchedulerChange,
type NuiSchedulerEvent,
NuiSchedulerResourceTemplate,
type NuiSchedulerSlot,
} from '@needless-ui/angular/scheduler';
import { downloadIcs } from './booking-ics';

@Component({
selector: 'app-bookings',
imports: [NuiButton, NuiScheduler, NuiSchedulerResourceTemplate],
templateUrl: './booking.html',
})
export class Bookings {
/** Rooms are resources; bookings are events, with their room in `resource`. */
protected readonly rooms = [
{ id: 'atlas', title: 'Atlas' },
{ id: 'boreal', title: 'Boreal' },
];
protected readonly bookings = signal<NuiSchedulerEvent[]>([]);
/** Open on weekdays from 8:00 to 19:00: other time is shaded. */
protected readonly hours = [{ days: [1, 2, 3, 4, 5], start: '08:00', end: '19:00' }];
/** The days on screen: load their bookings when it changes. */
protected readonly range = signal<{ start: string; end: string } | null>(null);

protected book({ start, end, resource }: NuiSchedulerSlot): void {
const booking = { id: crypto.randomUUID(), title: 'New booking', start, end, resource };
this.bookings.update((all) => [...all, booking]);
}

protected move({ event, start, end, resource }: NuiSchedulerChange): void {
this.bookings.update((all) =>
all.map((b) =>
b.id === event.id ? { ...b, start, end, resource: resource ?? b.resource } : b,
),
);
}

/** A room holds one booking at a time. */
protected readonly free = (time: NuiSchedulerChange | NuiSchedulerSlot): boolean => {
const id = 'event' in time ? time.event.id : null;
const room = 'event' in time ? (time.resource ?? time.event.resource) : time.resource;
return !this.bookings().some(
(b) => b.id !== id && b.resource === room && b.start < time.end && b.end > time.start,
);
};

protected download(): void {
downloadIcs(this.bookings(), 'bookings');
}
}

ડબલ બુકિંગ નહીં

બુકિંગ બને કે ખસે તે પહેલાં allow ને પૂછવામાં આવે છે. તે false પાછું આપે, તો ડ્રૅગ લાલ દેખાય છે અને છોડતાં કંઈ થતું નથી, અને કીબોર્ડ વાપરતાં શેડ્યૂલર કહે છે કે તે સમય ઉપલબ્ધ નથી. ઉદાહરણ રૂમનાં બીજાં બુકિંગ તપાસે છે; તમારા સર્વર પર ફરી તપાસો, કારણ કે અંતિમ નિર્ણય તેનો છે.

સ્ક્રીન પરના દિવસો લોડ કરો

rangeChange બતાવેલો પહેલો અને છેલ્લો દિવસ જણાવે છે, એક વાર શરૂઆતમાં અને પછી જ્યારે પણ લોકો પેજ બદલે ત્યારે, જેથી તમે ફક્ત તે જ બુકિંગ લાવી શકો, httpResource વડે કે તમને ગમે તે રિક્વેસ્ટથી.

કૅલેન્ડરમાં ઉમેરો

nuiSchedulerToIcs() બુકિંગને iCalendar ફાઇલ તરીકે લખે છે, જે Google Calendar, Outlook અને Apple Calendar ઇમ્પોર્ટ કરે છે. nuiSchedulerFromIcs() આવી ફાઇલ પાછી વાંચે છે, અને બીજા ટાઇમ ઝોનના સમયને વપરાશકર્તાના ટાઇમ ઝોનમાં ફેરવે છે.

booking-ics.ts
import { type NuiSchedulerEvent, nuiSchedulerToIcs } from '@needless-ui/angular/scheduler';

/** Saves events as an .ics file, which Google Calendar, Outlook and Apple Calendar import. */
export function downloadIcs(events: readonly NuiSchedulerEvent[], name: string): void {
const file = new Blob([nuiSchedulerToIcs(events, { name })], { type: 'text/calendar' });
const link = document.createElement('a');
link.href = URL.createObjectURL(file);
link.download = `${name}.ics`;
link.click();
URL.revokeObjectURL(link.href);
}

કીબોર્ડ અને સ્ક્રીન રીડર

આ બધું માઉસ વિના કામ કરે છે. ટાઇમલાઇન એક જ ટૅબ સ્ટૉપ છે: તીર કીથી સમય અને રૂમ વચ્ચે ફરાય છે, Shift સાથે તીર સમય પસંદ કરે છે, અને Enter તેને બુક કરે છે. બુકિંગ પર, Alt સાથે તીર તેને બીજા સમય કે રૂમમાં ખસેડે છે. દરેક બુકિંગ એક બટન છે, જેનું નામ તેનું શીર્ષક, રૂમ, દિવસ અને સમય છે.

એક દિવસમાં બાજુ-બાજુમાં રૂમ, પુનરાવર્તિત બુકિંગ અને બાકીના બધા વિકલ્પો માટે શેડ્યૂલરનું પેજ અને API જુઓ.