FEATURE: Add longer suspension defaults
Also refactors and DRYs up the future input date data a lot
This commit is contained in:
parent
f30366744a
commit
764cf7e3a5
|
@ -7,7 +7,7 @@
|
||||||
{{future-date-input
|
{{future-date-input
|
||||||
class="suspend-until"
|
class="suspend-until"
|
||||||
label="admin.user.suspend_duration"
|
label="admin.user.suspend_duration"
|
||||||
includeForever=true
|
includeFarFuture=true
|
||||||
input=suspendUntil}}
|
input=suspendUntil}}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
|
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
|
||||||
import {
|
import {
|
||||||
FORMAT,
|
FORMAT,
|
||||||
PICK_DATE_AND_TIME,
|
|
||||||
SET_BASED_ON_LAST_POST
|
|
||||||
} from "select-box-kit/components/future-date-input-selector";
|
} from "select-box-kit/components/future-date-input-selector";
|
||||||
|
|
||||||
import { PUBLISH_TO_CATEGORY_STATUS_TYPE } from 'discourse/controllers/edit-topic-timer';
|
import { PUBLISH_TO_CATEGORY_STATUS_TYPE } from 'discourse/controllers/edit-topic-timer';
|
||||||
|
@ -11,8 +9,8 @@ export default Ember.Component.extend({
|
||||||
selection: null,
|
selection: null,
|
||||||
date: null,
|
date: null,
|
||||||
time: null,
|
time: null,
|
||||||
isCustom: Ember.computed.equal('selection', PICK_DATE_AND_TIME),
|
isCustom: Ember.computed.equal('selection', 'pick_date_and_time'),
|
||||||
isBasedOnLastPost: Ember.computed.equal('selection', SET_BASED_ON_LAST_POST),
|
isBasedOnLastPost: Ember.computed.equal('selection', 'set_based_on_last_post'),
|
||||||
displayLabel: null,
|
displayLabel: null,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -22,9 +20,9 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
if (this.get('basedOnLastPost')) {
|
if (this.get('basedOnLastPost')) {
|
||||||
this.set('selection', SET_BASED_ON_LAST_POST);
|
this.set('selection', 'set_based_on_last_post');
|
||||||
} else {
|
} else {
|
||||||
this.set('selection', PICK_DATE_AND_TIME);
|
this.set('selection', 'pick_date_and_time');
|
||||||
const datetime = moment(input);
|
const datetime = moment(input);
|
||||||
this.set('date', datetime.toDate());
|
this.set('date', datetime.toDate());
|
||||||
this.set('time', datetime.format("HH:mm"));
|
this.set('time', datetime.format("HH:mm"));
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
value=selection
|
value=selection
|
||||||
input=input
|
input=input
|
||||||
includeWeekend=includeWeekend
|
includeWeekend=includeWeekend
|
||||||
includeForever=includeForever
|
includeFarFuture=includeFarFuture
|
||||||
none="topic.auto_update_input.none"}}
|
none="topic.auto_update_input.none"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,99 +3,139 @@ import ComboBoxComponent from "select-box-kit/components/combo-box";
|
||||||
import { CLOSE_STATUS_TYPE } from "discourse/controllers/edit-topic-timer";
|
import { CLOSE_STATUS_TYPE } from "discourse/controllers/edit-topic-timer";
|
||||||
import DatetimeMixin from "select-box-kit/components/future-date-input-selector/mixin";
|
import DatetimeMixin from "select-box-kit/components/future-date-input-selector/mixin";
|
||||||
|
|
||||||
export const LATER_TODAY = "later_today";
|
const TIMEFRAME_BASE = {
|
||||||
export const TOMORROW = "tomorrow";
|
enabled: () => true,
|
||||||
export const LATER_THIS_WEEK = "later_this_week";
|
when: () => null,
|
||||||
export const THIS_WEEKEND = "this_weekend";
|
icon: 'briefcase',
|
||||||
export const NEXT_WEEK = "next_week";
|
displayWhen: true,
|
||||||
export const TWO_WEEKS = "two_weeks";
|
};
|
||||||
export const NEXT_MONTH = "next_month";
|
|
||||||
export const FOREVER = "forever";
|
|
||||||
|
|
||||||
export const PICK_DATE_AND_TIME = "pick_date_and_time";
|
function buildTimeframe(opts) {
|
||||||
export const SET_BASED_ON_LAST_POST = "set_based_on_last_post";
|
return jQuery.extend({}, TIMEFRAME_BASE, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TIMEFRAMES = [
|
||||||
|
buildTimeframe({
|
||||||
|
id: 'later_today',
|
||||||
|
format: "h a",
|
||||||
|
enabled: opts => opts.canScheduleToday,
|
||||||
|
when: (time) => time.hour(18).minute(0),
|
||||||
|
icon: 'moon-o'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "tomorrow",
|
||||||
|
format: "ddd, h a",
|
||||||
|
when: (time, timeOfDay) => time.add(1, 'day').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'sun-o'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "later_this_week",
|
||||||
|
format: "ddd, h a",
|
||||||
|
enabled: opts => !opts.canScheduleToday && opts.day < 4,
|
||||||
|
when: (time, timeOfDay) => time.add(2, 'day').hour(timeOfDay).minute(0),
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "this_weekend",
|
||||||
|
format: "ddd, h a",
|
||||||
|
enabled: opts => opts.day < 5 && opts.includeWeekend,
|
||||||
|
when: (time, timeOfDay) => time.day(6).hour(timeOfDay).minute(0),
|
||||||
|
icon: 'bed'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "next_week",
|
||||||
|
format: "ddd, h a",
|
||||||
|
enabled: opts => opts.day !== 7,
|
||||||
|
when: (time, timeOfDay) => time.add(1, 'week').day(1).hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "two_weeks",
|
||||||
|
format: "MMM D",
|
||||||
|
when: (time, timeOfDay) => time.add(2, 'week').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "next_month",
|
||||||
|
format: "MMM D",
|
||||||
|
enabled: opts => opts.now.date() !== moment().endOf("month").date(),
|
||||||
|
when: (time, timeOfDay) => time.add(1, 'month').startOf('month').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "three_months",
|
||||||
|
format: "MMM D",
|
||||||
|
enabled: opts => opts.includeFarFuture,
|
||||||
|
when: (time, timeOfDay) => time.add(3, 'month').startOf('month').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "six_months",
|
||||||
|
format: "MMM D",
|
||||||
|
enabled: opts => opts.includeFarFuture,
|
||||||
|
when: (time, timeOfDay) => time.add(6, 'month').startOf('month').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "one_year",
|
||||||
|
format: "MMM D",
|
||||||
|
enabled: opts => opts.includeFarFuture,
|
||||||
|
when: (time, timeOfDay) => time.add(1, 'year').startOf('day').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'briefcase'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "forever",
|
||||||
|
enabled: opts => opts.includeFarFuture,
|
||||||
|
when: (time, timeOfDay) => time.add(1000, 'year').hour(timeOfDay).minute(0),
|
||||||
|
icon: 'gavel',
|
||||||
|
displayWhen: false
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "pick_date_and_time",
|
||||||
|
icon: 'calendar-plus-o'
|
||||||
|
}),
|
||||||
|
buildTimeframe({
|
||||||
|
id: "set_based_on_last_post",
|
||||||
|
enabled: opts => opts.includeBasedOnLastPost,
|
||||||
|
icon: 'clock-o'
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
let _timeframeById = null;
|
||||||
|
export function timeframeDetails(id) {
|
||||||
|
if (!_timeframeById) {
|
||||||
|
_timeframeById = {};
|
||||||
|
TIMEFRAMES.forEach(t => _timeframeById[t.id] = t);
|
||||||
|
}
|
||||||
|
return _timeframeById[id];
|
||||||
|
}
|
||||||
|
|
||||||
export const FORMAT = "YYYY-MM-DD HH:mm";
|
export const FORMAT = "YYYY-MM-DD HH:mm";
|
||||||
|
|
||||||
export default ComboBoxComponent.extend(DatetimeMixin, {
|
export default ComboBoxComponent.extend(DatetimeMixin, {
|
||||||
classNames: ["future-date-input-selector"],
|
classNames: ["future-date-input-selector"],
|
||||||
isCustom: Ember.computed.equal("value", PICK_DATE_AND_TIME),
|
isCustom: Ember.computed.equal("value", "pick_date_and_time"),
|
||||||
clearable: true,
|
clearable: true,
|
||||||
rowComponent: "future-date-input-selector/future-date-input-selector-row",
|
rowComponent: "future-date-input-selector/future-date-input-selector-row",
|
||||||
headerComponent: "future-date-input-selector/future-date-input-selector-header",
|
headerComponent: "future-date-input-selector/future-date-input-selector-header",
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
content() {
|
content() {
|
||||||
const selections = [];
|
let now = moment();
|
||||||
const now = moment();
|
let opts = {
|
||||||
const canScheduleToday = (24 - now.hour()) > 6;
|
now,
|
||||||
const day = now.day();
|
day: now.day(),
|
||||||
|
includeWeekend: this.get('includeWeekend'),
|
||||||
|
includeFarFuture: this.get('includeFarFuture'),
|
||||||
|
includeBasedOnLastPost: this.get("statusType") === CLOSE_STATUS_TYPE,
|
||||||
|
canScheduleToday: (24 - now.hour()) > 6,
|
||||||
|
};
|
||||||
|
|
||||||
if (canScheduleToday) {
|
return TIMEFRAMES.filter(tf => tf.enabled(opts)).map(tf => {
|
||||||
selections.push({
|
return {
|
||||||
id: LATER_TODAY,
|
id: tf.id,
|
||||||
name: I18n.t("topic.auto_update_input.later_today")
|
name: I18n.t(`topic.auto_update_input.${tf.id}`)
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
selections.push({
|
|
||||||
id: TOMORROW,
|
|
||||||
name: I18n.t("topic.auto_update_input.tomorrow")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!canScheduleToday && day < 4) {
|
|
||||||
selections.push({
|
|
||||||
id: LATER_THIS_WEEK,
|
|
||||||
name: I18n.t("topic.auto_update_input.later_this_week")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (day < 5 && this.get("includeWeekend")) {
|
|
||||||
selections.push({
|
|
||||||
id: THIS_WEEKEND,
|
|
||||||
name: I18n.t("topic.auto_update_input.this_weekend")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (day !== 7) {
|
|
||||||
selections.push({
|
|
||||||
id: NEXT_WEEK,
|
|
||||||
name: I18n.t("topic.auto_update_input.next_week")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
selections.push({
|
|
||||||
id: TWO_WEEKS,
|
|
||||||
name: I18n.t("topic.auto_update_input.two_weeks")
|
|
||||||
});
|
|
||||||
|
|
||||||
if (moment().endOf("month").date() !== now.date()) {
|
|
||||||
selections.push({
|
|
||||||
id: NEXT_MONTH,
|
|
||||||
name: I18n.t("topic.auto_update_input.next_month")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.get("includeForever")) {
|
|
||||||
selections.push({
|
|
||||||
id: FOREVER,
|
|
||||||
name: I18n.t("topic.auto_update_input.forever")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
selections.push({
|
|
||||||
id: PICK_DATE_AND_TIME,
|
|
||||||
name: I18n.t("topic.auto_update_input.pick_date_and_time")
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.get("statusType") === CLOSE_STATUS_TYPE) {
|
|
||||||
selections.push({
|
|
||||||
id: SET_BASED_ON_LAST_POST,
|
|
||||||
name: I18n.t("topic.auto_update_input.set_based_on_last_post")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return selections;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes("value")
|
@observes("value")
|
||||||
|
|
|
@ -1,17 +1,6 @@
|
||||||
import { iconHTML } from 'discourse-common/lib/icon-library';
|
import { iconHTML } from 'discourse-common/lib/icon-library';
|
||||||
import { CLOSE_STATUS_TYPE } from 'discourse/controllers/edit-topic-timer';
|
import { CLOSE_STATUS_TYPE } from 'discourse/controllers/edit-topic-timer';
|
||||||
import {
|
import { timeframeDetails } from 'select-box-kit/components/future-date-input-selector';
|
||||||
LATER_TODAY,
|
|
||||||
TOMORROW,
|
|
||||||
LATER_THIS_WEEK,
|
|
||||||
THIS_WEEKEND,
|
|
||||||
NEXT_WEEK,
|
|
||||||
TWO_WEEKS,
|
|
||||||
NEXT_MONTH,
|
|
||||||
FOREVER,
|
|
||||||
PICK_DATE_AND_TIME,
|
|
||||||
SET_BASED_ON_LAST_POST,
|
|
||||||
} from "select-box-kit/components/future-date-input-selector";
|
|
||||||
|
|
||||||
export default Ember.Mixin.create({
|
export default Ember.Mixin.create({
|
||||||
_computeIconForValue(value) {
|
_computeIconForValue(value) {
|
||||||
|
@ -30,72 +19,28 @@ export default Ember.Mixin.create({
|
||||||
}
|
}
|
||||||
|
|
||||||
let {time} = this._updateAt(value);
|
let {time} = this._updateAt(value);
|
||||||
|
|
||||||
if (time) {
|
if (time) {
|
||||||
if (value === LATER_TODAY) {
|
|
||||||
time = time.format("h a");
|
let details = timeframeDetails(value);
|
||||||
} else if (value === NEXT_MONTH || value === TWO_WEEKS) {
|
if (!details.displayWhen) {
|
||||||
time = time.format("MMM D");
|
time = null;
|
||||||
} else {
|
}
|
||||||
time = time.format("ddd, h a");
|
if (time && details.format) {
|
||||||
|
return time.format(details.format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return time;
|
||||||
if (time && value !== FOREVER) {
|
|
||||||
return time;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateAt(selection) {
|
_updateAt(selection) {
|
||||||
let time = moment();
|
let details = timeframeDetails(selection);
|
||||||
let icon;
|
if (details) {
|
||||||
const timeOfDay = this.get('statusType') !== CLOSE_STATUS_TYPE ? 8 : 18;
|
return {
|
||||||
|
time: details.when(moment(), this.get('statusType') !== CLOSE_STATUS_TYPE ? 8 : 18),
|
||||||
switch(selection) {
|
icon: details.icon
|
||||||
case LATER_TODAY:
|
};
|
||||||
time = time.hour(18).minute(0);
|
|
||||||
icon = 'moon-o';
|
|
||||||
break;
|
|
||||||
case TOMORROW:
|
|
||||||
time = time.add(1, 'day').hour(timeOfDay).minute(0);
|
|
||||||
icon = 'sun-o';
|
|
||||||
break;
|
|
||||||
case LATER_THIS_WEEK:
|
|
||||||
time = time.add(2, 'day').hour(timeOfDay).minute(0);
|
|
||||||
icon = 'briefcase';
|
|
||||||
break;
|
|
||||||
case THIS_WEEKEND:
|
|
||||||
time = time.day(6).hour(timeOfDay).minute(0);
|
|
||||||
icon = 'bed';
|
|
||||||
break;
|
|
||||||
case NEXT_WEEK:
|
|
||||||
time = time.add(1, 'week').day(1).hour(timeOfDay).minute(0);
|
|
||||||
icon = 'briefcase';
|
|
||||||
break;
|
|
||||||
case TWO_WEEKS:
|
|
||||||
time = time.add(2, 'week').hour(timeOfDay).minute(0);
|
|
||||||
icon = 'briefcase';
|
|
||||||
break;
|
|
||||||
case NEXT_MONTH:
|
|
||||||
time = time.add(1, 'month').startOf('month').hour(timeOfDay).minute(0);
|
|
||||||
icon = 'briefcase';
|
|
||||||
break;
|
|
||||||
case FOREVER:
|
|
||||||
time = time.add(1000, 'year').hour(timeOfDay).minute(0);
|
|
||||||
icon = 'gavel';
|
|
||||||
break;
|
|
||||||
case PICK_DATE_AND_TIME:
|
|
||||||
time = null;
|
|
||||||
icon = 'calendar-plus-o';
|
|
||||||
break;
|
|
||||||
case SET_BASED_ON_LAST_POST:
|
|
||||||
time = null;
|
|
||||||
icon = 'clock-o';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { time, icon };
|
return { time: moment() };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1572,6 +1572,9 @@ en:
|
||||||
next_week: "Next week"
|
next_week: "Next week"
|
||||||
two_weeks: "Two Weeks"
|
two_weeks: "Two Weeks"
|
||||||
next_month: "Next month"
|
next_month: "Next month"
|
||||||
|
three_months: "Three Months"
|
||||||
|
six_months: "Six Months"
|
||||||
|
one_year: "One Year"
|
||||||
forever: "Forever"
|
forever: "Forever"
|
||||||
pick_date_and_time: "Pick date and time"
|
pick_date_and_time: "Pick date and time"
|
||||||
set_based_on_last_post: "Close based on last post"
|
set_based_on_last_post: "Close based on last post"
|
||||||
|
|
Loading…
Reference in New Issue