Commit 7eb69eef by John Doe

fixed glitch in time range calculation for folders

parent 86a65d60
...@@ -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
......
...@@ -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]
......
...@@ -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
......
...@@ -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
......
...@@ -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
...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment