Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@

/app/assets/builds/*
!/app/assets/builds/.keep

/.idea
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: bin/rails server
rails: bin/rails server
css: bin/rails tailwindcss:watch
67 changes: 5 additions & 62 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -1,65 +1,8 @@
/*
* This is a manifest file that'll be compiled into application.css.
*
* With Propshaft, assets are served efficiently without preprocessing steps. You can still include
* application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
* cascading order, meaning styles declared later in the document or manifest will override earlier ones,
* depending on specificity.
*
* Consider organizing styles into separate files for maintainability.
* This is a minimal manifest file for additional application styles.
*
* Main styles are now handled by Tailwind CSS in app/assets/tailwind/application.css
* This file should only contain styles that cannot be expressed with Tailwind classes.
*/

:root {
/* GitHub-inspired light theme */
--color-bg-primary: #ffffff;
--color-bg-secondary: #f6f8fa;
--color-bg-tertiary: #f0f2f5;
--color-text-primary: #24292e;
--color-text-secondary: #586069;
--color-border: #e1e4e8;
--color-accent: #2ea44f;
--color-success: #2ea44f;
--color-danger: #cb2431;
--color-github: #24292e;
}

/* Dark theme - will be activated based on user preference */
@media (prefers-color-scheme: dark) {
:root {
--color-bg-primary: #0d1117;
--color-bg-secondary: #161b22;
--color-bg-tertiary: #21262d;
--color-text-primary: #c9d1d9;
--color-text-secondary: #8b949e;
--color-border: #30363d;
--color-accent: #238636;
--color-success: #238636;
--color-danger: #f85149;
--color-github: #161b22;
}
}

/* Utility classes to use the CSS variables */
.bg-bg-primary { background-color: var(--color-bg-primary); }
.bg-bg-secondary { background-color: var(--color-bg-secondary); }
.bg-bg-tertiary { background-color: var(--color-bg-tertiary); }
.text-text-primary { color: var(--color-text-primary); }
.text-text-secondary { color: var(--color-text-secondary); }
.border-border { border-color: var(--color-border); }
.bg-accent { background-color: var(--color-accent); }
.text-accent { color: var(--color-accent); }
.bg-success { background-color: var(--color-success); }
.text-success { color: var(--color-success); }
.bg-danger { background-color: var(--color-danger); }
.text-danger { color: var(--color-danger); }
.bg-github { background-color: var(--color-github); }

/* Common styling */
body {
background-color: var(--color-bg-primary);
color: var(--color-text-primary);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.transform { transform-origin: center; }
.rotate-180 { transform: rotate(180deg); }
/* Additional custom styles that don't fit Tailwind patterns go here */
45 changes: 42 additions & 3 deletions app/assets/tailwind/application.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
@import "tailwindcss";

:root {
/* GitHub-inspired light theme */
--color-bg-primary: #ffffff;
--color-bg-secondary: #f6f8fa;
--color-bg-tertiary: #f0f2f5;
--color-text-primary: #24292e;
--color-text-secondary: #586069;
--color-border: #e1e4e8;
--color-accent: #2ea44f;
--color-success: #2ea44f;
--color-danger: #cb2431;
--color-github: #24292e;
}

/* Dark theme - will be activated based on user preference */
@media (prefers-color-scheme: dark) {
:root {
--color-bg-primary: #0d1117;
--color-bg-secondary: #161b22;
--color-bg-tertiary: #21262d;
--color-text-primary: #c9d1d9;
--color-text-secondary: #8b949e;
--color-border: #30363d;
--color-accent: #238636;
--color-success: #238636;
--color-danger: #f85149;
--color-github: #161b22;
}
}

@layer base {
body {
background-color: var(--color-bg-primary);
color: var(--color-text-primary);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
}

@layer components {
.transform { transform-origin: center; }
.rotate-180 { transform: rotate(180deg); }

h1 {
@apply text-2xl font-bold mb-4;
}
h2 {
@apply text-xl font-semibold mb-3;
}
}

@layer components {

.btn-primary {
@apply bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition-colors;
}
Expand Down
16 changes: 16 additions & 0 deletions app/assets/tailwind/application.css.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@import "tailwindcss";

@layer base {
h1 {
@apply text-2xl font-bold mb-4;
}
h2 {
@apply text-xl font-semibold mb-3;
}
}

@layer components {
.btn-primary {
@apply bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 transition-colors;
}
}
38 changes: 38 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Repository < ApplicationRecord
validates :github_repo_id, presence: true, uniqueness: true
validates :name, presence: true, length: { maximum: 255 }
validates :full_name, presence: true, format: { with: /\A[\w\-\.]+\/[\w\-\.]+\z/ }
validates :private, inclusion: { in: [ true, false ] }

has_many :user_repositories, dependent: :destroy
has_many :users, through: :user_repositories
has_many :chats, dependent: :destroy

scope :private_repos, -> { where(private: true) }
scope :public_repos, -> { where(private: false) }
scope :for_user, ->(user) { joins(:users).where(users: { id: user.id }) }

def self.common_between_users(user_ids)
joins(:user_repositories)
.where(user_repositories: { user_id: user_ids })
.group("repositories.id")
.having("COUNT(DISTINCT user_repositories.user_id) = ?", user_ids.count)
end

def self.find_or_create_from_github(repo_data)
find_or_create_by(github_repo_id: repo_data[:id]) do |repository|
repository.name = repo_data[:name]
repository.full_name = repo_data[:full_name]
repository.private = repo_data[:private]
repository.description = repo_data[:description]
end
end

def to_s
full_name
end

def group_chat_name
"#{name.humanize} Team"
end
end
14 changes: 14 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ class User < ApplicationRecord
validates :github_id, presence: true, uniqueness: true
validates :username, presence: true

has_many :user_repositories, dependent: :destroy
has_many :repositories, through: :user_repositories
has_many :owned_repositories, -> { where(user_repositories: { role: "owner" }) },
through: :user_repositories, source: :repository

def self.create_from_github(auth)
create! do |user|
user.github_id = auth.uid
Expand All @@ -10,4 +15,13 @@ def self.create_from_github(auth)
user.avatar_url = auth.info.image
end
end

def private_repositories
repositories.private_repos
end

def common_repositories_with(other_users)
user_ids = Array(other_users).map(&:id) + [ id ]
Repository.common_between_users(user_ids)
end
end
19 changes: 19 additions & 0 deletions app/models/user_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class UserRepository < ApplicationRecord
belongs_to :user
belongs_to :repository

validates :user_id, uniqueness: { scope: :repository_id }
validates :role, inclusion: { in: %w[owner admin member] }

before_create :set_access_granted_at

scope :owners, -> { where(role: "owner") }
scope :admins, -> { where(role: "admin") }
scope :members, -> { where(role: "member") }

private

def set_access_granted_at
self.access_granted_at ||= Time.current
end
end
14 changes: 11 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Rules" %></title>
<title><%= content_for(:title) || "GitHub Chat" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
Expand All @@ -13,12 +13,20 @@
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>

<!-- Resource hints для критических ресурсов -->
<link rel="preload" href="/assets/tailwind.css" as="style">
<link rel="preload" href="/assets/application.js" as="script">
<link rel="preload" href="/assets/stimulus.min.js" as="script">

<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">

<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :application %>
<%# Основное подключение стилей %>
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
<%# Подключение дополнительных стилей если есть %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>

<%= javascript_importmap_tags %>
</head>

Expand Down
30 changes: 30 additions & 0 deletions app/views/layouts/application.html.erb.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Rules" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= yield :head %>

<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>

<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">

<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :application %>
<%= javascript_importmap_tags %>
</head>

<body>
<main class="container mx-auto mt-28 px-5 flex">
<%= yield %>
</main>
</body>
</html>
25 changes: 25 additions & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
content: [
'./app/views/**/*.html.erb',
'./app/helpers/**/*.rb',
'./app/assets/stylesheets/**/*.css',
'./app/javascript/**/*.js'
],
theme: {
extend: {
colors: {
'bg-primary': 'var(--color-bg-primary)',
'bg-secondary': 'var(--color-bg-secondary)',
'bg-tertiary': 'var(--color-bg-tertiary)',
'text-primary': 'var(--color-text-primary)',
'text-secondary': 'var(--color-text-secondary)',
'border': 'var(--color-border)',
'accent': 'var(--color-accent)',
'success': 'var(--color-success)',
'danger': 'var(--color-danger)',
'github': 'var(--color-github)'
}
}
},
plugins: []
}
17 changes: 17 additions & 0 deletions db/migrate/20250726184108_create_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateRepositories < ActiveRecord::Migration[8.0]
def change
create_table :repositories do |t|
t.bigint :github_repo_id, null: false
t.string :name, null: false, limit: 255
t.string :full_name, null: false # owner/repo format
t.text :description # для будущих нужд
t.boolean :private, null: false, default: false

t.timestamps
end

add_index :repositories, :github_repo_id, unique: true, name: 'idx_repos_github_id'
add_index :repositories, :private, name: 'idx_repos_private'
add_index :repositories, :full_name, name: 'idx_repos_full_name'
end
end
17 changes: 17 additions & 0 deletions db/migrate/20250726185115_create_user_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateUserRepositories < ActiveRecord::Migration[8.0]
def change
create_table :user_repositories do |t|
t.references :user, null: false, foreign_key: true
t.references :repository, null: false, foreign_key: true
t.string :role, default: 'member'
t.datetime :access_granted_at

t.timestamps
end

add_index :user_repositories, [ :user_id, :repository_id ],
unique: true, name: 'idx_user_repos_unique'
add_index :user_repositories, :repository_id, name: 'idx_user_repos_repo'
add_index :user_repositories, :role, name: 'idx_user_repos_role'
end
end
14 changes: 14 additions & 0 deletions db/migrate/[timestamp]_create_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateRepositories < ActiveRecord::Migration[7.0]
def change
create_table :repositories do |t|
t.bigint :github_repo_id, null: false
t.string :name, null: false
t.boolean :private, null: false, default: false

t.timestamps
end

add_index :repositories, :github_repo_id, unique: true
add_index :repositories, :private
end
end
Loading