-
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.
Merge branch 'master' of github.com:joshsoftware/lightair
Conflicts: Gemfile Gemfile.lock app/views/layouts/application.html.haml config/routes.rb spec/spec_helper.rb
- Loading branch information
Showing
35 changed files
with
2,561 additions
and
46 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,5 @@ 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class SpreadsheetsController < ApplicationController | ||
require 'google' | ||
include Google::Spreadsheets | ||
|
||
def index | ||
@spreadsheets = Spreadsheet.all.to_a | ||
end | ||
|
||
def new | ||
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 = list(spreadsheet) | ||
@token = spreadsheet.access_token | ||
else | ||
# Handle if data does not get saved | ||
@msg = 'Getting same access token. Try deleting ' | ||
end | ||
end | ||
|
||
def edit | ||
token = spreadsheet_params['token'] | ||
spreadsheet = Spreadsheet.where(access_token: token)[0] | ||
|
||
if spreadsheet.add_spreadsheet_credentials(spreadsheet_params) | ||
spreadsheet.save | ||
else | ||
@error = 'Already Present' | ||
end | ||
|
||
@spreadsheets = Spreadsheet.all.to_a | ||
|
||
render action: 'index' | ||
end | ||
|
||
def update | ||
spreadsheet = Spreadsheet.find(params['id']) | ||
@worksheet = 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 failure | ||
if params['message'].match('access_denied') | ||
@msg = 'Account integration Failed. User Refused to grant permissions' | ||
end | ||
@spreadsheets = Spreadsheet.all.to_a | ||
render action: 'index' | ||
end | ||
|
||
################################# | ||
private | ||
################################# | ||
|
||
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,27 @@ | ||
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, presence: true, 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 = {}) | ||
self['spreadsheet_id'] = credentials['id'] | ||
self['spreadsheet_title'] = credentials['title'] | ||
end | ||
|
||
def access_token | ||
self['access_token'] | ||
end | ||
|
||
end |
Oops, something went wrong.