Advertisement
Avdluna

MEU DEUS DO CEU

Nov 21st, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, ViewChild, Input, Inject, ChangeDetectionStrategy } from '@angular/core';
  2. import { NgxCroppieComponent } from 'ngx-croppie';
  3. import { CroppieOptions } from 'croppie';
  4. import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material';
  5. import { ImgCropperConfig, ImgCropperEvent } from '@alyle/ui/resizing-cropping-images';
  6. import { LyTheme2, ThemeVariables } from '@alyle/ui';
  7.  
  8. @Component({
  9.   selector: 'app-badge-image-editor',
  10.   templateUrl: './badge-image-editor.component.html',
  11.   changeDetection: ChangeDetectionStrategy.OnPush,
  12.   styleUrls: ['./badge-image-editor.component.css']
  13. })
  14.  
  15. export class BadgeImageEditorComponent implements OnInit {
  16.  
  17.   @ViewChild('ngxCroppie') ngxCroppie: NgxCroppieComponent;
  18.  
  19.  
  20.   widthPx = '319'//'319' //'3189';
  21.   heightPx = '370'//'370'//'3700';
  22.   currentImage: string;
  23.   croppieImage: string;
  24.  
  25.   constructor(public dialogRef: MatDialogRef<BadgeImageEditorComponent>, @Inject(MAT_DIALOG_DATA) public data:any) { }
  26.  
  27.   ngOnInit() {
  28.     this.currentImage = this.data.url;
  29.     this.croppieImage = this.data.url;
  30.   }
  31.  
  32.  
  33.   ngOnChanges(changes: any) {
  34.     if (this.croppieImage) { return; }
  35.     if (!changes.data.url) { return; }
  36.     if (!changes.data.url.previousValue && changes.data.url.currentValue) {
  37.       this.croppieImage = changes.data.url.currentValue;
  38.     }
  39.   }
  40.  
  41.   saveImage(){
  42.     this.dialogRef.close(this.croppieImage);
  43.   }
  44.  
  45.  
  46.   public get imageToDisplay() {
  47.     if (this.currentImage) { return this.currentImage; }
  48.     if (this.data.url) { return this.data.url; }
  49.     return `../../assets/images/idBadgeDefaultImg.png`;
  50.   }
  51.  
  52.   newImageResultFromCroppie(img: string) {
  53.     this.croppieImage = img;
  54.   }
  55.  
  56.   saveImageFromCroppie() {
  57.     this.currentImage = this.croppieImage;
  58.   }
  59.  
  60.   cancelCroppieEdit() {
  61.     this.croppieImage = this.currentImage;
  62.   }
  63.  
  64.    public get croppieOptions(): CroppieOptions {
  65.     const opts: CroppieOptions = {};
  66.     opts.viewport = {
  67.       width: parseInt(this.widthPx, 10),
  68.       height: parseInt(this.heightPx, 10)
  69.     };
  70.     opts.boundary = {
  71.       width: parseInt(this.widthPx, 10),
  72.       height: parseInt(this.heightPx, 10)
  73.     };
  74.     opts.enforceBoundary = true;
  75.     return opts;
  76.   }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement