[JS] Trello Card Organizer
Purpose
As part of our development tools, we used Trello extensively as our project management tool. With several boards in our organization, we used Labels as an effective means of determining relevance as well as severity on stories and bugs as they are populated on each board. However, as a practical matter, Trello does not have a great means of organizing cards by Label, instead offering filtering services as a means to accomplish similar goals. However, for our purposes this left much to be desired, as we had many tasks extending lists out even with filters, and for weekly summaries it was ideal to have these cards organized by label.
Taking advantage of the triggers in Google Apps Script, I created an ordering function which served as a tool to organize cards when weekly meetings came. This allowed us to focus on high priority tasks (red) first, as well as making them more visible to the team as a whole. This approach is not ideal for everyone, as it drastically changes the ordering of the cards of each Trello board in an organization, but for our purposes this met our needs and gave us the satisfaction for ordering that we desired out of Trello.
Taking advantage of the triggers in Google Apps Script, I created an ordering function which served as a tool to organize cards when weekly meetings came. This allowed us to focus on high priority tasks (red) first, as well as making them more visible to the team as a whole. This approach is not ideal for everyone, as it drastically changes the ordering of the cards of each Trello board in an organization, but for our purposes this met our needs and gave us the satisfaction for ordering that we desired out of Trello.
Notes
The ordering of cards was determined by what we used best for our Trello boards. As such, the following order is used:
- Red
- Orange
- Yellow
- Green
- Mint
/** * The arrays at this point may have duplicates in them, so we are going to remove * those before making the final PUT requests to Trello for organization. */ // Takes the arrays in order and removes any duplicate elements var orderedList = UniqueArrayElements([].concat(reds, oranges, yellows, greens, limes));
To add more label colors, or change how the labels are ordered (by name, by ID, etc.), just use a different JSON field in the switch statement.
CardOrganizer.gs
/** * \brief Orders Trello Cards in each board of an organization based * off of the following paradigm: * 1. Red * 2. Orange * 3. Yellow * 4. Green * 5. Mint * * The order of the preference is determined by the concatenation * statement inside of the function. */ function TrelloOrdering() { // Creates an OAuth Service called "trello" TrelloOAuth(); // Prefix for all Trello Rest API Commands var trelloAPIPrefix = "https://api.trello.com/1/"; // For use with POST / PUT operations var payload = {}; // Google Apps Script's options for GET requests var getOptions = { "method": "GET", "oAuthServiceName": "trello", "oAuthUseToken": "always", }; // Google Apps Script's options for POST requests var putOptions = { "method" : "PUT", "payload" : payload, "oAuthServiceName": "trello", "oAuthUseToken": "always", }; // Fetch all boards in an organization var result = UrlFetchApp.fetch( trelloAPIPrefix + "organizations/" + trelloOrganizationName + "/boards", getOptions); // JSON Response from the Request var response = JSON.parse(result); // Container that will hold all board ID's in an organization var boards = []; // For each item in the JSON array, push it into the boards array for (var r in response) // "id" is the boardID boards.push(response[r]["id"]); // Iterate over each board and complete the following actions for(var board in boards) { // Fetch the lists in a board var result = UrlFetchApp.fetch( trelloAPIPrefix + "boards/" + boards[board] + "/lists", getOptions); // JSON Response from the Request var response = JSON.parse(result); // Container which will hold all List ID's var lists = []; // Push each list ID onto the lists array for(var r in response) // "id" is the list ID retrieved from the request lists.push(response[r]["id"]); // For each list... for(var list in lists) { // Get all cards in the list var result = UrlFetchApp.fetch( trelloAPIPrefix + "lists/" + lists[list] + "/cards", getOptions); // Parse the JSON response var response = JSON.parse(result); // Each of these is a container to hold cards that are marked with var reds = []; var oranges = []; var yellows = []; var greens = []; var limes = []; // For each card... for(var r in response) { // Take each label in the cards labels field... for(var label in response[r]["labels"]) { // For this label, find the color it's in and add it to that list. switch(response[r]["labels"][label]["color"]) { case("red"): reds.push(response[r]); break; case("orange"): oranges.push(response[r]); break; case("yellow"): yellows.push(response[r]); break; case("green"): greens.push(response[r]); break; case("lime"): limes.push(response[r]); break; } } } /** * The arrays at this point may have duplicates in them, so we are going to remove * those before making the final PUT requests to Trello for organization. */ // Takes the arrays in order and removes any duplicate elements var orderedList = UniqueArrayElements([].concat(reds, oranges, yellows, greens, limes)); // If there are cards to add... if(orderedList.length > 0) { // For each card... for(var card in orderedList) { // Change the "value" in the payload to be the correct card position // Trello is 1-based not 0-based, so we increment the value. payload["value"] = card + 1; // Make the HTTP PUT request to update the card position var result = UrlFetchApp.fetch( trelloAPIPrefix + "cards/" + orderedList[card]["id"] + "/pos", putOptions); } } } } }