Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- +micrate Up
-- SQL in section 'Up' is executed when this migration is applied

ALTER TABLE sys
ADD COLUMN IF NOT EXISTS signage_last_seen TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS playlist_item_id TEXT;

ALTER TABLE sys
DROP CONSTRAINT IF EXISTS sys_playlist_item_id_fkey;

ALTER TABLE sys
ADD CONSTRAINT sys_playlist_item_id_fkey
FOREIGN KEY (playlist_item_id)
REFERENCES playlist_items(id)
ON DELETE SET NULL;

-- +micrate Down
-- SQL section 'Down' is executed when this migration is rolled back

ALTER TABLE sys
DROP CONSTRAINT IF EXISTS sys_playlist_item_id_fkey;

ALTER TABLE sys
DROP COLUMN IF EXISTS playlist_item_id,
DROP COLUMN IF EXISTS signage_last_seen;
2 changes: 1 addition & 1 deletion spec/doorkeeper_app_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module PlaceOS::Model
end

app.persisted?.should be_true
app.uid.should_not eq(Digest::MD5.hexdigest(app.redirect_uri))
app.uid.should eq(Digest::MD5.hexdigest(app.redirect_uri))
end

it "saves an app with a specified UID" do
Expand Down
17 changes: 17 additions & 0 deletions spec/playlist_item_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ module PlaceOS::Model
item.errors.any? { |e| e.field == :plugin_id }.should eq true
end

it "now playing item associated with a display (control system)" do
cs = Generator.control_system
cs.save!
cs.playlist_item_id.should be_nil
cs.signage_last_seen.should be_nil

item = Generator.item
item.save!

item_id = item.id
cs.update_last_seen_time(item_id)

cs.reload!
cs.signage_last_seen.should_not be_nil
cs.playlist_item_id.should eq item_id
end

it "validates plugin_params keys exist in plugin params properties" do
plugin = Generator.signage_plugin(
params: {
Expand Down
17 changes: 17 additions & 0 deletions src/placeos-models/control_system.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ module PlaceOS::Model
attribute playlists : Array(String) = [] of String, es_type: "keyword"
attribute signage : Bool = false

attribute signage_last_seen : Time? = nil, converter: PlaceOS::Model::Timestamps::EpochConverter, type: "integer", format: "Int64", mass_assignment: false
belongs_to Playlist::Item, foreign_key: "playlist_item_id"

def update_last_seen_time(item_id : String? = nil)
system_id = self.id.as(String)

::PgORM::Database.connection do |db|
db.exec(<<-SQL, args: [system_id, item_id])
UPDATE sys
SET
signage_last_seen = now(),
playlist_item_id = NULLIF($2, '')
WHERE id = $1;
SQL
end
end

# Associations
###############################################################################################

Expand Down
2 changes: 1 addition & 1 deletion src/placeos-models/playlist.cr
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module PlaceOS::Model
return false if starting && starting > now_unix
return false if ending && ending <= now_unix

if timezone && (hours = play_hours)
if timezone && (hours = play_hours.presence)
return between?(hours, now)
end

Expand Down
Loading