Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: or-app (pages config alterations) and or-asset-viewer updates

Rich Turner18cc4ce38d7a
diff --git a/ui/app/or-app/locales/en/app.json b/ui/app/or-app/locales/en/app.json
index c99b1e82d..69099d324 100644
--- a/ui/app/or-app/locales/en/app.json
+++ b/ui/app/or-app/locales/en/app.json
@@ -1,133 +1,14 @@
{
- "scenario": "Scenario",
- "colorRGBW": "Color RGBW",
- "groupNumber": "Group number",
- "lightStatus": "Status",
- "lightDimLevel": "Dim level (%)",
- "nO2": "NO2 (µg/m3)",
- "ozon": "Ozone",
- "relHumidity": "Relative humidity (%)",
- "Temperature": "Temperature (oC)",
- "particlesPM1": "Particulates PM1 (µg/m3)",
- "particlesPM10": "Particulates PM10 (µg/m3)",
- "particlesPM2_5": "Particulates PM2.5 (µg/m3)",
- "peopleCountIn": "People in",
- "peopleCountOut": "People out",
- "peopleCountTotal": "Total people",
- "peopleCountGrowth": "Increase of people",
- "peopleCountInMinute": "People in (/min)",
- "peopleCountOutMinute": "People out (/min)",
- "city": "City",
- "street": "Street",
- "country": "Country",
- "postalCode": "Postal code",
- "microphoneLevel": "Sound level",
- "allLightsOffSwitch": "All lights status",
- "dayScene": "Scene Day",
- "nightScene": "Scene Night",
- "alarmEnabled": "Alarm status",
- "eveningScene": "Scene Evening",
- "morningScene": "Scene Morning",
- "vacationUntil": "Vacation until",
- "ventilationAuto": "Ventilation auto",
- "enableSceneTimer": "Scene timer on",
- "presenceDetected": "Presence detected",
- "ventilationLevel": "Ventilation level (%)",
- "disableSceneTimer": "Scene timer out",
- "lastExecutedScene": "Latest scene",
- "sceneTimerEnabled": "Scene timer status",
- "daySceneTimeFRIDAY": "Scene Day start time Friday",
- "daySceneTimeMONDAY": "Scene Day start time Monday",
- "daySceneTimeSUNDAY": "Scene Day start time Sunday",
- "daySceneTimeTUESDAY": "Scene Day start time Tuesday",
- "daySceneAlarmEnabled": "Scene Day alarm status",
- "daySceneTimeSATURDAY": "Scene Day start time Saturday",
- "daySceneTimeTHURSDAY": "Scene Day start time Thursday",
- "nightSceneTimeFRIDAY": "Scene Night start time Friday",
- "nightSceneTimeMONDAY": "Scene Night start time Monday",
- "nightSceneTimeSUNDAY": "Scene Night start time Sunday",
- "daySceneEnabledFRIDAY": "Scene Day status Friday",
- "daySceneEnabledMONDAY": "Scene Day status Monday",
- "daySceneEnabledSUNDAY": "Scene Day status Sunday",
- "daySceneTimeWEDNESDAY": "Scene Day start time Wednesday",
- "nightSceneTimeTUESDAY": "Scene Night start time Tuesday",
- "daySceneEnabledTUESDAY": "Scene Day status Tuesday",
- "eveningSceneTimeFRIDAY": "Scene Evening start time Friday",
- "eveningSceneTimeMONDAY": "Scene Evening start time Monday",
- "eveningSceneTimeSUNDAY": "Scene Evening start time Sunday",
- "morningSceneTimeFRIDAY": "Scene Morning start time Friday",
- "morningSceneTimeMONDAY": "Scene Morning start time Monday",
- "morningSceneTimeSUNDAY": "Scene Morning start time Sunday",
- "nightSceneAlarmEnabled": "Scene Night alarm status",
- "nightSceneTimeSATURDAY": "Scene Night start time Saturday",
- "nightSceneTimeTHURSDAY": "Scene Night start time Thursday",
- "daySceneEnabledSATURDAY": "Scene Day status Saturday",
- "daySceneEnabledTHURSDAY": "Scene Day status Thursday",
- "eveningSceneTimeTUESDAY": "Scene Evening start time Tuesday",
- "morningSceneTimeTUESDAY": "Scene Morning start time Tuesday",
- "nightSceneEnabledFRIDAY": "Scene Night status Friday",
- "nightSceneEnabledMONDAY": "Scene Night status Monday",
- "nightSceneEnabledSUNDAY": "Scene Night status Sunday",
- "nightSceneTimeWEDNESDAY": "Scene Night start time Wednesday",
- "daySceneEnabledWEDNESDAY": "Scene Day status Wednesday",
- "eveningSceneAlarmEnabled": "Scene Evening alarm status",
- "eveningSceneTimeSATURDAY": "Scene Evening start time Saturday",
- "eveningSceneTimeTHURSDAY": "Scene Evening start time Thursday",
- "morningSceneAlarmEnabled": "Scene Morning alarm status",
- "morningSceneTimeSATURDAY": "Scene Morning start time Saturday",
- "morningSceneTimeTHURSDAY": "Scene Morning start time Thursday",
- "nightSceneEnabledTUESDAY": "Scene Night status Tuesday",
- "daySceneTargetTemperature": "Scene Morning temperature",
- "eveningSceneEnabledFRIDAY": "Scene Evening status Friday",
- "eveningSceneEnabledMONDAY": "Scene Evening status Monday",
- "eveningSceneEnabledSUNDAY": "Scene Evening status Sunday",
- "eveningSceneTimeWEDNESDAY": "Scene Evening start time Wednesday",
- "morningSceneEnabledFRIDAY": "Scene Morning status Friday",
- "morningSceneEnabledMONDAY": "Scene Morning status Monday",
- "morningSceneEnabledSUNDAY": "Scene Morning status Sunday",
- "morningSceneTimeWEDNESDAY": "Scene Morning start time Wednesday",
- "nightSceneEnabledSATURDAY": "Scene Night status Saturday",
- "nightSceneEnabledTHURSDAY": "Scene Night status Thursday",
- "eveningSceneEnabledTUESDAY": "Scene Evening status Tuesday",
- "morningSceneEnabledTUESDAY": "Scene Morning status Tuesday",
- "nightSceneEnabledWEDNESDAY": "Scene Night status Wednesday",
- "eveningSceneEnabledSATURDAY": "Scene Evening status Saturday",
- "eveningSceneEnabledTHURSDAY": "Scene Evening status Thursday",
- "morningSceneEnabledSATURDAY": "Scene Morning status Saturday",
- "morningSceneEnabledTHURSDAY": "Scene Morning status Thursday",
- "nightSceneTargetTemperature": "Scene Night temperature",
- "eveningSceneEnabledWEDNESDAY": "Scene Evening status Wednesday",
- "morningSceneEnabledWEDNESDAY": "Scene Morning status Wednesday",
- "eveningSceneTargetTemperature": "Scene Evening temperature",
- "morningSceneTargetTemperature": "Scene Morning temperature",
- "lights": "Lights",
- "motionSensor": "Motion sensor",
- "lastPresenceDetected": "Last presence",
- "firstPresenceDetected": "First presence",
- "co2Level": "CO2 (µg/m3)",
- "humidity": "Humidity (%)",
- "targetTemperature": "Set temperature",
- "currentTemperature": "Current temperature",
- "lightsCeiling": "Ceiling light",
- "smartSwitchModeA": "Smart switch A",
- "smartSwitchModeB": "Smart switch B",
- "smartSwitchModeC": "Smart switch C",
- "smartSwitchEnabledA": "Smart switch A status",
- "smartSwitchEnabledB": "Smart switch B status",
- "smartSwitchEnabledC": "Smart switch C status",
- "smartSwitchBeginEndA": "Smart switch A start-stop",
- "smartSwitchBeginEndB": "Smart switch B start-stop",
- "smartSwitchBeginEndC": "Smart switch C start-stop",
- "smartSwitchStopTimeA": "Smart switch A stoptijd",
- "smartSwitchStopTimeB": "Smart switch B stoptijd",
- "smartSwitchStopTimeC": "Smart switch C stoptijd",
- "smartSwitchStartTimeA": "Smart switch A starttijd",
- "smartSwitchStartTimeB": "Smart switch B starttijd",
- "smartSwitchStartTimeC": "Smart switch C starttijd",
- "plantsWaterLevels": "Waterlevel plants",
- "lightSwitch": "Light switch",
- "windowOpen": "Window open",
- "lightSwitchTriggerTimes": "Light switch times",
- "lightsStand": "Standing light",
- "gateway": "Gateway"
+ "userFlushSeconds": "User flush (s)",
+ "smartFlushSeconds": "Smart flush (s)",
+ "idleTimeoutMinutes": "Idle timeout (mins)",
+ "maxTemperatureLimit": "Max temp limit (C)",
+ "flushPeriod": "Flush period",
+ "startHour": "Start hour",
+ "endHour": "End hour",
+ "disablePeriod": "Disable period",
+ "startQuarter": "Start quarter",
+ "endQuarter": "End quarter",
+ "config": "Config",
+ "flush": "Flush"
}
\ No newline at end of file
diff --git a/ui/app/or-app/src/pages/page-assets.ts b/ui/app/or-app/src/pages/page-assets.ts
index a1342dfa3..7a646ec10 100644
--- a/ui/app/or-app/src/pages/page-assets.ts
+++ b/ui/app/or-app/src/pages/page-assets.ts
@@ -1,14 +1,17 @@
-import {customElement, html, property, TemplateResult, css, unsafeCSS} from "lit-element";
+import {css, customElement, html, property, TemplateResult, unsafeCSS} from "lit-element";
import "@openremote/or-asset-tree";
import "@openremote/or-asset-viewer";
import {ViewerConfig} from "@openremote/or-asset-viewer";
import {OrAssetTreeSelectionChangedEvent} from "@openremote/or-asset-tree";
import {DefaultBoxShadow} from "@openremote/core";
-import moment from "moment";
import {AppStateKeyed, Page, router} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
-export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config?: ViewerConfig) {
+export interface PageAssetsConfig {
+ viewer: ViewerConfig;
+}
+
+export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config: PageAssetsConfig = PAGE_ASSETS_DEFAULT_CONFIG) {
return {
routes: [
"assets",
@@ -16,391 +19,427 @@ export function pageAssetsProvider<S extends AppStateKeyed>(store: EnhancedStore
],
pageCreator: () => {
const page = new PageAssets(store);
- if(config) page.config = config;
+ if (config) {
+ page.config = config;
+ }
return page;
}
};
}
-const viewerConfig: ViewerConfig = {
- historyConfig: {
- table: {
- attributeNames: {
- "gunshotEvent": {
- columns: [
- {
- header: "area",
- type: "prop",
- path: "$.content.area",
- styles: {
- width: "20%"
- }
- },
- {
- header: "location",
- type: "prop",
- path: "$.content.triggers[0].position.coordinates",
- styles: {
- width: "30%"
- },
- contentProvider: (datapoint, value, config) => {
- if (Array.isArray(value)) {
- return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
- }
- }
- },
- {
- header: "intensity",
- type: "prop",
- path: "$.content.triggers[0].intensity",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
- }
- },
- {
- header: "timestamp",
- type: "prop",
- path: "$.content.time",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- if (value) {
- return moment(value).format("L HH:mm:ss");
- }
- }
- }
- ]
- },
- "aggressionEvent": {
- columns: [
- {
- header: "area",
- type: "prop",
- path: "$.content.area",
- styles: {
- width: "20%"
- }
- },
- {
- header: "location",
- type: "prop",
- path: "$.content.triggers[0].position.coordinates",
- styles: {
- width: "30%"
- },
- contentProvider: (datapoint, value, config) => {
- if (Array.isArray(value)) {
- return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
- }
- }
- },
- {
- header: "intensity",
- type: "prop",
- path: "$.content.triggers[0].intensity",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
- }
- },
- {
- header: "timestamp",
- type: "prop",
- path: "$.content.time",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- if (value) {
- return moment(value).format("L HH:mm:ss");
- }
- }
- }
- ]
- },
- "alarmEvent": {
- columns: [
- {
- header: "area",
- type: "prop",
- path: "$.content.area",
- styles: {
- width: "20%"
- }
- },
- {
- header: "location",
- type: "prop",
- path: "$.content.triggers[0].position.coordinates",
- styles: {
- width: "30%"
- },
- contentProvider: (datapoint, value, config) => {
- if (Array.isArray(value)) {
- return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
- }
- }
- },
- {
- header: "intensity",
- type: "prop",
- path: "$.content.triggers[0].intensity",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
- }
- },
- {
- header: "timestamp",
- type: "prop",
- path: "$.content.time",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- if (value) {
- return moment(value).format("L HH:mm:ss");
- }
- }
- }
- ]
- },
- "intensityEvent": {
- columns: [
- {
- header: "area",
- type: "prop",
- path: "$.content.area",
- styles: {
- width: "20%"
- }
- },
- {
- header: "location",
- type: "prop",
- path: "$.content.triggers[0].position.coordinates",
- styles: {
- width: "30%"
- },
- contentProvider: (datapoint, value, config) => {
- if (Array.isArray(value)) {
- return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
- }
- }
- },
- {
- header: "intensity",
- type: "prop",
- path: "$.content.triggers[0].intensity",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
- }
- },
- {
- header: "timestamp",
- type: "prop",
- path: "$.content.time",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- if (value) {
- return moment(value).format("L HH:mm:ss");
- }
- }
- }
- ]
- },
- "breakingGlassEvent": {
- columns: [
- {
- header: "area",
- type: "prop",
- path: "$.content.area",
- styles: {
- width: "20%"
- }
- },
- {
- header: "location",
- type: "prop",
- path: "$.content.triggers[0].position.coordinates",
- styles: {
- width: "30%"
- },
- contentProvider: (datapoint, value, config) => {
- if (Array.isArray(value)) {
- return "[" + Number(value[0]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + ", " + Number(value[1]).toLocaleString(undefined, {minimumFractionDigits: 5, maximumFractionDigits: 5}) + "]"
- }
- }
- },
- {
- header: "intensity",
- type: "prop",
- path: "$.content.triggers[0].intensity",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
- }
- },
- {
- header: "timestamp",
- type: "prop",
- path: "$.content.time",
- styles: {
- width: "25%"
- },
- contentProvider: (datapoint, value, config) => {
- if (value) {
- return moment(value).format("L HH:mm:ss");
- }
- }
- }
- ]
- }
- }
- }
- },
- default: {
- panels: {
- "attributes": {
- exclude: ["location"]
- },
- "info": {
- exclude: ["accessPublicRead"]
- }
- }
- },
- assetTypes: {
- "urn:openremote:asset:topic": {
- panels: {
- "attributes": {
- exclude: ["location", "status"]
+export const PAGE_ASSETS_DEFAULT_CONFIG: PageAssetsConfig = {
+ viewer: {
+ historyConfig: {
+ table: {
+ attributeNames: {
+ // TODO: These need to move to custom project
+ // "gunshotEvent": {
+ // columns: [
+ // {
+ // header: "area",
+ // type: "prop",
+ // path: "$.content.area",
+ // styles: {
+ // width: "20%"
+ // }
+ // },
+ // {
+ // header: "location",
+ // type: "prop",
+ // path: "$.content.triggers[0].position.coordinates",
+ // styles: {
+ // width: "30%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (Array.isArray(value)) {
+ // return "[" + Number(value[0]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + ", " + Number(value[1]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + "]"
+ // }
+ // }
+ // },
+ // {
+ // header: "intensity",
+ // type: "prop",
+ // path: "$.content.triggers[0].intensity",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ // }
+ // },
+ // {
+ // header: "timestamp",
+ // type: "prop",
+ // path: "$.content.time",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (value) {
+ // return moment(value).format("L HH:mm:ss");
+ // }
+ // }
+ // }
+ // ]
+ // },
+ // "aggressionEvent": {
+ // columns: [
+ // {
+ // header: "area",
+ // type: "prop",
+ // path: "$.content.area",
+ // styles: {
+ // width: "20%"
+ // }
+ // },
+ // {
+ // header: "location",
+ // type: "prop",
+ // path: "$.content.triggers[0].position.coordinates",
+ // styles: {
+ // width: "30%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (Array.isArray(value)) {
+ // return "[" + Number(value[0]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + ", " + Number(value[1]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + "]"
+ // }
+ // }
+ // },
+ // {
+ // header: "intensity",
+ // type: "prop",
+ // path: "$.content.triggers[0].intensity",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ // }
+ // },
+ // {
+ // header: "timestamp",
+ // type: "prop",
+ // path: "$.content.time",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (value) {
+ // return moment(value).format("L HH:mm:ss");
+ // }
+ // }
+ // }
+ // ]
+ // },
+ // "alarmEvent": {
+ // columns: [
+ // {
+ // header: "area",
+ // type: "prop",
+ // path: "$.content.area",
+ // styles: {
+ // width: "20%"
+ // }
+ // },
+ // {
+ // header: "location",
+ // type: "prop",
+ // path: "$.content.triggers[0].position.coordinates",
+ // styles: {
+ // width: "30%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (Array.isArray(value)) {
+ // return "[" + Number(value[0]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + ", " + Number(value[1]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + "]"
+ // }
+ // }
+ // },
+ // {
+ // header: "intensity",
+ // type: "prop",
+ // path: "$.content.triggers[0].intensity",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ // }
+ // },
+ // {
+ // header: "timestamp",
+ // type: "prop",
+ // path: "$.content.time",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (value) {
+ // return moment(value).format("L HH:mm:ss");
+ // }
+ // }
+ // }
+ // ]
+ // },
+ // "intensityEvent": {
+ // columns: [
+ // {
+ // header: "area",
+ // type: "prop",
+ // path: "$.content.area",
+ // styles: {
+ // width: "20%"
+ // }
+ // },
+ // {
+ // header: "location",
+ // type: "prop",
+ // path: "$.content.triggers[0].position.coordinates",
+ // styles: {
+ // width: "30%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (Array.isArray(value)) {
+ // return "[" + Number(value[0]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + ", " + Number(value[1]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + "]"
+ // }
+ // }
+ // },
+ // {
+ // header: "intensity",
+ // type: "prop",
+ // path: "$.content.triggers[0].intensity",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ // }
+ // },
+ // {
+ // header: "timestamp",
+ // type: "prop",
+ // path: "$.content.time",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (value) {
+ // return moment(value).format("L HH:mm:ss");
+ // }
+ // }
+ // }
+ // ]
+ // },
+ // "breakingGlassEvent": {
+ // columns: [
+ // {
+ // header: "area",
+ // type: "prop",
+ // path: "$.content.area",
+ // styles: {
+ // width: "20%"
+ // }
+ // },
+ // {
+ // header: "location",
+ // type: "prop",
+ // path: "$.content.triggers[0].position.coordinates",
+ // styles: {
+ // width: "30%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (Array.isArray(value)) {
+ // return "[" + Number(value[0]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + ", " + Number(value[1]).toLocaleString(undefined, {
+ // minimumFractionDigits: 5,
+ // maximumFractionDigits: 5
+ // }) + "]"
+ // }
+ // }
+ // },
+ // {
+ // header: "intensity",
+ // type: "prop",
+ // path: "$.content.triggers[0].intensity",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // return Number(value).toLocaleString(undefined, {maximumFractionDigits: 0})
+ // }
+ // },
+ // {
+ // header: "timestamp",
+ // type: "prop",
+ // path: "$.content.time",
+ // styles: {
+ // width: "25%"
+ // },
+ // contentProvider: (datapoint, value, config) => {
+ // if (value) {
+ // return moment(value).format("L HH:mm:ss");
+ // }
+ // }
+ // }
+ // ]
+ // }
}
}
},
- "urn:openremote:asset:tcn:soilmoisture": {
+ default: {
panels: {
"attributes": {
- exclude: ["location", "name", "id", "code", "type"]
- }
- }
- },
- "urn:openremote:asset:tcn:meteo": {
- panels: {
- "attributes": {
- exclude: ["location", "name", "id", "code", "type"]
- }
- }
- },
- "urn:openremote:asset:tcn:point": {
- panels: {
- "attributes": {
- exclude: ["location", "name", "id", "code", "type"]
+ exclude: ["location"]
+ },
+ "info": {
+ exclude: ["accessPublicRead"]
}
}
},
- "urn:openremote:asset:residence": {
- panels: {
- "attributes": {
- exclude: [
- "dayScene",
- "daySceneEnabledFRIDAY",
- "daySceneEnabledMONDAY",
- "daySceneEnabledTUESDAY",
- "daySceneEnabledWEDNESDAY",
- "daySceneEnabledTHURSDAY",
- "daySceneEnabledSATURDAY",
- "daySceneEnabledSUNDAY",
- "daySceneTimeFRIDAY",
- "daySceneTimeMONDAY",
- "daySceneTimeTUESDAY",
- "daySceneTimeWEDNESDAY",
- "daySceneTimeTHURSDAY",
- "daySceneTimeSATURDAY",
- "daySceneTimeSUNDAY",
- "disableSceneTimer",
- "enableSceneTimer",
- "eveningScene",
- "dayScene",
- "eveningSceneEnabledFRIDAY",
- "eveningSceneEnabledMONDAY",
- "eveningSceneEnabledTUESDAY",
- "eveningSceneEnabledWEDNESDAY",
- "eveningSceneEnabledTHURSDAY",
- "eveningSceneEnabledSATURDAY",
- "eveningSceneEnabledSUNDAY",
- "eveningSceneTimeFRIDAY",
- "eveningSceneTimeMONDAY",
- "eveningSceneTimeTUESDAY",
- "eveningSceneTimeWEDNESDAY",
- "eveningSceneTimeTHURSDAY",
- "eveningSceneTimeSATURDAY",
- "eveningSceneTimeSUNDAY",
- "morningScene",
- "nightscene",
- "morningSceneEnabledFRIDAY",
- "morningSceneEnabledMONDAY",
- "morningSceneEnabledTUESDAY",
- "morningSceneEnabledWEDNESDAY",
- "morningSceneEnabledTHURSDAY",
- "morningSceneEnabledSATURDAY",
- "morningSceneEnabledSUNDAY",
- "morningSceneTimeFRIDAY",
- "morningSceneTimeMONDAY",
- "morningSceneTimeTUESDAY",
- "morningSceneTimeWEDNESDAY",
- "morningSceneTimeTHURSDAY",
- "morningSceneTimeSATURDAY",
- "morningSceneTimeSUNDAY",
- "nightSceneEnabledFRIDAY",
- "nightSceneEnabledMONDAY",
- "nightSceneEnabledTUESDAY",
- "nightSceneEnabledWEDNESDAY",
- "nightSceneEnabledTHURSDAY",
- "nightSceneEnabledSATURDAY",
- "nightSceneEnabledSUNDAY",
- "nightSceneTimeFRIDAY",
- "nightSceneTimeMONDAY",
- "nightSceneTimeTUESDAY",
- "nightSceneTimeWEDNESDAY",
- "nightSceneTimeTHURSDAY",
- "nightSceneTimeSATURDAY",
- "nightSceneTimeSUNDAY",
- "vacationUntil",
- "ventilationLevel",
- "location",
- "firstPresenceDetected",
- "lastPresenceDetected",
- "smartSwitchStartTimeA",
- "smartSwitchStartTimeB",
- "smartSwitchStartTimeC",
- "smartSwitchEnabledA",
- "smartSwitchEnabledB",
- "smartSwitchEnabledC",
- "smartSwitchStopTimeA",
- "smartSwitchStopTimeB",
- "smartSwitchStopTimeC",
- "smartSwitchBeginEndA",
- "smartSwitchBeginEndB",
- "smartSwitchBeginEndC",
- "smartSwitchModeA",
- "smartSwitchModeB",
- "smartSwitchModeC"
- ]
+ assetTypes: {
+ // TODO: These need to move to custom project
+ // "urn:openremote:asset:topic": {
+ // panels: {
+ // "attributes": {
+ // exclude: ["location", "status"]
+ // }
+ // }
+ // },
+ // "urn:openremote:asset:tcn:soilmoisture": {
+ // panels: {
+ // "attributes": {
+ // exclude: ["location", "name", "id", "code", "type"]
+ // }
+ // }
+ // },
+ // "urn:openremote:asset:tcn:meteo": {
+ // panels: {
+ // "attributes": {
+ // exclude: ["location", "name", "id", "code", "type"]
+ // }
+ // }
+ // },
+ // "urn:openremote:asset:tcn:point": {
+ // panels: {
+ // "attributes": {
+ // exclude: ["location", "name", "id", "code", "type"]
+ // }
+ // }
+ // },
+ "urn:openremote:asset:residence": {
+ panels: {
+ "attributes": {
+ exclude: [
+ "dayScene",
+ "daySceneEnabledFRIDAY",
+ "daySceneEnabledMONDAY",
+ "daySceneEnabledTUESDAY",
+ "daySceneEnabledWEDNESDAY",
+ "daySceneEnabledTHURSDAY",
+ "daySceneEnabledSATURDAY",
+ "daySceneEnabledSUNDAY",
+ "daySceneTimeFRIDAY",
+ "daySceneTimeMONDAY",
+ "daySceneTimeTUESDAY",
+ "daySceneTimeWEDNESDAY",
+ "daySceneTimeTHURSDAY",
+ "daySceneTimeSATURDAY",
+ "daySceneTimeSUNDAY",
+ "disableSceneTimer",
+ "enableSceneTimer",
+ "eveningScene",
+ "dayScene",
+ "eveningSceneEnabledFRIDAY",
+ "eveningSceneEnabledMONDAY",
+ "eveningSceneEnabledTUESDAY",
+ "eveningSceneEnabledWEDNESDAY",
+ "eveningSceneEnabledTHURSDAY",
+ "eveningSceneEnabledSATURDAY",
+ "eveningSceneEnabledSUNDAY",
+ "eveningSceneTimeFRIDAY",
+ "eveningSceneTimeMONDAY",
+ "eveningSceneTimeTUESDAY",
+ "eveningSceneTimeWEDNESDAY",
+ "eveningSceneTimeTHURSDAY",
+ "eveningSceneTimeSATURDAY",
+ "eveningSceneTimeSUNDAY",
+ "morningScene",
+ "nightscene",
+ "morningSceneEnabledFRIDAY",
+ "morningSceneEnabledMONDAY",
+ "morningSceneEnabledTUESDAY",
+ "morningSceneEnabledWEDNESDAY",
+ "morningSceneEnabledTHURSDAY",
+ "morningSceneEnabledSATURDAY",
+ "morningSceneEnabledSUNDAY",
+ "morningSceneTimeFRIDAY",
+ "morningSceneTimeMONDAY",
+ "morningSceneTimeTUESDAY",
+ "morningSceneTimeWEDNESDAY",
+ "morningSceneTimeTHURSDAY",
+ "morningSceneTimeSATURDAY",
+ "morningSceneTimeSUNDAY",
+ "nightSceneEnabledFRIDAY",
+ "nightSceneEnabledMONDAY",
+ "nightSceneEnabledTUESDAY",
+ "nightSceneEnabledWEDNESDAY",
+ "nightSceneEnabledTHURSDAY",
+ "nightSceneEnabledSATURDAY",
+ "nightSceneEnabledSUNDAY",
+ "nightSceneTimeFRIDAY",
+ "nightSceneTimeMONDAY",
+ "nightSceneTimeTUESDAY",
+ "nightSceneTimeWEDNESDAY",
+ "nightSceneTimeTHURSDAY",
+ "nightSceneTimeSATURDAY",
+ "nightSceneTimeSUNDAY",
+ "vacationUntil",
+ "ventilationLevel",
+ "location",
+ "firstPresenceDetected",
+ "lastPresenceDetected",
+ "smartSwitchStartTimeA",
+ "smartSwitchStartTimeB",
+ "smartSwitchStartTimeC",
+ "smartSwitchEnabledA",
+ "smartSwitchEnabledB",
+ "smartSwitchEnabledC",
+ "smartSwitchStopTimeA",
+ "smartSwitchStopTimeB",
+ "smartSwitchStopTimeC",
+ "smartSwitchBeginEndA",
+ "smartSwitchBeginEndB",
+ "smartSwitchBeginEndC",
+ "smartSwitchModeA",
+ "smartSwitchModeB",
+ "smartSwitchModeC"
+ ]
+ }
}
}
}
@@ -448,7 +487,7 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
}
@property()
- public config?: ViewerConfig;
+ public config?: PageAssetsConfig;
@property()
protected _assetId;
@@ -465,7 +504,7 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
const selectedIds = [this._assetId];
return html`
<or-asset-tree id="pageAssetTree" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
- <or-asset-viewer class="${!this._assetId ? "hideMobile" : ""}" .config="${this.config ? this.config : viewerConfig}" .assetId="${this._assetId}"></or-asset-viewer>
+ <or-asset-viewer class="${!this._assetId ? "hideMobile" : ""}" .config="${this.config && this.config.viewer ? this.config.viewer : PAGE_ASSETS_DEFAULT_CONFIG}" .assetId="${this._assetId}"></or-asset-viewer>
`;
}
diff --git a/ui/app/or-app/src/pages/page-rules.ts b/ui/app/or-app/src/pages/page-rules.ts
index 24e8dcf88..24a6ffeea 100644
--- a/ui/app/or-app/src/pages/page-rules.ts
+++ b/ui/app/or-app/src/pages/page-rules.ts
@@ -5,7 +5,11 @@ import {AssetType, RulesetLang, NotificationTargetType} from "@openremote/model"
import {AppStateKeyed, Page} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
-export function pageRulesProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config?:RulesConfig) {
+export interface PageRulesConfig {
+ rules: RulesConfig;
+}
+
+export function pageRulesProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config: PageRulesConfig = PAGE_RULES_CONFIG_DEFAULT) {
return {
routes: [
"rules",
@@ -13,33 +17,35 @@ export function pageRulesProvider<S extends AppStateKeyed>(store: EnhancedStore<
],
pageCreator: () => {
const page = new PageRules(store);
- if(config) page.rulesConfig = config;
- return page
+ if (config) {
+ page.config = config;
+ }
+ return page;
}
};
}
-const rulesConfig: RulesConfig = {
- controls: {
- allowedLanguages: [RulesetLang.JSON, RulesetLang.FLOW, RulesetLang.GROOVY],
- hideNotificationTargetType: {
- "email": [NotificationTargetType.TENANT, NotificationTargetType.ASSET],
- "push": [NotificationTargetType.TENANT, NotificationTargetType.CUSTOM],
- }
- },
- descriptors: {
- all: {
- excludeAssets: [
- AssetType.BUILDING.type,
- AssetType.CITY.type,
- AssetType.AREA.type,
- AssetType.FLOOR.type,
- AssetType.AGENT.type
- ]
- }
- },
- json: {
-
+export const PAGE_RULES_CONFIG_DEFAULT: PageRulesConfig = {
+ rules: {
+ controls: {
+ allowedLanguages: [RulesetLang.JSON, RulesetLang.FLOW, RulesetLang.GROOVY],
+ hideNotificationTargetType: {
+ email: [NotificationTargetType.TENANT, NotificationTargetType.ASSET],
+ push: [NotificationTargetType.TENANT, NotificationTargetType.CUSTOM],
+ }
+ },
+ descriptors: {
+ all: {
+ excludeAssets: [
+ AssetType.BUILDING.type,
+ AssetType.CITY.type,
+ AssetType.AREA.type,
+ AssetType.FLOOR.type,
+ AssetType.AGENT.type
+ ]
+ }
+ },
+ json: {}
}
};
@@ -47,7 +53,7 @@ const rulesConfig: RulesConfig = {
class PageRules<S extends AppStateKeyed> extends Page<S> {
@property()
- public rulesConfig?: RulesConfig;
+ public config?: PageRulesConfig;
static get styles() {
// language=CSS
@@ -69,7 +75,7 @@ class PageRules<S extends AppStateKeyed> extends Page<S> {
protected render() {
return html`
- <or-rules .config="${this.rulesConfig ? this.rulesConfig : rulesConfig}"></or-rules>
+ <or-rules .config="${this.config && this.config.rules ? this.config.rules : PAGE_RULES_CONFIG_DEFAULT.rules}"></or-rules>
`;
}
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 0970644d4..d4fbcdd00 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -36,6 +36,7 @@ export type PanelType = "property" | "location" | "attribute" | "history" | "cha
export interface PanelConfig {
type?: PanelType;
+ title?: string;
hide?: boolean;
hideOnMobile?: boolean;
defaults?: string[];
@@ -50,15 +51,15 @@ export interface GroupPanelConfig extends PanelConfig {
childAssetTypes?: { [assetType: string]: {
availableAttributes?: string[];
selectedAttributes?: string[];
- }}
+ }};
}
export interface AssetViewerConfig {
- panels: {[name: string]: PanelConfig};
+ panels?: {[name: string]: PanelConfig};
viewerStyles?: { [style: string]: string };
- propertyViewProvider?: (property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- attributeViewProvider?: (attribute: Attribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- panelViewProvider?: (attributes: AssetAttribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
+ propertyViewProvider?: (asset: Asset, property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
+ attributeViewProvider?: (asset: Asset, attribute: Attribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
+ panelViewProvider?: (asset: Asset, attributes: Attribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
mapType?: MapType;
historyConfig?: HistoryConfig;
chartConfig?: OrChartConfig;
@@ -67,9 +68,6 @@ export interface AssetViewerConfig {
export interface ViewerConfig {
default?: AssetViewerConfig;
assetTypes?: { [assetType: string]: AssetViewerConfig };
- propertyViewProvider?: (property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- attributeViewProvider?: (attribute: Attribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
- panelViewProvider?: (attributes: AssetAttribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;
mapType?: MapType;
historyConfig?: HistoryConfig;
}
@@ -97,13 +95,423 @@ class EventHandler {
}
const onRenderComplete = new EventHandler();
+function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResult | undefined) {
+
+ if (!content) {
+ return;
+ }
+
+ return html`
+ <div class=${classMap({panel: true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
+ <div class="panel-content-wrapper">
+ <div class="panel-title">
+ <or-translate value="${panelConfig.title ? panelConfig.title : name}"></or-translate>
+ </div>
+ <div class="panel-content">
+ ${content}
+ </div>
+ </div>
+ </div>
+ `;
+}
+
+export function getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null): TemplateResult | undefined {
+ if (panelConfig.hide || attributes.length === 0) {
+ return;
+ }
+
+ if (viewerConfig.panelViewProvider) {
+ const template = viewerConfig.panelViewProvider(asset, attributes, panelName, viewerConfig, panelConfig);
+ if (template) {
+ return template;
+ }
+ }
+
+ const styles = panelConfig ? panelConfig.fieldStyles : undefined;
+ const defaultAttributes = panelConfig && panelConfig.defaults ? panelConfig.defaults : undefined;
+ const includedAttributes = panelConfig && panelConfig.include ? panelConfig.include : undefined;
+ const excludedAttributes = panelConfig && panelConfig.exclude ? panelConfig.exclude : [];
+ const attrs = attributes.filter((attr) =>
+ (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));
+
+ let content: TemplateResult | undefined;
+
+ // if (panelConfig && panelConfig.type === "property") {
+ // // Special handling for info panel which only shows properties
+ // let properties = OrAssetViewer.getInfoProperties(panelConfig);
+
+ // if (properties.length === 0) {
+ // return;
+ // }
+
+ // content = html`
+ // ${properties.map((prop) => {
+ // let style = styles ? styles[prop!] : undefined;
+ // return prop === "attributes" ? `` : OrAssetViewer.getField(prop, true, style, OrAssetViewer.getPropertyTemplate(prop, (asset as { [index: string]: any })[prop], viewerConfig, panelConfig, shadowRoot));
+ // })}
+ // `;
+ // } else
+ if (panelConfig && panelConfig.type === "history") {
+ // Special handling for history panel which shows an attribute selector and a graph/data table of historical values
+ const historyAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));
+ if (historyAttrs.length > 0) {
+
+ const attributeChanged = (attributeName: string) => {
+ if (shadowRoot) {
+ const attributeHistory = shadowRoot.getElementById("attribute-history") as OrAttributeHistory;
+
+ if (attributeHistory) {
+
+ let attribute: AssetAttribute | undefined;
+
+ if (attributeName) {
+ attribute = Util.getAssetAttribute(asset, attributeName);
+ }
+
+ attributeHistory.attribute = attribute;
+ }
+ }
+ };
+
+
+ const options = historyAttrs.map((attr) => {
+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);
+ let label = Util.getAttributeLabel(attr, attributeDescriptor);
+ let unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);
+ if(unit) {
+ label = label + " ("+i18next.t(unit)+")";
+ }
+ return [attr.name, label]
+ });
+ const attrName: string = historyAttrs[0].name!;
+ onRenderComplete.addCallback(() => attributeChanged(attrName));
+ content = html`
+ <style>
+ or-attribute-history{
+ min-height: 70px;
+ width: 100%;
+ }
+ #history-controls {
+ flex: 0;
+ margin-bottom: 10px;
+ position: absolute;
+ }
+
+ #history-attribute-picker {
+ flex: 0;
+ width: 200px;
+ }
+
+ or-attribute-history {
+ --or-attribute-history-controls-margin: 0 0 20px 204px;
+ }
+
+ @media screen and (max-width: 2028px) {
+ #history-controls {
+ position: unset;
+ margin: 0 0 10px 0;
+ }
+
+ or-attribute-history {
+ --or-attribute-history-controls-margin: 10px 0 0 0;
+ --or-attribute-history-controls-margin-children: 0 20px 20px 0;
+ }
+ }
+ </style>
+ <div id="history-controls">
+ <or-input id="history-attribute-picker" .checkAssetWrite="${false}" value="${historyAttrs[0].name}" .label="${i18next.t("attribute")}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${options}"></or-input>
+ </div>
+ <or-attribute-history id="attribute-history" .config="${viewerConfig.historyConfig}" .assetType="${asset.type}"></or-attribute-history>
+
+ `;
+ }
+
+ }
+ // DEPRECATED
+ // else if (panelConfig && panelConfig.type === "chart") {
+
+ // let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))
+
+ // let assetAttributes;
+ // // let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));
+ // // if(defaultAttrs.length > 0){
+ // // assetAttributes = defaultAttrs;
+ // // } else
+ // if(storeDataPointAttrs.length > 0) {
+ // assetAttributes = storeDataPointAttrs;
+ // assetAttributes.length = 1;
+ // }
+ // const assetList:Asset[] = [];
+ // if(assetAttributes) {
+ // assetAttributes.forEach(attr => assetList.push(asset));
+ // }
+ // content = html`
+ // <or-chart id="chart" panelName="${panelName}" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>
+ // `;
+
+ // }
+ else if (panelConfig && panelConfig.type === "location") {
+
+ const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);
+ if (attribute) {
+ // Special handling for location panel which shows an attribute selector and a map showing the location of the attribute
+ const mapType = viewerConfig.mapType || OrAssetViewer.DEFAULT_MAP_TYPE;
+ const lngLat = MapUtil.getLngLat(attribute);
+ const center = lngLat ? lngLat.toArray() : undefined;
+ const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);
+ const attributeMetaChanged = async (value: string) => {
+ if (shadowRoot) {
+
+ if (attribute) {
+
+ if(asset.id && asset.attributes && asset.attributes.location){
+
+ const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);
+ if(showOnMapMeta) {
+ showOnMapMeta.value = value;
+ } else {
+ const meta:MetaItem = {
+ name: MetaItemType.SHOW_ON_DASHBOARD.urn,
+ value: value
+ }
+
+ if(attribute.meta){
+ attribute.meta.push(meta);
+ }
+ }
+ asset.attributes.location = {...attribute};
+ const response = await manager.rest.api.AssetResource.update(asset.id, asset);
+
+ if (response.status !== 200) {
+ }
+ }
+
+
+ }
+ }
+ };
+
+ content = html`
+ <style>
+ or-map {
+ border: #e5e5e5 1px solid;
+ }
+
+ #location-map-input {
+ padding: 20px 0 0 0;
+ }
+ </style>
+ <or-map id="location-map" class="or-map" .center="${center}" type="${mapType}">
+ <or-map-marker-asset active .asset="${asset}"></or-map-marker-asset>
+ </or-map>
+ ${attribute.name === AttributeType.LOCATION.attributeName ? html`
+ <or-input id="location-map-input" type="${InputType.SWITCH}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeMetaChanged(evt.detail.value)}" dense .value="${showOnMapMeta ? showOnMapMeta.value : undefined}" label="${i18next.t("showOnMap")}"></or-input>
+ ` : ``}
+ `;
+ }
+ } else if (panelConfig && panelConfig.type === "group") {
+
+ if (asset.type !== "urn:openremote:asset:group") {
+ return;
+ }
+
+ // Get child asset type attribute value
+ const childAssetTypeAttribute = Util.getAssetAttribute(asset, "childAssetType");
+ const groupConfig = panelConfig as GroupPanelConfig;
+
+ if (!childAssetTypeAttribute || typeof childAssetTypeAttribute.value !== "string") {
+ return;
+ }
+ let childAssetType = childAssetTypeAttribute.value as string;
+ let childAssets: Asset[] = [];
+
+ // Determine available and selected attributes for the child asset type
+ let availableAttributes: string[] = [];
+ let selectedAttributes: string[] = [];
+ let newlySelectedAttributes: string[] = []; // Updated when the dialog is open
+
+ if (groupConfig.childAssetTypes && groupConfig.childAssetTypes[childAssetType]) {
+ availableAttributes = groupConfig.childAssetTypes[childAssetType].availableAttributes ? groupConfig.childAssetTypes[childAssetType].availableAttributes! : [];
+ selectedAttributes = groupConfig.childAssetTypes[childAssetType].selectedAttributes ? groupConfig.childAssetTypes[childAssetType].selectedAttributes! : [];
+ }
+
+ // Get available and selected attributes from asset descriptor if not defined in config
+ if (availableAttributes.length === 0) {
+ const descriptor = AssetModelUtil.getAssetDescriptor(childAssetType);
+ if (descriptor && descriptor.attributeDescriptors) {
+ availableAttributes = descriptor.attributeDescriptors.map((descriptor) => descriptor.attributeName!);
+ }
+ }
+ if ((!selectedAttributes || selectedAttributes.length === 0) && availableAttributes) {
+ selectedAttributes = [...availableAttributes];
+ }
+
+ const attributePickerModalActions: DialogAction[] = [
+ {
+ actionName: "ok",
+ default: true,
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("ok")}"></or-input>`,
+ action: () => {
+ selectedAttributes.length = 0;
+ selectedAttributes.push(...newlySelectedAttributes);
+ updateTable();
+ }
+ },
+ {
+ actionName: "cancel",
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,
+ action: () => {
+ // Nothing to do here
+ }
+ },
+ ];
+
+ const attributePickerModalOpen = () => {
+ const dialog: OrMwcDialog = shadowRoot!.getElementById(panelName + "-attribute-modal") as OrMwcDialog;
+
+ if (dialog) {
+ newlySelectedAttributes.length = 0;
+ newlySelectedAttributes.push(...selectedAttributes);
+ // Update content which will cause a re-render
+ dialog.dialogContent = html`
+ <div style="display:grid">
+ ${availableAttributes.sort().map((attribute) =>
+ html`<div style="grid-column: 1 / -1;">
+ <or-input .type="${InputType.CHECKBOX}" .label="${i18next.t(attribute)}" .value="${!!newlySelectedAttributes.find((selected) => selected === attribute)}"
+ @or-input-changed="${(evt: OrInputChangedEvent) => evt.detail.value ? newlySelectedAttributes.push(attribute) : newlySelectedAttributes.splice(newlySelectedAttributes.findIndex((s) => s == attribute), 1)}"></or-input>
+ </div>`)}
+ </div>
+ `;
+ dialog.open();
+ }
+ };
+
+ // let headers = ["a", "b", "c"];
+ // let rows = [["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"],
+ // ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"]];
+ // let columnFilter = viewerConfig.groupConfig!.columnFilters || ["a"];
+
+ // Function to update the table and message when assets or config changes
+ let updateTable = () => {
+
+ const loadingMsg: OrTranslate = shadowRoot!.getElementById(panelName + "-attribute-table-msg") as OrTranslate;
+ const attributeTable: OrTable = shadowRoot!.getElementById(panelName + "-attribute-table") as OrTable;
+
+ if (!loadingMsg || !attributeTable) {
+ return;
+ }
+
+ if (selectedAttributes.length === 0 || !childAssets || childAssets.length === 0) {
+ loadingMsg.value = "noData";
+ loadingMsg.hidden = false;
+ attributeTable.hidden = true;
+ return;
+ }
+
+ // Update table properties which will cause a re-render
+ loadingMsg.hidden = true;
+ attributeTable.hidden = false;
+ const headers = [...selectedAttributes].sort();
+ attributeTable.headers = headers.map((header) => i18next.t(header));
+ attributeTable.headers.unshift(i18next.t("groupAssetName"));
+ attributeTable.rows = childAssets.map((asset) => {
+ // todo: it's only processing including selected headers here...
+ // move this to the columnFilter option of the table
+ const arr = headers.map((attributeName) => {
+ return asset.attributes![attributeName] ? asset.attributes![attributeName].value! as string : "";
+ });
+ arr.unshift(asset.name!);
+ return arr;
+ });
+ };
+
+ // Load child assets async then update the table
+ getAssetChildren(asset.id!, asset.attributes!.childAssetType.value).then((assetChildren) => {
+ childAssets = assetChildren;
+ updateTable();
+ });
+
+ // Define the DOM content for this panel
+ content = html`
+ <style>
+ #asset-group-add-remove-columns {
+ position: absolute;
+ top: 20px;
+ right: var(--internal-or-asset-viewer-panel-padding);
+ }
+ </style>
+ <or-icon id="asset-group-add-remove-columns" icon="plus-minus" @click="${() => attributePickerModalOpen()}"></or-icon>
+ <or-table hidden .id="${panelName}-attribute-table" .options="{stickyFirstColumn:true}"></or-table>
+ <span><or-translate id="${panelName}-attribute-table-msg" value="loading"></or-translate></span>
+ <or-mwc-dialog id="${panelName}-attribute-modal" dialogTitle="addRemoveAttributes" .dialogActions="${attributePickerModalActions}"></or-mwc-dialog>
+ `;
+ } else {
+ if(attrs.length === 0) {
+ return undefined;
+ }
+
+ content = html`
+ ${attrs.sort((attr1, attr2) => attr1.name! < attr2.name! ? -1 : attr1.name! > attr2.name! ? 1 : 0).map((attr) => {
+ let style = styles ? styles[attr.name!] : undefined;
+ return getField(attr.name!, false, style, getAttributeTemplate(asset, attr, viewerConfig, panelConfig));
+ })}
+ `;
+ }
+
+ return content;
+}
+
+export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {
+ if (viewerConfig.attributeViewProvider) {
+ const result = viewerConfig.attributeViewProvider(asset, attribute, viewerConfig, panelConfig);
+ if (result) {
+ return result;
+ }
+ }
+ return html`
+ <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>
+ `;
+}
+
+export function getField(name: string, isProperty: boolean, styles: { [style: string]: string } | undefined, content: TemplateResult | undefined): TemplateResult {
+ if (!content) {
+ return html``;
+ }
+ return html`
+ <div id="field-${name}" style="${styles ? styleMap(styles) : ""}" class="field ${isProperty ? "field-property" : "field-attribute"}">
+ ${content}
+ </div>
+ `;
+}
+
+async function getAssetChildren(id: string, childAssetType: string): Promise<Asset[]> {
+ const response = await manager.rest.api.AssetResource.queryAssets({
+ select: {
+ excludePath: true,
+ excludeParentInfo: true
+ },
+ parents: [
+ {
+ id: id
+ }
+ ]
+ });
+
+ if (response.status !== 200 || !response.data) {
+ return [];
+ }
+
+ return response.data.filter((asset) => asset.type === childAssetType);
+}
+
@customElement("or-asset-viewer")
export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElement)) {
public static DEFAULT_MAP_TYPE = MapType.VECTOR;
public static DEFAULT_PANEL_TYPE: PanelType = "attribute";
- public static DEFAULT_CONFIG: AssetViewerConfig = {
+ public static DEFAULT_VIEWER_CONFIG: AssetViewerConfig = {
viewerStyles: {
},
@@ -248,10 +656,10 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
<div id="created" class="mobileHidden"><or-translate value="createdOnWithDate" .options="${{ date: new Date(this.asset!.createdOn!) } as i18next.TOptions<i18next.InitOptions>}"></or-translate></div>
</div>
<div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
- ${html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
- const panelTemplate = OrAssetViewer.getPanel(name, this.asset!, this._attributes!, this._viewerConfig!, panelConfig, this.shadowRoot);
+ ${this._viewerConfig.panels ? html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
+ const panelTemplate = getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this._viewerConfig!, panelConfig, this.shadowRoot));
return panelTemplate || ``;
- })}`}
+ })}` : ``}
</div>
</div>
`;
@@ -312,375 +720,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
return properties;
}
- public static getPanel(name: string, asset: Asset, attributes: AssetAttribute[], viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null) {
-
- const content = OrAssetViewer.getPanelContent(name, asset, attributes, viewerConfig, panelConfig, shadowRoot);
- if (!content) {
- return;
- }
-
- return html`
- <div class=${classMap({"panel": true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
- <div class="panel-content-wrapper">
- <div class="panel-title">
- <or-translate value="${name}"></or-translate>
- </div>
- <div class="panel-content">
- ${content}
- </div>
- </div>
- </div>
- `;
- }
-
- public static getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null): TemplateResult | undefined {
- if (panelConfig.hide || attributes.length === 0) {
- return;
- }
-
- if (viewerConfig.panelViewProvider) {
- const template = viewerConfig.panelViewProvider(attributes, panelName, viewerConfig, panelConfig);
- if (template) {
- return template;
- }
- }
-
- let styles = panelConfig ? panelConfig.fieldStyles : undefined;
- const defaultAttributes = panelConfig && panelConfig.defaults ? panelConfig.defaults : undefined;
- const includedAttributes = panelConfig && panelConfig.include ? panelConfig.include : undefined;
- const excludedAttributes = panelConfig && panelConfig.exclude ? panelConfig.exclude : [];
- const attrs = attributes.filter((attr) =>
- (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
- && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));
-
- let content: TemplateResult | undefined;
-
-
- // if (panelConfig && panelConfig.type === "property") {
- // // Special handling for info panel which only shows properties
- // let properties = OrAssetViewer.getInfoProperties(panelConfig);
-
- // if (properties.length === 0) {
- // return;
- // }
-
- // content = html`
- // ${properties.map((prop) => {
- // let style = styles ? styles[prop!] : undefined;
- // return prop === "attributes" ? `` : OrAssetViewer.getField(prop, true, style, OrAssetViewer.getPropertyTemplate(prop, (asset as { [index: string]: any })[prop], viewerConfig, panelConfig, shadowRoot));
- // })}
- // `;
- // } else
- if (panelConfig && panelConfig.type === "history") {
- // Special handling for history panel which shows an attribute selector and a graph/data table of historical values
- const historyAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));
- if (historyAttrs.length > 0) {
-
- const attributeChanged = (attributeName: string) => {
- if (shadowRoot) {
- const attributeHistory = shadowRoot.getElementById("attribute-history") as OrAttributeHistory;
-
- if (attributeHistory) {
-
- let attribute: AssetAttribute | undefined;
-
- if (attributeName) {
- attribute = Util.getAssetAttribute(asset, attributeName);
- }
-
- attributeHistory.attribute = attribute;
- }
- }
- };
-
-
- const options = historyAttrs.map((attr) => {
- const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);
- let label = Util.getAttributeLabel(attr, attributeDescriptor);
- let unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);
- if(unit) {
- label = label + " ("+i18next.t(unit)+")";
- }
- return [attr.name, label]
- });
- const attrName: string = historyAttrs[0].name!;
- onRenderComplete.addCallback(() => attributeChanged(attrName));
- content = html`
- <style>
- or-attribute-history{
- min-height: 70px;
- width: 100%;
- }
- #history-controls {
- flex: 0;
- margin-bottom: 10px;
- position: absolute;
- }
-
- #history-attribute-picker {
- flex: 0;
- width: 200px;
- }
-
- or-attribute-history {
- --or-attribute-history-controls-margin: 0 0 20px 204px;
- }
-
- @media screen and (max-width: 2028px) {
- #history-controls {
- position: unset;
- margin: 0 0 10px 0;
- }
-
- or-attribute-history {
- --or-attribute-history-controls-margin: 10px 0 0 0;
- --or-attribute-history-controls-margin-children: 0 20px 20px 0;
- }
- }
- </style>
- <div id="history-controls">
- <or-input id="history-attribute-picker" .checkAssetWrite="${false}" value="${historyAttrs[0].name}" .label="${i18next.t("attribute")}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${options}"></or-input>
- </div>
- <or-attribute-history id="attribute-history" .config="${viewerConfig.historyConfig}" .assetType="${asset.type}"></or-attribute-history>
-
- `;
- }
-
- }
- // DEPRECATED
- // else if (panelConfig && panelConfig.type === "chart") {
-
- // let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))
-
- // let assetAttributes;
- // // let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));
- // // if(defaultAttrs.length > 0){
- // // assetAttributes = defaultAttrs;
- // // } else
- // if(storeDataPointAttrs.length > 0) {
- // assetAttributes = storeDataPointAttrs;
- // assetAttributes.length = 1;
- // }
- // const assetList:Asset[] = [];
- // if(assetAttributes) {
- // assetAttributes.forEach(attr => assetList.push(asset));
- // }
- // content = html`
- // <or-chart id="chart" panelName="${panelName}" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>
- // `;
-
- // }
- else if (panelConfig && panelConfig.type === "location") {
-
- const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);
- if (attribute) {
- // Special handling for location panel which shows an attribute selector and a map showing the location of the attribute
- const mapType = viewerConfig.mapType || OrAssetViewer.DEFAULT_MAP_TYPE;
- const lngLat = MapUtil.getLngLat(attribute);
- const center = lngLat ? lngLat.toArray() : undefined;
- const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);
- const attributeMetaChanged = async (value: string) => {
- if (shadowRoot) {
-
- if (attribute) {
-
- if(asset.id && asset.attributes && asset.attributes.location){
-
- const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);
- if(showOnMapMeta) {
- showOnMapMeta.value = value;
- } else {
- const meta:MetaItem = {
- name: MetaItemType.SHOW_ON_DASHBOARD.urn,
- value: value
- }
-
- if(attribute.meta){
- attribute.meta.push(meta);
- }
- }
- asset.attributes.location = {...attribute};
- const response = await manager.rest.api.AssetResource.update(asset.id, asset);
-
- if (response.status !== 200) {
- }
- }
-
-
- }
- }
- };
-
- content = html`
- <style>
- or-map {
- border: #e5e5e5 1px solid;
- }
-
- #location-map-input {
- padding: 20px 0 0 0;
- }
- </style>
- <or-map id="location-map" class="or-map" .center="${center}" type="${mapType}">
- <or-map-marker-asset active .asset="${asset}"></or-map-marker-asset>
- </or-map>
- ${attribute.name === AttributeType.LOCATION.attributeName ? html`
- <or-input id="location-map-input" type="${InputType.SWITCH}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeMetaChanged(evt.detail.value)}" dense .value="${showOnMapMeta ? showOnMapMeta.value : undefined}" label="${i18next.t("showOnMap")}"></or-input>
- ` : ``}
- `;
- }
- } else if (panelConfig && panelConfig.type === "group") {
-
- if (asset.type !== "urn:openremote:asset:group") {
- return;
- }
-
- // Get child asset type attribute value
- const childAssetTypeAttribute = Util.getAssetAttribute(asset, "childAssetType");
- const groupConfig = panelConfig as GroupPanelConfig;
-
- if (!childAssetTypeAttribute || typeof childAssetTypeAttribute.value !== "string") {
- return;
- }
- let childAssetType = childAssetTypeAttribute.value as string;
- let childAssets: Asset[] = [];
-
- // Determine available and selected attributes for the child asset type
- let availableAttributes: string[] = [];
- let selectedAttributes: string[] = [];
- let newlySelectedAttributes: string[] = []; // Updated when the dialog is open
-
- if (groupConfig.childAssetTypes && groupConfig.childAssetTypes[childAssetType]) {
- availableAttributes = groupConfig.childAssetTypes[childAssetType].availableAttributes ? groupConfig.childAssetTypes[childAssetType].availableAttributes! : [];
- selectedAttributes = groupConfig.childAssetTypes[childAssetType].selectedAttributes ? groupConfig.childAssetTypes[childAssetType].selectedAttributes! : [];
- }
-
- // Get available and selected attributes from asset descriptor if not defined in config
- if (availableAttributes.length === 0) {
- const descriptor = AssetModelUtil.getAssetDescriptor(childAssetType);
- if (descriptor && descriptor.attributeDescriptors) {
- availableAttributes = descriptor.attributeDescriptors.map((descriptor) => descriptor.attributeName!);
- }
- }
- if ((!selectedAttributes || selectedAttributes.length === 0) && availableAttributes) {
- selectedAttributes = [...availableAttributes];
- }
-
- const attributePickerModalActions: DialogAction[] = [
- {
- actionName: "ok",
- default: true,
- content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("ok")}"></or-input>`,
- action: () => {
- selectedAttributes.length = 0;
- selectedAttributes.push(...newlySelectedAttributes);
- updateTable();
- }
- },
- {
- actionName: "cancel",
- content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,
- action: () => {
- // Nothing to do here
- }
- },
- ];
-
- const attributePickerModalOpen = () => {
- const dialog: OrMwcDialog = shadowRoot!.getElementById(panelName + "-attribute-modal") as OrMwcDialog;
-
- if (dialog) {
- newlySelectedAttributes.length = 0;
- newlySelectedAttributes.push(...selectedAttributes);
- // Update content which will cause a re-render
- dialog.dialogContent = html`
- <div style="display:grid">
- ${availableAttributes.sort().map((attribute) =>
- html`<div style="grid-column: 1 / -1;">
- <or-input .type="${InputType.CHECKBOX}" .label="${i18next.t(attribute)}" .value="${!!newlySelectedAttributes.find((selected) => selected === attribute)}"
- @or-input-changed="${(evt: OrInputChangedEvent) => evt.detail.value ? newlySelectedAttributes.push(attribute) : newlySelectedAttributes.splice(newlySelectedAttributes.findIndex((s) => s == attribute), 1)}"></or-input>
- </div>`)}
- </div>
- `;
- dialog.open();
- }
- };
-
- // let headers = ["a", "b", "c"];
- // let rows = [["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"],
- // ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"]];
- // let columnFilter = viewerConfig.groupConfig!.columnFilters || ["a"];
-
- // Function to update the table and message when assets or config changes
- let updateTable = () => {
-
- const loadingMsg: OrTranslate = shadowRoot!.getElementById(panelName + "-attribute-table-msg") as OrTranslate;
- const attributeTable: OrTable = shadowRoot!.getElementById(panelName + "-attribute-table") as OrTable;
-
- if (!loadingMsg || !attributeTable) {
- return;
- }
-
- if (selectedAttributes.length === 0 || !childAssets || childAssets.length === 0) {
- loadingMsg.value = "noData";
- loadingMsg.hidden = false;
- attributeTable.hidden = true;
- return;
- }
-
- // Update table properties which will cause a re-render
- loadingMsg.hidden = true;
- attributeTable.hidden = false;
- const headers = [...selectedAttributes].sort();
- attributeTable.headers = headers.map((header) => i18next.t(header));
- attributeTable.headers.unshift(i18next.t("groupAssetName"));
- attributeTable.rows = childAssets.map((asset) => {
- // todo: it's only processing including selected headers here...
- // move this to the columnFilter option of the table
- const arr = headers.map((attributeName) => {
- return asset.attributes![attributeName] ? asset.attributes![attributeName].value! as string : "";
- });
- arr.unshift(asset.name!);
- return arr;
- });
- };
-
- // Load child assets async then update the table
- this.getAssetChildren(asset.id!, asset.attributes!.childAssetType.value).then((assetChildren) => {
- childAssets = assetChildren;
- updateTable();
- });
-
- // Define the DOM content for this panel
- content = html`
- <style>
- #asset-group-add-remove-columns {
- position: absolute;
- top: 20px;
- right: var(--internal-or-asset-viewer-panel-padding);
- }
- </style>
- <or-icon id="asset-group-add-remove-columns" icon="plus-minus" @click="${() => attributePickerModalOpen()}"></or-icon>
- <or-table hidden .id="${panelName}-attribute-table" .options="{stickyFirstColumn:true}"></or-table>
- <span><or-translate id="${panelName}-attribute-table-msg" value="loading"></or-translate></span>
- <or-mwc-dialog id="${panelName}-attribute-modal" dialogTitle="addRemoveAttributes" .dialogActions="${attributePickerModalActions}"></or-mwc-dialog>
- `;
- } else {
- if(attrs.length === 0) {
- return undefined;
- }
-
- content = html`
- ${attrs.sort((attr1, attr2) => attr1.name! < attr2.name! ? -1 : attr1.name! > attr2.name! ? 1 : 0).map((attr) => {
- let style = styles ? styles[attr.name!] : undefined;
- return this.getField(attr.name!, false, style, OrAssetViewer.getAttributeTemplate(asset, attr, viewerConfig, panelConfig));
- })}
- `;
- }
-
- return content;
- }
-
// public static getPropertyTemplate(property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null) {
// let type = InputType.TEXT;
// let minLength: number | undefined;
@@ -727,28 +766,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
// return html`<or-input id="property-${property}" type="${type}" .minLength="${minLength}" .maxLength="${maxLength}" dense .value="${value}" readonly label="${i18next.t(property)}"></or-input>`;
// }
- public static getAttributeTemplate(asset: Asset, attribute: AssetAttribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {
- if (viewerConfig.attributeViewProvider) {
- const result = viewerConfig.attributeViewProvider(attribute, viewerConfig, panelConfig);
- if (result) {
- return result;
- }
- }
- return html`
- <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>
- `;
- }
-
- public static getField(name: string, isProperty: boolean, styles: { [style: string]: string } | undefined, content: TemplateResult | undefined) {
- if (!content) {
- return ``;
- }
- return html`
- <div id="field-${name}" style="${styles ? styleMap(styles) : ""}" class="field ${isProperty ? "field-property" : "field-attribute"}">
- ${content}
- </div>
- `;
- }
// TODO: Add debounce in here to minimise render calls
onAttributeEvent(event: AttributeEvent) {
@@ -768,7 +785,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
protected _getPanelConfig(asset: Asset): AssetViewerConfig {
- let config = {...OrAssetViewer.DEFAULT_CONFIG};
+ const config = {...OrAssetViewer.DEFAULT_VIEWER_CONFIG};
if (this.config) {
@@ -784,45 +801,25 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
if (assetConfig.panels) {
Object.entries(assetConfig.panels).forEach(([name, assetPanelConfig]) => {
- if (config.panels.hasOwnProperty(name)) {
- const panelStyles = {...config.panels[name].panelStyles};
- const fieldStyles = {...config.panels[name].fieldStyles};
- config.panels[name] = Object.assign(config.panels[name], {...assetPanelConfig});
- config.panels[name].panelStyles = Object.assign(panelStyles, assetPanelConfig.panelStyles);
- config.panels[name].fieldStyles = Object.assign(fieldStyles, assetPanelConfig.fieldStyles);
+ if (config.panels!.hasOwnProperty(name)) {
+ const panelStyles = {...config.panels![name].panelStyles};
+ const fieldStyles = {...config.panels![name].fieldStyles};
+ config.panels![name] = Object.assign(config.panels![name], {...assetPanelConfig});
+ config.panels![name].panelStyles = Object.assign(panelStyles, assetPanelConfig.panelStyles);
+ config.panels![name].fieldStyles = Object.assign(fieldStyles, assetPanelConfig.fieldStyles);
} else {
- config.panels[name] = {...assetPanelConfig};
+ config.panels![name] = {...assetPanelConfig};
}
});
}
- config.attributeViewProvider = assetConfig.attributeViewProvider || this.config.attributeViewProvider;
- config.panelViewProvider = assetConfig.panelViewProvider || this.config.panelViewProvider;
- config.propertyViewProvider = assetConfig.propertyViewProvider || this.config.propertyViewProvider;
+ config.attributeViewProvider = assetConfig.attributeViewProvider || (this.config.default ? this.config.default.attributeViewProvider : undefined);
+ config.panelViewProvider = assetConfig.panelViewProvider || (this.config.default ? this.config.default.panelViewProvider : undefined);
+ config.propertyViewProvider = assetConfig.propertyViewProvider || (this.config.default ? this.config.default.propertyViewProvider : undefined);
config.mapType = assetConfig.mapType || this.config.mapType;
config.historyConfig = assetConfig.historyConfig || this.config.historyConfig;
}
}
return config;
}
-
- public static async getAssetChildren(id: string, childAssetType: string): Promise<Asset[]> {
- const response = await manager.rest.api.AssetResource.queryAssets({
- select: {
- excludePath: true,
- excludeParentInfo: true
- },
- parents: [
- {
- id: id
- }
- ]
- });
-
- if (response.status !== 200 || !response.data) {
- return [];
- }
-
- return response.data.filter((asset) => asset.type === childAssetType);
- }
}