Exemplo n.º 1
0
            util.forEachArray(matrix, function(row) {
                util.forEachArray(row, function(viewModel, col) {
                    var startTime,
                        endTime,
                        hasCollide,
                        i;

                    if (!viewModel) {
                        return;
                    }

                    startTime = viewModel.getStarts().getTime() + 1;
                    endTime = viewModel.getEnds().getTime() - 1;

                    for (i = (col + 1); i < maxRowLength; i += 1) {
                        hasCollide = Week.hasCollide(binaryMap[i - 1], startTime, endTime);

                        if (hasCollide) {
                            viewModel.hasCollide = true;
                            break;
                        }

                        viewModel.extraSpace += 1;
                    }
                });
            });
Exemplo n.º 2
0
Base.prototype.findByDateRange = function(start, end) {
    var range = datetime.range(
            datetime.start(start),
            datetime.end(end),
            datetime.MILLISECONDS_PER_DAY
        ),
        ownSchedules = this.schedules.items,
        ownMatrix = this.dateMatrix,
        dformat = datetime.format,
        result = {},
        matrix,
        ymd,
        viewModels;

    util.forEachArray(range, function(date) {
        ymd = dformat(date, 'YYYYMMDD');
        matrix = ownMatrix[ymd];
        viewModels = result[ymd] = common.createScheduleCollection();

        if (matrix && matrix.length) {
            viewModels.add.apply(viewModels, util.map(matrix, function(id) {
                return ScheduleViewModel.create(ownSchedules[id]);
            }));
        }
    });

    return result;
};
Exemplo n.º 3
0
Base.prototype.splitScheduleByDateRange = function(start, end, scheduleCollection) {
    var range = datetime.range(
            datetime.start(start),
            datetime.end(end),
            datetime.MILLISECONDS_PER_DAY
        ),
        ownMatrix = this.dateMatrix,
        result = {};

    util.forEachArray(range, function(date) {
        var ymd = datetime.format(date, 'YYYYMMDD'),
            matrix = ownMatrix[ymd],
            collection;

        collection = result[ymd] = common.createScheduleCollection();

        if (matrix && matrix.length) {
            util.forEachArray(matrix, function(id) {
                scheduleCollection.doWhenHas(id, function(schedule) {
                    collection.add(schedule);
                });
            });
        }
    });

    return result;
};
Exemplo n.º 4
0
    arr2dCalendar: function(month, options, iteratee) {
        var weekArr,
            start, end,
            startIndex, endIndex,
            totalDate, afterDates,
            cursor, week,
            calendar = [],
            startDayOfWeek = options.startDayOfWeek,
            isAlways6Week = options.isAlways6Week,
            visibleWeeksCount = options.visibleWeeksCount,
            workweek = options.workweek;

        if (visibleWeeksCount) {
            start = new TZDate(month);
            end = dw(new TZDate(month));
            end.addDate(7 * (visibleWeeksCount - 1));
            end = end.d;
        } else {
            start = datetime.startDateOfMonth(month);
            end = datetime.endDateOfMonth(month);
        }

        // create day number array by startDayOfWeek number
        // 4 -> [4, 5, 6, 0, 1, 2, 3]
        // 2 -> [2, 3, 4, 5, 6, 0, 1]
        weekArr = util.range(startDayOfWeek, 7).concat(util.range(7)).slice(0, 7);
        startIndex = util.inArray(start.getDay(), weekArr);
        endIndex = util.inArray(end.getDay(), weekArr);
        // free dates after last date of this month
        afterDates = 7 - (endIndex + 1);

        if (visibleWeeksCount) {
            totalDate = 7 * visibleWeeksCount;
        } else {
            totalDate = isAlways6Week ? (7 * 6) : (startIndex + end.getDate() + afterDates);
        }
        cursor = new TZDate(new TZDate(start).setDate(start.getDate() - startIndex));
        // iteratee all dates to render
        util.forEachArray(util.range(totalDate), function(i) {
            var date;

            if (!(i % 7)) {
                // group each date by week
                week = calendar[i / 7] = [];
            }

            date = new TZDate(cursor);
            date = iteratee ? iteratee(date) : date;
            if (!workweek || !datetime.isWeekend(date.getDay())) {
                week.push(date);
            }

            // add date
            cursor.setDate(cursor.getDate() + 1);
        });

        return calendar;
    },
Exemplo n.º 5
0
    _initElements: function() {
        var config = this._config;

        this.elementCount = 0;

        snippet.forEachArray(this.wrapper.children, function(element) {
            if (element.nodeType === 1) {
                element.style[config.dimension] = config.width + 'px';
                this.elementCount += 1;
            }
        }, this);
    },
Exemplo n.º 6
0
    util.forEachArray(range, function(date) {
        var ymd = datetime.format(date, 'YYYYMMDD'),
            matrix = ownMatrix[ymd],
            collection;

        collection = result[ymd] = common.createScheduleCollection();

        if (matrix && matrix.length) {
            util.forEachArray(matrix, function(id) {
                scheduleCollection.doWhenHas(id, function(schedule) {
                    collection.add(schedule);
                });
            });
        }
    });
Exemplo n.º 7
0
  /**
   * Process for blob item
   * @memberof ImportManager
   * @param {Array.<string>} items Item array
   * @param {object} evData Event data
   * @private
   */
  _processBlobItems(items, evData) {
    if (items) {
      util.forEachArray(items, item => {
        if (item.type.indexOf('image') !== -1) {
          evData.preventDefault();
          evData.codemirrorIgnore = true;

          const blob = item.name ? item : item.getAsFile(); // Blob or File
          this._emitAddImageBlobHook(blob, evData.type);

          return false;
        }

        return true;
      });
    }
  }
Exemplo n.º 8
0
  /**
   * graceful decode uri component
   * @param {string} originalURI - string to be decoded
   * @returns {string} decoded string
   * @memberof ImportManager
   * @static
   */
  static decodeURIGraceful(originalURI) {
    let uris = originalURI.split(' ');
    const decodedURIs = [];
    let decodedURI;

    util.forEachArray(uris, uri => {
      try {
        decodedURI = decodeURIComponent(uri);
        decodedURI = decodedURI.replace(/ /g, '%20');
      } catch (e) {
        decodedURI = uri;
      }

      return decodedURIs.push(decodedURI);
    });

    return decodedURIs.join(' ');
  }
Exemplo n.º 9
0
Collection.prototype.groupBy = function(key, groupFunc) {
    var result = {},
        collection,
        baseValue,
        keyIsFunc = isFunc(key),
        getItemIDFn = this.getItemID;

    if (util.isArray(key)) {
        util.forEachArray(key, function(k) {
            result[String(k)] = new Collection(getItemIDFn);
        });

        if (!groupFunc) {
            return result;
        }

        key = groupFunc;
        keyIsFunc = true;
    }

    this.each(function(item) {
        if (keyIsFunc) {
            baseValue = key(item);
        } else {
            baseValue = item[key];

            if (isFunc(baseValue)) {
                baseValue = baseValue.apply(item);
            }
        }

        collection = result[baseValue];

        if (!collection) {
            collection = result[baseValue] = new Collection(getItemIDFn);
        }

        collection.add(item);
    });

    return result;
};
Exemplo n.º 10
0
    getCollides: function(matrices) {
        util.forEachArray(matrices, function(matrix) {
            var binaryMap,
                maxRowLength;

            binaryMap = Week.generateTimeArrayInRow(matrix);
            maxRowLength = Math.max.apply(null, util.map(matrix, function(row) {
                return row.length;
            }));

            util.forEachArray(matrix, function(row) {
                util.forEachArray(row, function(viewModel, col) {
                    var startTime,
                        endTime,
                        hasCollide,
                        i;

                    if (!viewModel) {
                        return;
                    }

                    startTime = viewModel.getStarts().getTime() + 1;
                    endTime = viewModel.getEnds().getTime() - 1;

                    for (i = (col + 1); i < maxRowLength; i += 1) {
                        hasCollide = Week.hasCollide(binaryMap[i - 1], startTime, endTime);

                        if (hasCollide) {
                            viewModel.hasCollide = true;
                            break;
                        }

                        viewModel.extraSpace += 1;
                    }
                });
            });
        });
    },
Exemplo n.º 11
0
    const from = {
      line: range.from.line,
      ch: 0
    };

    const to = {
      line: range.to.line,
      ch: doc.getLineHandle(range.to.line).text.length
    };

    const lengthOfCurrentLineBefore = doc.getLine(to.line).length;
    const textToModify = doc.getRange(from, to);
    const textLinesToModify = textToModify.split('\n');

    util.forEachArray(textLinesToModify, (line, index) => {
      textLinesToModify[index] = getHeadingMarkdown(line, size);
    });

    doc.replaceRange(textLinesToModify.join('\n'), from, to);

    range.to.ch += doc.getLine(to.line).length - lengthOfCurrentLineBefore;

    doc.setSelection(from, range.to);

    cm.focus();
  }
});

/**
 * Get heading markdown
 * @param {string} text Source test
Exemplo n.º 12
0
    const range = mde.getCurrentRange();
    const from = {
      line: range.from.line,
      ch: 0
    };
    const to = {
      line: range.to.line,
      ch: doc.getLineHandle(range.to.line).text.length
    };

    const lengthOfCurrentLineBefore = doc.getLine(to.line).length;
    const textToModify = doc.getRange(from, to);
    const textLines = textToModify.split('\n');

    util.forEachArray(textLines, (line, index) => {
      textLines[index] = getParagraphMarkdown(line);
    });

    doc.replaceRange(textLines.join('\n'), from, to);

    range.to.ch += doc.getLine(to.line).length - lengthOfCurrentLineBefore;

    doc.setSelection(from, to);

    cm.focus();
  }
});
/**
 * Get paragraph markdown lineText
 * @param {string} lineText line lineText
 * @returns {string}