(()=>{function e(n,t,i,r,l,s,a,e,o,u,c){var g=this,f=[];function d(e){return n.refreshLoading=!0,r.list(_.assign({onlyDevices:!0},e)).then(h).finally(function(){n.refreshLoading=!1})}function h(e){return n.users&&!n.refreshLoading||(n.users=[],g.users=n.users),e.forEach(function(e){n.users.push(e)}),n.paging=e.paging,n.users.length}function p(e){return r.detail(e).then(a.getResData).then(_.partial(_.assign,e))}_.assign(g,{filtering:{applied:!1,filters:{}},applyFilters:function(){d(g.filtering.filters).then(function(){g.filtering.applied=!0})},clearFilters:function(){g.filtering.filters={},d(g.filtering.filters).then(function(){g.filtering.applied=!1})},isAnyFilterSelected:function(){return 0<_.get(g.filtering.filters,"username","").length}}),_.assign(n,{enabledIcon:function(e){return e.enabled?"check-circle":"minus-circle"},enabledClass:function(e){return e.enabled?"text-success":"text-danger"},enabledTooltip:function(e){return e.enabled?"Enabled":"Disabled"},toggleUserStatus:function(e){var n=e.enabled?o("User enabled."):o("User disabled.");r.save(e).then(function(){return i.success(n)})},groups:r.groups,navigateToDetail:function(e){t.path("/deviceusers/".concat(e.id))},onClickDelete:function(e){s({title:o("Delete user"),body:u.getString('You are about to delete user "{{userName}}". Do you want to proceed?',e),status:"danger",labels:{ok:o("Delete")}}).then(angular.bind(r,r.remove,e)).then(angular.bind(a,a.removeFromList,n.users,e)).then(function(){i.success(o("User deleted."))})},refresh:function(){n.refreshLoading=!0,n.paging.refresh().then(h).finally(function(){n.refreshLoading=!1})},loadNext:function(){n.paging.loading=!0,n.paging.next().then(h).finally(function(){n.paging.loading=!1})},mapRolesForUser:_.memoize(function(e){return _.map(e,"group")}),globalRolesAvailable:function(e){return _.get(e,"_owner._globalRoles",f)},onChangeRoles:function(e,n){return l.global.updateGroups(e,_.map(n,"id")).then(c.triggerEvent("dmCredentialManagement",{action:"assignRole",name:"role"})).then(_.partial(p,e))},getSubtitle:function(){return u.getPlural(n.users?n.users.length:0,"1 device credentials","{{$count}} device credentials",{})},getUsers:d}),l.global.list({pageSize:1e3}).then(function(e){f=e,n.globalRoles=f}),d()}e.$inject=["$scope","$location","c8yAlert","c8yUser","c8yRoles","c8yModal","c8yBase","c8yTitle","gettext","gettextCatalog","c8yGainsightService"],angular.module("c8y.parts.deviceUsers").controller("deviceUserListCtrl",e)})();