basic integration of entities to profile
This commit is contained in:
parent
38f51a5de6
commit
d869eab476
@ -3,7 +3,6 @@ class Entity < ApplicationRecord
|
||||
|
||||
validates :name , presence: true
|
||||
validates :ha_id , presence: true
|
||||
validates :ha_type , presence: true
|
||||
validates :member_id , presence: true
|
||||
|
||||
def value
|
||||
@ -11,6 +10,10 @@ class Entity < ApplicationRecord
|
||||
@data["state"]
|
||||
end
|
||||
|
||||
def type
|
||||
ha_id.split(".").first.capitalize
|
||||
end
|
||||
|
||||
def self.ha_entities
|
||||
res = response()
|
||||
res.collect{|i| i["entity_id"]}.select{|i| i.include?("4a") || i.include?("2d")}
|
||||
@ -20,6 +23,6 @@ class Entity < ApplicationRecord
|
||||
token = Rails.application.credentials[:ha_token]
|
||||
all = RestClient.get( "10.30.39.238:8123/api/states#{path}" ,
|
||||
{"Authorization" => "Bearer #{token}" })
|
||||
JSON.parse(all.body)
|
||||
res = JSON.parse(all.body)
|
||||
end
|
||||
end
|
||||
|
@ -6,8 +6,8 @@ class Member < ApplicationRecord
|
||||
|
||||
mount_uploader :picture, PictureUploader
|
||||
|
||||
has_many :entity
|
||||
|
||||
has_many :entities
|
||||
|
||||
def admin
|
||||
true
|
||||
end
|
||||
|
@ -10,8 +10,6 @@
|
||||
= f.input :name
|
||||
.field
|
||||
= f.input :ha_id , collection: Entity.ha_entities
|
||||
.field
|
||||
= f.input :ha_type , collection: ["text" , "bool"]
|
||||
.field
|
||||
= f.input :member_id , collection: Member.all.collect{|m| [m.name , m.id ]}
|
||||
.actions{class: button_classes}
|
||||
|
@ -16,8 +16,8 @@
|
||||
%tr
|
||||
%td= entity.name
|
||||
%td= entity.ha_id
|
||||
%td= entity.ha_type
|
||||
%td= entity.member
|
||||
%td= entity.type
|
||||
%td= entity.member.name
|
||||
%td= link_to 'Show', entity
|
||||
%td= link_to 'Edit', edit_entity_path(entity)
|
||||
%td= link_to 'Destroy', entity, method: :delete, data: { confirm: 'Are you sure?' }
|
||||
|
@ -9,9 +9,9 @@
|
||||
= @entity.ha_id
|
||||
%p
|
||||
%b Type:
|
||||
= @entity.ha_type
|
||||
= @entity.type
|
||||
%p
|
||||
%b Type:
|
||||
%b Value:
|
||||
= @entity.value
|
||||
%p
|
||||
%b Member:
|
||||
|
@ -17,11 +17,17 @@
|
||||
%svg.inline-block.w-3.ml-2{:fill => "currentColor", :viewbox => "0 0 12 12"}
|
||||
%path{:d => "M9.707,5.293l-5-5A1,1,0,0,0,3.293,1.707L7.586,6,3.293,10.293a1,1,0,1,0,1.414,1.414l5-5A1,1,0,0,0,9.707,5.293Z"}
|
||||
|
||||
.flex.justify-around
|
||||
= link_to edit_member_path(@member) do
|
||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
||||
Edit
|
||||
-if @member == current_member or current_member.admin?
|
||||
|
||||
= form_tag( destroy_member_session_path , {method: :delete } ) do
|
||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit}
|
||||
Sign out
|
||||
.flex.justify-around
|
||||
= link_to edit_member_path(@member) do
|
||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400
|
||||
Edit
|
||||
.grid.grid-cols-3.gap-4
|
||||
-@member.entities.each do |entity|
|
||||
%div= entity.type
|
||||
%div= entity.name
|
||||
%div= entity.value
|
||||
= form_tag( destroy_member_session_path , {method: :delete } ) do
|
||||
%button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit}
|
||||
Sign out
|
||||
|
Loading…
Reference in New Issue
Block a user