Skip to content

Commit

Permalink
Merge pull request #753 from hashmapinc/Tempus-FilterAssetBasedonDevice
Browse files Browse the repository at this point in the history
Tempus filter asset based on device customer id
  • Loading branch information
NandiniMGawade committed Oct 11, 2018
2 parents 8fcf72b + aa8eee9 commit eaca999
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 26 deletions.
3 changes: 2 additions & 1 deletion ui/src/app/asset/assets.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" md-on-select="vm.grid.triggerResize()" label="{{ 'relation.relations' | translate }}">
<tb-relation-table flex
entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.asset}}">
entity-type="{{vm.types.entityType.asset}}"
entity-detail="vm.grid.operatingItem()">
</tb-relation-table>
</md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.grid.isTenantAdmin()" md-on-select="vm.grid.triggerResize()" label="{{ 'audit-log.audit-logs' | translate }}">
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/components/dashboard.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" md-on-select="vm.grid.triggerResize()" label="{{ 'relation.relations' | translate }}">
<tb-relation-table flex
entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.asset}}">
entity-type="{{vm.types.entityType.asset}}"
entity-detail="vm.grid.operatingItem()">
</tb-relation-table>
</md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.grid.isTenantAdmin()" md-on-select="vm.grid.triggerResize()" label="{{ 'audit-log.audit-logs' | translate }}">
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/device/devices.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode" md-on-select="vm.grid.triggerResize()" label="{{ 'relation.relations' | translate }}">
<tb-relation-table flex
entity-id="vm.grid.operatingItem().id.id"
entity-type="{{vm.types.entityType.device}}">
entity-type="{{vm.types.entityType.device}}"
entity-detail="vm.grid.operatingItem()">
</tb-relation-table>
</md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.grid.operatingItem().additionalInfo.gateway" md-on-select="vm.grid.triggerResize()" label="{{ 'extension.extensions' | translate }}">
Expand Down
14 changes: 11 additions & 3 deletions ui/src/app/entity/entity-autocomplete.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,30 @@ export default function EntityAutocomplete($compile, $templateCache, $q, $filter
scope.fetchEntities = function(searchText) {
var deferred = $q.defer();
var limit = 50;
var entities = [];
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
limit += scope.excludeEntityIds.length;
}
var targetType = scope.entityType;
if (targetType == types.aliasEntityType.current_customer) {
targetType = types.entityType.customer;
}

entityService.getEntitiesByNameFilter(targetType, searchText, limit, {ignoreLoading: true}, scope.entitySubtype).then(function success(result) {
if (result) {
if (scope.excludeEntityIds && scope.excludeEntityIds.length) {
var entities = [];
result.forEach(function(entity) {
if (scope.excludeEntityIds.indexOf(entity.id.id) == -1) {
entities.push(entity);
}
});
deferred.resolve(entities);
} else if(((scope.relation.to && (scope.relation.to.entityType == 'DEVICE' || scope.relation.to.entityType == 'ASSET' )) || (scope.relation.from && (scope.relation.from.entityType == 'DEVICE' || scope.relation.from.entityType == 'ASSET' ))) && scope.entityDetail.customerId && scope.entityDetail.customerId.id !='13814000-1dd2-11b2-8080-808080808080' ) {
result.forEach(function(entity) {
if (scope.entityDetail.customerId.id == entity.customerId.id) {
entities.push(entity);
}
});
deferred.resolve(entities);
} else {
deferred.resolve(result);
}
Expand Down Expand Up @@ -200,7 +206,9 @@ export default function EntityAutocomplete($compile, $templateCache, $q, $filter
disabled:'=ngDisabled',
entityType: '=',
entitySubtype: '=?',
excludeEntityIds: '=?'
excludeEntityIds: '=?',
entityDetail: '=',
relation:'='
}
};
}
6 changes: 4 additions & 2 deletions ui/src/app/entity/entity-select.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function EntitySelect($compile, $templateCache) {

scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false;
scope.model = {};

scope.updateView = function () {
if (!scope.disabled) {
var value = ngModelCtrl.$viewValue;
Expand All @@ -46,6 +45,7 @@ export default function EntitySelect($compile, $templateCache) {
ngModelCtrl.$setViewValue(null);
}
}

}

ngModelCtrl.$render = function () {
Expand Down Expand Up @@ -107,7 +107,9 @@ export default function EntitySelect($compile, $templateCache) {
theForm: '=?',
tbRequired: '=?',
disabled:'=ngDisabled',
useAliasEntityTypes: "=?"
useAliasEntityTypes: "=?",
entityDetail:'=',
relation:'='
}
};
}
4 changes: 3 additions & 1 deletion ui/src/app/entity/entity-select.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
ng-disabled="disabled"
tb-required="tbRequired"
entity-type="model.entityType"
ng-model="model.entityId">
ng-model="model.entityId"
entity-detail="entityDetail"
relation="relation">
</tb-entity-autocomplete>
</div>
16 changes: 15 additions & 1 deletion ui/src/app/entity/relation/relation-dialog.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import './relation-dialog.scss';
const js_beautify = beautify.js;

/*@ngInject*/
export default function RelationDialogController($scope, $mdDialog, types, entityRelationService, isAdd, direction, relation, showingCallback) {
export default function RelationDialogController($scope, $mdDialog, types, entityRelationService, isAdd, direction, relation, showingCallback, entityDetail, assetService, deviceService) {

var vm = this;

vm.types = types;
vm.isAdd = isAdd;
vm.direction = direction;
vm.entityDetail = entityDetail;

showingCallback.onShowing = function(scope, element) {
updateEditorSize(element);
Expand Down Expand Up @@ -114,6 +115,19 @@ export default function RelationDialogController($scope, $mdDialog, types, entit
if (valid) {
entityRelationService.saveRelation(vm.relation).then(
function success() {
if((relation.from.entityType == 'DEVICE' || relation.from.entityType == 'ASSET' )&& vm.entityDetail && vm.entityDetail.customerId.id == '13814000-1dd2-11b2-8080-808080808080'){
assetService.getAsset(vm.relation.to.id).then(function success(response){

if(response){
if(relation.to.entityType == 'ASSET' && relation.from.entityType == 'DEVICE'){
deviceService.assignDeviceToCustomer(response.customerId.id,vm.entityDetail.id.id).then();
}else if(relation.to.entityType == 'ASSET' && relation.from.entityType == 'ASSET'){
assetService.assignAssetToCustomer(response.customerId.id,vm.entityDetail.id.id).then();
}

}
});
}
$mdDialog.hide();
}
);
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/entity/relation/relation-dialog.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ <h2 translate>{{ vm.isAdd ? 'relation.add' : 'relation.edit'}}</h2>
ng-disabled="!vm.isAdd"
the-form="theForm"
tb-required="true"
ng-model="vm.targetEntityId">
ng-model="vm.targetEntityId",
entity-detail="vm.entityDetail"
relation="vm.relation">
</tb-entity-select>
<div class="md-caption" style="padding-left: 3px; padding-bottom: 10px; color: rgba(0,0,0,0.57);" translate>relation.additional-info</div>
<div flex class="tb-relation-additional-info-panel" layout="column">
Expand Down
8 changes: 5 additions & 3 deletions ui/src/app/entity/relation/relation-table.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default function RelationTable() {
scope: true,
bindToController: {
entityId: '=',
entityType: '@'
entityType: '@',
entityDetail:'='
},
controller: RelationTableController,
controllerAs: 'vm',
Expand All @@ -46,6 +47,7 @@ function RelationTableController($scope, $q, $mdDialog, $document, $translate, $

let vm = this;


vm.types = types;

vm.direction = vm.types.entitySearchDirection.from;
Expand All @@ -72,7 +74,6 @@ function RelationTableController($scope, $q, $mdDialog, $document, $translate, $
vm.deleteRelations = deleteRelations;
vm.reloadRelations = reloadRelations;
vm.updateRelations = updateRelations;

$scope.$watch("vm.entityId", function(newVal, prevVal) {
if (newVal && !angular.equals(newVal, prevVal)) {
reloadRelations();
Expand Down Expand Up @@ -151,7 +152,8 @@ function RelationTableController($scope, $q, $mdDialog, $document, $translate, $
locals: { isAdd: isAdd,
direction: vm.direction,
relation: relation,
showingCallback: onShowingCallback},
showingCallback: onShowingCallback,
entityDetail:vm.entityDetail},
targetEvent: $event,
fullscreen: true,
skipHide: true,
Expand Down
5 changes: 3 additions & 2 deletions ui/src/app/widget/lib/entity-list-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ function DeviceListWidgetController($rootScope, $scope, $filter, dashboardServic
vm.loadTableData(vm.devicesScope);
}
function loadTableData(scope){
dashboardService.getDashboard($state.params.dashboardId).then(function success(response) {

dashboardService.getDashboard($state.params.dashboardId).then(function success(response) {
if(response){
if (scope === 'tenant') {
assetService.getTenantAssets({limit: 200, textSearch: ''}, true, null, false).
Expand All @@ -266,7 +267,7 @@ function DeviceListWidgetController($rootScope, $scope, $filter, dashboardServic
if(result.data.length > 0){
$scope.showList = true;
angular.forEach(result.data, function(value){
if(value.dataModelObjectId.id == dataObjectId){
if(value.dataModelObjectId && value.dataModelObjectId.id == dataObjectId){
list.push(value);
}
});
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/widget/lib/entity-list-widget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
margin-top: 20%;
}
.div-scroll{
height: 58%;
height: 87%;
}
.dash-cont {
margin-top: -3%
margin-top: 10%
}
.assetWidth{
width: 20%;
Expand Down
9 changes: 1 addition & 8 deletions ui/src/app/widget/lib/entity-list-widget.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
limitations under the License.
-->
<mat-list>
<mat-list-item>
<div ng-if="!showList">
<span class="msg-align">{{ 'widget.entity-list-is-empty' | translate }}</span>
</div>
Expand All @@ -42,13 +40,8 @@
</table>
</md-table-container>
</div>
</mat-list-item>
<mat-divider></mat-divider>
<mat-list-item ng-if="showList">
<md-table-pagination class ="tb-device-container dash-cont" md-limit="query.limit" md-limit-options="[5, 10, 15]"
<md-table-pagination style="position:fixed;" ng-if="showList" md-limit="query.limit" md-limit-options="[5, 10, 15]"
md-page="query.page" md-total="{{entityList.count}}"
md-on-paginate="onPaginate" md-page-select>
</md-table-pagination>
</mat-list-item>
</mat-list>

0 comments on commit eaca999

Please sign in to comment.