From a0054eed19a7d7067e3f5e6f7ff4f54a98e441ea Mon Sep 17 00:00:00 2001
From: lukemelia
Date: Sun, 14 Oct 2007 05:33:00 +0000
Subject: [PATCH] Add an Integrations page, with assistance for implementing
AppleScripts and cron jobs that integrate with Tracks.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@619 a4c988fc-2ded-0310-b66e-134b36920a42
---
.../controllers/integrations_controller.rb | 21 +++++
tracks/app/helpers/integrations_helper.rb | 2 +
.../views/integrations/_applescript1.rhtml | 20 ++++
.../views/integrations/_applescript2.rhtml | 79 ++++++++++++++++
.../_quicksilver_applescript.rhtml | 15 +++
tracks/app/views/integrations/index.rhtml | 92 +++++++++++++++++++
tracks/app/views/sidebar/sidebar.rhtml | 2 +
tracks/config/routes.rb | 10 +-
tracks/public/stylesheets/standard.css | 25 +++++
.../integrations_controller_test.rb | 18 ++++
10 files changed, 276 insertions(+), 8 deletions(-)
create mode 100644 tracks/app/controllers/integrations_controller.rb
create mode 100644 tracks/app/helpers/integrations_helper.rb
create mode 100644 tracks/app/views/integrations/_applescript1.rhtml
create mode 100644 tracks/app/views/integrations/_applescript2.rhtml
create mode 100644 tracks/app/views/integrations/_quicksilver_applescript.rhtml
create mode 100644 tracks/app/views/integrations/index.rhtml
create mode 100644 tracks/test/functional/integrations_controller_test.rb
diff --git a/tracks/app/controllers/integrations_controller.rb b/tracks/app/controllers/integrations_controller.rb
new file mode 100644
index 00000000..542c8bb4
--- /dev/null
+++ b/tracks/app/controllers/integrations_controller.rb
@@ -0,0 +1,21 @@
+class IntegrationsController < ApplicationController
+
+ def index
+ @page_title = 'TRACKS::Integrations'
+ end
+
+ def get_quicksilver_applescript
+ context = current_user.contexts.find params[:context_id]
+ render :partial => 'quicksilver_applescript', :locals => { :context => context }
+ end
+
+ def get_applescript1
+ context = current_user.contexts.find params[:context_id]
+ render :partial => 'applescript1', :locals => { :context => context }
+ end
+
+ def get_applescript2
+ context = current_user.contexts.find params[:context_id]
+ render :partial => 'applescript2', :locals => { :context => context }
+ end
+end
diff --git a/tracks/app/helpers/integrations_helper.rb b/tracks/app/helpers/integrations_helper.rb
new file mode 100644
index 00000000..e6b84107
--- /dev/null
+++ b/tracks/app/helpers/integrations_helper.rb
@@ -0,0 +1,2 @@
+module IntegrationsHelper
+end
diff --git a/tracks/app/views/integrations/_applescript1.rhtml b/tracks/app/views/integrations/_applescript1.rhtml
new file mode 100644
index 00000000..9966ae8f
--- /dev/null
+++ b/tracks/app/views/integrations/_applescript1.rhtml
@@ -0,0 +1,20 @@
+(* Pops up a dialog box in which you enter a description for a next action.
+ It then creates that next action in Tracks in the context specified below.
+ *)
+
+set myUsername to "<%= current_user.login %>"
+set myToken to "<%= current_user.token %>"
+set myContextID to <%= context.id %> (* <%= context.name %> *)
+
+-- Display dialog to enter your description
+display dialog "Description of next action:" default answer ""
+set myDesc to text returned of the result
+
+-- Now send all that info to Tracks
+-- Edit the URL of your Tracks installation if necessary"
+tell application "<%= home_url %>backend/api"
+ set returnValue to call xmlrpc {method name:"NewTodo", parameters:{myUsername, myToken, myContextID, myDesc}}
+end tell
+
+-- Show the ID of the newly created next action
+display dialog "New next action with id " & returnValue & " created"
\ No newline at end of file
diff --git a/tracks/app/views/integrations/_applescript2.rhtml b/tracks/app/views/integrations/_applescript2.rhtml
new file mode 100644
index 00000000..d63ee561
--- /dev/null
+++ b/tracks/app/views/integrations/_applescript2.rhtml
@@ -0,0 +1,79 @@
+(*
+Script to grab the sender and subject of the selected
+Mail message(s), and create new next action(s) with description
+"Email [sender] about [subject]"
+
+If you have Growl, it pops a notification up with the id of
+the newly created action.
+*)
+
+(* Edit appropriately for your setup *)
+property myUsername to "<%= current_user.login %>"
+property myToken to "<%= current_user.token %>"
+property myContextID to <%= context.id %> (* <%= context.name %> *)
+
+-- this string is used when the message subject is empty
+property emptySubject : "No Subject Specified"
+
+-- Get the selected email in Mail
+tell application "Mail"
+ set theSelection to the selection
+ if the length of theSelection is less than 1 then
+ display dialog "One or more messages must be selected." buttons {"OK"} default button 1 with icon caution
+ else
+ repeat with theMessage in theSelection
+ my importMessage(theMessage)
+ end repeat
+ end if
+end tell
+
+on importMessage(theMessage)
+
+ -- Get the info from the email message
+ tell application "Mail"
+ try
+ set theSender to the sender of theMessage
+ set theSubject to subject of theMessage
+ if theSubject is equal to "" then set theSubject to emptySubject
+
+ -- Construct the description string from the email info
+ set myDesc to "Email " & theSender & " about " & theSubject
+ -- Trim the string to 100 characters otherwise it won't validate
+ if length of myDesc > 100 then
+ set myDesc to characters 1 thru 100 of myDesc
+ end if
+ end try
+ end tell
+
+ -- Now send all that info to Tracks
+ -- Edit the URL of your Tracks installation if necessary"
+ tell application "<%= home_url %>backend/api"
+ set returnValue to call xmlrpc {method name:"NewTodo", parameters:{myUsername, myToken, myContextID, myDesc}}
+ end tell
+
+ (* Growl support - comment out or delete this section if
+ you don't have Growl *)
+ tell application "GrowlHelperApp"
+ set the allNotificationsList to ¬
+ {"Tracks Notification"}
+
+ -- Make a list of the notifications
+ -- that will be enabled by default.
+ -- Those not enabled by default can be enabled later
+ -- in the 'Applications' tab of the growl prefpane.
+ set the enabledNotificationsList to ¬
+ {"Tracks Notification"}
+
+ -- Register our script with growl.
+ -- You can optionally (as here) set a default icon
+ -- for this script's notifications.
+ register as application ¬
+ "Tracks Applescript" all notifications allNotificationsList ¬
+ default notifications enabledNotificationsList ¬
+ icon of application "Script Editor"
+ set growlDescription to "Action with ID " & returnValue & " was created."
+ notify with name "Tracks Notification" title "New action sent to Tracks" description growlDescription application name "Tracks Applescript" icon of application "Script Editor.app"
+ end tell
+ (* End of Growl section *)
+
+end importMessage
diff --git a/tracks/app/views/integrations/_quicksilver_applescript.rhtml b/tracks/app/views/integrations/_quicksilver_applescript.rhtml
new file mode 100644
index 00000000..35db68db
--- /dev/null
+++ b/tracks/app/views/integrations/_quicksilver_applescript.rhtml
@@ -0,0 +1,15 @@
+using terms from application "Quicksilver"
+ on process text ThisClipping
+
+ set myUsername to "<%= current_user.login %>"
+ set myToken to "<%= current_user.token %>"
+ set myContextID to <%= context.id %> (* <%= context.name %> *)
+
+ tell application "<%= home_url %>backend/api"
+ set returnValue to call xmlrpc {method name:"NewTodo", parameters:{myUsername, myToken, myContextID, ThisClipping}}
+ end tell
+ tell application "Quicksilver"
+ show notification "Tracks: action added."
+ end tell
+ end process text
+end using terms from
\ No newline at end of file
diff --git a/tracks/app/views/integrations/index.rhtml b/tracks/app/views/integrations/index.rhtml
new file mode 100644
index 00000000..6ee51b92
--- /dev/null
+++ b/tracks/app/views/integrations/index.rhtml
@@ -0,0 +1,92 @@
+
Integrations
+
Tracks can be integrated with a number of other tools... whatever it takes to help you get things done! This page has information on setting up some of these. Not all of these are applicable to all platforms, and some require more technical knowledge than others.
Copy the Applescript below to the clipboard.
+
+
+
+
Open Script Editor and paste the script into a new document.
+
Compile and save the script. Run it as necessary.
+
+
+
+
Add an Action with Applescript based on the currently selected Email in Mail.app
+
This script takes the sender and subject of the selected email(s) in Mail and creates a new action for each one, with the description, "Email [sender] about [subject]". The description gets truncated to 100 characters (the validation limit for the field) if it is longer than that. It also has Growl notifications if you have Growl installed.
Copy the Applescript below to the clipboard.
+
+
+
+
Open Script Editor and paste the script into a new document.
+
Compile and save the script as "Add to Tracks.scpt" in ~/Library/Application Support/Quicksilver/Actions/ (you may need to create the Actions directory)
+
Restart Quicksilver
+
Activate Quicksilver (Ctrl+Space by default)
+
Press "." to put quicksilver into text mode
+
Type the description of the next action you want to add
+
Press tab to switch to the action pane.
+
By typing or scrolling, choose the "Add to Tracks" action.
+
+
+
+
Automatically Email Yourself Upcoming Actions
+
+
If you enter the following entry to your crontab, you will receive email every day around 5 AM with a list of the upcoming actions which are due within the next 7 days.
+
+
+
+
You can of course use other text <%= link_to 'feeds provided by Tracks', feeds_path %> -- why not email a list of next actions in a particular project to a group of colleagues who are working on the project?