-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Revert "removed unnecessary files"""
This reverts commit ba665fc.
- Loading branch information
Showing
23 changed files
with
2,195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
/* | ||
* Copyright © 2016-2017 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-disable import/no-unresolved, import/default */ | ||
|
||
import dashboardLayoutTemplate from './dashboard-layout.tpl.html'; | ||
|
||
/* eslint-enable import/no-unresolved, import/default */ | ||
|
||
/*@ngInject*/ | ||
export default function DashboardLayout() { | ||
return { | ||
restrict: "E", | ||
scope: true, | ||
bindToController: { | ||
layoutCtx: '=', | ||
dashboardCtx: '=', | ||
isEdit: '=', | ||
isMobile: '=', | ||
widgetEditMode: '=' | ||
}, | ||
controller: DashboardLayoutController, | ||
controllerAs: 'vm', | ||
templateUrl: dashboardLayoutTemplate | ||
}; | ||
} | ||
|
||
/*@ngInject*/ | ||
function DashboardLayoutController($scope, $rootScope, $translate, $window, hotkeys, itembuffer) { | ||
|
||
var vm = this; | ||
|
||
vm.noData = noData; | ||
vm.addWidget = addWidget; | ||
vm.editWidget = editWidget; | ||
vm.exportWidget = exportWidget; | ||
vm.widgetMouseDown = widgetMouseDown; | ||
vm.widgetClicked = widgetClicked; | ||
vm.prepareDashboardContextMenu = prepareDashboardContextMenu; | ||
vm.prepareWidgetContextMenu = prepareWidgetContextMenu; | ||
vm.removeWidget = removeWidget; | ||
vm.pasteWidget = pasteWidget; | ||
vm.pasteWidgetReference = pasteWidgetReference; | ||
vm.dashboardInited = dashboardInited; | ||
vm.dashboardInitFailed = dashboardInitFailed; | ||
|
||
vm.reload = function() { | ||
if (vm.dashboardContainer) { | ||
vm.dashboardContainer.reload(); | ||
} | ||
}; | ||
|
||
vm.setResizing = function(resizing) { | ||
if (vm.dashboardContainer) { | ||
vm.dashboardContainer.isResizing = resizing; | ||
} | ||
} | ||
|
||
vm.resetHighlight = function() { | ||
if (vm.dashboardContainer) { | ||
vm.dashboardContainer.resetHighlight(); | ||
} | ||
}; | ||
|
||
vm.highlightWidget = function(widget, delay) { | ||
if (vm.dashboardContainer) { | ||
vm.dashboardContainer.highlightWidget(widget, delay); | ||
} | ||
}; | ||
|
||
vm.selectWidget = function(widget, delay) { | ||
if (vm.dashboardContainer) { | ||
vm.dashboardContainer.selectWidget(widget, delay); | ||
} | ||
}; | ||
|
||
vm.dashboardInitComplete = false; | ||
|
||
initHotKeys(); | ||
|
||
$scope.$on('$destroy', function() { | ||
vm.dashboardContainer = null; | ||
}); | ||
|
||
$scope.$watch('vm.layoutCtx', function () { | ||
if (vm.layoutCtx) { | ||
vm.layoutCtx.ctrl = vm; | ||
} | ||
}); | ||
|
||
function noData() { | ||
return vm.dashboardInitComplete && vm.layoutCtx && | ||
vm.layoutCtx.widgets && vm.layoutCtx.widgets.length == 0; | ||
} | ||
|
||
function addWidget($event) { | ||
if (vm.dashboardCtx.onAddWidget) { | ||
vm.dashboardCtx.onAddWidget($event, vm.layoutCtx); | ||
} | ||
} | ||
|
||
function editWidget($event, widget) { | ||
if (vm.dashboardCtx.onEditWidget) { | ||
vm.dashboardCtx.onEditWidget($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function exportWidget($event, widget) { | ||
if (vm.dashboardCtx.onExportWidget) { | ||
vm.dashboardCtx.onExportWidget($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function widgetMouseDown($event, widget) { | ||
if (vm.dashboardCtx.onWidgetMouseDown) { | ||
vm.dashboardCtx.onWidgetMouseDown($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function widgetClicked($event, widget) { | ||
if (vm.dashboardCtx.onWidgetClicked) { | ||
vm.dashboardCtx.onWidgetClicked($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function prepareDashboardContextMenu() { | ||
if (vm.dashboardCtx.prepareDashboardContextMenu) { | ||
return vm.dashboardCtx.prepareDashboardContextMenu(vm.layoutCtx); | ||
} | ||
} | ||
|
||
function prepareWidgetContextMenu(widget) { | ||
if (vm.dashboardCtx.prepareWidgetContextMenu) { | ||
return vm.dashboardCtx.prepareWidgetContextMenu(vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function removeWidget($event, widget) { | ||
if (vm.dashboardCtx.onRemoveWidget) { | ||
vm.dashboardCtx.onRemoveWidget($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function dashboardInitFailed() { | ||
var parentScope = $window.parent.angular.element($window.frameElement).scope(); | ||
parentScope.$emit('widgetEditModeInited'); | ||
parentScope.$apply(); | ||
vm.dashboardInitComplete = true; | ||
} | ||
|
||
function dashboardInited(dashboardContainer) { | ||
vm.dashboardContainer = dashboardContainer; | ||
vm.dashboardInitComplete = true; | ||
} | ||
|
||
function isHotKeyAllowed(event) { | ||
var target = event.target || event.srcElement; | ||
var scope = angular.element(target).scope(); | ||
return scope && scope.$parent !== $rootScope; | ||
} | ||
|
||
function initHotKeys() { | ||
$translate(['action.copy', 'action.paste', 'action.delete']).then(function (translations) { | ||
hotkeys.bindTo($scope) | ||
.add({ | ||
combo: 'ctrl+c', | ||
description: translations['action.copy'], | ||
callback: function (event) { | ||
if (isHotKeyAllowed(event) && | ||
vm.isEdit && !vm.isEditingWidget && !vm.widgetEditMode) { | ||
var widget = vm.dashboardContainer.getSelectedWidget(); | ||
if (widget) { | ||
event.preventDefault(); | ||
copyWidget(event, widget); | ||
} | ||
} | ||
} | ||
}) | ||
.add({ | ||
combo: 'ctrl+r', | ||
description: translations['action.copy-reference'], | ||
callback: function (event) { | ||
if (isHotKeyAllowed(event) && | ||
vm.isEdit && !vm.isEditingWidget && !vm.widgetEditMode) { | ||
var widget = vm.dashboardContainer.getSelectedWidget(); | ||
if (widget) { | ||
event.preventDefault(); | ||
copyWidgetReference(event, widget); | ||
} | ||
} | ||
} | ||
}) | ||
.add({ | ||
combo: 'ctrl+v', | ||
description: translations['action.paste'], | ||
callback: function (event) { | ||
if (isHotKeyAllowed(event) && | ||
vm.isEdit && !vm.isEditingWidget && !vm.widgetEditMode) { | ||
if (itembuffer.hasWidget()) { | ||
event.preventDefault(); | ||
pasteWidget(event); | ||
} | ||
} | ||
} | ||
}) | ||
.add({ | ||
combo: 'ctrl+i', | ||
description: translations['action.paste-reference'], | ||
callback: function (event) { | ||
if (isHotKeyAllowed(event) && | ||
vm.isEdit && !vm.isEditingWidget && !vm.widgetEditMode) { | ||
if (itembuffer.canPasteWidgetReference(vm.dashboardCtx.dashboard, | ||
vm.dashboardCtx.state, vm.layoutCtx.id)) { | ||
event.preventDefault(); | ||
pasteWidgetReference(event); | ||
} | ||
} | ||
} | ||
}) | ||
|
||
.add({ | ||
combo: 'ctrl+x', | ||
description: translations['action.delete'], | ||
callback: function (event) { | ||
if (isHotKeyAllowed(event) && | ||
vm.isEdit && !vm.isEditingWidget && !vm.widgetEditMode) { | ||
var widget = vm.dashboardContainer.getSelectedWidget(); | ||
if (widget) { | ||
event.preventDefault(); | ||
vm.dashboardCtx.onRemoveWidget(event, vm.layoutCtx, widget); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function copyWidget($event, widget) { | ||
if (vm.dashboardCtx.copyWidget) { | ||
vm.dashboardCtx.copyWidget($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function copyWidgetReference($event, widget) { | ||
if (vm.dashboardCtx.copyWidgetReference) { | ||
vm.dashboardCtx.copyWidgetReference($event, vm.layoutCtx, widget); | ||
} | ||
} | ||
|
||
function pasteWidget($event) { | ||
var pos = vm.dashboardContainer.getEventGridPosition($event); | ||
if (vm.dashboardCtx.pasteWidget) { | ||
vm.dashboardCtx.pasteWidget($event, vm.layoutCtx, pos); | ||
} | ||
} | ||
|
||
function pasteWidgetReference($event) { | ||
var pos = vm.dashboardContainer.getEventGridPosition($event); | ||
if (vm.dashboardCtx.pasteWidgetReference) { | ||
vm.dashboardCtx.pasteWidgetReference($event, vm.layoutCtx, pos); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<!-- | ||
Copyright © 2016-2017 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-content style="position: relative; width: 100%; height: 100%;" | ||
ng-style="{'background-color': vm.layoutCtx.gridSettings.backgroundColor, | ||
'background-image': 'url('+vm.layoutCtx.gridSettings.backgroundImageUrl+')', | ||
'background-repeat': 'no-repeat', | ||
'background-attachment': 'scroll', | ||
'background-size': vm.layoutCtx.gridSettings.backgroundSizeMode || '100%', | ||
'background-position': '0% 0%'}"> | ||
<section ng-show="!loading && vm.noData()" layout-align="center center" | ||
ng-style="{'color': vm.layoutCtx.gridSettings.color}" | ||
style="text-transform: uppercase; display: flex; z-index: 1; pointer-events: none;" | ||
class="md-headline tb-absolute-fill"> | ||
<span translate ng-if="!vm.isEdit"> | ||
dashboard.no-widgets | ||
</span> | ||
<md-button ng-if="vm.isEdit && !vm.widgetEditMode" class="tb-add-new-widget" ng-click="vm.addWidget({event: $event})"> | ||
<md-icon aria-label="{{ 'action.add' | translate }}" class="material-icons tb-md-96">add</md-icon> | ||
{{ 'dashboard.add-widget' | translate }} | ||
</md-button> | ||
</section> | ||
<tb-dashboard | ||
dashboard-style="{'background-color': vm.layoutCtx.gridSettings.backgroundColor, | ||
'background-image': 'url('+vm.layoutCtx.gridSettings.backgroundImageUrl+')', | ||
'background-repeat': 'no-repeat', | ||
'background-attachment': 'scroll', | ||
'background-size': vm.layoutCtx.gridSettings.backgroundSizeMode || '100%', | ||
'background-position': '0% 0%'}" | ||
widgets="vm.layoutCtx.widgets" | ||
widget-layouts="vm.layoutCtx.widgetLayouts" | ||
columns="vm.layoutCtx.gridSettings.columns" | ||
margins="vm.layoutCtx.gridSettings.margins" | ||
alias-controller="vm.dashboardCtx.aliasController" | ||
state-controller="vm.dashboardCtx.stateController" | ||
dashboard-timewindow="vm.dashboardCtx.dashboardTimewindow" | ||
is-edit="vm.isEdit" | ||
autofill-height="vm.layoutCtx.gridSettings.autoFillHeight && !vm.isEdit" | ||
mobile-autofill-height="vm.layoutCtx.gridSettings.mobileAutoFillHeight && !vm.isEdit" | ||
mobile-row-height="vm.layoutCtx.gridSettings.mobileRowHeight" | ||
is-mobile="vm.isMobile" | ||
is-mobile-disabled="vm.widgetEditMode" | ||
is-edit-action-enabled="vm.isEdit" | ||
is-export-action-enabled="vm.isEdit && !vm.widgetEditMode" | ||
is-remove-action-enabled="vm.isEdit && !vm.widgetEditMode" | ||
on-edit-widget="vm.editWidget(event, widget)" | ||
on-export-widget="vm.exportWidget(event, widget)" | ||
on-widget-mouse-down="vm.widgetMouseDown(event, widget)" | ||
on-widget-clicked="vm.widgetClicked(event, widget)" | ||
prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()" | ||
prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)" | ||
on-remove-widget="vm.removeWidget(event, widget)" | ||
on-init="vm.dashboardInited(dashboard)" | ||
on-init-failed="vm.dashboardInitFailed(e)" | ||
ignore-loading="vm.layoutCtx.ignoreLoading"> | ||
</tb-dashboard> | ||
</md-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright © 2016-2017 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. | ||
*/ | ||
|
||
import ManageDashboardLayoutsController from './manage-dashboard-layouts.controller'; | ||
import SelectTargetLayoutController from './select-target-layout.controller'; | ||
import DashboardLayoutDirective from './dashboard-layout.directive'; | ||
|
||
export default angular.module('thingsboard.dashboard.layouts', []) | ||
.controller('ManageDashboardLayoutsController', ManageDashboardLayoutsController) | ||
.controller('SelectTargetLayoutController', SelectTargetLayoutController) | ||
.directive('tbDashboardLayout', DashboardLayoutDirective) | ||
.name; |
Oops, something went wrong.