Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7eb69eef
authored
Jan 19, 2017
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fixed glitch in time range calculation for folders
parent
86a65d60
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
11 deletions
app/controllers/db_folders_controller.rb
app/models/db_folder.rb
app/services/db_folder/edit_folder.rb
app/services/db_folder/update_folder.rb
app/services/service_status.rb
spec/services/db_stream/update_stream_spec.rb
spec/services/folder/update_folder_spec.rb
app/controllers/db_folders_controller.rb
View file @
7eb69eef
...
@@ -12,7 +12,12 @@ class DbFoldersController < ApplicationController
...
@@ -12,7 +12,12 @@ class DbFoldersController < ApplicationController
folder
=
DbFolder
.
find
(
params
[
:id
])
folder
=
DbFolder
.
find
(
params
[
:id
])
adapter
=
DbAdapter
.
new
(
folder
.
db
.
url
)
adapter
=
DbAdapter
.
new
(
folder
.
db
.
url
)
service
=
EditFolder
.
new
(
adapter
)
service
=
EditFolder
.
new
(
adapter
)
render
json:
service
.
run
(
folder
,
params
)
service
.
run
(
folder
,
folder_params
.
symbolize_keys
)
if
(
service
.
success?
)
render
json:
folder
,
shallow:
false
else
render
json:
service
,
status: :unprocessable_entity
end
end
end
private
private
...
...
app/models/db_folder.rb
View file @
7eb69eef
...
@@ -15,6 +15,19 @@ class DbFolder < ActiveRecord::Base
...
@@ -15,6 +15,19 @@ class DbFolder < ActiveRecord::Base
dependent: :destroy
dependent: :destroy
validates_presence_of
:name
validates_presence_of
:name
validate
:name_is_unique_in_group
#:section: Utility Methods
#vaildator to ensure the name is unique to the parent.
def
name_is_unique_in_group
self
.
parent
.
subfolders
.
each
do
|
folder
|
if
((
folder
.
name
==
self
.
name
)
and
(
folder
.
id
!=
self
.
id
))
self
.
errors
.
add
(
:name
,
"[
#{
self
.
name
}
] is already used"
)
end
end
end
def
self
.
defined_attributes
def
self
.
defined_attributes
[
:name
,
:description
,
:hidden
]
[
:name
,
:description
,
:hidden
]
...
...
app/services/db_folder/edit_folder.rb
View file @
7eb69eef
...
@@ -16,7 +16,9 @@ class EditFolder
...
@@ -16,7 +16,9 @@ class EditFolder
# result is valid (eg folder's can't have the same name)
# result is valid (eg folder's can't have the same name)
db_folder
.
assign_attributes
(
attribs
)
db_folder
.
assign_attributes
(
attribs
)
unless
db_folder
.
valid?
unless
db_folder
.
valid?
add_error
(
db_folder
.
errors
)
db_folder
.
errors
.
full_messages
.
each
{
|
e
|
add_error
(
e
)}
return
self
return
self
end
end
# local model checks out, update the remote NilmDB
# local model checks out, update the remote NilmDB
...
...
app/services/db_folder/update_folder.rb
View file @
7eb69eef
...
@@ -183,15 +183,16 @@ class UpdateFolder
...
@@ -183,15 +183,16 @@ class UpdateFolder
# update extents based on result of updater
# update extents based on result of updater
# (either a stream or a subfolder)
# (either a stream or a subfolder)
def
absorb_data_extents
(
updater
)
def
absorb_data_extents
(
updater
)
@start_time
=
if
@start_time
.
nil?
byebug
if
(
@folder
.
name
==
"tutorial"
)
updater
.
start_time
if
@start_time
.
nil?
else
@start_time
=
updater
.
start_time
[
@start_time
,
updater
.
start_time
].
min
elsif
!
updater
.
start_time
.
nil?
end
@start_time
=
[
@start_time
,
updater
.
start_time
].
min
@end_time
=
if
@end_time
.
nil?
end
updater
.
end_time
if
@end_time
.
nil?
else
@end_time
=
updater
.
end_time
[
@start_time
,
updater
.
end_time
].
max
elsif
!
updater
.
end_time
.
nil?
@end_time
=
[
@end_time
,
updater
.
end_time
].
max
end
end
@size_on_disk
+=
updater
.
size_on_disk
@size_on_disk
+=
updater
.
size_on_disk
end
end
...
...
app/services/service_status.rb
View file @
7eb69eef
...
@@ -41,6 +41,10 @@ module ServiceStatus
...
@@ -41,6 +41,10 @@ module ServiceStatus
!
@warnings
.
empty?
!
@warnings
.
empty?
end
end
def
success?
!
self
.
warnings?
&&
!
self
.
errors?
end
def
run
def
run
raise
'Implement in client, return service object'
raise
'Implement in client, return service object'
end
end
...
@@ -56,4 +60,11 @@ module ServiceStatus
...
@@ -56,4 +60,11 @@ module ServiceStatus
end
end
true
true
end
end
def
as_json
(
_options
=
{})
{
errors:
@errors
,
warnings:
@warnings
}
end
end
end
spec/services/db_stream/update_stream_spec.rb
View file @
7eb69eef
spec/services/folder/update_folder_spec.rb
View file @
7eb69eef
...
@@ -34,6 +34,7 @@ describe 'UpdateFolder service' do
...
@@ -34,6 +34,7 @@ describe 'UpdateFolder service' do
service
.
run
([
build_entry
(
'/a/path'
,
1
,
90
,
20
,
8
),
service
.
run
([
build_entry
(
'/a/path'
,
1
,
90
,
20
,
8
),
build_entry
(
'/a/path~decim-4'
,
10
,
110
,
25
,
24
),
build_entry
(
'/a/path~decim-4'
,
10
,
110
,
25
,
24
),
build_entry
(
'/a/path2'
,
-
10
,
100
,
28
,
24
),
build_entry
(
'/a/path2'
,
-
10
,
100
,
28
,
24
),
#build_entry('/a/path', nil, nil, 0, 24),
build_entry
(
'/a/deep/path'
,
0
,
400
,
8
,
10
)])
build_entry
(
'/a/deep/path'
,
0
,
400
,
8
,
10
)])
folder
=
DbFolder
.
find_by_path
(
'/a'
)
folder
=
DbFolder
.
find_by_path
(
'/a'
)
expect
(
folder
.
start_time
).
to
eq
(
-
10
)
expect
(
folder
.
start_time
).
to
eq
(
-
10
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment