Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHG:排序规则修改 #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ DEPENDENCIES
sass (>= 3.4.0)

BUNDLED WITH
1.17.2
2.3.25
76 changes: 35 additions & 41 deletions lib/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Calendar = (function(superClass) {
content: 'content'
},
allowDrag: 'event',
draggable: null,
draggable: null
};

Calendar.prototype._tpl = {
Expand Down Expand Up @@ -409,6 +409,36 @@ Calendar = (function(superClass) {
return event;
};

Calendar.prototype._differentInCalendarDays = function(time1, time2) {
var time1Start, time2Start;
time1Start = time1.clone().startOf('day');
time2Start = time2.clone().startOf('day');
return time1Start.diff(time2Start, 'days');
};

Calendar.prototype._sortItems = function(items) {
items.sort((function(_this) {
return function(item1, item2) {
var result;
result = _this._differentInCalendarDays(item1.start, item2.start);
if (result === 0) {
result = _this._differentInCalendarDays(item2.end, item1.start) - _this._differentInCalendarDays(item1.end, item2.start);
}
if (result === 0) {
result = item1.start.diff(item2.start);
}
if (result === 0) {
result = item1.end.diff(item2.end);
}
if (result === 0) {
result = item1.content.length - item2.content.length;
}
return result;
};
})(this));
return items;
};

Calendar.prototype.addEvent = function(events) {
var $event, $eventList, event, eventsAcrossDay, eventsInDay, j, k, l, len, len1, len2, ref, ref1, reorderList, results;
if (!$.isArray(events)) {
Expand All @@ -431,9 +461,7 @@ Calendar = (function(superClass) {
}
if (eventsInDay.length > 0) {
$.merge(this.events.inDay, eventsInDay);
this.events.inDay.sort(function(e1, e2) {
return e1.start.diff(e2.start);
});
this.events.inDay = this._sortItems(this.events.inDay);
this.el.find(".day .day-events").empty();
ref = this.events.inDay;
for (k = 0, len1 = ref.length; k < len1; k++) {
Expand All @@ -447,23 +475,7 @@ Calendar = (function(superClass) {
}
if (eventsAcrossDay.length > 0) {
$.merge(this.events.acrossDay, eventsAcrossDay);
this.events.acrossDay.sort(function(e1, e2) {
var result;
result = e1.start.diff(e2.start, 'd');
if (result === 0) {
result = e2.end.diff(e1.start, 'd') - e1.end.diff(e2.start, 'd');
}
if (result === 0) {
result = e1.start.diff(e2.start);
}
if (result === 0) {
result = e1.end.diff(e2.end);
}
if (result === 0) {
result = e1.content.length - e2.content.length;
}
return result;
});
this.events.acrossDay = this._sortItems(this.events.acrossDay);
this.el.find('.event-spacers').empty();
this.el.find('.events').empty();
ref1 = this.events.acrossDay;
Expand Down Expand Up @@ -709,9 +721,7 @@ Calendar = (function(superClass) {
}
if (todosInDay.length > 0) {
$.merge(this.todos.inDay, todosInDay);
this.todos.inDay.sort(function(t1, t2) {
return t1.end.diff(t2.end);
});
this.todos.inDay = this._sortItems(this.todos.inDay);
this.el.find(".day .day-todos").empty();
ref = this.todos.inDay;
for (k = 0, len1 = ref.length; k < len1; k++) {
Expand All @@ -725,23 +735,7 @@ Calendar = (function(superClass) {
}
if (todosAcrossDay.length > 0) {
$.merge(this.todos.acrossDay, todosAcrossDay);
this.todos.acrossDay.sort(function(e1, e2) {
var result;
result = e1.start.diff(e2.start, 'd');
if (result === 0) {
result = e2.end.diff(e1.start, 'd') - e1.end.diff(e2.start, 'd');
}
if (result === 0) {
result = e1.start.diff(e2.start);
}
if (result === 0) {
result = e1.end.diff(e2.end);
}
if (result === 0) {
result = e1.content.length - e2.content.length;
}
return result;
});
this.todos.acrossDay = this._sortItems(this.todos.acrossDay);
this.el.find('.events .todo').remove();
ref1 = this.todos.acrossDay;
results = [];
Expand Down
46 changes: 25 additions & 21 deletions src/calendar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Calendar extends SimpleModule
end: 'end'
completed: 'completed'
content: 'content'
allowDrag: 'event' # 可取值:all(日程,任务均可拖拽), disable(不能拖拽), event(仅日程可拖拽)
allowDrag: 'event' # 可取值:all(日程,任务均可拖拽), disable(不能拖拽), event(仅日程可拖拽)
draggable: null,

_tpl:
layout: '''
Expand Down Expand Up @@ -200,7 +201,9 @@ class Calendar extends SimpleModule
_initDrag: ->
return unless simple.dragdrop and @opts.allowDrag != 'disable'

if @opts.allowDrag is 'all'
if @opts.draggable
draggable = @opts.draggable
else if @opts.allowDrag is 'all'
draggable = '.event, .todo:not(.completed)'
else
draggable = '.event'
Expand Down Expand Up @@ -323,6 +326,22 @@ class Calendar extends SimpleModule

event

_differentInCalendarDays: (time1, time2) ->
time1Start = time1.clone().startOf('day')
time2Start = time2.clone().startOf('day')
time1Start.diff(time2Start, 'days')

_sortItems: (items) ->
items.sort (item1, item2) =>
result = @_differentInCalendarDays(item1.start,item2.start)
result = @_differentInCalendarDays(item2.end, item1.start) - @_differentInCalendarDays(item1.end, item2.start) if result == 0
result = item1.start.diff(item2.start) if result ==0
result = item1.end.diff(item2.end) if result == 0
result = item1.content.length - item2.content.length if result == 0
result

items

addEvent: (events) ->
events = [events] unless $.isArray(events)
eventsAcrossDay = []
Expand All @@ -342,8 +361,7 @@ class Calendar extends SimpleModule
# render one day events
if eventsInDay.length > 0
$.merge @events.inDay, eventsInDay
@events.inDay.sort (e1, e2) ->
e1.start.diff e2.start
@events.inDay = @_sortItems(@events.inDay)

@el.find( ".day .day-events" ).empty()
for event in @events.inDay
Expand All @@ -354,14 +372,7 @@ class Calendar extends SimpleModule
# render multi day events
if eventsAcrossDay.length > 0
$.merge @events.acrossDay, eventsAcrossDay
@events.acrossDay.sort (e1, e2) ->
result = e1.start.diff(e2.start, 'd')
result = e2.end.diff(e1.start, 'd') - e1.end.diff(e2.start, 'd') if result == 0
result = e1.start.diff(e2.start) if result ==0
result = e1.end.diff(e2.end) if result == 0
result = e1.content.length - e2.content.length if result == 0
result

@events.acrossDay = @_sortItems(@events.acrossDay)
@el.find('.event-spacers').empty()
@el.find('.events').empty()
for event in @events.acrossDay
Expand Down Expand Up @@ -541,8 +552,7 @@ class Calendar extends SimpleModule
# render one day todos
if todosInDay.length > 0
$.merge @todos.inDay, todosInDay
@todos.inDay.sort (t1, t2) ->
t1.end.diff t2.end
@todos.inDay = @_sortItems(@todos.inDay)

@el.find(".day .day-todos").empty()
for todo in @todos.inDay
Expand All @@ -553,13 +563,7 @@ class Calendar extends SimpleModule
# render multi day events
if todosAcrossDay.length > 0
$.merge @todos.acrossDay, todosAcrossDay
@todos.acrossDay.sort (e1, e2) ->
result = e1.start.diff(e2.start, 'd')
result = e2.end.diff(e1.start, 'd') - e1.end.diff(e2.start, 'd') if result == 0
result = e1.start.diff(e2.start) if result ==0
result = e1.end.diff(e2.end) if result == 0
result = e1.content.length - e2.content.length if result == 0
result
@todos.acrossDay = @_sortItems(@todos.acrossDay)

@el.find('.events .todo').remove()
for todo in @todos.acrossDay
Expand Down