Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added migration to add googledoc custom field

implemented switch between regular and google app docs
  • Loading branch information...
commit d0b1b2a8ca938fee9d3658dbdeab9e55ca1ada04 1 parent c2c722c
@pulse00 authored
View
55 app/controllers/authsubs_controller.rb
@@ -2,24 +2,59 @@ class AuthsubsController < ApplicationController
unloadable
def listdocs
+
+
+ token = User.current.authsubtoken
+
+ if token.nil? || token.empty?
+ return render :partial => 'notconnected'
+ end
+
client = GData::Client::DocList.new
- client.authsub_token = User.current.authsubtoken
+ client.authsub_token = token
+
+
@feed = client.get('http://docs.google.com/feeds/documents/private/full?title=' + params[:q]).to_xml
render :partial => 'listdocs'
end
- def finish
-
- client = GData::Client::DocList.new
- client.authsub_token = params[:token] # extract the single-use token from the URL query params
- session[:token] = client.auth_handler.upgrade()
- client.authsub_token = session[:token] if session[:token]
+
+ def disconnect
user = User.current
- user.authsubtoken = session[:token]
- user.save
+ user.authsubtoken = nil
+
+ if user.save
+ flash[:notice] = l(:gdocs_disconnect_success)
+ else
+ flash[:error] = l(:gdocs_disconnect_failure)
+ end
+
+ redirect_to :controller => 'my', :action => 'account'
+
+ end
+
+ def finish
+
+ begin
+
+ client = GData::Client::DocList.new
+ client.authsub_token = params[:token] # extract the single-use token from the URL query params
+ session[:token] = client.auth_handler.upgrade()
+ client.authsub_token = session[:token] if session[:token]
+
+ user = User.current
+ user.authsubtoken = session[:token]
+ user.save
+
+ flash[:notice] = "Google Account connected successfully."
+
+ rescue GData::Client::AuthorizationError => e
+
+ flash[:error] = "An authorization error occurred while connecting your Google Account."
+
+ end
- flash[:notice] = "Google Account connected successfully!"
redirect_to :controller => 'my', :action => 'account'
end
View
2  app/views/authsubs/_listdocs.html.erb
@@ -1,5 +1,5 @@
<ul>
<% @feed.elements.each('entry') do |entry| %>
- <li><%= entry.elements['title'].text %></li>
+ <li id="<%= entry.elements['link'].attribute('href').to_s%>"><%= entry.elements['title'].text %></li>
<% end %>
</ul>
View
3  app/views/authsubs/_notconnected.html.erb
@@ -0,0 +1,3 @@
+<ul>
+ <li id="notconnected"><%= l(:gdocs_not_connected) %></li>
+</ul>
View
7 app/views/shared/_view_my_account_gdocs.html.erb
@@ -8,5 +8,10 @@
<%= label :googledocs, :app_domain %>
<%= text_field :googledocs, :app_domain, :value => app_domain %>
</p>
-<%= link_to(l(:gdocs_connect), authsub_link)%>
+
+<% if User.current.has_googledocs_connection?%>
+ <%= link_to(l(:gdocs_disconnect), {:controller => 'authsubs', :action => 'disconnect' })%>
+<% else %>
+ <%= link_to(l(:gdocs_connect), authsub_link)%><br/>
+<% end %>
</div>
View
39 assets/javascripts/googledocs.js
@@ -1,19 +1,26 @@
document.observe('dom:loaded', function() {
- $('issue_custom_field_values_1').up().up().insert('<div class="autocomplete" id="docs_candidates" style="display: none;"></div>');
-
-
- ac = new Ajax.Autocompleter('issue_custom_field_values_1',
- 'docs_candidates',
- '/authsubs/listdocs',
- { minChars: 3,
- frequency: 0.5,
- paramName: 'q',
- updateElement: function(value) {
-
- console.log(value);
- // setCurrentIssue(value.id, $(value).innerHTML);
- // $('issue_id').clear();
- }});
-
+ $$('input.gdocs_input').each(function(element) {
+
+ var id = element.identify();
+ var container = id + '_candidates';
+
+ element.up().up().insert('<div class="autocomplete" id="' + container + '" style="display: none;"></div>');
+
+ new Ajax.Autocompleter(id,
+ container,
+ '/authsubs/listdocs',
+ { minChars: 3,
+ frequency: 0.5,
+ paramName: 'q',
+ updateElement: function(value) {
+
+ if (value.id == 'notconnected') {
+ return;
+ }
+
+ var text = '"' + value.innerHTML + '":' + value.id;
+ element.value = text;
+ }});
+ });
});
View
5 config/locales/de.yml
@@ -2,3 +2,8 @@
de:
google_docs: "Google Docs"
gdocs_connect: "Verbinden"
+ gdocs_disconnect: "Verbindung trennen"
+ googledoc: "googledoc"
+ gdocs_disconnect_success: "GoogleDocs Verbindung wurde entfernt"
+ gdocs_disconnect_failure: "Beim Trennen der GoogleDocs Verbindung ist ein Fehler aufgetreten"
+ gdocs_not_connected: "Ihr Konto ist nicht mit GoogleDocs verbunden"
View
5 config/locales/en.yml
@@ -2,3 +2,8 @@
en:
google_docs: "Google Docs"
gdocs_connect: "Connect"
+ gdocs_disconnect: "Disconnect"
+ googledoc: "googledoc"
+ gdocs_disconnect_success: "GoogleDocs connection disconnected successfully"
+ gdocs_disconnect_failure: "Error disconnecting your GoogleDocs connection"
+ gdocs_not_connected: "Your account is not connected to GoogleDocs"
View
16 db/migrate/006_add_custom_field.rb
@@ -0,0 +1,16 @@
+class AddCustomField < ActiveRecord::Migration
+ def self.up
+ field = IssueCustomField.new(
+ :field_format => 'googledoc',
+ :name => 'Google Doc',
+ :is_for_all => 1,
+ :searchable => 1,
+ :is_filter => 1
+ )
+
+ field.save
+ end
+
+ def self.down
+ end
+end
View
18 init.rb
@@ -5,8 +5,9 @@
require_dependency 'issue'
require_dependency 'googledocs_user_patch'
require_dependency 'googledocs_my_controller_patch'
+ require_dependency 'googledocs_custom_fields_helper_patch'
- Issue::SAFE_ATTRIBUTES << "Authsubtoken" if Issue.const_defined? "SAFE_ATTRIBUTES"
+ Issue::SAFE_ATTRIBUTES << "authsubtoken" if Issue.const_defined? "SAFE_ATTRIBUTES"
end
config.gem 'gdata', :lib => 'gdata'
@@ -19,8 +20,8 @@
author 'Robert Gründler'
description 'This is a google docs plugin for Redmine'
version '0.0.1'
- url 'http://example.com/path/to/plugin'
- author_url 'http://example.com/about'
+ url 'https://github.com/pulse00/redmine_googledocs_plugin'
+ author_url 'https://github.com/pulse00'
end
class GoogleDocCustomFieldFormat < Redmine::CustomFieldFormat
@@ -28,17 +29,12 @@ class GoogleDocCustomFieldFormat < Redmine::CustomFieldFormat
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
- def format_as_url(value)
+ def format_as_googledoc(value)
textilizable (value)
end
- def escape_html?
- false
- end
-
-
end
Redmine::CustomFieldFormat.map do |fields|
- fields.register GoogleDocCustomFieldFormat.new('googledoc', :label => :label_googledoc, :order => 8)
-end
+ fields.register GoogleDocCustomFieldFormat.new('googledoc', :label => 'googledoc', :order => 8)
+end
View
88 javascripts/googledocs.js
@@ -1,78 +1,26 @@
-function handleFeed(response) {
-
- var entries = response.feed.entry;
-
- if (!entries.length) {
-
- alert('no documents found');
- return;
- }
-
- var html = [];
-
- for (var i = 0, entry; entry = entries[i]; i++) {
- var title = entry.title.$t;
-
- $('docs').insert('<li rel="' + entry.link[0].href + '">' + title + '</li>')
- }
-
- console.log(response);
-
-}
-
-
-function handleError(e) {
-
-
-
-}
-
document.observe('dom:loaded', function() {
- var email = $('gdocs_email').readAttribute('rel');
-
- if (email.length == 0)
- return;
+ $$('input.gdocs_input').each(function(element) {
+ var id = element.identify();
+ var container = id + '_candidates';
- $('issue_custom_field_values_1').observe('click', function() {
+ element.up().up().insert('<div class="autocomplete" id="' + container + '" style="display: none;"></div>');
-
- try {
- Modalbox.show('<div><ul id="docs"></ul></div>', {
- doNotMove: true,
- title: 'Search your Google Docs',
- overlayDuration: 0.0,
- slideDownDuration: 0.0,
- slideUpDuration: 0.0,
- resizeDuration: 0.0,
- overlayOpacity: 0.01,
- autoFocusing: false,
- afterLoad: function(){
-
-
- var scope = 'https://docs.google.com/feeds/';
- start = new Date().getTime();
- if (google.accounts.user.checkLogin(scope)) {
- var service = new google.gdata.client.GoogleService('writely', 'DocList-App-v2.0');
- service.getFeed(scope + 'documents/private/full/', handleFeed, handleError);
- } else {
- var token = google.accounts.user.login(scope); // can ignore returned token
- }
-
- console.log('test');
-
+ new Ajax.Autocompleter(id,
+ container,
+ '/authsubs/listdocs',
+ { minChars: 3,
+ frequency: 0.5,
+ paramName: 'q',
+ updateElement: function(value) {
+
+ if (value.id == 'notconnected') {
+ return;
}
-
- });
- } catch (e) {
-
- console.log(e);
-
- }
-
+
+ var text = '"' + value.innerHTML + '":' + value.id;
+ element.value = text;
+ }});
});
-
-
-
});
View
31 lib/googledocs_custom_fields_helper_patch.rb
@@ -0,0 +1,31 @@
+require_dependency 'custom_fields_helper'
+
+module GoogleDocsCustomFieldsHelperPatch
+ def self.included(base) # :nodoc:
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ alias_method_chain :custom_field_tag, :google_docs
+ end
+ end
+
+ module InstanceMethods
+
+ # adds the gdocs_input css class to make the autocompletion javascript work
+ def custom_field_tag_with_google_docs(name, custom_value)
+
+ case custom_value.custom_field.field_format
+
+ when 'googledoc'
+ custom_field = custom_value.custom_field
+ field_name = "#{name}[custom_field_values][#{custom_field.id}]"
+ field_id = "#{name}_custom_field_values_#{custom_field.id}"
+ return text_field_tag(field_name, custom_value.value, {:id => field_id, :class => 'gdocs_input'})
+ else
+ return custom_field_tag_without_google_docs(name, custom_value)
+ end
+ end
+ end
+end
+
+CustomFieldsHelper.send(:include, GoogleDocsCustomFieldsHelperPatch)
View
28 lib/googledocs_user_patch.rb
@@ -14,14 +14,32 @@ module ClassMethods
module InstanceMethods
+
+ def has_googledocs_connection?
+
+ return !self.authsubtoken.nil? && !self.authsubtoken.empty?
+
+ end
+
def authsub_link(next_url)
-
- client = GData::Client::DocList.new
- secure = false # set secure = true for signed AuthSub requests
- sess = true
+
domain = googledocs_preference(:app_domain) # force users to login to a Google Apps hosted domain
- return authsub_link = client.authsub_url(next_url, secure, sess, domain)
+ if !domain.nil? && !domain.empty?
+
+ client = GData::Client::DocList.new
+ secure = false # set secure = true for signed AuthSub requests
+ sess = true
+ return client.authsub_url(next_url, secure, sess, domain)
+
+ else
+
+ scope = 'http://docs.google.com/feeds/'
+ secure = false # set secure = true for signed AuthSub requests
+ sess = true
+ return GData::Auth::AuthSub.get_url(next_url, scope, secure, sess)
+
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.