Feature custom icon in Custom icon init implementation.
This commit is contained in:
		
							parent
							
								
									04005f203e
								
							
						
					
					
						commit
						a3c28e9db4
					
				@ -14,8 +14,9 @@
 | 
				
			|||||||
/// limitations under the License.
 | 
					/// limitations under the License.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
 | 
					import { ChangeDetectionStrategy, Component, Input, OnInit, OnChanges, SimpleChanges } from '@angular/core';
 | 
				
			||||||
import { MenuSection } from '@core/services/menu.models';
 | 
					import { MenuSection } from '@core/services/menu.models';
 | 
				
			||||||
 | 
					import { tbImageIcon } from '@shared/models/custom-menu.models';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'tb-menu-link',
 | 
					  selector: 'tb-menu-link',
 | 
				
			||||||
@ -23,14 +24,27 @@ import { MenuSection } from '@core/services/menu.models';
 | 
				
			|||||||
  styleUrls: ['./menu-link.component.scss'],
 | 
					  styleUrls: ['./menu-link.component.scss'],
 | 
				
			||||||
  changeDetection: ChangeDetectionStrategy.OnPush
 | 
					  changeDetection: ChangeDetectionStrategy.OnPush
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class MenuLinkComponent implements OnInit {
 | 
					export class MenuLinkComponent implements OnInit, OnChanges {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Input() section: MenuSection;
 | 
					  @Input() section: MenuSection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  isCustomIcon: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor() {
 | 
					  constructor() {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngOnInit() {
 | 
					  ngOnInit() {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ngOnChanges(changes: SimpleChanges): void {
 | 
				
			||||||
 | 
					    for (const propName of Object.keys(changes)) {
 | 
				
			||||||
 | 
					      const change = changes[propName];
 | 
				
			||||||
 | 
					      if (change.currentValue !== change.previousValue) {
 | 
				
			||||||
 | 
					        if (propName === 'section' && change.currentValue) {
 | 
				
			||||||
 | 
					          this.isCustomIcon = tbImageIcon(change.currentValue.icon);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -37,6 +37,10 @@
 | 
				
			|||||||
          [disabled]="disabled"
 | 
					          [disabled]="disabled"
 | 
				
			||||||
          #matButton
 | 
					          #matButton
 | 
				
			||||||
          (click)="openIconPopup($event, matButton)">
 | 
					          (click)="openIconPopup($event, matButton)">
 | 
				
			||||||
 | 
					    @if (!isCustomIcon) {
 | 
				
			||||||
      <tb-icon matButtonIcon>{{materialIconFormGroup.get('icon').value}}</tb-icon>
 | 
					      <tb-icon matButtonIcon>{{materialIconFormGroup.get('icon').value}}</tb-icon>
 | 
				
			||||||
 | 
					    } @else {
 | 
				
			||||||
 | 
					      <img class="mat-icon" alt="icon" [src]="materialIconFormGroup.get('icon').value | image | async">
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  </button>
 | 
					  </button>
 | 
				
			||||||
</ng-template>
 | 
					</ng-template>
 | 
				
			||||||
 | 
				
			|||||||
@ -36,6 +36,7 @@ import { TbPopoverService } from '@shared/components/popover.service';
 | 
				
			|||||||
import { MaterialIconsComponent } from '@shared/components/material-icons.component';
 | 
					import { MaterialIconsComponent } from '@shared/components/material-icons.component';
 | 
				
			||||||
import { MatButton } from '@angular/material/button';
 | 
					import { MatButton } from '@angular/material/button';
 | 
				
			||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
 | 
					import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
 | 
				
			||||||
 | 
					import { tbImageIcon } from '@shared/models/custom-menu.models';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'tb-material-icon-select',
 | 
					  selector: 'tb-material-icon-select',
 | 
				
			||||||
@ -71,6 +72,12 @@ export class MaterialIconSelectComponent extends PageComponent implements OnInit
 | 
				
			|||||||
  @coerceBoolean()
 | 
					  @coerceBoolean()
 | 
				
			||||||
  iconClearButton = false;
 | 
					  iconClearButton = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Input()
 | 
				
			||||||
 | 
					  @coerceBoolean()
 | 
				
			||||||
 | 
					  allowedCustomIcon = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  isCustomIcon = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private requiredValue: boolean;
 | 
					  private requiredValue: boolean;
 | 
				
			||||||
  get required(): boolean {
 | 
					  get required(): boolean {
 | 
				
			||||||
    return this.requiredValue;
 | 
					    return this.requiredValue;
 | 
				
			||||||
@ -131,11 +138,13 @@ export class MaterialIconSelectComponent extends PageComponent implements OnInit
 | 
				
			|||||||
    this.materialIconFormGroup.patchValue(
 | 
					    this.materialIconFormGroup.patchValue(
 | 
				
			||||||
      { icon: this.modelValue }, {emitEvent: false}
 | 
					      { icon: this.modelValue }, {emitEvent: false}
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					    this.defineIconType(value);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private updateModel() {
 | 
					  private updateModel() {
 | 
				
			||||||
    const icon: string = this.materialIconFormGroup.get('icon').value;
 | 
					    const icon: string = this.materialIconFormGroup.get('icon').value;
 | 
				
			||||||
    if (this.modelValue !== icon) {
 | 
					    if (this.modelValue !== icon) {
 | 
				
			||||||
 | 
					      this.defineIconType(icon);
 | 
				
			||||||
      this.modelValue = icon;
 | 
					      this.modelValue = icon;
 | 
				
			||||||
      this.propagateChange(this.modelValue);
 | 
					      this.propagateChange(this.modelValue);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -169,7 +178,8 @@ export class MaterialIconSelectComponent extends PageComponent implements OnInit
 | 
				
			|||||||
        this.viewContainerRef, MaterialIconsComponent, 'left', true, null,
 | 
					        this.viewContainerRef, MaterialIconsComponent, 'left', true, null,
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          selectedIcon: this.materialIconFormGroup.get('icon').value,
 | 
					          selectedIcon: this.materialIconFormGroup.get('icon').value,
 | 
				
			||||||
          iconClearButton: this.iconClearButton
 | 
					          iconClearButton: this.iconClearButton,
 | 
				
			||||||
 | 
					          allowedCustomIcon: this.allowedCustomIcon,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {},
 | 
					        {},
 | 
				
			||||||
        {}, {}, true);
 | 
					        {}, {}, true);
 | 
				
			||||||
@ -188,4 +198,10 @@ export class MaterialIconSelectComponent extends PageComponent implements OnInit
 | 
				
			|||||||
    this.materialIconFormGroup.get('icon').patchValue(null, {emitEvent: true});
 | 
					    this.materialIconFormGroup.get('icon').patchValue(null, {emitEvent: true});
 | 
				
			||||||
    this.cd.markForCheck();
 | 
					    this.cd.markForCheck();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private defineIconType(icon: string) {
 | 
				
			||||||
 | 
					    if (this.allowedCustomIcon) {
 | 
				
			||||||
 | 
					      this.isCustomIcon = tbImageIcon(icon);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,15 @@
 | 
				
			|||||||
-->
 | 
					-->
 | 
				
			||||||
<div class="tb-material-icons-panel">
 | 
					<div class="tb-material-icons-panel">
 | 
				
			||||||
  <div *ngIf="showTitle" class="tb-material-icons-title" translate>icon.icons</div>
 | 
					  <div *ngIf="showTitle" class="tb-material-icons-title" translate>icon.icons</div>
 | 
				
			||||||
 | 
					  @if (allowedCustomIcon) {
 | 
				
			||||||
 | 
					    <div class="flex w-full flex-row items-center justify-end">
 | 
				
			||||||
 | 
					      <tb-toggle-select [(ngModel)]="isCustomIcon" [ngModelOptions]="{standalone: true}" (ngModelChange)="selectedIcon = null">
 | 
				
			||||||
 | 
					        <tb-toggle-option [value]="false">{{ 'resource.system' | translate }}</tb-toggle-option>
 | 
				
			||||||
 | 
					        <tb-toggle-option [value]="true">{{ 'icon.custom' | translate }}</tb-toggle-option>
 | 
				
			||||||
 | 
					      </tb-toggle-select>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  @if (!isCustomIcon) {
 | 
				
			||||||
    <mat-form-field class="tb-material-icons-search tb-inline-field" appearance="outline" subscriptSizing="dynamic">
 | 
					    <mat-form-field class="tb-material-icons-search tb-inline-field" appearance="outline" subscriptSizing="dynamic">
 | 
				
			||||||
      <mat-icon matPrefix>search</mat-icon>
 | 
					      <mat-icon matPrefix>search</mat-icon>
 | 
				
			||||||
      <input matInput [formControl]="searchIconControl" placeholder="{{ 'icon.search-icon' | translate }}"/>
 | 
					      <input matInput [formControl]="searchIconControl" placeholder="{{ 'icon.search-icon' | translate }}"/>
 | 
				
			||||||
@ -37,7 +46,7 @@
 | 
				
			|||||||
                  class="tb-select-icon-button"
 | 
					                  class="tb-select-icon-button"
 | 
				
			||||||
                  mat-raised-button
 | 
					                  mat-raised-button
 | 
				
			||||||
                  color="primary"
 | 
					                  color="primary"
 | 
				
			||||||
                (click)="selectIcon(icon)"
 | 
					                  (click)="selectIcon(icon.name)"
 | 
				
			||||||
                  matTooltip="{{ icon.displayName }}"
 | 
					                  matTooltip="{{ icon.displayName }}"
 | 
				
			||||||
                  matTooltipPosition="above"
 | 
					                  matTooltipPosition="above"
 | 
				
			||||||
                  type="button">
 | 
					                  type="button">
 | 
				
			||||||
@ -46,7 +55,7 @@
 | 
				
			|||||||
          <button *ngIf="icon.name !== selectedIcon"
 | 
					          <button *ngIf="icon.name !== selectedIcon"
 | 
				
			||||||
                  class="tb-select-icon-button"
 | 
					                  class="tb-select-icon-button"
 | 
				
			||||||
                  mat-button
 | 
					                  mat-button
 | 
				
			||||||
                (click)="selectIcon(icon)"
 | 
					                  (click)="selectIcon(icon.name)"
 | 
				
			||||||
                  matTooltip="{{ icon.displayName }}"
 | 
					                  matTooltip="{{ icon.displayName }}"
 | 
				
			||||||
                  matTooltipPosition="above"
 | 
					                  matTooltipPosition="above"
 | 
				
			||||||
                  type="button">
 | 
					                  type="button">
 | 
				
			||||||
@ -75,4 +84,17 @@
 | 
				
			|||||||
        {{ 'action.show-more' | translate }}
 | 
					        {{ 'action.show-more' | translate }}
 | 
				
			||||||
      </button>
 | 
					      </button>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					  } @else {
 | 
				
			||||||
 | 
					    <tb-gallery-image-input class="min-w-[520px]"
 | 
				
			||||||
 | 
					                            [(ngModel)]="selectedIcon">
 | 
				
			||||||
 | 
					    </tb-gallery-image-input>
 | 
				
			||||||
 | 
					    <div class="tb-material-icons-panel-buttons">
 | 
				
			||||||
 | 
					      <span class="flex-1"></span>
 | 
				
			||||||
 | 
					      <button class="tb-material-icons-show-more" mat-button color="primary"
 | 
				
			||||||
 | 
					              [disabled]="!selectedIcon"
 | 
				
			||||||
 | 
					              (click)="selectIcon(selectedIcon)">
 | 
				
			||||||
 | 
					        {{ 'action.set' | translate }}
 | 
				
			||||||
 | 
					      </button>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
				
			|||||||
@ -37,6 +37,7 @@ import { TbPopoverComponent } from '@shared/components/popover.component';
 | 
				
			|||||||
import { BreakpointObserver } from '@angular/cdk/layout';
 | 
					import { BreakpointObserver } from '@angular/cdk/layout';
 | 
				
			||||||
import { MediaBreakpoints } from '@shared/models/constants';
 | 
					import { MediaBreakpoints } from '@shared/models/constants';
 | 
				
			||||||
import { coerceBoolean } from '@shared/decorators/coercion';
 | 
					import { coerceBoolean } from '@shared/decorators/coercion';
 | 
				
			||||||
 | 
					import { tbImageIcon } from '@shared/models/custom-menu.models';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'tb-material-icons',
 | 
					  selector: 'tb-material-icons',
 | 
				
			||||||
@ -61,6 +62,10 @@ export class MaterialIconsComponent extends PageComponent implements OnInit {
 | 
				
			|||||||
  @coerceBoolean()
 | 
					  @coerceBoolean()
 | 
				
			||||||
  showTitle = true;
 | 
					  showTitle = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Input()
 | 
				
			||||||
 | 
					  @coerceBoolean()
 | 
				
			||||||
 | 
					  allowedCustomIcon = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Input()
 | 
					  @Input()
 | 
				
			||||||
  popover: TbPopoverComponent;
 | 
					  popover: TbPopoverComponent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -71,6 +76,8 @@ export class MaterialIconsComponent extends PageComponent implements OnInit {
 | 
				
			|||||||
  showAllSubject = new BehaviorSubject<boolean>(false);
 | 
					  showAllSubject = new BehaviorSubject<boolean>(false);
 | 
				
			||||||
  searchIconControl: UntypedFormControl;
 | 
					  searchIconControl: UntypedFormControl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  isCustomIcon = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  iconsRowHeight = 48;
 | 
					  iconsRowHeight = 48;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  iconsPanelHeight: string;
 | 
					  iconsPanelHeight: string;
 | 
				
			||||||
@ -122,14 +129,15 @@ export class MaterialIconsComponent extends PageComponent implements OnInit {
 | 
				
			|||||||
      map((data) => data.iconRows),
 | 
					      map((data) => data.iconRows),
 | 
				
			||||||
      share()
 | 
					      share()
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					    this.isCustomIcon = tbImageIcon(this.selectedIcon)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  clearSearch() {
 | 
					  clearSearch() {
 | 
				
			||||||
    this.searchIconControl.patchValue('', {emitEvent: true});
 | 
					    this.searchIconControl.patchValue('', {emitEvent: true});
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  selectIcon(icon: MaterialIcon) {
 | 
					  selectIcon(icon: string) {
 | 
				
			||||||
    this.iconSelected.emit(icon.name);
 | 
					    this.iconSelected.emit(icon);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  clearIcon() {
 | 
					  clearIcon() {
 | 
				
			||||||
 | 
				
			|||||||
@ -9507,6 +9507,7 @@
 | 
				
			|||||||
    "icon": {
 | 
					    "icon": {
 | 
				
			||||||
        "icon": "Icon",
 | 
					        "icon": "Icon",
 | 
				
			||||||
        "icons": "Icons",
 | 
					        "icons": "Icons",
 | 
				
			||||||
 | 
					        "custom": "Custom",
 | 
				
			||||||
        "select-icon": "Select icon",
 | 
					        "select-icon": "Select icon",
 | 
				
			||||||
        "material-icons": "Material icons",
 | 
					        "material-icons": "Material icons",
 | 
				
			||||||
        "show-all": "Show all icons",
 | 
					        "show-all": "Show all icons",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user