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
8201bc3b
authored
Aug 09, 2019
by
source_reader
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
added edit endpoints for annotations, better logging, and bug fixes
parent
1765b262
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
3 deletions
app/adapters/joule/adapter.rb
app/adapters/joule/backend.rb
app/adapters/nilmdb/adapter.rb
app/controllers/annotations_controller.rb
app/controllers/interfaces_controller.rb
app/adapters/joule/adapter.rb
View file @
8201bc3b
...
...
@@ -55,8 +55,8 @@ module Joule
@backend
.
module_interface
(
joule_module
,
req
)
end
def
module_post_interface
(
joule_module
,
req
)
@backend
.
module_post_interface
(
joule_module
,
req
)
def
module_post_interface
(
joule_module
,
req
,
body
)
@backend
.
module_post_interface
(
joule_module
,
req
,
body
)
end
# === ANNOTATIONS ===
...
...
@@ -88,6 +88,20 @@ module Joule
# returns nil
@backend
.
delete_annotation
(
annotation
.
id
)
end
def
edit_annotation
(
id
,
title
,
content
,
stream
)
json
=
@backend
.
edit_annotation
(
id
,
title
,
content
)
annotation
=
Annotation
.
new
annotation
.
id
=
json
[
"id"
]
annotation
.
title
=
json
[
"title"
]
annotation
.
content
=
json
[
"content"
]
annotation
.
start_time
=
json
[
"start"
]
annotation
.
end_time
=
json
[
"end"
]
# ignore joule stream_id parameter
# use the db_stream model instead
annotation
.
db_stream
=
stream
annotation
end
# === END ANNOTATIONS ===
def
node_type
...
...
app/adapters/joule/backend.rb
View file @
8201bc3b
This diff is collapsed.
Click to expand it.
app/adapters/nilmdb/adapter.rb
View file @
8201bc3b
...
...
@@ -95,5 +95,24 @@ module Nilmdb
end
@backend
.
write_annotations
(
path
,
updated_annotations
)
end
def
edit_annotation
(
id
,
title
,
content
,
stream
)
path
=
stream
.
path
json
=
@backend
.
read_annotations
(
path
)
index
=
json
.
index
{
|
item
|
item
[
'id'
]
==
id
.
to_i
}
raise
"error, invalid annotation id"
if
index
.
nil?
# find the specified id
json
[
index
][
'title'
]
=
title
json
[
index
][
'content'
]
=
content
@backend
.
write_annotations
(
path
,
json
)
annotation
=
Annotation
.
new
annotation
.
id
=
json
[
index
][
"id"
]
annotation
.
title
=
json
[
index
][
"title"
]
annotation
.
content
=
json
[
index
][
"content"
]
annotation
.
start_time
=
json
[
index
][
"start"
]
annotation
.
end_time
=
json
[
index
][
"end"
]
annotation
.
db_stream
=
stream
annotation
end
end
end
app/controllers/annotations_controller.rb
View file @
8201bc3b
...
...
@@ -38,6 +38,22 @@ class AnnotationsController < ApplicationController
render
:index
end
# PATCH/PUT /annotations/1.json
def
update
@service
=
StubService
.
new
begin
annotation
=
@node_adapter
.
edit_annotation
(
params
[
:id
],
params
[
:title
],
params
[
:content
],
@db_stream
)
rescue
RuntimeError
=>
e
@service
.
add_error
(
"Cannot update annotation [
#{
e
}
]"
)
render
'helpers/empty_response'
,
status: :unprocessable_entity
and
return
end
@annotations
=
[
annotation
]
render
:index
end
# DELETE /annotations/1.json
def
destroy
annotation
=
Annotation
.
new
...
...
app/controllers/interfaces_controller.rb
View file @
8201bc3b
...
...
@@ -47,7 +47,7 @@ class InterfacesController < ActionController::Base
def
post
path
=
create_proxy_path
(
request
.
fullpath
,
@joule_module
.
id
)
proxied_response
=
@node_adapter
.
module_post_interface
(
@joule_module
,
path
)
proxied_response
=
@node_adapter
.
module_post_interface
(
@joule_module
,
path
,
request
.
raw_post
)
render
plain:
proxied_response
.
body
proxied_response
.
headers
.
each
do
|
key
,
value
|
...
...
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