From 0105ed5b8bd55f219e4470a388aebd48855e78ea Mon Sep 17 00:00:00 2001 From: "C. Thomas Bailey" Date: Thu, 5 Jan 2017 12:31:30 +0900 Subject: [PATCH] Put logic for formatting Alfred items in one module. --- handle-action.js | 2 +- index.js | 7 +++---- info.plist | 4 ++-- show-actions.js | 29 ----------------------------- show-cards.js | 17 +++++++---------- show-lists.js | 14 ++------------ 6 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 show-actions.js diff --git a/handle-action.js b/handle-action.js index ffb4c9e..b19fdf5 100644 --- a/handle-action.js +++ b/handle-action.js @@ -8,7 +8,7 @@ const input = JSON.parse(alfy.input) const notify = (title, message) => notifier.notify({ title, message }) if (input.action === 'create') { - postCard(input.card) + postCard(input.data) .then(() => notify('It worked ⚡️', "Your card's now on Trello.")) .catch(reason => notify('Oops 🌧', `Hit a problem: ${reason}`)) } else if (input.action === 'show') { diff --git a/index.js b/index.js index ee2f588..c26b994 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,7 @@ -const alfy = require('alfy') +const config = require('./config') -const userPermissionToken = alfy.config.get('userPermissionToken') -const developerKey = alfy.config.get('developerKey') -const boardId = alfy.config.get('boardId') +if (config.complete()) { +} // TODO: finish this module. Should prompt user to provide userPermissionToken // etc. if not present. Otherwise, should call show-lists module. diff --git a/info.plist b/info.plist index f066bde..185e35b 100644 --- a/info.plist +++ b/info.plist @@ -104,11 +104,11 @@ queuedelaymode 1 queuemode - 2 + 1 runningsubtext Thinking... script - ./node_modules/.bin/run-node show-actions.js "$1" + ./node_modules/.bin/run-node show-cards "$1" scriptargtype 1 scriptfile diff --git a/show-actions.js b/show-actions.js deleted file mode 100644 index 419e2a7..0000000 --- a/show-actions.js +++ /dev/null @@ -1,29 +0,0 @@ -const alfy = require('alfy') -const trello = require('./trello') -const iconFor = require('./icon-for') - -const formatCard = ({ id, name, url }) => ({ - title: name, - arg: JSON.stringify({action: 'show', url}), - quicklookurl: url -}) - -const listId = process.env.listId - -const parts = alfy.input.split(';') -var title = parts[0] -if (title.trim().length === 0) title = 'Create a new card' -const subtitle = parts[1] -const newCard = { action: 'create', card: { name: title, desc: subtitle, pos: 'top', idList: listId } } -const newCardItem = { - title, - subtitle, - arg: JSON.stringify(newCard), - icon: iconFor('new card') -} - -trello.getCards(listId).then(cards => { - const items = alfy.inputMatches(cards, 'name').map(formatCard) - items.unshift(newCardItem) - alfy.output(items) -}) diff --git a/show-cards.js b/show-cards.js index d43e869..1e36d8a 100644 --- a/show-cards.js +++ b/show-cards.js @@ -1,14 +1,11 @@ const alfy = require('alfy') -const { getCards } = require('./trello') +const alfred = require('./alfred') -const formatCard = ({ id, name, url }) => ({ - title: name, - arg: url, - quicklookurl: url -}) +const { listId } = process.env +const gotCards = alfred.getCards(listId) +const gotCreateCard = alfred.getCreateCard(alfy.input, listId) -const listId = process.env.listId -getCards(listId).then(cards => { - const items = cards.map(formatCard) - alfy.output(items) +Promise.all([gotCards, gotCreateCard]).then(([cardItems, createCardItem]) => { + cardItems.unshift(createCardItem) + alfy.output(cardItems) }) diff --git a/show-lists.js b/show-lists.js index 997137f..4a99bce 100644 --- a/show-lists.js +++ b/show-lists.js @@ -1,14 +1,4 @@ const alfy = require('alfy') -const { getLists } = require('./trello') +const alfred = require('./alfred') -const formatList = ({ id, name, icon, uid }) => ({ - title: name, - arg: id, - icon, - uid -}) - -getLists().then(lists => { - var items = lists.map(formatList) - alfy.output(items) -}) +alfred.getLists().then(listItems => alfy.output(listItems))