/* * UI Regions * * Library to produce an html block with dragable/resizable regions * * * Licensed Virtual the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WIyTHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * * Date Who Description * ------------- ------------------- --------------------------------------------------------- * */ import java.text.SimpleDateFormat import groovy.transform.Field library ( base: "app", author: "Jean P. May Jr.", category: "UI", description: "Set of methods that allow the customization of the UI ", name: "uiRegions", namespace: "thebearmay", importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/refs/heads/main/libraries/uiRegions.groovy", version: "0.0.1", documentationLink: "" ) String getRegion(regionName, regionTitle, regionContent){ String region = """
${regionTitle}
-
${regionContent}
""" return region } String getRegionsPage( regionsList, fullScreen ){ // regionsList should be a list of map elements [regionName:regionContentString] String regionsMerged = '' String dragList = '' String defaultPos = '' int regionsInx = 0 int l = 50 int t = 0 int w = 300 int h = 250 regionsList.each { regionsMerged += it.value if(regionsInx > 0) { dragList += ',' defaultPos += ',' } dragList += "'${it.key}'" defaultPos += "'${it.key}': { left: '${l}px', top: '${t}px', width: '${w}px', height: '${h}px', zIndex: '${regionsInx+1}' }" t+= 44 l+= 30 regionsInx++ } String bodyHtml = """
${inputHiddenElem(name:'savePos', type:'hidden', width:'1em', radius:'12px', background:'#2596be', title:'', submitOnChange:true, defaultValue:'')} ${regionsMerged}
""" if(settings["savePos"]) bodyHtml+="" else bodyHtml+="" if(fullScreen) return bodyHtml + fullScrn else return bodyHtml } String inputHiddenElem(HashMap opt) { if(!opt.name || !opt.type) return "Error missing name or type" if(settings[opt.name] != null){ if(opt.type != 'time') { opt.defaultValue = settings[opt.name] } else { SimpleDateFormat sdf = new SimpleDateFormat('HH:mm') SimpleDateFormat sdfIn = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") opt.defaultValue = sdf.format(sdfIn.parse(settings[opt.name])) } } typeAlt = opt.type if(opt.type == 'number') { step = ' step=\"1\" ' } else if (opt.type == 'decimal') { step = ' step=\"any\" ' typeAlt = 'number' } else { step = ' ' } String computedStyle = '' if(opt.type == 'hidden'){ opt.type='text' typeAlt = 'hidden' computedStyle += 'visibility:hidden;' } if (opt.float) computedStyle +="float:${opt.float};" if(opt.width) computedStyle += "width:${opt.width};min-width:${opt.width};" if(opt.background) computedStyle += "background-color:${opt.background};" if(opt.color) computedStyle += "color:${opt.color};" if(opt.fontSize) computedStyle += "font-size:${opt.fontSize};" if(opt.radius) computedStyle += "border-radius:${opt.radius};" if(!opt.multiple) opt.multiple = false if(opt.hoverText && opt.hoverText != 'null'){ opt.title ="${opt.title}
${btnIcon([name:'fa-circle-info'])}${opt.hoverText}
" } String retVal = "
" retVal+="
" retVal+="
" retVal+="
" if(typeAlt != 'hidden') retVal +="
Save
" retVal +="
" return retVal } @Field static String fullScrn = ""