|
@@ -1,9 +1,9 @@
|
|
|
const {
|
|
const {
|
|
|
- inputBlock, actionsBlock, buttonElement, checkboxesElementOption,
|
|
|
|
|
|
|
+ inputBlock, actionsBlock, buttonElement, markdownSectionBlock,
|
|
|
} = require('@growi/slack');
|
|
} = require('@growi/slack');
|
|
|
-const { fromUnixTime, format } = require('date-fns');
|
|
|
|
|
|
|
+const { format } = require('date-fns');
|
|
|
|
|
|
|
|
-module.exports = () => {
|
|
|
|
|
|
|
+module.exports = (crowi) => {
|
|
|
const BaseSlackCommandHandler = require('./slack-command-handler');
|
|
const BaseSlackCommandHandler = require('./slack-command-handler');
|
|
|
const handler = new BaseSlackCommandHandler();
|
|
const handler = new BaseSlackCommandHandler();
|
|
|
|
|
|
|
@@ -25,34 +25,17 @@ module.exports = () => {
|
|
|
|
|
|
|
|
handler.togetterMessageBlocks = function(messages, body, args, limit) {
|
|
handler.togetterMessageBlocks = function(messages, body, args, limit) {
|
|
|
return [
|
|
return [
|
|
|
- inputBlock(this.togetterCheckboxesElement(messages), 'selected_messages', 'Select massages to use.'),
|
|
|
|
|
- actionsBlock(buttonElement({ text: 'Show more', actionId: 'togetterShowMore', value: JSON.stringify({ body, args, limit }) })),
|
|
|
|
|
|
|
+ markdownSectionBlock('Select the oldest and latest datetime of the messages to use'),
|
|
|
|
|
+ inputBlock(this.plainTextInputElementWithInitialTime('togetter:oldestDateTime'), 'oldest_time', 'Oldest datetime'),
|
|
|
|
|
+ inputBlock(this.plainTextInputElementWithInitialTime('togetter:latestDateTime'), 'latest_time', 'Latest datetime'),
|
|
|
inputBlock(this.togetterInputBlockElement('page_path', '/'), 'page_path', 'Page path'),
|
|
inputBlock(this.togetterInputBlockElement('page_path', '/'), 'page_path', 'Page path'),
|
|
|
actionsBlock(
|
|
actionsBlock(
|
|
|
- buttonElement({ text: 'Cancel', actionId: 'togetterCancelPageCreation' }),
|
|
|
|
|
- buttonElement({ text: 'Create page', actionId: 'togetterCreatePage', color: 'primary' }),
|
|
|
|
|
|
|
+ buttonElement({ text: 'Cancel', actionId: 'togetter:cancel' }),
|
|
|
|
|
+ buttonElement({ text: 'Create page', actionId: 'togetter:createPage', style: 'primary' }),
|
|
|
),
|
|
),
|
|
|
];
|
|
];
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- handler.togetterCheckboxesElement = function(messages) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: 'checkboxes',
|
|
|
|
|
- options: this.togetterCheckboxesElementOptions(messages),
|
|
|
|
|
- action_id: 'checkboxes_changed',
|
|
|
|
|
- };
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- handler.togetterCheckboxesElementOptions = function(messages) {
|
|
|
|
|
- const options = messages
|
|
|
|
|
- .sort((a, b) => { return a.ts - b.ts })
|
|
|
|
|
- .map((message, index) => {
|
|
|
|
|
- const date = fromUnixTime(message.ts);
|
|
|
|
|
- return checkboxesElementOption(`*${message.user}* ${format(new Date(date), 'yyyy/MM/dd HH:mm:ss')}`, message.text, `selected-${index}`);
|
|
|
|
|
- });
|
|
|
|
|
- return options;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Plain-text input element
|
|
* Plain-text input element
|
|
|
* https://api.slack.com/reference/block-kit/block-elements#input
|
|
* https://api.slack.com/reference/block-kit/block-elements#input
|
|
@@ -68,5 +51,16 @@ module.exports = () => {
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ handler.plainTextInputElementWithInitialTime = function(actionId) {
|
|
|
|
|
+ const tzDateSec = new Date().getTime();
|
|
|
|
|
+ const grwTzoffset = crowi.appService.getTzoffset() * 60 * 1000;
|
|
|
|
|
+ const initialDateTime = format(new Date(tzDateSec - grwTzoffset), 'yyyy/MM/dd-HH:mm');
|
|
|
|
|
+ return {
|
|
|
|
|
+ type: 'plain_text_input',
|
|
|
|
|
+ action_id: actionId,
|
|
|
|
|
+ initial_value: initialDateTime,
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return handler;
|
|
return handler;
|
|
|
};
|
|
};
|