![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-card/js/dom/MonthTable.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ItemCmp = ItemCmp; exports.default = void 0; require("../../css/monthtable.css"); var _Core = _interopRequireDefault(require("./Core")); var _datetime = require("absol/src/Time/datetime"); var _CActivity = _interopRequireDefault(require("./CActivity")); var _CActivityTooltip = _interopRequireDefault(require("./CActivityTooltip")); var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2")); var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle")); var _DomSignal = _interopRequireDefault(require("absol/src/HTML5/DomSignal")); var _CWeekRow = _interopRequireDefault(require("./CWeekRow")); var _CDayCell = _interopRequireDefault(require("./CDayCell")); var _SegmentFinder = _interopRequireDefault(require("../helper/SegmentFinder")); var _CDayOfWeekRow = _interopRequireDefault(require("./CDayOfWeekRow")); var _ = _Core.default._; var $ = _Core.default.$; var defaultFocusDate = (0, _datetime.beginOfMonth)(new Date()); /** * * @param {CActivity} a * @param {CActivity} b */ function ItemCmp(a, b) { var d = a.startTime.getTime() - b.startTime.getTime(); if (d == 0) return a.getDayLength() - b.getDayLength(); return d; } function MonthTable() { var thisMT = this; this.domSignal = new _DomSignal.default(); this.domSignal.on('requestUpdateCardPosition', this.updateCardPosition.bind(this)); /** * @type {Array<CActivity>} */ this.activities = []; /** * @type {CActivity} */ this.activeActivity = null; /** * @type {CActivity} */ this._lastVisiblePeriod = null; // this.clonedCard = null; // this._initCloneIdx = -1; // this._currentCloneIdx = -1; // this._dragTimeFactor = [0, 0]; this.$attachook = _('attachhook').addTo(this).on('error', this.eventHandler.attached); this.$selectDate = null; this._focusDate = new Date(0); this._week = (0, _datetime.beginOfWeek)((0, _datetime.prevMonth)(this._focusDate)); this._firstDayOfWeek = 0; /** * @type {CDayOfWeekRow} */ this.$dayOfWeekRow = $('cdayofweekrow', this); // this._selectDateFormat = 'mmm-dd'; this.$body = $('.cd-month-table-body', this).removeClass('as-bscroller').on('scroll', this.eventHandler.scrollBody); this.$content = $('.cd-month-table-content', this).on('click', this.eventHandler.clickDay); /** * @type {Array<CWeekRow>} */ this.$weekRows = Array(18).fill(null).map(function () { return _('cweekrow').addTo(thisMT.$content); }); this.$header = $('.cd-month-table-header', this); this.$daysOfWeek = []; $('.cd-month-table-header-day', this.$header, function (day) { thisMT.$daysOfWeek.push(day); }); this.focusDate = defaultFocusDate; this.$placeHolder = []; // this.$clonedPlaceHolder = []; } MonthTable.tag = 'MonthTable'.toLowerCase(); MonthTable.$placePool = []; MonthTable.$clonedPlacePool = []; MonthTable.render = function () { return _({ extendEvent: ['presscell', 'presscard', 'visibleperiodchange'], class: 'cd-month-table', child: [{ class: 'cd-month-table-header', child: { tag: 'cdayofweekrow' } }, { tag: 'bscroller', class: 'cd-month-table-body', child: { class: 'cd-month-table-content' } }, { class: 'cd-month-table-footer' }] }); }; MonthTable.prototype._appendTop = function () { var rowElt; var weekMillis = this._week.getTime(); for (var i = 1; i <= 3; ++i) { rowElt = _({ tag: 'cweekrow', props: { date: new Date(weekMillis - i * _datetime.MILLIS_PER_DAY * 7) } }); this.$content.addChildBefore(rowElt, this.$content.firstChild); this.$weekRows.unshift(rowElt); } this._week = this.$weekRows[0].date; this.domSignal.emit('requestUpdateCardPosition'); }; MonthTable.prototype._appendBottom = function () { var rowElt; var weekMillis = this._week.getTime() + _datetime.MILLIS_PER_DAY * 7 * this.$weekRows.length; for (var i = 0; i < 3; ++i) { rowElt = _({ tag: 'cweekrow', props: { date: new Date(weekMillis + i * _datetime.MILLIS_PER_DAY * 7) } }); this.$content.addChild(rowElt, this.$content.firstChild); this.$weekRows.push(rowElt); } this.domSignal.emit('requestUpdateCardPosition'); }; MonthTable.prototype.scrollIntoDate = function (date) { var row = this.getWeekRowByDate(date); if (row) { this.$body.scrollInto(row); } }; MonthTable.prototype._scrollToFocusMonth = function () { var month = (0, _datetime.beginOfMonth)(this._focusDate); this.scrollIntoDate(month); }; /** * * @param {Date} date * @returns {CWeekRow} */ MonthTable.prototype.getWeekRowByDate = function (date) { return this.$weekRows[this.getWeekRowIdxByDate(date)]; }; /** * * @param {Date} date * @returns {Number} */ MonthTable.prototype.getWeekRowIdxByDate = function (date) { var week = this._beginOfWeek(date); var idx = Math.floor((0, _datetime.compareDate)(week, this._week) / 7); return idx; }; /** * * @param {Date} date * @returns {CDayCell} */ MonthTable.prototype.getCellByDate = function (date) { var row = this.getWeekRowByDate(date); if (row) { return row.getCellByDate(date); } return null; }; MonthTable.prototype._beginOfWeek = function (date) { return (0, _datetime.beginOfWeek)(date, false, this._firstDayOfWeek); }; /** * @param {import('./CActivity').MonthTableItemProperty} props */ MonthTable.prototype.addActivity = function (props) { var mc = new _CActivity.default(this, props); mc.on('click', this.eventHandler.clickActivity); this.activities.push(mc); this.requestUpdateCardPosition(); return mc; }; /** * @param {CActivity} activity */ MonthTable.prototype.removeActivity = function (activity) { var cardIndex = this.activities.indexOf(activity); if (cardIndex >= 0) { this.activities.splice(cardIndex, 1); activity.removeAllDaySegment(); activity.$table = null; activity.off('mouseenter', this.eventHandler.enterActivity).off('mouseleave', this.eventHandler.leaveActivity); // .off('dragstart', this.eventHandler.dragStartCard) // .off('dragend', this.eventHandler.dragEndCard) // .off('drag', this.eventHandler.dragCard); } else { throw new Error("Card is not a member of MonthTable"); } }; MonthTable.prototype.removeAllActivity = function () { var activity; for (var i = 0; i < this.activities.length; ++i) { activity = this.activities[i]; activity.removeAllDaySegment(); activity.$table = null; activity.off('mouseenter', this.eventHandler.enterActivity).off('mouseleave', this.eventHandler.leaveActivity); } this.activities = []; this.requestUpdateCardPosition(); }; /** * @param {CActivity} activity */ MonthTable.prototype.containsActivity = function (activity) { var cardIndex = this.activities.indexOf(activity); return cardIndex >= 0; }; MonthTable.prototype._updateDays = function () { var startMillis = this._week.getTime(); for (var i = 0; i < this.$weekRows.length; ++i) { this.$weekRows[i].date = new Date(startMillis + _datetime.MILLIS_PER_DAY * 7 * i); } }; MonthTable.prototype._updateSelectedDate = function () { if (this.$selectDate) { this.$selectDate.removeClass('cd-selected'); } var date = this._selectedDate; if (!date) return; var cell = this.getCellByDate(date); if (cell) { this.$selectDate = cell; this.$selectDate.addClass('cd-selected'); } else { this._selectedDate = null; //selected day is out } }; MonthTable.prototype.selectDate = function (date) { this._selectedDate = date; this._updateSelectedDate(); }; MonthTable.prototype.selectActivity = function (activity) { if (activity == this.activeActivity) return; if (this.activeActivity) { this.activeActivity.active = false; this.activeActivity.updateActive(); } this.activeActivity = activity; if (this.activeActivity) { this.activeActivity.active = true; this.activeActivity.updateActive(); } }; MonthTable.prototype._dateOfCell = function (cell) { /** * @type {CWeekRow} */ var parent = cell.parentElement; var idx = parent.$dayCells.indexOf(cell); return new Date(parent.date.getTime() + _datetime.MILLIS_PER_DAY * idx); }; MonthTable.prototype.getCellByPosition = function (clientX, clientY) { var point = new _Vec.default(clientX, clientY); var bound; var j; for (var i = 0; i < this.$weekRows.length; ++i) { bound = _Rectangle.default.fromClientRect(this.$weekRows[i].getBoundingClientRect()); if (bound.containsPoint(point)) { j = Math.floor((bound.x - clientX) / (bound.width / 7)); return this.$weekRows[i].$dayCells[j]; } } return null; }; MonthTable.prototype._clearPlaceHolder = function () { var pool = MonthTable.$placePool; this.$placeHolder.forEach(function (ph) { ph.clearChild(); ph.selfRemove(); pool.push(ph); }); this.$placeHolder = []; }; MonthTable.prototype._makeOnePlaceHolder = function () { var holder; if (MonthTable.$placePool.length > 0) { holder = MonthTable.$placePool.pop(); } else { holder = _('.cd-month-table-item-place-holder'); } this.$placeHolder.push(holder); return holder; }; MonthTable.prototype._clearClonedPlaceHolder = function () {// var pool = MonthTable.$clonedPlacePool; // this.$clonedPlaceHolder.forEach(function (ph) { // ph.clearChild(); // ph.selfRemove(); // pool.push(ph); // }); // this.$clonedPlaceHolder = []; }; MonthTable.prototype._makeOneClonedPlaceHolder = function () { var holder; if (MonthTable.$clonedPlacePool.length > 0) { holder = MonthTable.$clonedPlacePool.pop(); } else { holder = _('.cd-month-table-item-place-holder.cd-cloned'); } this.$clonedPlaceHolder.push(holder); return holder; }; /** * * @param {Element} cell * @returns {Number} */ MonthTable.prototype._countPlaceHolder = function (cell) { var count = 0; var child; for (var i = 0; i < cell.childNodes.length; ++i) { child = cell.childNodes[i]; if (child.containsClass && child.containsClass('cd-month-table-item-place-holder') && !child.containsClass('cd-cloned')) count++; } return count; }; /** * * @param {Element} cell * @param {Number} n */ MonthTable.prototype._fillHolderToCell = function (cell, n) { var n0 = this._countPlaceHolder(cell); while (n0 < n) { cell.addChild(this._makeOnePlaceHolder()); ++n0; } }; MonthTable.prototype.updateCardPosition = function () { this._clearPlaceHolder(); var thisMT = this; var holder; var segments; var holders = this.activities.slice(); holders.sort(ItemCmp); var sf = new _SegmentFinder.default(); while (holders.length > 0) { holder = holders.shift(); segments = holder.getVisibleDaySegments(); segments.forEach(function (seg) { var pHolder = thisMT._makeOnePlaceHolder(); pHolder.addChild(seg.$item); var cell = thisMT.getCellByDate(seg.startTime); if (cell) { var idx = (0, _datetime.compareDate)(seg.startTime, thisMT._week); var yMin = sf.getMinYFreeAt(idx); thisMT._fillHolderToCell(cell, yMin); cell.addChild(pHolder); sf.push(idx, idx + seg.dayLength, yMin, seg); } else { throw new Error("Bug"); } }); } }; MonthTable.prototype._updateClonedCardPosition = function () {// this._clearClonedPlaceHolder(); // var thisMT = this; // this.clonedSegments = this.clonedCard.getVisibleDaySegments(); // this.clonedSegments.forEach(function (seg) { // var pHolder = thisMT._makeOneClonedPlaceHolder(); // var cell = thisMT.getCellByDate(seg.startTime); // var cellBound = cell.getBoundingClientRect(); // var contentBound = thisMT.$content.getBoundingClientRect(); // var firstHolder = $('.cd-month-table-item-place-holder', cell.parentElement); // if (firstHolder) { // var holderBound = firstHolder.getBoundingClientRect(); // pHolder.addStyle({ // width: cellBound.width + 'px', // left: cellBound.left - contentBound.left + 1 + 'px', // top: holderBound.top - contentBound.top + 'px', // }); // } // else { // pHolder.addStyle({ // width: cellBound.width + 'px', // left: cellBound.left - contentBound.left + 'px', // top: cellBound.top - contentBound.top + 30 + 'px', // }); // } // thisMT.$content.addChild(pHolder); // pHolder.addChild(seg.$item); // }); }; MonthTable.prototype._appendIfNeed = function () { var firstRow = this.$weekRows[0]; var firstRowBound = firstRow.getBoundingClientRect(); var bodyBound = this.$body.getBoundingClientRect(); if (firstRowBound.bottom > bodyBound.top) { this._appendTop(); return; } var lastRow = this.$weekRows[this.$weekRows.length - 1]; var lastRowBound = lastRow.getBoundingClientRect(); if (lastRowBound.top < bodyBound.bottom) { this._appendBottom(); } }; MonthTable.prototype.notifyPeriodChange = function () { this.emit('visibleperiodchange', { target: this, visiblePeriod: this._lastVisiblePeriod || this.getVisiblePeriod() }, this); }; MonthTable.prototype.notifyPeriodChangeIfNeed = function () { var currentVisiblePeriod = this.getVisiblePeriod(); if (!this._lastVisiblePeriod || (0, _datetime.compareDate)(currentVisiblePeriod.startTime, this._lastVisiblePeriod.startTime, false) !== 0 || currentVisiblePeriod.rowCount !== this._lastVisiblePeriod.rowCount) { this._lastVisiblePeriod = currentVisiblePeriod; this.notifyPeriodChange(); } }; MonthTable.prototype.getVisiblePeriod = function (delta) { delta = delta || 0; var lIdx = 0, hIdx = this.$weekRows.length - 1; var bodyBound = this.$body.getBoundingClientRect(); var mIdx; var mBound; while (lIdx < hIdx) { mIdx = lIdx + hIdx >> 1; mBound = this.$weekRows[mIdx].getBoundingClientRect(); if (mBound.top + mBound.height / 2 < bodyBound.top + delta) { lIdx = mIdx + 1; } else { hIdx = mIdx; } } var topRowIdx = lIdx; lIdx = 0; hIdx = this.$weekRows.length - 1; while (lIdx < hIdx) { mIdx = lIdx + hIdx + 1 >> 1; mBound = this.$weekRows[mIdx].getBoundingClientRect(); if (mBound.top + mBound.height / 2 > bodyBound.bottom + delta) { hIdx = mIdx - 1; } else { lIdx = mIdx; } } var botRowIdx = hIdx; return { startTime: new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * 7 * topRowIdx), endTime: new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * 7 * (botRowIdx + 1)), rowIdx: topRowIdx, rowCount: botRowIdx - topRowIdx + 1, startRowElt: this.$weekRows[topRowIdx], endRowElt: this.$weekRows[botRowIdx] }; }; MonthTable.prototype.prevPeriod = function () { var bodyBound = this.$body.getBoundingClientRect(); var vp = this.getVisiblePeriod(bodyBound.height); this.focusInto(vp.startTime); return vp.startTime; }; MonthTable.prototype.nextPeriod = function () { var vp = this.getVisiblePeriod(); this.focusInto(vp.endTime); return vp.endTime; }; MonthTable.prototype.focusInto = function (date) { var startTime = this.startTime; var endTime = this.endTime; if ((0, _datetime.compareDate)(date, startTime, false) < 14 || (0, _datetime.compareDate)(endTime, date, false) < 42) { this.focusDate = date; } this.selectDate(date); this.scrollIntoDate(date); this.notifyPeriodChangeIfNeed(); }; MonthTable.prototype.requestUpdateCardPosition = function () { this.domSignal.emit('requestUpdateCardPosition'); }; MonthTable.property = {}; /** * @type {MonthTable} */ MonthTable.property.focusDate = { set: function (date) { this._focusDate = date; this._week = (0, _datetime.beginOfWeek)(new Date(date.getTime() - 42 * _datetime.MILLIS_PER_DAY), false, this._firstDayOfWeek); this._updateDays(); this._updateSelectedDate(); this.requestUpdateCardPosition(); }, get: function () { return this._focusDate; } }; MonthTable.property.startTime = { get: function () { return this._week; } }; MonthTable.property.endTime = { get: function () { return new Date(this._week.getTime() + _datetime.MILLIS_PER_DAY * this.$weekRows.length * 7); } }; /** * @type {MonthTable} */ MonthTable.property.firstDayOfWeek = { set: function (value) { if (!(value >= 0 && value < 7)) { value = 0; } if (this._firstDayOfWeek == value) return; this._firstDayOfWeek = value; var month = (0, _datetime.beginOfMonth)(this._focusDate); this._week = (0, _datetime.beginOfWeek)(new Date(month.getTime() - 42 * _datetime.MILLIS_PER_DAY), false, this._firstDayOfWeek); this.$dayOfWeekRow.firstDay = value; this._updateDays(); this.requestUpdateCardPosition(); }, get: function () { return this._firstDayOfWeek; } }; /** * @type {MonthTable} */ MonthTable.eventHandler = {}; MonthTable.eventHandler.attached = function () { this._scrollToFocusMonth(); }; MonthTable.eventHandler.clickDay = function (event) { var target = event.target; if (target.containsClass && target.containsClass('cd-day-cell')) { this.selectActivity(null); this.selectDate(this._dateOfCell(target)); this.emit('presscell', { originEvent: event, type: 'presscell', cell: target, date: this._dateOfCell(target) }); } }; /** * @param {MouseEvent} event * @param {CActivity} sender */ MonthTable.eventHandler.clickActivity = function (event, sender) { this.selectDate(null); this.selectActivity(sender); this.emit('presscard', { originEvent: event, type: 'presscard', activity: sender }, this); }; //lock all feature drag card MonthTable.eventHandler.dragEndCard = function (event, sender) { return; if (this.clonedCard) { if (this.clonedCard.cloneFrom.startTime.getTime() != this.clonedCard.startTime.getTime() || this.clonedCard.cloneFrom.endTime.getTime() != this.clonedCard.endTime.getTime()) { //TODO: emit event or call plugin this.clonedCard.cloneFrom.startTime = this.clonedCard.startTime; this.clonedCard.cloneFrom.endTime = this.clonedCard.endTime; this.updateCardPosition(); } this.clonedCard.remove(); this._clearClonedPlaceHolder(); this.clonedCard = null; } document.body.classList.remove('cd-moving-activity'); }; MonthTable.eventHandler.dragStartCard = function (event, sender) { return; this._dragTimeFactor = [1, 1]; if (event.target.classList.contains('cd-month-table-item-right-drag-line')) { this._dragTimeFactor[0] = 0; } else if (event.target.classList.contains('cd-month-table-item-left-drag-line')) { this._dragTimeFactor[1] = 0; } this.eventHandler.clickActivity(event, sender); this.clonedCard = this.activeActivity.clone(); this._initCloneIdx = this.getCellIdxByPosition(event.clientX, event.clientY); this._currentCloneIdx = this._initCloneIdx; this._updateClonedCardPosition(); document.body.classList.add('cd-moving-activity'); }; MonthTable.eventHandler.dragCard = function (event, sender) { return; var newIdx = this.getCellIdxByPosition(event.clientX, event.clientY); if (newIdx != -1 && newIdx != this._currentCloneIdx) { this._currentCloneIdx = newIdx; var dMil = _datetime.MILLIS_PER_DAY * (newIdx - this._initCloneIdx); var newStartTimeMil = this.clonedCard.cloneFrom.startTime.getTime() + dMil * this._dragTimeFactor[0]; var newEndTimeMil = this.clonedCard.cloneFrom.endTime.getTime() + dMil * this._dragTimeFactor[1]; if (newEndTimeMil > newStartTimeMil) { //valid time this.clonedCard.startTime = new Date(newStartTimeMil); this.clonedCard.endTime = new Date(newEndTimeMil); this._updateClonedCardPosition(); } } }; MonthTable.eventHandler.scrollBody = function () { this._appendIfNeed(); this.notifyPeriodChangeIfNeed(); //todo }; _Core.default.install(MonthTable); var _default = MonthTable; exports.default = _default;