@@ -48,7 +48,8 @@ module PlaceOS::Model
4848 attribute support_url : String = " "
4949 attribute timetable_url : String ? # The timetable visualisation
5050 attribute camera_snapshot_url : String ? # snapshot images of the room
51- attribute camera_url : String ? # admin control
51+ attribute camera_snapshot_urls : Array (String ) = - > { [] of String }
52+ attribute camera_url : String ? # admin control
5253
5354 # if not bookable via google / O365 calendaring systems
5455 attribute room_booking_url : String ?
@@ -110,10 +111,49 @@ module PlaceOS::Model
110111
111112 # Validate support URI
112113 validate - > (this : ControlSystem ) {
114+ if url = this.camera_snapshot_url
115+ this.validation_error(:camera_snapshot_url , " is an invalid URI" ) unless Validation .valid_uri?(url)
116+ end
117+
118+ this.camera_snapshot_urls.each do |url |
119+ if ! Validation .valid_uri?(url)
120+ this.validation_error(:camera_snapshot_urls , " contains an invalid URI" )
121+ break
122+ end
123+ end
124+
113125 return if this.support_url.blank?
114126 this.validation_error(:support_url , " is an invalid URI" ) unless Validation .valid_uri?(this.support_url)
115127 }
116128
129+ before_save :unique_camera_urls
130+
131+ def unique_camera_urls
132+ update_camera_urls
133+ unique_urls = self .camera_snapshot_urls.uniq
134+ if unique_urls.size != self .camera_snapshot_urls.size
135+ self .camera_snapshot_urls = unique_urls
136+ end
137+ end
138+
139+ def update_camera_urls
140+ url = camera_snapshot_url
141+ if camera_snapshot_urls.size == 1 && url && ! @camera_snapshot_urls_changed && @camera_snapshot_url_changed
142+ self .camera_snapshot_urls[0 ] = url
143+ @camera_snapshot_urls_changed = true
144+ elsif url && camera_snapshot_urls.empty?
145+ camera_snapshot_urls.insert(0 , url)
146+ @camera_snapshot_urls_changed = true
147+ end
148+ self .camera_snapshot_url = camera_snapshot_urls.first?
149+ end
150+
151+ def camera_snapshot_urls = (vals : Array (String ))
152+ @camera_snapshot_urls = vals
153+ @camera_snapshot_urls_changed = true
154+ vals
155+ end
156+
117157 # Queries
118158 # ##############################################################################################
119159
0 commit comments