Browse Source

convert layout to goodness

master
Richard Cagle 1 year ago
parent
commit
6a68a15de4
12 changed files with 81 additions and 44 deletions
  1. 3
    0
      .rubocop.yml
  2. 12
    13
      Rakefile
  3. 4
    4
      app.rb
  4. 31
    13
      basecamp3.rb
  5. 2
    0
      db/migrate/001_schema.rb
  6. 2
    0
      models/bucket.rb
  7. 8
    1
      models/person.rb
  8. 2
    0
      models/todo_item.rb
  9. 2
    0
      models/todo_item_assignee.rb
  10. 2
    0
      models/todo_list.rb
  11. 3
    1
      models/token.rb
  12. 10
    12
      views/team.erb

+ 3
- 0
.rubocop.yml View File

@@ -73,3 +73,6 @@ Style/WordArray:

Style/Documentation:
Enabled: false

Security/YAMLLoad:
Enabled: false

+ 12
- 13
Rakefile View File

@@ -1,3 +1,4 @@
# frozen_string_literal: true

require "dotenv/load"
require "bundler/setup"
@@ -6,27 +7,25 @@ require "pg"
require "logger"
require "sinatra"
require "sinatra/reloader" if development?
ActiveRecord::Base.logger = Logger.new('debug.log')
configuration = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection(configuration[ENV.fetch("APP_ENV")].merge({database: ENV.fetch("DB_NAME")}))

task :default => :migrate
ActiveRecord::Base.logger = Logger.new("debug.log")
configuration = YAML.load(IO.read("database.yml"))
ActiveRecord::Base.establish_connection(configuration[ENV.fetch("APP_ENV")].merge({ database: ENV.fetch("DB_NAME") }))

task default: :migrate

def schema_migrations
ActiveRecord::SchemaMigration.tap do |sm|
sm.create_table
end
ActiveRecord::SchemaMigration.tap(&:create_table)
end

def migration_context
ActiveRecord::MigrationContext.new('db/migrate', schema_migrations)
ActiveRecord::MigrationContext.new("db/migrate", schema_migrations)
end

desc "Create database"
task :create_database do
configuration = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection(configuration['development'].merge({'database': 'postgres', 'schema_search_path': 'public'}))
configuration = YAML.safe_load(IO.read("database.yml"))
ActiveRecord::Base.establish_connection(configuration["development"].merge({ 'database': "postgres", 'schema_search_path': "public" }))
ActiveRecord::Base.connection.create_database(ENV.fetch("DB_NAME"))
puts "Created database: #{ENV.fetch("DB_NAME")}"
end
@@ -43,8 +42,8 @@ end

desc "Drop database"
task :drop_database do
configuration = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection(configuration['development'].merge({'database': 'postgres', 'schema_search_path': 'public'}))
configuration = YAML.safe_load(IO.read("database.yml"))
ActiveRecord::Base.establish_connection(configuration["development"].merge({ 'database': "postgres", 'schema_search_path': "public" }))
ActiveRecord::Base.connection.drop_database(ENV.fetch("DB_NAME"))
puts "Dropped database: #{ENV.fetch("DB_NAME")}"
end

+ 4
- 4
app.rb View File

@@ -7,10 +7,10 @@ require "pg"
require "logger"
require "sinatra"
require "sinatra/reloader" if development?
ActiveRecord::Base.logger = Logger.new('debug.log')
configuration = YAML::load(IO.read('database.yml'))
ActiveRecord::Base.establish_connection(configuration[ENV.fetch("APP_ENV")].merge({database: ENV.fetch("DB_NAME")}))
ActiveRecord::Base.logger = Logger.new("debug.log")
configuration = YAML.load(IO.read("database.yml"))
ActiveRecord::Base.establish_connection(configuration[ENV.fetch("APP_ENV")].merge({ database: ENV.fetch("DB_NAME") }))

require_relative "models/bucket.rb"
require_relative "models/person.rb"

+ 31
- 13
basecamp3.rb View File

@@ -51,46 +51,49 @@ class Basecamp3
TodoItemAssignee.delete_all
TodoList.delete_all

@request_start = Time.now
@request_count = 0

todo_items.each do |item|
Bucket.find_or_initialize(id: item["bucket"]["id"], name: item["bucket"]["name"], bucket_type: item["bucket"]["type"]).save!
Bucket.find_or_create_by(id: item["bucket"]["id"], name: item["bucket"]["name"], bucket_type: item["bucket"]["type"]).save!

TodoList.create(
TodoList.find_or_create_by(
id: item["parent"]["id"],
bucket_id: item["bucket"]["id"],
title: item["parent"]["title"],
list_type: item["parent"]["type"],
url: item["parent"]["url"]
)
).save!

Person.create(
Person.find_or_create_by(
id: item["creator"]["id"],
name: item["creator"]["name"],
email_address: item["creator"]["email_address"],
title: item["creator"]["title"],
bio: item["creator"]["bio"],
avatar_url: item["creator"]["avatar_url"]
)
).save!

item["assignees"].each do |person|
Person.create(
Person.find_or_create_by(
id: person["id"],
name: person["name"],
email_address: person["email_address"],
title: person["title"],
bio: person["bio"],
avatar_url: person["avatar_url"]
)
).save!

TodoItemAssignee.create(todo_item_id: item["id"], person_id: person["id"])
TodoItemAssignee.find_or_create_by(todo_item_id: item["id"], person_id: person["id"]).save!
end

TodoItem.create(
TodoItem.find_or_create_by(
id: item["id"],
todo_list_id: item["parent"]["id"],
creator_id: item["creator"]["id"],
status: item["status"],
visible_to_clients: item["visible_to_clients"] ? 1 : 0,
created_at: DateTime.strptime(item["created_at"], "%s"),
created_at: DateTime.strptime(item["created_at"].to_s, "%s"),
title: item["title"],
item_type: item["type"],
url: item["url"],
@@ -98,9 +101,9 @@ class Basecamp3
completed: item["completed"] ? 1 : 0,
description: item["description"],
content: item["content"],
starts_on: DateTime.strptime(item["starts_on"], "%s"),
due_on: DateTime.strptime(item["due_on"], "%s")
)
starts_on: item["starts_on"].nil? ? nil : DateTime.strptime(item["starts_on"].to_s, "%s"),
due_on: item["due_on"].nil? ? nil : DateTime.strptime(item["due_on"].to_s, "%s")
).save!
end
end

@@ -134,6 +137,21 @@ class Basecamp3
end

def all_results(result)
if @request_start
puts "Made #{@request_count} requests in #{(Time.now - @request_start).to_i} seconds"
if (Time.now - @request_start).to_i > 10
puts "Ten seconds with no problem? Cool. Resetting Counters"
@request_start = Time.now
@request_count = 1
elsif @request_count >= 48 && ((Time.now - @request_start).to_i < 10)
puts "Approaching rate limit! Waiting ten seconds before carrying on."
sleep 10
@request_start = Time.now
@request_count = 1
end
@request_count += 2
end

results = result.parsed || []
if result.headers["x-total-count"].to_i > results.count
until result.headers["link"].nil?

+ 2
- 0
db/migrate/001_schema.rb View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Schema < ActiveRecord::Migration[6.0]
def change
create_table :tokens, force: true do |t|

+ 2
- 0
models/bucket.rb View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Bucket < ActiveRecord::Base
has_many :todo_lists
end

+ 8
- 1
models/person.rb View File

@@ -1,3 +1,10 @@
# frozen_string_literal: true

class Person < ActiveRecord::Base
has_many :todo_items, primary_key: :creator_id
has_many :created_todo_items, primary_key: :creator_id, class_name: "TodoItem"

has_many :todo_item_assignees
has_many :todo_items, through: :todo_item_assignees, source: :todo_item
has_many :todo_lists, through: :todo_items
has_many :projects, through: :todo_lists, class_name: "Bucket", source: :bucket
end

+ 2
- 0
models/todo_item.rb View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TodoItem < ActiveRecord::Base
belongs_to :todo_list
belongs_to :person, foreign_key: :creator_id

+ 2
- 0
models/todo_item_assignee.rb View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TodoItemAssignee < ActiveRecord::Base
belongs_to :todo_item
belongs_to :person

+ 2
- 0
models/todo_list.rb View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TodoList < ActiveRecord::Base
belongs_to :bucket
has_many :todo_items

+ 3
- 1
models/token.rb View File

@@ -1,10 +1,12 @@
# frozen_string_literal: true

class Token < ActiveRecord::Base
def oauth_hash
{
access_token: access_token,
refresh_token: refresh_token,
expires_in: expires_in,
expires_at: expires_at.to_i,
expires_at: expires_at.to_i
}
end
end

+ 10
- 12
views/team.erb View File

@@ -1,28 +1,26 @@
<% b3.db.team.group_by { |t| t["person_name"] }.each do |name, todos| %>
<% next if name == "Mr. Backlog" %>
<% Person.where.not(name: "Mr. Backlog").all.each do |person| %>
<div class="media">
<div class="media-left">
<figure class="image is-64x64">
<img class="is-rounded" src="<%= todos.first["avatar_url"] %>">
<img class="is-rounded" src="<%= person.avatar_url %>">
</figure>
</div>
<div class="media-content">
<p class="title is-4"><%= name %></p>
<p class="subtitle is-6">Working on <%= todos.count %> To-Do(s)</p>
<p class="title is-4"><%= person.name %></p>
<p class="subtitle is-6">Working on <%= person.todo_items.count %> To-Do(s)</p>
</div>
</div>
<div class="content">
<% todos.group_by { |t| t["bucket_name"] }.each do |project, todos| %>
<p class="has-text-weight-bold"><u>Project: <%= project %></u></p>
<% person.projects.each do |project| %>
<p class="has-text-weight-bold"><u>Project: <%= project.name %></u></p>
<ul>
<% todos.group_by { |t| t["list_title"] }.each do |list, todos| %>
<li class="is-italic"><%= list %></li>
<% project.todo_lists.each do |todo_list| %>
<li class="is-italic"><%= todo_list.title %></li>
<ul>
<% todos.each do |todo| %>
<li><%= todo["todo_title"] %></li>
<% todo_list.todo_items.each do |todo| %>
<li><%= todo.title %></li>
<% end %>
</ul>

<% end %>
</ul>
<% end %>

Loading…
Cancel
Save