-
+
+ ng-class="{ 'tb-padded' : !vm.widgetEditMode && (vm.isEdit || vm.displayTitle()), 'tb-shrinked' : vm.isEditingWidget }">
-
diff --git a/ui/src/app/dashboard/index.js b/ui/src/app/dashboard/index.js
index 74004639e6..461f56ec82 100644
--- a/ui/src/app/dashboard/index.js
+++ b/ui/src/app/dashboard/index.js
@@ -29,6 +29,7 @@ import thingsboardDashboard from '../components/dashboard.directive';
import thingsboardExpandFullscreen from '../components/expand-fullscreen.directive';
import thingsboardWidgetsBundleSelect from '../components/widgets-bundle-select.directive';
import thingsboardTypes from '../common/types.constant';
+import thingsboardItemBuffer from '../services/item-buffer.service';
import DashboardRoutes from './dashboard.routes';
import DashboardsController from './dashboards.controller';
@@ -45,6 +46,7 @@ export default angular.module('thingsboard.dashboard', [
uiRouter,
gridster.name,
thingsboardTypes,
+ thingsboardItemBuffer,
thingsboardGrid,
thingsboardApiWidget,
thingsboardApiUser,
diff --git a/ui/src/app/device/attribute/add-widget-to-dashboard-dialog.controller.js b/ui/src/app/device/attribute/add-widget-to-dashboard-dialog.controller.js
index 9149cf1c8f..3f6d7698ef 100644
--- a/ui/src/app/device/attribute/add-widget-to-dashboard-dialog.controller.js
+++ b/ui/src/app/device/attribute/add-widget-to-dashboard-dialog.controller.js
@@ -14,7 +14,7 @@
* limitations under the License.
*/
/*@ngInject*/
-export default function AddWidgetToDashboardDialogController($scope, $mdDialog, $state, dashboardService, deviceId, deviceName, widget) {
+export default function AddWidgetToDashboardDialogController($scope, $mdDialog, $state, itembuffer, dashboardService, deviceId, deviceName, widget) {
var vm = this;
@@ -34,62 +34,20 @@ export default function AddWidgetToDashboardDialogController($scope, $mdDialog,
function add() {
$scope.theForm.$setPristine();
var theDashboard;
- var deviceAliases;
- widget.col = 0;
- widget.sizeX /= 2;
- widget.sizeY /= 2;
if (vm.addToDashboardType === 0) {
theDashboard = vm.dashboard;
- if (!theDashboard.configuration) {
- theDashboard.configuration = {};
- }
- deviceAliases = theDashboard.configuration.deviceAliases;
- if (!deviceAliases) {
- deviceAliases = {};
- theDashboard.configuration.deviceAliases = deviceAliases;
- }
- var newAliasId;
- for (var aliasId in deviceAliases) {
- if (deviceAliases[aliasId].deviceId === deviceId) {
- newAliasId = aliasId;
- break;
- }
- }
- if (!newAliasId) {
- var newAliasName = createDeviceAliasName(deviceAliases, deviceName);
- newAliasId = 0;
- for (aliasId in deviceAliases) {
- newAliasId = Math.max(newAliasId, aliasId);
- }
- newAliasId++;
- deviceAliases[newAliasId] = {alias: newAliasName, deviceId: deviceId};
- }
- widget.config.datasources[0].deviceAliasId = newAliasId;
-
- if (!theDashboard.configuration.widgets) {
- theDashboard.configuration.widgets = [];
- }
-
- var row = 0;
- for (var w in theDashboard.configuration.widgets) {
- var existingWidget = theDashboard.configuration.widgets[w];
- var wRow = existingWidget.row ? existingWidget.row : 0;
- var wSizeY = existingWidget.sizeY ? existingWidget.sizeY : 1;
- var bottom = wRow + wSizeY;
- row = Math.max(row, bottom);
- }
- widget.row = row;
- theDashboard.configuration.widgets.push(widget);
} else {
theDashboard = vm.newDashboard;
- deviceAliases = {};
- deviceAliases['1'] = {alias: deviceName, deviceId: deviceId};
- theDashboard.configuration = {};
- theDashboard.configuration.widgets = [];
- widget.row = 0;
- theDashboard.configuration.widgets.push(widget);
- theDashboard.configuration.deviceAliases = deviceAliases;
}
+ var aliasesInfo = {
+ datasourceAliases: {},
+ targetDeviceAliases: {}
+ };
+ aliasesInfo.datasourceAliases[0] = {
+ aliasName: deviceName,
+ deviceId: deviceId
+ };
+ theDashboard = itembuffer.addWidgetToDashboard(theDashboard, widget, aliasesInfo, 48, -1, -1);
dashboardService.saveDashboard(theDashboard).then(
function success(dashboard) {
$mdDialog.hide();
@@ -98,25 +56,6 @@ export default function AddWidgetToDashboardDialogController($scope, $mdDialog,
}
}
);
-
- }
-
- function createDeviceAliasName(deviceAliases, alias) {
- var c = 0;
- var newAlias = angular.copy(alias);
- var unique = false;
- while (!unique) {
- unique = true;
- for (var devAliasId in deviceAliases) {
- var devAlias = deviceAliases[devAliasId];
- if (newAlias === devAlias.alias) {
- c++;
- newAlias = alias + c;
- unique = false;
- }
- }
- }
- return newAlias;
}
}
diff --git a/ui/src/app/device/attribute/attribute-table.directive.js b/ui/src/app/device/attribute/attribute-table.directive.js
index 0a5e0cdfda..24e9022803 100644
--- a/ui/src/app/device/attribute/attribute-table.directive.js
+++ b/ui/src/app/device/attribute/attribute-table.directive.js
@@ -239,6 +239,8 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
index: 0
}
scope.widgetsBundle = null;
+ scope.firstBundle = true;
+ scope.selectedWidgetsBundleAlias = types.systemBundleAlias.cards;
scope.deviceAliases = {};
scope.deviceAliases['1'] = {alias: scope.deviceName, deviceId: scope.deviceId};
@@ -326,13 +328,6 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
}
}
});
-
- widgetService.getWidgetsBundleByAlias(types.systemBundleAlias.cards).then(
- function success(widgetsBundle) {
- scope.firstBundle = true;
- scope.widgetsBundle = widgetsBundle;
- }
- );
}
scope.exitWidgetMode = function() {
@@ -344,6 +339,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.widgetsIndexWatch();
scope.widgetsIndexWatch = null;
}
+ scope.selectedWidgetsBundleAlias = null;
scope.mode = 'default';
scope.getDeviceAttributes(true);
}
diff --git a/ui/src/app/device/attribute/attribute-table.tpl.html b/ui/src/app/device/attribute/attribute-table.tpl.html
index 880d8808a9..a88fe02daf 100644
--- a/ui/src/app/device/attribute/attribute-table.tpl.html
+++ b/ui/src/app/device/attribute/attribute-table.tpl.html
@@ -105,7 +105,8 @@
+ select-first-bundle="false"
+ select-bundle-alias="selectedWidgetsBundleAlias">
diff --git a/ui/src/app/layout/breadcrumb.tpl.html b/ui/src/app/layout/breadcrumb.tpl.html
index b5ae8634c7..3253974e0f 100644
--- a/ui/src/app/layout/breadcrumb.tpl.html
+++ b/ui/src/app/layout/breadcrumb.tpl.html
@@ -15,7 +15,7 @@
limitations under the License.
-->
-