twenty-server 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twenty/server/migration/3_add_color_to_projects.rb +1 -1
- data/lib/twenty/server/migration.rb +8 -7
- data/lib/twenty/server/mixin/colorable.rb +34 -0
- data/lib/twenty/server/mixin.rb +3 -0
- data/lib/twenty/server/model/project.rb +35 -33
- data/lib/twenty/server/model.rb +0 -1
- data/lib/twenty/server.rb +44 -12
- metadata +3 -3
- data/lib/twenty/server/model/mixin/colorable_mixin.rb +0 -32
- data/lib/twenty/server/path.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dea1ad302d6a0d97724553541aa9fc2b01f8a4a48faa9e30983f51827b9407ba
|
4
|
+
data.tar.gz: 8bec34fcf0498dcc2fedaa95dd6d857d400cc6728dd5d891edfc68155ce0a094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20de5cea99568ce83847aaf13ee125298d58fa76640c4986298da9eb794f86feaf07fc71aef5d1cc51406c49ceb357d159ef124c5261cebf3f897eef7130287c
|
7
|
+
data.tar.gz: 8d621a10caa0e5074a570b80574f2efb8bc4337126e0915a6dbd24c2e0f16b30a2dfdf1af01ae7c8c962b9e9a8a516f754d53bc06cd9a86c9d66b2bd77005960
|
@@ -1,25 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Twenty::Migration
|
4
|
-
|
4
|
+
Sequel.extension(:migration)
|
5
|
+
|
5
6
|
##
|
6
7
|
# @return [String]
|
7
|
-
# Returns the path to
|
8
|
+
# Returns the path to the migrations directory
|
8
9
|
def self.migrations_path
|
9
10
|
File.join(__dir__, "migration")
|
10
11
|
end
|
11
12
|
|
12
13
|
##
|
13
|
-
#
|
14
|
+
# Run migrations
|
14
15
|
# @return [void]
|
15
|
-
def self.run!
|
16
|
-
Sequel::Migrator.run(Twenty.connection, migrations_path)
|
16
|
+
def self.run!(options = {})
|
17
|
+
Sequel::Migrator.run(Twenty.connection, migrations_path, options)
|
17
18
|
end
|
18
19
|
|
19
20
|
##
|
20
21
|
# @return [Boolean]
|
21
|
-
# Returns true when there are pending migrations
|
22
|
+
# Returns true when there are pending migrations
|
22
23
|
def self.pending_migrations?
|
23
|
-
Sequel::Migrator.is_current?(Twenty.connection, migrations_path)
|
24
|
+
! Sequel::Migrator.is_current?(Twenty.connection, migrations_path)
|
24
25
|
end
|
25
26
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Twenty::Mixin
|
4
|
+
module Colorable
|
5
|
+
extend self
|
6
|
+
|
7
|
+
COLORS = [
|
8
|
+
"#222222", "#333333", "#444444", "#555555", "#666666",
|
9
|
+
"#777777", "#888888", "#999999", "#AA2222", "#22AA22",
|
10
|
+
"#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
|
11
|
+
"#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
|
12
|
+
"#112233", "#445566", "#778899", "#AA4455", "#5544AA",
|
13
|
+
"#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
|
14
|
+
"#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
|
15
|
+
"#993366", "#2200AA", "#557788", "#998877", "#BB4400"
|
16
|
+
]
|
17
|
+
|
18
|
+
def before_validation
|
19
|
+
super if defined?(super)
|
20
|
+
set_random_color
|
21
|
+
end
|
22
|
+
|
23
|
+
def random_color
|
24
|
+
COLORS.sample
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def set_random_color
|
30
|
+
return if id
|
31
|
+
self.color = random_color
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,42 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Twenty
|
4
|
+
class Project < Sequel::Model
|
5
|
+
include Model
|
6
|
+
include Mixin::Colorable
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
validates_presence_of :name
|
9
|
+
validates_presence_of :path
|
10
|
+
one_to_many :tasks, class_name: "Twenty::Task"
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
##
|
13
|
+
# @api private
|
14
|
+
def validate
|
15
|
+
super
|
16
|
+
errors.add(:path, "does not exist on disk") if !path_exist?
|
17
|
+
errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
##
|
21
|
+
# @return [String]
|
22
|
+
# The path to a project
|
23
|
+
def path
|
24
|
+
super&.sub(Dir.home, "~")
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
##
|
28
|
+
# @return [Boolean]
|
29
|
+
# Returns true when {#path} exists on disk
|
30
|
+
def path_exist?
|
31
|
+
File.exist? File.expand_path(path)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
##
|
35
|
+
# @return [Integer]
|
36
|
+
# Returns the number of open tasks a project has
|
37
|
+
def open_task_count
|
38
|
+
@open_task_count ||= Twenty::Task
|
39
|
+
.where(project_id: id)
|
40
|
+
.where(Sequel.lit("status IN (0,1,2)"))
|
41
|
+
.count
|
42
|
+
end
|
41
43
|
end
|
42
44
|
end
|
data/lib/twenty/server/model.rb
CHANGED
data/lib/twenty/server.rb
CHANGED
@@ -1,22 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Twenty
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
extend Module.new {
|
5
|
+
require "tmpdir"
|
6
|
+
require "fileutils"
|
7
|
+
extend self
|
8
|
+
extend FileUtils
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
##
|
11
|
+
# @return [String]
|
12
|
+
# Returns the path for the default SQLite database
|
13
|
+
def default_database
|
14
|
+
@default_database ||= File.join(datadir, "database.sqlite")
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# @return [String]
|
19
|
+
# Returns the directory where twenty stores data
|
20
|
+
def datadir
|
21
|
+
File.join(Dir.home, ".local", "share", "twenty")
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# @return [String]
|
26
|
+
# Returns the directory where twenty stores temporary data
|
27
|
+
def tmpdir
|
28
|
+
File.join(Dir.tmpdir, "twenty")
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# @return [String]
|
33
|
+
# Returns the path to a PID file
|
34
|
+
def pid
|
35
|
+
File.join(tmpdir, "server.pid")
|
36
|
+
end
|
37
|
+
|
38
|
+
mkdir_p(datadir)
|
39
|
+
mkdir_p(tmpdir)
|
40
|
+
}
|
14
41
|
|
15
42
|
##
|
16
|
-
# Establishes a database connection
|
43
|
+
# Establishes a database connection
|
17
44
|
#
|
18
45
|
# @param [String] path
|
19
|
-
# The path to a
|
46
|
+
# The path to a SQLite database
|
20
47
|
#
|
21
48
|
# @return [void]
|
22
49
|
def self.establish_connection(path:)
|
@@ -26,12 +53,17 @@ module Twenty
|
|
26
53
|
)
|
27
54
|
end
|
28
55
|
|
56
|
+
##
|
57
|
+
# @return [Sequel::Database::SQLite]
|
58
|
+
# Returns the connection to a database
|
29
59
|
def self.connection
|
30
60
|
establish_connection unless @connection
|
31
61
|
@connection
|
32
62
|
end
|
33
63
|
|
34
|
-
|
64
|
+
require "sequel"
|
65
|
+
require_relative "server/mixin"
|
66
|
+
require_relative "server/migration"
|
35
67
|
require_relative "server/graphql"
|
36
68
|
require_relative "server/rack"
|
37
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twenty-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
@@ -123,11 +123,11 @@ files:
|
|
123
123
|
- "./lib/twenty/server/migration/1_create_projects.rb"
|
124
124
|
- "./lib/twenty/server/migration/2_create_tasks.rb"
|
125
125
|
- "./lib/twenty/server/migration/3_add_color_to_projects.rb"
|
126
|
+
- "./lib/twenty/server/mixin.rb"
|
127
|
+
- "./lib/twenty/server/mixin/colorable.rb"
|
126
128
|
- "./lib/twenty/server/model.rb"
|
127
|
-
- "./lib/twenty/server/model/mixin/colorable_mixin.rb"
|
128
129
|
- "./lib/twenty/server/model/project.rb"
|
129
130
|
- "./lib/twenty/server/model/task.rb"
|
130
|
-
- "./lib/twenty/server/path.rb"
|
131
131
|
- "./lib/twenty/server/rack.rb"
|
132
132
|
- "./lib/twenty/server/rack/graphql.rb"
|
133
133
|
- "./share/twenty/server/schema.graphql"
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Twenty::ColorableMixin
|
4
|
-
extend self
|
5
|
-
|
6
|
-
COLORS = [
|
7
|
-
"#222222", "#333333", "#444444", "#555555", "#666666",
|
8
|
-
"#777777", "#888888", "#999999", "#AA2222", "#22AA22",
|
9
|
-
"#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
|
10
|
-
"#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
|
11
|
-
"#112233", "#445566", "#778899", "#AA4455", "#5544AA",
|
12
|
-
"#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
|
13
|
-
"#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
|
14
|
-
"#993366", "#2200AA", "#557788", "#998877", "#BB4400"
|
15
|
-
]
|
16
|
-
|
17
|
-
def before_validation
|
18
|
-
super if defined?(super)
|
19
|
-
set_random_color
|
20
|
-
end
|
21
|
-
|
22
|
-
def random_color
|
23
|
-
COLORS.sample
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def set_random_color
|
29
|
-
return if id
|
30
|
-
self.color = random_color
|
31
|
-
end
|
32
|
-
end
|
data/lib/twenty/server/path.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Twenty::Path
|
4
|
-
require "tmpdir"
|
5
|
-
extend self
|
6
|
-
|
7
|
-
##
|
8
|
-
# @return [String]
|
9
|
-
# Returns the directory where twenty stores persistent data.
|
10
|
-
def datadir
|
11
|
-
File.join(Dir.home, ".local", "share", "twenty")
|
12
|
-
end
|
13
|
-
|
14
|
-
##
|
15
|
-
# @return [String]
|
16
|
-
# Returns the directory where twenty stores temporary data.
|
17
|
-
def tmpdir
|
18
|
-
File.join(Dir.tmpdir, "twenty")
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
# @return [String]
|
23
|
-
# Returns the file where twenty can write the PID of
|
24
|
-
# a web server running in the background.
|
25
|
-
def pidfile
|
26
|
-
File.join(tmpdir, "server.pid")
|
27
|
-
end
|
28
|
-
|
29
|
-
FileUtils.mkdir_p(datadir)
|
30
|
-
FileUtils.mkdir_p(tmpdir)
|
31
|
-
end
|