make it possible to show a week or month's worth of messages in the river view

This commit is contained in:
Myk Melez 2009-08-20 17:48:09 -07:00
Родитель d37e2e9295
Коммит 1b3e6e0349
3 изменённых файлов: 123 добавлений и 56 удалений

Просмотреть файл

@ -167,6 +167,48 @@ let SnowlMessageView = {
return this._periodLabel = document.getElementById("periodLabel");
},
_point: Date.today(),
get _startTime() {
// We have to create a new date from this._point to start out with
// because some Datejs functions mutate their operand, and we don't want
// to modify this._point in the process of deriving this value from it.
let date = new Date(this._point);
switch(this._periodMenu.selectedIndex) {
case 0: // day
return date.at("0am");
case 1: // week
return date.last().monday().at("0am");
case 2: // month
return date.set({ day: 1 }).at("0am");
default:
throw "unexpected period: " + this._periodMenu.selectedIndex;
}
},
get _endTime() {
// We have to create a new date from this._point to start out with
// because some Datejs functions mutate their operand, and we don't want
// to modify this._point in the process of deriving this value from it.
let date = new Date(this._point);
// To get the end of the current period, we get the beginning of
// the next period, subtract one millisecond (which converts the date
// into a time number representing the last millisecond of the current
// period), and then create a new date from the number.
switch(this._periodMenu.selectedIndex) {
case 0: // day
return new Date(date.next().day().at("0am") - 1);
case 1: // week
return new Date(date.next().monday().at("0am") - 1);
case 2: // month
return new Date(date.next().month().set({ day: 1 }).at("0am") - 1);
default:
throw "unexpected period: " + this._periodMenu.selectedIndex;
}
},
get _periodStartTime() {
if (!this._periodMenu.selectedItem)
return 0;
@ -308,7 +350,7 @@ let SnowlMessageView = {
// Set the period to today.
// FIXME: move this into _updateToolbar.
this._updatePeriod(new Date());
this._updatePeriodLabel();
// _updateToolbar selects a collection, which triggers a view rebuild,
// so we don't have to call rebuildView here. This is pretty convoluted,
@ -518,12 +560,6 @@ let SnowlMessageView = {
},
onCommandPeriodMenu: function(event) {
this._periodMenu.setAttribute("selectedindex", this._periodMenu.selectedIndex);
this._updateURI();
this._applyFilters();
},
_updateURI: function() {
let newParams = [];
@ -549,27 +585,75 @@ let SnowlMessageView = {
updateURI();
},
onSelectPeriod: function(event) {
this._updatePeriodLabel();
this.rebuild();
},
onDecrementPeriod: function(event) {
let point = this._periodLabel.point || Date.today();
let newPoint = point.last().day();
this._periodLabel.point = newPoint;
this._updatePeriod(newPoint);
switch(this._periodMenu.selectedIndex) {
case 0: // day
this._point = this._point.last().day();
break;
case 1: // week
this._point = this._point.last().week();
break;
case 2: // month
this._point = this._point.last().month();
break;
}
this._updatePeriodLabel();
this.rebuild();
},
onIncrementPeriod: function(event) {
let point = this._periodLabel.point || Date.today();
let newPoint = point.next().day();
this._periodLabel.point = newPoint;
this._updatePeriod(newPoint);
},
switch(this._periodMenu.selectedIndex) {
case 0: // day
this._point = this._point.next().day();
break;
case 1: // week
this._point = this._point.next().week();
break;
case 2: // month
this._point = this._point.next().month();
break;
}
_updatePeriod: function(date) {
[this._periodLabel.startTime, this._periodLabel.endTime] =
SnowlDateUtils.getDayBounds(date);
this._periodLabel.setAttribute("value", SnowlDateUtils.formatDay(date));
this._updatePeriodLabel();
this.rebuild();
},
_updatePeriodLabel: function() {
switch(this._periodMenu.selectedIndex) {
case 0: // day
this._periodLabel.setAttribute("value", this._point.toString("d"));
break;
case 1: // week
// FIXME: make this localizable.
// XXX show start and end dates instead of the week number?
this._periodLabel.setAttribute("value", this._point.toString("yyyy") +
" week " + this._point.getWeek());
break;
case 2: // month
this._periodLabel.setAttribute("value", this._point.toString("y"));
break;
}
},
/**
* Return the start and end times (inclusive) for the given date.
*
* @param date {Date} the date
* @returns {Array} the start and end times
*/
getDayBounds: function(date) {
return [new Date(date.getFullYear(), date.getMonth(), date.getDate()),
new Date(date.getFullYear(), date.getMonth(), date.getDate(),
23, 59, 59, 999)];
},
//**************************************************************************//
// Event & Notification Handlers
@ -723,8 +807,8 @@ this._log.info("onMessageAdded: REFRESH RIVER");
// parameters: { filter: SnowlUtils.appendAsterisks(SnowlMessageView._filter.value) } });
//}
constraints.push({ name: "received", operator: ">=", value: this._periodLabel.startTime });
constraints.push({ name: "received", operator: "<=", value: this._periodLabel.endTime });
constraints.push({ name: "received", operator: ">=", value: this._startTime });
constraints.push({ name: "received", operator: "<=", value: this._endTime });
// Rebuild the view based on the constrained collection.
this._rebuildView();

Просмотреть файл

@ -104,6 +104,20 @@
oncommand="SnowlMessageView.onCommandColumnsButton(event)"
tooltiptext="&columnsButton.tooltip;"/>
<menulist id="periodMenu" oncommand="SnowlMessageView.onSelectPeriod(event)">
<menupopup id="periodMenuPopup">
<menuitem label="&periodDay.label;"
class="menuitem-iconic"
image="chrome://snowl/content/icons/date.png"/>
<menuitem label="&periodWeek.label;"
class="menuitem-iconic"
image="chrome://snowl/content/icons/calendar_view_week.png"/>
<menuitem label="&periodMonth.label;"
class="menuitem-iconic"
image="chrome://snowl/content/icons/calendar_view_month.png"/>
</menupopup>
</menulist>
<toolbarbutton id="decrementPeriodButton" label="&lt;"
class="tabbable"
oncommand="SnowlMessageView.onDecrementPeriod()"
@ -114,35 +128,6 @@
oncommand="SnowlMessageView.onIncrementPeriod()"
tooltiptext="&incrementPeriodButton.tooltip;"/>
<menulist id="periodMenu"
selectedindex=""
persist="selectedindex"
oncommand="SnowlMessageView.onCommandPeriodMenu(event)"
hidden="true">
<menupopup id="periodMenuPopup">
<menuitem label="&periodAnytime.label;"
value="all"
class="menuitem-iconic"
image="chrome://snowl/content/icons/calendar.png"/>
<menuitem label="&periodToday.label;"
value="today"
class="menuitem-iconic"
image="chrome://snowl/content/icons/date.png"/>
<menuitem label="&periodYesterday.label;"
value="yesterday"
class="menuitem-iconic"
image="chrome://snowl/content/icons/date_previous.png"/>
<menuitem label="&periodLast7Days.label;"
value="last7days"
class="menuitem-iconic"
image="chrome://snowl/content/icons/calendar_view_week.png"/>
<menuitem label="&periodLast4Weeks.label;"
value="last4weeks"
class="menuitem-iconic"
image="chrome://snowl/content/icons/calendar_view_month.png"/>
</menupopup>
</menulist>
<spacer flex="1"/>
<!-- FIXME: change type="timed" to type="search" once we no longer

Просмотреть файл

@ -5,8 +5,6 @@
<!ENTITY decrementPeriodButton.tooltip "Previous day">
<!ENTITY incrementPeriodButton.tooltip "Next day">
<!ENTITY periodAnytime.label "Anytime">
<!ENTITY periodToday.label "Today">
<!ENTITY periodYesterday.label "Yesterday">
<!ENTITY periodLast7Days.label "Last 7 Days">
<!ENTITY periodLast4Weeks.label "Last 4 Weeks">
<!ENTITY periodDay.label "Day">
<!ENTITY periodWeek.label "Week">
<!ENTITY periodMonth.label "Month">