Browse Source
* Merge with master * Refactoring code * Add license header Co-authored-by: Andrew Shvayka <ashvayka@thingsboard.io>pull/2474/head
committed by
GitHub
25 changed files with 464 additions and 130 deletions
@ -0,0 +1,45 @@ |
|||
/* |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under 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, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
export default angular.module('tbJsonToString', []) |
|||
.directive('tbJsonToString', InputJson) |
|||
.name; |
|||
|
|||
function InputJson() { |
|||
return { |
|||
restrict: 'A', |
|||
require: 'ngModel', |
|||
link: function(scope, element, attr, ngModelCtrl) { |
|||
function into(input) { |
|||
try { |
|||
ngModelCtrl.$setValidity('invalidJSON', true); |
|||
return angular.fromJson(input); |
|||
} catch (e) { |
|||
ngModelCtrl.$setValidity('invalidJSON', false); |
|||
} |
|||
} |
|||
function out(data) { |
|||
try { |
|||
ngModelCtrl.$setValidity('invalidJSON', true); |
|||
return angular.toJson(data); |
|||
} catch (e) { |
|||
ngModelCtrl.$setValidity('invalidJSON', false); |
|||
} |
|||
} |
|||
ngModelCtrl.$parsers.push(into); |
|||
ngModelCtrl.$formatters.push(out); |
|||
} |
|||
}; |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
/* |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under 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, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
/* eslint-enable import/no-unresolved, import/default */ |
|||
|
|||
import './attribute-dialog-edit-json.scss'; |
|||
|
|||
/*@ngInject*/ |
|||
export default function AttributeDialogEditJsonController($mdDialog, types, jsonValue, readOnly) { |
|||
|
|||
let vm = this; |
|||
vm.json = angular.toJson(jsonValue, 4); |
|||
vm.readOnly = readOnly; |
|||
vm.contentType = types.contentType.JSON.value; |
|||
|
|||
vm.save = () => { |
|||
$mdDialog.hide(angular.fromJson(vm.json)); |
|||
}; |
|||
|
|||
vm.cancel = () => { |
|||
$mdDialog.cancel(); |
|||
}; |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
/** |
|||
* Copyright © 2016-2020 The Thingsboard Authors |
|||
* |
|||
* Licensed under 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, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
.attribute-edit-json-dialog{ |
|||
min-width: 400px; |
|||
} |
|||
|
|||
@media (max-width: 425px){ |
|||
.attribute-edit-json-dialog { |
|||
min-width: 200px; |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 The Thingsboard Authors |
|||
|
|||
Licensed under 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, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<md-dialog class="attribute-edit-json-dialog"> |
|||
<form name="theForm" ng-submit="vm.save()"> |
|||
<md-toolbar> |
|||
<div class="md-toolbar-tools"> |
|||
<h2>{{ 'details.edit-json' | translate }}</h2> |
|||
<span flex></span> |
|||
<md-button class="md-icon-button" |
|||
ng-click="vm.cancel()" |
|||
aria-label="{{'action.close'|translate}}"> |
|||
<ng-md-icon icon="close" aria-label="Close"></ng-md-icon> |
|||
</md-button> |
|||
</div> |
|||
</md-toolbar> |
|||
<md-dialog-content> |
|||
<div class="md-dialog-content"> |
|||
<tb-json-content |
|||
ng-model="vm.json" |
|||
label="{{ 'value.json-value' | translate }}" |
|||
content-type="vm.contentType" |
|||
validate-content="true" |
|||
hide-error-toast="true" |
|||
fill-height="false" |
|||
ng-readonly="vm.readOnly"> |
|||
</tb-json-content> |
|||
</div> |
|||
</md-dialog-content> |
|||
<md-dialog-actions layout="row" layout-align="end center" class="action-buttons"> |
|||
<md-button ng-disabled="$root.loading || theForm.$invalid || !theForm.$dirty" type="submit" |
|||
class="md-raised md-primary"> |
|||
{{'action.save'|translate}} |
|||
</md-button> |
|||
<md-button id="cancel-btn" ng-disabled="$root.loading" ng-click="vm.cancel()"> |
|||
{{'action.cancel'|translate }} |
|||
</md-button> |
|||
</md-dialog-actions> |
|||
</form> |
|||
</md-dialog> |
|||
Loading…
Reference in new issue