-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
434 additions
and
44 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ build/ | |
/log/ | ||
/tmp | ||
*.log | ||
test.html.haml |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ | ||
xyz = -> | ||
alert "welcome" | ||
return |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import "bootstrap"; | ||
|
||
body | ||
{ | ||
padding-top: 80px; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the spreadsheets controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class SpreadsheetsController < ApplicationController | ||
include GoogleSpreadsheets | ||
|
||
def index | ||
@spreadsheets = Spreadsheet.all.to_a | ||
end | ||
|
||
def new | ||
@req = params | ||
=begin | ||
if params[:access_token] | ||
spreadsheet = Spreadsheet.where(access_token: params['access_token'])[0] | ||
else | ||
spreadsheet = Spreadsheet.new | ||
spreadsheet.add_tokens(request.env['omniauth.auth'].fetch('credentials')) | ||
end | ||
if spreadsheet.save | ||
# Spreadsheets from google | ||
@spreadsheets = get_spreadsheets(spreadsheet) | ||
@token = spreadsheet.access_token | ||
@msg = 'work' | ||
else | ||
@msg = 'no work' | ||
# Handle if data does not get saved | ||
end | ||
=end | ||
end | ||
|
||
def edit | ||
token = spreadsheet_params['token'] | ||
spreadsheet = Spreadsheet.where(access_token: token)[0] | ||
spreadsheet.add_spreadsheet_credentials(spreadsheet_params) | ||
#binding.pry | ||
spreadsheet.save | ||
|
||
@spreadsheets = Spreadsheet.all.to_a | ||
|
||
render action: 'index' | ||
end | ||
|
||
def update | ||
spreadsheet = Spreadsheet.find(params['id']) | ||
@worksheet = get_worksheets(spreadsheet) | ||
User.add_users_from_worksheet(@worksheet) | ||
redirect_to users_path | ||
end | ||
|
||
def destroy | ||
Spreadsheet.find(params['id']).delete | ||
redirect_to spreadsheets_path | ||
end | ||
|
||
def spreadsheet_params | ||
params.permit(:title, :id, :token) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SpreadsheetsHelper | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Spreadsheet | ||
include Mongoid::Document | ||
|
||
field :spreadsheet_id, type: String | ||
field :spreadsheet_title, type: String | ||
field :refresh_token, type: String | ||
field :expires_at, type: Time | ||
field :access_token, type: String | ||
|
||
validates :access_token, uniqueness: true | ||
|
||
def add_tokens(tokens = {}) | ||
self['access_token'] = tokens.fetch('token') | ||
self['refresh_token'] = tokens.fetch('refresh_token') | ||
self['expires_at'] = tokens.fetch('expires_at') | ||
end | ||
|
||
def add_spreadsheet_credentials(credentials = {}) | ||
#binding.pry | ||
self['spreadsheet_id'] = credentials['id'] | ||
self['spreadsheet_title'] = credentials['title'] | ||
end | ||
|
||
def access_token | ||
self['access_token'] | ||
end | ||
|
||
end |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
=debug @sp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
%h4 | ||
=link_to 'Add New Spreadsheet', 'auth/google/' | ||
|
||
%table.table.table-striped | ||
%tr.info | ||
%td | ||
%strong # | ||
%td | ||
%strong | ||
Spreadsheets ( | ||
=Spreadsheet.count | ||
) | ||
%td | ||
%strong Operations | ||
- i = 0 | ||
- @spreadsheets.each do |ss| | ||
%tr | ||
%td | ||
= i = i + 1 | ||
%td | ||
- if ss['spreadsheet_title'] | ||
=ss['spreadsheet_title'] | ||
-else | ||
=link_to 'Spreadsheet not initialised', new_spreadsheet_path(access_token: ss['access_token']) | ||
%td | ||
=link_to 'Delete', spreadsheet_path(ss), method: :delete | ||
-if ss['spreadsheet_title'] | ||
| | ||
=link_to 'Update', spreadsheet_path(ss), method: :patch | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=@req | ||
%br | ||
-#count = @spreadsheets.count | ||
=#count | ||
-#count.times do |i| | ||
=#link_to @spreadsheets[i]['title'], edit_spreadsheet_path(@spreadsheets[i]['id'], title: @spreadsheets[i]['title'], token: @token) if @spreadsheets[i]['mimeType'].include?('spreadsheet') | ||
%br |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :google_oauth2, ENV['GOOGLE_ID'], ENV['GOOGLE_KEY'], | ||
{ | ||
name: "google", | ||
name: 'google', | ||
scope: 'userinfo.profile,userinfo.email,drive,https://spreadsheets.google.com/feeds', | ||
prompt: 'consent', | ||
access_type: "offline", | ||
access_type: 'offline', | ||
#redirect_uri: 'http://localhost:8080/auth/google/spreadsheets' | ||
} | ||
|
||
#provider :linkedin, '75cmlzl0cpmwa2', 'I5y0aRBkfpgMmTqp', redirect_uri: 'http://localhost:8080/auth/linkedin/callback', scope:'r_emailaddress r_network r_contactinfo rw_company_admin rw_nus rw_groups w_messages r_basicprofile r_fullprofile' | ||
end |
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
Oops, something went wrong.