أكواد جاهزة لاستعراض مربعات حوار (Dialogs)

<strong [matTooltip]="'BUTTONS.VIEW_DETAILS' | translate"
(click)="openViewDepartmentDialog(data.department)"
class="cursor-pointer d-inline-block">
{{lang === 'ar'? data.department.ar_name :
 data.department.en_name}}</strong>

  permissions: any[] = this.localStorageService.getWithDecryption('privilege').permissions;
  //-----------------------------------------------------------------------------------
  // أذونات الأصول
  public crudPermissionAssets(action: string = 'CREATE'): boolean {
    let table: string = 'ASSETS';

    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === table)?.delete;
      default:
        return false;
    }
  }
  // عرض الأصول
  public openViewAssetDialog(item: Asset | null) {
    let dialogRef;

    if (item?.id) {
      this.assetsService.getOneItem(item.id).subscribe(res => {
        item = res;
        if (this.crudPermissionAssets('READ')) {//AssetsListDialogComponent
          dialogRef = this.dialog.open(ViewAssetDialogComponent, {
            data: item,
            disableClose: true,
            height: '96%',
            width: '98%',
            panelClass: 'full-screen-modal',
          });
        } else {
          this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
        }
        // Check afterClosed exists before subscribing
        if (dialogRef?.afterClosed) {
          dialogRef.afterClosed().subscribe((_item: Asset) => {
            if (_item) {
              if (_item.assigned_to) {
                _item.administrator = this.lang === "ar" ? _item.assigned_to.ar_employee_name : _item.assigned_to.en_employee_name + " (" + _item.assigned_to.employee_id + ")";
              }
            }
          });
        } else {
          console.error('Dialog reference is undefined or invalid.');
        }
      });
    } else {
    }
  }
  //-----------------------------------------------------------------------------------
  // أذونات الفروع
  public crudPermissionBranches(action: string = 'CREATE'): boolean {
    let table = 'BRANCHES_MANAGEMENT';

    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === table)?.delete;
      default:
        return false;
    }
  }

  // عرض الفروع
  public openViewBranchDialog(item: Branch | null) {
    let dialogRef;
    if (item) {
      if (this.crudPermissionBranches('READ')) {
        dialogRef = this.dialog.open(BranchViewDialogComponent, {
          data: item,
          disableClose: true,
          height: '96%',
          width: '98%',
          panelClass: 'full-screen-modal',
        });
      } else {
        this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
      }
    } else {

    }
    dialogRef.afterClosed().subscribe((_item: Branch) => {
      if (_item) {
      }
    });
  }
  //-----------------------------------------------------------------------------------
  // أذونات الأقسام
  public crudPermissionDeparments(action: string = 'CREATE'): boolean {
    let table = 'DEPARTMENTS_MANAGEMENT';
    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === table)?.delete;
      default:
        return false;
    }
  }

  // عرض الأقسام
  public openViewDepartmentDialog(item: Department | null) {
    let dialogRef;
    if (item) {
      if (this.crudPermissionDeparments('READ')) {
        dialogRef = this.dialog.open(ViewDepartmentDialogComponent, {
          data: item
        });
      } else {
        this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
      }
    } else {

    }
    dialogRef.afterClosed().subscribe((_item: Department) => {
      if (_item) {
      }
    });
  }
  //-----------------------------------------------------------------------------------

  // أذونات الموردين
  public crudPermissionSuppliers(action: string = 'CREATE'): boolean {
    let table = 'SUPPLIER_COMPANIES';
    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === table)?.delete;
      default:
        return false;
    }
  }

  // عرض الموردين
  public openViewSupplierDialog(item: SupplierCompany | null) {
    let dialogRef;
    if (item) {
      if (this.crudPermissionSuppliers('READ')) {
        dialogRef = this.dialog.open(ViewSupplierDialogComponent, {
          data: item
        });
      } else {
        this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
      }
    } else {

    }
    dialogRef.afterClosed().subscribe((_item: SupplierCompany) => {
      if (_item) {
      }
    });
  }
  //-----------------------------------------------------------------------------------
  // أذونات العلامة التجارية
  public crudPermissionBrands(action: string = 'CREATE'): boolean {
    let table = 'BRANDS';
    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === table)?.delete;
      default:
        return false;
    }
  }

  // عرض العلامة التجارية
  public openViewBrandDialog(item: Brand | null) {
    let dialogRef;
    if (item) {
      if (this.crudPermissionBrands('READ')) {
        dialogRef = this.dialog.open(ViewBrandDialogComponent, {
          data: item
        });
      } else {
        this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
      }
    } else {

    }
    dialogRef.afterClosed().subscribe((_item: Brand) => {
      if (_item) {
      }
    });
  }
  //-----------------------------------------------------------------------------------
  // أذونات تذاكر الصيانة
  public crudPermission(action: string = 'CREATE'): boolean {
    let table = 'MAINTENANCE_TICKETS';
    switch (action) {
      case 'CREATE':
        return this.permissions.find((res: any) => res.name === this.table)?.create;
      case 'READ':
        return this.permissions.find((res: any) => res.name === this.table)?.widget;
      case 'UPDATE':
        return this.permissions.find((res: any) => res.name === this.table)?.edit;
      case 'DELETE':
        return this.permissions.find((res: any) => res.name === this.table)?.delete;
      default:
        return false;
    }
  }
  // عرض تذاكر الصيانة
  public openViewDialog(item: Maintenance) {
    let dialogRef;
    if (item) {
      if (this.crudPermission('READ')) {
        dialogRef = this.dialog.open(MaintenanceDialogViewComponent, {
          data: item,
          // disableClose: true,
          height: '85%',
          width: '70%',
          panelClass: 'full-screen-modal',
        });
      } else {
        this.snackBarService.warning(this.translateService.instant('ERRORS._ACCESS_DENIED'));
      }
    }
  }




















































 

تعليقات

المشاركات الشائعة من هذه المدونة

ngx-extended-pdf-viewer

how to getting access token for https://fcm.googleapis.com/v1/projects/al-ayahya-co/messages:send for angular and backend nestjs

طريقة تفعيل زر Inline Keyboard في Telegram Bot