ContextHub提供了几个可在解决方案中使用的示例UI模块。 提供了以下信息:
有关将UI模块添加到ContextHub的信息,请参阅 添加UI模块. 有关开发UI模块的信息,请参阅 创建ContextHub UI模块类型.
contexthub.base UI模块类型是所有其他UI模块类型的基类型。 因此,它提供了用于呈现存储数据的通用功能。
可以使用以下功能:
源代码位于 /libs/granite/contexthub/code/ui/container/js/ContextHub.UI.BaseModuleRenderer.js
.
使用JSON格式的JavaScript对象配置contexthub.base UI模块。 包括以下任意属性以配置UI模块功能:
true
支持全屏和 false
以防止使用全屏模式。<p>
标记之间。listType
属性以配置其他外观(见下文)。list
个项目。以下示例配置contexthub.base
用于从显示信息的UI模块 contexthub.emulators 商店。 此 template
项目演示了如何使用键 storeMapping
项目已建立。
{
"icon": "coral-Icon--move",
"title": "Screen Resolution",
"storeMapping": {
"emulator": "emulators"
},
"template": "<p>{{{ i18n \"Resolution\"}}}</p><p>{{{emulator.currentDevice.width}}} x {{{emulator.currentDevice.height}}}</p>"
}
此 contexthub.browserinfo
UI模块显示有关客户端Web浏览器和操作系统的信息。 信息是从surferinfo商店获得的,根据 contexthub.surferinfo 商店候选者。
UI模块的源代码位于 /libs/granite/contexthub/components/modules/browserinfo
. 虽然 contexthub.browserinfo
扩展 contexthub.base
UI模块,它不会覆盖或提供其他功能。 该实施提供了用于呈现浏览器信息的默认配置。
contexthub.browserinfo UI模块的实例不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。
{
"icon":"coral-Icon--globe",
"title":"Browser/OS Information",
"storeMapping":{"surferinfo":"surferinfo"},
"template":"<p>{{surferinfo.browser.family}} {{surferinfo.browser.version}}</p><p>{{surferinfo.os.name}} {{surferinfo.os.version}}</p>"
}
此 contexthub.datetime
UI模块显示存储在名为datetime的存储区中的日期和时间,该存储区基于 contexthub.datetime
商店候选者。
模块提供了一个弹出窗体,通过该窗体可以更改存储中的日期和时间。
源 contexthub.datetime
用户界面模块位于 /libs/granite/contexthub/components/modules/datetime
.
Contexthub.datetime UI模块的实例不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。
{
"icon":"coral-Icon--clock",
"title":"DATE&TIME",
"clickable":true,
"storeMapping":{"d":"datetime"},
"template":"<p class=\"contexthub-module-line1\">{{i18n \"Date&Time\"}}</p><p class=\"contexthub-module-line2\">{{d.formatted.locale.date}} {{d.formatted.locale.time}}</p>",
"popoverTemplate":"<div class=\"datetime center\"><div class=\"coral-DatePicker-calendar\" data-init=\"datepicker\"><input class=\"coral-Textfield\" type=\"datetime\" value=\"{{d.formatted.iso}}\"><button class=\"coral-Button coral-Button--secondary coral-Button--square\" title=\"{{i18n \"Datetime picker\"}}\"><i class=\"coral-Icon coral-Icon--calendar coral-Icon--sizeS\"></i></button></div></div>"
}
此 contexthub.location
UI模块显示客户端的经度和纬度。 该模块提供了一个弹出窗口,用于显示Google地图,单击该地图可更改当前位置。 模块从名为geolocation的ContextHub存储中获取信息,该存储基于 contexthub.geolocation 商店候选者。
UI模块的源位于 /etc/cloudsettings/default/contexthub/geolocation
.
Contexthub.location UI模块的实例不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。
{
"icon":"coral-Icon--compass",
"title":"Location",
"clickable":true,
"editable":{"key":"/geolocation","disabled":[],"hidden":["/geolocation/generatedThumbnail","/geolocation/city","/geolocation/country"]},
"fullscreen":true,
"storeMapping":{"g":"geolocation"},
"template":"<p>{{i18n \"Location\"}}</p><p>{{g.address.postalCode}} {{g.address.city}}{{#if g.address.city}}{{#if g.address.region}},{{/if}}{{/if}} {{g.address.region}}</p>",
"list":[
{"title":"Basel, Switzerland",
"data":{"longitude":7.58929,"latitude":47.554746,"city":"Basel","country":"Switzerland"}},
{"title":"Melbourne, Australia",
"data":{"longitude":144.96328,"latitude":-37.814107,"city":"Melbourne","country":"Australia"}},
{"title":"Beijing, China",
"data":{"longitude":116.407526,"latitude":39.90403,"city":"Beijing","country":"China"}},
{"title":"New York, NY, USA",
"data":{"longitude":-74.005973,"latitude":40.714353,"city":"New York","country":"United States"}},
{"title":"Paris, France",
"data":{"longitude":2.352222,"latitude":48.856614,"city":"Paris","country":"France"}},
{"title":"Rio de Janeiro, Brazil",
"data":{"longitude":-43.20071,"latitude":-22.913395,"city":"Rio","country":"Brazil"}},
{"title":"San Jose, CA, USA",
"data":{"longitude":-121.894955,"latitude":37.339386,"city":"San Jose","country":"United States"}},
{"title":"Tokyo, Japan",
"data":{"longitude":139.691706,"latitude":35.689487,"city":"Shinjuku","country":"Japan"}}
],
"listType":"checkmark"
}
此 contexthub.screen-orientation
UI模块显示客户端的当前屏幕方向。 尽管默认情况下处于禁用状态,但模块会提供一个弹出窗口,允许您选择方向。 模块从名为emulator的ContextHub存储中获取信息,该存储基于 granite.emulators 商店候选者。
UI模块的源位于 /libs/granite/contexthub/components/modules/screen-orientation
.
的实例 contexthub.screen-orientation
UI模块不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。 请注意 clickable
属性为 false
默认情况下。 如果您覆盖要设置的默认配置 clickable
到 true
,单击模块将显示一个弹出窗口,您可以在其中选择方向。
{
"icon":"coral-Icon--rotateRight",
"title":"Screen Orientation",
"clickable":false,
"storeMapping":{"emulator":"emulators"},
"template":"<p>{{{ i18n \"Screen Orientation\" }}}</p><p>{{{ emulator.currentDevice.orientation }}}",
"listReference":"/emulators/orientations",
"listType":"checkmark"
}
此 contexthub.tagcloud
UI模块显示有关标记的信息。 在工具栏上,UI模块显示标记数量。 弹出窗口将显示一个tagcloud和一个用于添加新标记的文本框。 UI模块从名为tagcloud且基于 contexthub.tagcloud
商店候选者。
UI模块的源位于 /libs/granite/contexthub/components/modules/tagcloud
.
的实例 contexthub.tagcloud
UI模块不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。
{
"icon":"coral-Icon--tag",
"title":"TagCloud",
"clickable":true,
"storeMapping":{"t":"tagcloud"},
"maxTags":20,
"template":"<p class=\"contexthub-module-line1\">{{i18n \"TagCloud\"}}</p><p class=\"contexthub-module-line2\">{{stats.total}} {{i18n \"Tags\"}}</p>",
"popoverTemplate":"<div class=\"contexthub-popover-content center\"><p class=\"stats\">{{stats.total}} {{i18n \"Tags\"}} | {{stats.hits}} {{i18n \"Hits\"}} | {{i18n \"Last tag\"}}: {{#if stats.recent}}{{stats.recent}}{{else}}{{i18n \"Unknown\"}}{{/if}}</p><p class=\"tagcloud\">{{#each tags}}<span class=\"tag{{this.weight}}\">{{this.name}}</span> {{/each}}</p><div class=\"coral-InputGroup\"><input type=\"text\" class=\"coral-InputGroup-input coral-Textfield tag-name\" placeholder=\"{{i18n \"Add a namespace:my/tag\"}}\" pattern=\"^[A-Za-z0-9_\\-]+(:[A-Za-z0-9_\\-\\/]+)?$\" title=\"{{i18n \"namespace:my/tag\"}}\"><span class=\"coral-InputGroup-button\"><button class=\"coral-Button coral-Button--secondary coral-Button--square contexthub-new-tag\" type=\"button\" title=\"{{i18n \"increment\"}}\"><i class=\"coral-Icon coral-Icon--sizeS coral-Icon--add\"></i></button></span></div></div>"
}
此 granite.profile
ContextHub UI模块显示当前用户的显示名称。 弹出窗口将显示用户的登录名,并允许您更改显示名的值。 UI模块从名为profile的ContextHub存储中获取信息,该配置文件基于 granite.profile 商店候选者。
UI模块的源位于 /libs/granite/contexthub/components/modules/profile
.
的实例 granite.profile
UI模块不需要详细信息配置的值。 以下JSON文本表示模块的默认配置。
{
"icon":"coral-Icon--user",
"title":"Profile",
"clickable":true,
"editable":{
"key":"/profile",
"disabled":["/profile/authorizableId"],
"hidden":["/profile/avatar","/profile/path"]},
"storeMapping":{"p":"profile"},
"template":"<p class=\"contexthub-module-line1\">{{i18n \"Persona\"}}</p><p class=\"contexthub-module-line2\">{{p.displayName}}</p>",
"listType":"checkmark"
}