File

feature-libs/organization/administration/components/user-group/users/user-group-user-list.service.ts

Extends

SubListService

Index

Properties
Methods

Constructor

constructor(tableService: TableService, userGroupService: UserGroupService, userService: B2BUserService)
Parameters :
Name Type Optional
tableService TableService No
userGroupService UserGroupService No
userService B2BUserService No

Methods

assign
assign(userGroupCode: string, customerId: string)
Inherited from SubListService
Defined in SubListService:47

Assign user to the user group.

Parameters :
Name Type Optional
userGroupCode string No
customerId string No
Protected load
load(pagination: PaginationModel, code: string)
Inherited from ListService
Defined in ListService:36

Loads all b2b users.

Parameters :
Name Type Optional Description
pagination PaginationModel No
code string No

The user group code.

Returns : Observable<EntitiesModel<B2BUser>>
unassign
unassign(userGroupCode: string, customerId: string)
Inherited from SubListService
Defined in SubListService:59

Unassigns the user from the user group.

Parameters :
Name Type Optional
userGroupCode string No
customerId string No
unassignAllMembers
unassignAllMembers(userGroupCode: string)
Parameters :
Name Type Optional
userGroupCode string No
Protected filterSelected
filterSelected(list: EntitiesModel<T>)
Inherited from SubListService
Defined in SubListService:43

As we can't filter with the backend API, we do this client side.

Parameters :
Name Type Optional
list EntitiesModel<T> No
Returns : EntitiesModel<T>
getData
getData(...args: any)
Inherited from ListService
Defined in ListService:93

Loads the data by delegating to the load method, which must be implemented in specific implementations of this abstract class.

The load method is streamed from the pagination$ stream, which is initialized with default pagination and structure drive properties.

Parameters :
Name Type Optional
args any No
getStructure
getStructure()
Inherited from ListService
Defined in ListService:112

Returns the TableStructure for the OrganizationTableType.

The table structure is build by the TableService based on configuration. The defaultTableStructure is deep merged as a fallback configuration.

Returns : Observable<TableStructure>
hasGhostData
hasGhostData(data: EntitiesModel<T>)
Inherited from ListService
Defined in ListService:143

Indicates whether the given data equals to the ghost data.

This is used to validate the initial loading state, which is different from the loading state; the loading state occurs while sorting and paginating, where as the initial loading state only happens at the very first load.

Parameters :
Name Type Optional
data EntitiesModel<T> No
Returns : boolean
key
key()
Inherited from ListService
Defined in ListService:82

Indicates the unique key for the item model. The key is different for various organizations, i.e. budget.code, user.uid.

Returns : string
sort
sort(pagination: P, _obsoleteSort?: string)
Inherited from ListService
Defined in ListService:131

Updates the sort code for the PaginationModel.

The currentPage is reset to 0.

Parameters :
Name Type Optional
pagination P No
_obsoleteSort string Yes
Returns : void
view
view(pagination: P, nextPage?: number)
Inherited from ListService
Defined in ListService:122

Views the page.

Parameters :
Name Type Optional
pagination P No
nextPage number Yes
Returns : void

Properties

Protected _domainType
Default value : OrganizationTableType.USER
Inherited from ListService
Defined in ListService:19
Protected tableType
Default value : OrganizationTableType.USER_GROUP_USERS
Inherited from ListService
Defined in ListService:18
Protected defaultTableStructure
Type : ResponsiveTableConfiguration
Default value : { options: { layout: TableLayout.VERTICAL }, }
Inherited from ListService
Defined in ListService:19

The default table structure for sub lists is only showing tables with vertical layout.

Protected ghostData
Default value : { values: new Array(3) } as EntitiesModel<T>
Inherited from ListService
Defined in ListService:26
notification$
Type : Subject<any>
Default value : new Subject()
Inherited from ListService
Defined in ListService:42
Protected pagination$
Type : BehaviorSubject<P>
Default value : new BehaviorSubject({ pageSize: 10, } as any as P)
Inherited from ListService
Defined in ListService:72

The pagination state of the listing.

The pagination size defaults to 10, but can be overridden by the table configuration for each entity type.

import { Injectable } from '@angular/core';
import { EntitiesModel, PaginationModel, B2BUser } from '@spartacus/core';
import {
  UserGroup,
  UserGroupService,
  B2BUserService,
  OrganizationItemStatus,
} from '@spartacus/organization/administration/core';
import { TableService } from '@spartacus/storefront';
import { Observable } from 'rxjs';
import { SubListService } from '../../shared/sub-list/sub-list.service';
import { OrganizationTableType } from '../../shared/organization.model';

@Injectable({
  providedIn: 'root',
})
export class UserGroupUserListService extends SubListService<B2BUser> {
  protected tableType = OrganizationTableType.USER_GROUP_USERS;
  protected _domainType = OrganizationTableType.USER;

  constructor(
    protected tableService: TableService,
    protected userGroupService: UserGroupService,
    protected userService: B2BUserService
  ) {
    super(tableService);
  }

  /**
   *
   * @override
   * Loads all b2b users.
   *
   * @param code The user group code.
   */
  protected load(
    pagination: PaginationModel,
    code: string
  ): Observable<EntitiesModel<B2BUser>> {
    return this.userGroupService.getAvailableOrgCustomers(code, pagination);
  }

  /**
   * @override
   * Assign user to the user group.
   */
  assign(
    userGroupCode: string,
    customerId: string
  ): Observable<OrganizationItemStatus<B2BUser>> {
    this.userGroupService.assignMember(userGroupCode, customerId);
    return this.userService.getLoadingStatus(customerId);
  }

  /**
   * @override
   * Unassigns the user from the user group.
   */
  unassign(
    userGroupCode: string,
    customerId: string
  ): Observable<OrganizationItemStatus<B2BUser>> {
    this.userGroupService.unassignMember(userGroupCode, customerId);
    return this.userService.getLoadingStatus(customerId);
  }

  unassignAllMembers(
    userGroupCode: string
  ): Observable<OrganizationItemStatus<UserGroup>> {
    this.userGroupService.unassignAllMembers(userGroupCode);
    return this.userGroupService.getLoadingStatus(userGroupCode);
  }
}

result-matching ""

    No results matching ""