Some ignored filles was missing
This commit is contained in:
parent
7db22245e2
commit
fd5ab6bc0d
268 changed files with 31970 additions and 4 deletions
106
wwwroot/js/managers/ViewManager.js
Normal file
106
wwwroot/js/managers/ViewManager.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import { ConfigManager } from '../configurations/ConfigManager';
|
||||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
export class ViewManager {
|
||||
constructor(eventBus, config) {
|
||||
this.currentView = 'week';
|
||||
this.buttonListeners = new Map();
|
||||
this.eventBus = eventBus;
|
||||
this.config = config;
|
||||
this.setupEventListeners();
|
||||
}
|
||||
setupEventListeners() {
|
||||
this.setupEventBusListeners();
|
||||
this.setupButtonHandlers();
|
||||
}
|
||||
setupEventBusListeners() {
|
||||
this.eventBus.on(CoreEvents.INITIALIZED, () => {
|
||||
this.initializeView();
|
||||
});
|
||||
this.eventBus.on(CoreEvents.DATE_CHANGED, () => {
|
||||
this.refreshCurrentView();
|
||||
});
|
||||
}
|
||||
setupButtonHandlers() {
|
||||
this.setupButtonGroup('swp-view-button[data-view]', 'data-view', (value) => {
|
||||
if (this.isValidView(value)) {
|
||||
this.changeView(value);
|
||||
}
|
||||
});
|
||||
this.setupButtonGroup('swp-preset-button[data-workweek]', 'data-workweek', (value) => {
|
||||
this.changeWorkweek(value);
|
||||
});
|
||||
}
|
||||
setupButtonGroup(selector, attribute, handler) {
|
||||
const buttons = document.querySelectorAll(selector);
|
||||
buttons.forEach(button => {
|
||||
const clickHandler = (event) => {
|
||||
event.preventDefault();
|
||||
const value = button.getAttribute(attribute);
|
||||
if (value) {
|
||||
handler(value);
|
||||
}
|
||||
};
|
||||
button.addEventListener('click', clickHandler);
|
||||
this.buttonListeners.set(button, clickHandler);
|
||||
});
|
||||
}
|
||||
getViewButtons() {
|
||||
return document.querySelectorAll('swp-view-button[data-view]');
|
||||
}
|
||||
getWorkweekButtons() {
|
||||
return document.querySelectorAll('swp-preset-button[data-workweek]');
|
||||
}
|
||||
initializeView() {
|
||||
this.updateAllButtons();
|
||||
this.emitViewRendered();
|
||||
}
|
||||
changeView(newView) {
|
||||
if (newView === this.currentView)
|
||||
return;
|
||||
const previousView = this.currentView;
|
||||
this.currentView = newView;
|
||||
this.updateAllButtons();
|
||||
this.eventBus.emit(CoreEvents.VIEW_CHANGED, {
|
||||
previousView,
|
||||
currentView: newView
|
||||
});
|
||||
}
|
||||
changeWorkweek(workweekId) {
|
||||
this.config.setWorkWeek(workweekId);
|
||||
// Update all CSS properties to match new configuration
|
||||
ConfigManager.updateCSSProperties(this.config);
|
||||
this.updateAllButtons();
|
||||
const settings = this.config.getWorkWeekSettings();
|
||||
this.eventBus.emit(CoreEvents.WORKWEEK_CHANGED, {
|
||||
workWeekId: workweekId,
|
||||
settings: settings
|
||||
});
|
||||
}
|
||||
updateAllButtons() {
|
||||
this.updateButtonGroup(this.getViewButtons(), 'data-view', this.currentView);
|
||||
this.updateButtonGroup(this.getWorkweekButtons(), 'data-workweek', this.config.currentWorkWeek);
|
||||
}
|
||||
updateButtonGroup(buttons, attribute, activeValue) {
|
||||
buttons.forEach(button => {
|
||||
const buttonValue = button.getAttribute(attribute);
|
||||
if (buttonValue === activeValue) {
|
||||
button.setAttribute('data-active', 'true');
|
||||
}
|
||||
else {
|
||||
button.removeAttribute('data-active');
|
||||
}
|
||||
});
|
||||
}
|
||||
emitViewRendered() {
|
||||
this.eventBus.emit(CoreEvents.VIEW_RENDERED, {
|
||||
view: this.currentView
|
||||
});
|
||||
}
|
||||
refreshCurrentView() {
|
||||
this.emitViewRendered();
|
||||
}
|
||||
isValidView(view) {
|
||||
return ['day', 'week', 'month'].includes(view);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ViewManager.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue