Skip to content

Commit

Permalink
[MNOE-978] Remove edit role from local-list
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Seessel committed Mar 27, 2018
1 parent 9cca25d commit 1d14af9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@App.directive('mnoeOrganizationsList', ($filter, $translate, MnoeOrganizations, MnoeAdminConfig, MnoeCurrentUser) ->
restrict: 'E'
scope: {
list: '=',
user: '<',
customizations: '<'
fields: '<',
searchParams: '<',
bindings: '<'
},
templateUrl: 'app/components/mnoe-organizations-list/mnoe-organizations-list.html',
link: (scope, elem) ->
Expand Down Expand Up @@ -74,7 +74,7 @@
{ header: locale['mnoe_admin_panel.dashboard.organization.widget.list.table.currency'],
attr:'financial_metrics.currency', doNotSort: true, style: width: '110px'}])

scope.organizations.fields = scope.organizations.fields.concat(scope.customizations.fields) if scope.customizations.fields
scope.organizations.fields = scope.organizations.fields.concat(scope.fields) if scope.fields
)

# Smart table callback
Expand All @@ -89,12 +89,19 @@
# Fetch organisations
fetchOrganizations = (limit, offset, sort = 'created_at') ->
scope.organizations.loading = true
scope.customizations.getOrganizations(limit, offset, sort)
.then((response) ->
scope.organizations.totalItems = response.headers('x-total-count')
scope.organizations.list = response.data
)
.finally(() -> scope.organizations.loading = false )
MnoeCurrentUser.getUser().then( ->
params = if MnoeAdminConfig.isAccountManagerEnabled()
{sub_tenant_id: MnoeCurrentUser.user.mnoe_sub_tenant_id, account_manager_id: MnoeCurrentUser.user.id}
else
{}
params = angular.extend({}, params, scope.searchParams) if scope.searchParams
return MnoeOrganizations.list(limit, offset, sort, params).then(
(response) ->
scope.organizations.totalItems = response.headers('x-total-count')
scope.organizations.list = response.data
).finally(-> scope.organizations.loading = false)
)


displayCurrentState = () ->
setAllOrganizationsList()
Expand Down Expand Up @@ -123,7 +130,7 @@
search = scope.organizations.search.toLowerCase()
terms = {'name.like': "%#{search}%"}
# Custom search parameters are given to the directive. E.g. when we only want to search orgs of a particular user.
params = scope.customizations.searchParams || {}
params = scope.searchParams || {}
MnoeOrganizations.search(terms, params).then(
(response) ->
scope.organizations.totalItems = response.headers('x-total-count')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
is-loading="organizations.loading"
fields="organizations.fields"
pipe="pipe(tableState)"
bindings="customizations.bindings">
bindings="bindings">
</mno-sortable-table>
</mno-widget-body>
<mno-widget-footer ng-show="organizations.list && !searchMode">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,6 @@
else
setSearchOrganizationsList()

scope.editRole = (organization) ->
# Keep track of old roles when editing organization's roles.
organization.beforeEditRole = organization.role
organization.editMode = true

scope.exitEditRole = (organization) ->
organization.role = organization.beforeEditRole
organization.editMode = false

scope.updateUserRole = (organization, user) ->
user.isUpdatingRole = true
# The role must be set on the user for #updateUserRole.
user.role = organization.role
MnoeUsers.updateUserRole(organization, user).then(
() ->
$translate(UserRoles.keyFromRole(user.role)).then((tls) ->
toastr.success('mnoe_admin_panel.dashboard.users.widget.local_list.role_update_success', {extraData: {user: "#{user.email}", role: tls}})
)
(error) ->
organization.role = organization.beforeEditRole
toastr.error('mnoe_admin_panel.dashboard.users.widget.local_list.role_update_error')
MnoErrorsHandler.processServerError(error)
).finally( () ->
# So that the organization/user reverts back to non-editing view.
organization.beforeEditRole = null
organization.isUpdatingRole = false
organization.editMode = false
)

scope.$watch('list', (newVal) ->
if newVal
displayNormalState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<tr>
<th translate>mnoe_admin_panel.dashboard.organization.widget.local_list.search_organizations.table.name</th>
<th style="width: 100px;" translate>mnoe_admin_panel.dashboard.organization.widget.local_list.search_organizations.table.created_at</th>
<th style="width: 130px;" translate>mnoe_admin_panel.dashboard.organization.widget.local_list.search_organizations.table.role</th>
</tr>
</thead>
<tbody>
Expand All @@ -22,15 +21,6 @@
</a>
</td>
<td>{{organization.created_at | date: 'dd/MM/yyyy'}}</td>
<td>
<select ng-show="organization.editMode" ng-model="organization.role" ng-options="role.value as role.translatedLabel for role in userRoles.availableRolesForOptions"></select>
<span ng-show="organization.isUpdatingRole"><i class="fa fa-spinner fa-pulse fa-fw"></i></span>
<span ng-click="editRole(organization)" ng-hide="organization.editMode">{{ userRoles.keyFromRole(organization.role) | translate }}</span>
<a class="role_edit_link" ng-hide="organization.editMode" ng-click="editRole(organization)"><i class="fa fa-pencil"></i></a>
<a class="role_edit_link" ng-show="organization.editMode" ng-click="updateUserRole(organization, user)"><i class="fa fa-check"></i></a>
<a class="role_edit_link" ng-show="organization.editMode" ng-click="exitEditRole(organization)"><i class="fa fa-times"></i></a>
<span ng-show="vm.isSaving"><i class="fa fa-spinner fa-pulse fa-fw"></i></span>
</td>
</tr>
</tbody>
</table>
Expand Down
15 changes: 1 addition & 14 deletions src/app/views/home/home.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@App.controller 'HomeController', (moment, MnoeUsers, MnoeOrganizations, MnoeInvoices, MnoeAdminConfig, MnoeCurrentUser) ->
@App.controller 'HomeController', (moment, MnoeUsers, MnoeOrganizations, MnoeInvoices, MnoeAdminConfig) ->
'ngInject'
vm = this

Expand Down Expand Up @@ -33,17 +33,4 @@
vm.invoices.outstandingAmount = response.data
) if MnoeAdminConfig.isFinanceEnabled()

vm.orgTableCustomizations = {
getOrganizations: (limit, offset, sort = 'created_at') ->
MnoeCurrentUser.getUser().then( ->
params = {}

if MnoeAdminConfig.isAccountManagerEnabled()
params['sub_tenant_id'] = MnoeCurrentUser.user.mnoe_sub_tenant_id
params['account_manager_id'] = MnoeCurrentUser.user.id

MnoeOrganizations.list(limit, offset, sort, params)
)
}

return
2 changes: 1 addition & 1 deletion src/app/views/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<div class="row">
<div class="col-md-12">
<mnoe-organizations-list customizations="vm.orgTableCustomizations"></mnoe-organizations-list>
<mnoe-organizations-list></mnoe-organizations-list>
</div>
</div>
<div class="row">
Expand Down
16 changes: 5 additions & 11 deletions src/app/views/user/user.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@App.controller 'UserController', ($stateParams, MnoeUsers, UserRoles, $translate, toastr, MnoErrorsHandler, MnoeOrganizations) ->
@App.controller 'UserController', ($stateParams, MnoeUsers, UserRoles, $translate, toastr, MnoErrorsHandler) ->
'ngInject'
vm = this
vm.user = {}
vm.orgTableCustomizations = {}
vm.orgSearchParams = { 'where[users.id]': $stateParams.userId }

# Get the user
MnoeUsers.get($stateParams.userId).then(
(response) ->
Expand All @@ -12,10 +13,8 @@
if phone && countryCode
vm.user.phone = '+' + countryCode + phone

vm.orgTableCustomizations.searchParams = { 'where[users.id]': vm.user.id }

# These bindings are so that we can add additional fields with functionality to the organization table.
vm.orgTableCustomizations.bindings = {
vm.orgTableBindings = {
userRoles: UserRoles
user: vm.user

Expand Down Expand Up @@ -53,7 +52,7 @@

$translate('mnoe_admin_panel.dashboard.organization.widget.local_list.search_organizations.table.role')
.then((translation) ->
vm.orgTableCustomizations.fields = [
vm.orgTableFields= [
{
header: translation
style: {
Expand Down Expand Up @@ -82,9 +81,4 @@
]
)

vm.orgTableCustomizations.getOrganizations = (limit, offset, sort = 'created_at') ->
return unless vm.user['id']
params = vm.orgTableCustomizations.searchParams
MnoeOrganizations.list(limit, offset, sort, params)

return
4 changes: 2 additions & 2 deletions src/app/views/user/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ <h3 ng-show="!vm.user.name && !vm.user.surname" class="panel-title">{{::vm.user.
<mnoe-impersonate-button wrapper-class-names="col-sm-4 col-sm-offset-4" btn-class-names="btn btn-primary center-block" user="vm.user"></mnoe-impersonate-button>
<div class="col-sm-12 top-buffer-2">
<mnoe-organizations-list
user="vm.user"
fields="vm.orgTableFields"
customizations="vm.orgTableCustomizations">
search-params="vm.orgSearchParams"
bindings="vm.orgTableBindings"
</mnoe-organizations-list>
</div>
</div>
Expand Down

0 comments on commit 1d14af9

Please sign in to comment.