feature-libs/organization/administration/components/shared/detail/disable-info/disable-info.component.ts
| host | { |
| selector | cx-org-disable-info |
| templateUrl | ./disable-info.component.html |
Properties |
Methods |
Inputs |
Accessors |
constructor(itemService: ItemService<T>, disableInfoService: DisableInfoService<T>)
|
|||||||||
|
Parameters :
|
| displayCustomInfo | |
Type : boolean
|
|
Default value : false
|
|
|
Flag to enable display custom message(s) even if no condition has been met |
|
| displayInfoConfig | |
Type : literal type
|
|
|
To configure the messages to display and override defaultMessageConfig |
|
| i18nRoot | |
Type : string
|
|
|
The localization of messages is based on the i18n root. Messages are concatenated to the root, such as:
|
|
| displayDisabledCreate | ||||||
displayDisabledCreate(item: T)
|
||||||
|
Parameters :
Returns :
any
|
| displayDisabledDisable | ||||||
displayDisabledDisable(item: T)
|
||||||
|
Parameters :
Returns :
any
|
| displayDisabledEdit | ||||||
displayDisabledEdit(item: T)
|
||||||
|
Parameters :
Returns :
any
|
| displayDisabledEnable | ||||||
displayDisabledEnable(item: T)
|
||||||
|
Parameters :
Returns :
any
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| current$ |
Type : Observable<T>
|
Default value : this.itemService.current$
|
|
resolves the current item. |
| displayCustomInfo |
Default value : false
|
Decorators :
@Input()
|
|
Flag to enable display custom message(s) even if no condition has been met |
| displayInfoConfig |
Type : literal type
|
Decorators :
@Input()
|
|
To configure the messages to display and override defaultMessageConfig |
| i18nRoot |
Type : string
|
Decorators :
@Input()
|
|
The localization of messages is based on the i18n root. Messages are concatenated to the root, such as:
|
| iconTypes |
Default value : ICON_TYPE
|
| defaultInfoConfig |
getdefaultInfoConfig()
|
import { Component, Input, OnInit } from '@angular/core';
import { ICON_TYPE } from '@spartacus/storefront';
import { Observable } from 'rxjs';
import { ItemService } from '../../item.service';
import { BaseItem } from '../../organization.model';
import { DisableInfoService } from './disable-info.service';
@Component({
selector: 'cx-org-disable-info',
templateUrl: './disable-info.component.html',
host: { class: 'content-wrapper' },
})
export class DisableInfoComponent<T extends BaseItem> implements OnInit {
/**
* The localization of messages is based on the i18n root. Messages are
* concatenated to the root, such as:
*
* `[i18nRoot].info.disabledEdit`
*/
@Input() i18nRoot: string;
/**
* To configure the messages to display and override defaultMessageConfig
*/
@Input() displayInfoConfig: {
disabledCreate?: boolean;
disabledEdit?: boolean;
disabledEnable?: boolean;
disabledDisable?: boolean;
};
/**
* Flag to enable display custom message(s) even if no condition has been met
*/
@Input() displayCustomInfo = false;
/**
* resolves the current item.
*/
current$: Observable<T> = this.itemService.current$;
iconTypes = ICON_TYPE;
constructor(
protected itemService: ItemService<T>,
protected disableInfoService: DisableInfoService<T>
) {}
protected get defaultInfoConfig() {
return {
disabledCreate: false,
disabledEdit: true,
disabledEnable: true,
disabledDisable: false,
};
}
ngOnInit() {
this.displayInfoConfig = {
...this.defaultInfoConfig,
...this.displayInfoConfig,
};
}
displayDisabledCreate(item: T) {
return (
this.displayInfoConfig?.disabledCreate &&
this.disableInfoService.isItemDisabled(item)
);
}
displayDisabledEdit(item: T) {
return (
this.displayInfoConfig?.disabledEdit &&
this.disableInfoService.isItemDisabled(item)
);
}
displayDisabledEnable(item: T) {
return (
this.displayInfoConfig?.disabledEnable &&
this.disableInfoService.isParentDisabled(item)
);
}
displayDisabledDisable(item: T) {
return (
this.displayInfoConfig?.disabledDisable &&
this.disableInfoService.isRootUnit(item)
);
}
}
<ng-container *ngIf="current$ | async as item">
<section
*ngIf="
displayDisabledCreate(item) ||
displayDisabledEdit(item) ||
displayDisabledEnable(item) ||
displayDisabledDisable(item) ||
displayCustomInfo
"
>
<cx-icon [type]="iconTypes.INFO"></cx-icon>
<ul>
<li *ngIf="displayDisabledEnable(item)">
{{ i18nRoot + '.info.disabledEnable' | cxTranslate }}
</li>
<li *ngIf="displayDisabledCreate(item)">
{{ i18nRoot + '.info.disabledCreate' | cxTranslate }}
</li>
<li *ngIf="displayDisabledEdit(item)">
{{ i18nRoot + '.info.disabledEdit' | cxTranslate }}
</li>
<li *ngIf="displayDisabledDisable(item)">
{{ i18nRoot + '.info.disabledDisable' | cxTranslate }}
</li>
<ng-content></ng-content>
</ul>
</section>
</ng-container>