Last active
February 13, 2019 00:35
-
-
Save markdon/1a481ea6016751c63da22a99e5f7c038 to your computer and use it in GitHub Desktop.
[Boards Date Shifter]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script will find an origin node (which must already have a due date), | |
find the difference between the current origin dueDate and NEW_ORIGIN_DATE, | |
then adjust all due dates in the board by the difference in dates. | |
In other words... | |
It shifts all due dates forwards or backwards based on | |
how much we change the date on the origin card. | |
HOW TO USE: | |
Modify the NEW_ORIGIN_DATE value to be your desired origin date. | |
Copy all of the code below, paste it into your browser console and hit enter. | |
All dates in the board will be updated. You should see a message when saving is complete. | |
You may change ORIGIN_NAME if you want to change the name of your origin node | |
or choose a different origin card. This name should be unique in this board. | |
NOTE: A 'node' means card, comment, list or board. | |
If any of these have a due date, it will be changed. | |
*/ | |
(() => { | |
const ORIGIN_NAME = `EVENT DATE`; | |
const NEW_ORIGIN_DATE = `2019-07-01`; // YYYY-MM-DD | |
const allNodes = Boards.current.boardNode.getAllDescendants(); | |
const originNode = allNodes.find( | |
node => node.attributes.name === ORIGIN_NAME | |
); | |
if (!(originNode instanceof Boards.models.Node)) | |
throw new Error(`Could not find origin node by name.`); | |
const currentOriginDate = originNode.attributes.dueDate; | |
if (typeof currentOriginDate !== `number`) | |
throw new Error(`Origin node does not have a date set.`); | |
const dateDifference = Date.parse(NEW_ORIGIN_DATE) - currentOriginDate; | |
allNodes.forEach(node => { | |
if (typeof node.attributes.dueDate === `number`) | |
node.set(`dueDate`, node.attributes.dueDate + dateDifference); | |
}); | |
const consoleStyle = "border: 2px solid #00FF00;"; | |
console.log(`%c Please wait for all changes to be saved...`, consoleStyle); | |
const pollingId = setInterval(() => { | |
if (Boards.current.nodeRequestInProgress === 0) { | |
console.log(`%c All changes have been saved!`, consoleStyle); | |
clearInterval(pollingId); | |
} | |
}, 100); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment