Commit 4dde2eec1a1c53b9291bd832a48b04c40d5c117f
1 parent
ab494596
add SceemaGroup so that it can display better when there are many configuration item
Showing
7 changed files
with
113 additions
and
21 deletions
... | ... | @@ -145,11 +145,13 @@ function JsonForm($compile, $templateCache, $mdColorPicker) { |
145 | 145 | }; |
146 | 146 | schema.strict = true; |
147 | 147 | var form = scope.form ? angular.copy(scope.form) : [ "*" ]; |
148 | + var groupInfoes = scope.groupInfoes ? angular.copy(scope.groupInfoes) : []; | |
148 | 149 | var model = scope.model || {}; |
149 | 150 | scope.model = inspector.sanitize(schema, model).data; |
150 | 151 | scope.formProps.option.formDefaults.readonly = readonly; |
151 | 152 | scope.formProps.schema = schema; |
152 | 153 | scope.formProps.form = form; |
154 | + scope.formProps.groupInfoes = groupInfoes; | |
153 | 155 | scope.formProps.model = angular.copy(scope.model); |
154 | 156 | if (!skipRerender) { |
155 | 157 | recompile(); |
... | ... | @@ -176,6 +178,12 @@ function JsonForm($compile, $templateCache, $mdColorPicker) { |
176 | 178 | } |
177 | 179 | }); |
178 | 180 | |
181 | + scope.$watch('groupInfoes',function(newValue, prevValue) { | |
182 | + if (newValue && newValue != prevValue) { | |
183 | + scope.updateValues(); | |
184 | + } | |
185 | + }); | |
186 | + | |
179 | 187 | scope.validate(); |
180 | 188 | |
181 | 189 | recompile(); |
... | ... | @@ -189,6 +197,7 @@ function JsonForm($compile, $templateCache, $mdColorPicker) { |
189 | 197 | form: '=', |
190 | 198 | model: '=', |
191 | 199 | formControl: '=', |
200 | + groupInfoes: '=', | |
192 | 201 | readonly: '=' |
193 | 202 | }, |
194 | 203 | link: linker | ... | ... |
... | ... | @@ -47,6 +47,7 @@ class ReactSchemaForm extends React.Component { |
47 | 47 | ReactSchemaForm.propTypes = { |
48 | 48 | schema: React.PropTypes.object, |
49 | 49 | form: React.PropTypes.array, |
50 | + groupInfoes: React.PropTypes.array, | |
50 | 51 | model: React.PropTypes.object, |
51 | 52 | option: React.PropTypes.object, |
52 | 53 | onModelChange: React.PropTypes.func, |
... | ... | @@ -56,7 +57,8 @@ ReactSchemaForm.propTypes = { |
56 | 57 | |
57 | 58 | ReactSchemaForm.defaultProps = { |
58 | 59 | schema: {}, |
59 | - form: [ "*" ] | |
60 | + form: [ "*" ], | |
61 | + groupInfoes:[] | |
60 | 62 | } |
61 | 63 | |
62 | 64 | ReactSchemaForm.childContextTypes = { | ... | ... |
... | ... | @@ -83,6 +83,7 @@ class ThingsboardSchemaForm extends React.Component { |
83 | 83 | this.props.onToggleFullscreen(); |
84 | 84 | } |
85 | 85 | |
86 | + | |
86 | 87 | builder(form, model, index, onChange, onColorClick, onToggleFullscreen, mapper) { |
87 | 88 | var type = form.type; |
88 | 89 | let Field = this.mapper[type]; |
... | ... | @@ -99,8 +100,8 @@ class ThingsboardSchemaForm extends React.Component { |
99 | 100 | return <Field model={model} form={form} key={index} onChange={onChange} onColorClick={onColorClick} onToggleFullscreen={onToggleFullscreen} mapper={mapper} builder={this.builder}/> |
100 | 101 | } |
101 | 102 | |
102 | - render() { | |
103 | - let merged = utils.merge(this.props.schema, this.props.form, this.props.ignore, this.props.option); | |
103 | + createSchema(theForm) { | |
104 | + let merged = utils.merge(this.props.schema, theForm, this.props.ignore, this.props.option); | |
104 | 105 | let mapper = this.mapper; |
105 | 106 | if(this.props.mapper) { |
106 | 107 | mapper = _.merge(this.mapper, this.props.mapper); |
... | ... | @@ -118,5 +119,43 @@ class ThingsboardSchemaForm extends React.Component { |
118 | 119 | <div style={{width: '100%'}} className={formClass}>{forms}</div> |
119 | 120 | ); |
120 | 121 | } |
122 | + | |
123 | + render() { | |
124 | + if(this.props.groupInfoes&&this.props.groupInfoes.length>0){ | |
125 | + let content=[]; | |
126 | + for(let info of this.props.groupInfoes){ | |
127 | + let forms = this.createSchema(this.props.form[info.formIndex]); | |
128 | + let item = <ThingsboardSchemaGroup key={content.length} forms={forms} info={info}></ThingsboardSchemaGroup>; | |
129 | + content.push(item); | |
130 | + } | |
131 | + return (<div>{content}</div>); | |
132 | + } | |
133 | + else | |
134 | + return this.createSchema(this.props.form); | |
135 | + } | |
121 | 136 | } |
122 | 137 | export default ThingsboardSchemaForm; |
138 | + | |
139 | + | |
140 | +class ThingsboardSchemaGroup extends React.Component{ | |
141 | + constructor(props) { | |
142 | + super(props); | |
143 | + this.state={ | |
144 | + showGroup:true | |
145 | + } | |
146 | + } | |
147 | + | |
148 | + toogleGroup(index) { | |
149 | + this.setState({ | |
150 | + showGroup:!this.state.showGroup | |
151 | + }); | |
152 | + } | |
153 | + | |
154 | + render() { | |
155 | + let theCla = "pull-right fa fa-chevron-down md-toggle-icon"+(this.state.showGroup?"":" tb-toggled") | |
156 | + return (<section className="md-whiteframe-z1" style={{marginTop: '10px'}}> | |
157 | + <div className='SchemaGroupname md-button-toggle' onClick={this.toogleGroup.bind(this)}>{this.props.info.GroupTitle}<span className={theCla}></span></div> | |
158 | + <div style={{padding: '20px'}} className={this.state.showGroup?"":"invisible"}>{this.props.forms}</div> | |
159 | + </section>); | |
160 | + } | |
161 | +} | |
\ No newline at end of file | ... | ... |
... | ... | @@ -63,6 +63,8 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout |
63 | 63 | type: "object", |
64 | 64 | properties: {} |
65 | 65 | }; |
66 | + | |
67 | + scope.emptySettingsGroupInfoes=[]; | |
66 | 68 | scope.defaultSettingsForm = [ |
67 | 69 | '*' |
68 | 70 | ]; |
... | ... | @@ -90,6 +92,7 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout |
90 | 92 | |
91 | 93 | scope.currentSettingsSchema = {}; |
92 | 94 | scope.currentSettings = angular.copy(scope.emptySettingsSchema); |
95 | + scope.currentSettingsGroupInfoes = angular.copy(scope.emptySettingsGroupInfoes); | |
93 | 96 | |
94 | 97 | scope.targetDeviceAlias = { |
95 | 98 | value: null |
... | ... | @@ -189,10 +192,12 @@ function WidgetConfig($compile, $templateCache, $rootScope, $translate, $timeout |
189 | 192 | if (scope.widgetSettingsSchema && scope.widgetSettingsSchema.schema) { |
190 | 193 | scope.currentSettingsSchema = scope.widgetSettingsSchema.schema; |
191 | 194 | scope.currentSettingsForm = scope.widgetSettingsSchema.form || angular.copy(scope.defaultSettingsForm); |
195 | + scope.currentSettingsGroupInfoes = scope.widgetSettingsSchema.groupInfoes; | |
192 | 196 | scope.currentSettings = scope.settings; |
193 | 197 | } else { |
194 | 198 | scope.currentSettingsForm = angular.copy(scope.defaultSettingsForm); |
195 | 199 | scope.currentSettingsSchema = angular.copy(scope.emptySettingsSchema); |
200 | + scope.currentSettingsGroupInfoes = angular.copy(scope.emptySettingsGroupInfoes); | |
196 | 201 | scope.currentSettings = {}; |
197 | 202 | } |
198 | 203 | } | ... | ... |
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | 7 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | 9 | * |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
... | ... | @@ -83,10 +83,10 @@ export default class TbMapWidgetV2 { |
83 | 83 | this.map = new TbGoogleMap($element, this.utils, initCallback, this.defaultZoomLevel, this.dontFitMapBounds, settings.disableScrollZooming, minZoomLevel, settings.gmApiKey, settings.gmDefaultMapType); |
84 | 84 | } else if (mapProvider === 'openstreet-map') { |
85 | 85 | if (settings.useCustomProvider && settings.customProviderTileUrl) { |
86 | - openStreetMapProvider.name = settings.customProviderTileUrl; | |
87 | - openStreetMapProvider.isCustom = true; | |
86 | + openStreetMapProvider.name = settings.customProviderTileUrl; | |
87 | + openStreetMapProvider.isCustom = true; | |
88 | 88 | } else { |
89 | - openStreetMapProvider.name = settings.mapProvider; | |
89 | + openStreetMapProvider.name = settings.mapProvider; | |
90 | 90 | } |
91 | 91 | this.map = new TbOpenStreetMap($element, this.utils, initCallback, this.defaultZoomLevel, this.dontFitMapBounds, settings.disableScrollZooming, minZoomLevel, openStreetMapProvider); |
92 | 92 | } else if (mapProvider === 'here') { |
... | ... | @@ -669,22 +669,49 @@ export default class TbMapWidgetV2 { |
669 | 669 | var schema; |
670 | 670 | if (mapProvider === 'google-map') { |
671 | 671 | schema = angular.copy(googleMapSettingsSchema); |
672 | + schema.groupInfoes=[{ | |
673 | + "formIndex":0, | |
674 | + "GroupTitle":"Google Map Settings" | |
675 | + }]; | |
672 | 676 | } else if (mapProvider === 'openstreet-map') { |
673 | 677 | schema = angular.copy(openstreetMapSettingsSchema); |
678 | + schema.groupInfoes=[{ | |
679 | + "formIndex":0, | |
680 | + "GroupTitle":"Openstreet Map Settings" | |
681 | + }]; | |
674 | 682 | } else if (mapProvider === 'image-map') { |
675 | 683 | return imageMapSettingsSchema; |
676 | 684 | } else if (mapProvider === 'tencent-map') { |
677 | 685 | schema = angular.copy(tencentMapSettingsSchema); |
686 | + schema.groupInfoes=[{ | |
687 | + "formIndex":0, | |
688 | + "GroupTitle":"Tencent Map Settings" | |
689 | + }]; | |
678 | 690 | } else if (mapProvider === 'here') { |
679 | 691 | schema = angular.copy(hereMapSettingsSchema); |
692 | + schema.groupInfoes=[{ | |
693 | + "formIndex":0, | |
694 | + "GroupTitle":"Here Map Settings" | |
695 | + }]; | |
680 | 696 | } |
697 | + if(!schema.groupInfoes)schema.groupInfoes=[]; | |
698 | + schema.form = [schema.form]; | |
699 | + | |
681 | 700 | angular.merge(schema.schema.properties, commonMapSettingsSchema.schema.properties); |
682 | 701 | schema.schema.required = schema.schema.required.concat(commonMapSettingsSchema.schema.required); |
683 | - schema.form = schema.form.concat(commonMapSettingsSchema.form); | |
702 | + schema.form.push(commonMapSettingsSchema.form);//schema.form.concat(commonMapSettingsSchema.form); | |
703 | + schema.groupInfoes.push({ | |
704 | + "formIndex":schema.groupInfoes.length, | |
705 | + "GroupTitle":"Common Map Settings" | |
706 | + }); | |
684 | 707 | if (drawRoutes) { |
685 | 708 | angular.merge(schema.schema.properties, routeMapSettingsSchema.schema.properties); |
686 | 709 | schema.schema.required = schema.schema.required.concat(routeMapSettingsSchema.schema.required); |
687 | - schema.form = schema.form.concat(routeMapSettingsSchema.form); | |
710 | + schema.form.push(routeMapSettingsSchema.form);//schema.form = schema.form.concat(routeMapSettingsSchema.form); | |
711 | + schema.groupInfoes.push({ | |
712 | + "formIndex":schema.groupInfoes.length, | |
713 | + "GroupTitle":"Route Map Settings" | |
714 | + }); | |
688 | 715 | } |
689 | 716 | return schema; |
690 | 717 | } |
... | ... | @@ -871,16 +898,16 @@ const openstreetMapSettingsSchema = |
871 | 898 | "type": "string", |
872 | 899 | "default": "OpenStreetMap.Mapnik" |
873 | 900 | }, |
874 | - "useCustomProvider": { | |
875 | - "title": "Use custom provider", | |
876 | - "type": "boolean", | |
877 | - "default": false | |
878 | - }, | |
879 | - "customProviderTileUrl": { | |
880 | - "title": "Custom provider tile URL", | |
881 | - "type": "string", | |
882 | - "default": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | |
883 | - } | |
901 | + "useCustomProvider": { | |
902 | + "title": "Use custom provider", | |
903 | + "type": "boolean", | |
904 | + "default": false | |
905 | + }, | |
906 | + "customProviderTileUrl": { | |
907 | + "title": "Custom provider tile URL", | |
908 | + "type": "string", | |
909 | + "default": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | |
910 | + } | |
884 | 911 | }, |
885 | 912 | "required": [] |
886 | 913 | }, |
... | ... | @@ -920,8 +947,8 @@ const openstreetMapSettingsSchema = |
920 | 947 | } |
921 | 948 | ] |
922 | 949 | }, |
923 | - "useCustomProvider", | |
924 | - "customProviderTileUrl" | |
950 | + "useCustomProvider", | |
951 | + "customProviderTileUrl" | |
925 | 952 | ] |
926 | 953 | }; |
927 | 954 | ... | ... |