Last active
          November 5, 2020 18:38 
        
      - 
      
- 
        Save charleslcsantos/3dfeb83a3821d6162175b7acd8f0aa73 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export function removeSpecialCaracters(text: String): string { | |
| const a = "àáäãâèéëêìíïîòóöôõùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;"; | |
| const b = "aaaaaeeeeiiiiooooouuuuncsyoarsnpwgnmuxzh------"; | |
| const p = new RegExp(a.split("").join("|"), "g"); | |
| return text | |
| .toString() | |
| .toLowerCase() | |
| .replace(p, c => b.charAt(a.indexOf(c))); | |
| } | |
| /** | |
| * searchKeyword | |
| * Function para buscar uma string em outra. | |
| * Exemplos: | |
| * - searchKeyword('janei', 'Rio de janeiro') => retorna true | |
| * - searchKeyword('Paco', 'paçoquita') => retorna true | |
| * | |
| * @param key string : é a palavra que deseja buscar | |
| * @param target string : é o alvo da busca. | |
| */ | |
| public static searchKeyword(key: string, target: string): boolean { | |
| const keyPure = VXJSHelper.removeSpecialCaracters(key).toUpperCase(); | |
| const targetPure = VXJSHelper.removeSpecialCaracters(target).toUpperCase(); | |
| return targetPure.search(keyPure) >= 0; | |
| } | |
| export class IAlert { | |
| public message: String; | |
| public type: String; | |
| public title?: String; | |
| } | |
| @Injectable({ | |
| providedIn: "root" | |
| }) | |
| export class AlertService { | |
| public alerts = Array<IAlert>(); | |
| private alertSource = new Subject<IAlert>(); | |
| public alert$ = this.alertSource.asObservable(); | |
| /** | |
| * Cria um alerta na tela | |
| * alert | |
| * @param {String} message : mensagem a ser exibida | |
| * @param {String} type: tipo de mensagem [success, warning, danger, info] | |
| */ | |
| public alert( | |
| message: String, | |
| type: "success" | "warning" | "danger" | "info" = "info" | |
| ) { | |
| const newAlert: IAlert = { | |
| message: message, | |
| type: type | |
| }; | |
| this.alerts.push(newAlert); | |
| // Limitando a exibição de alertas para 3 | |
| if (this.alerts && this.alerts.length === 4) { | |
| this.alerts.splice(0, 1); | |
| } | |
| // Aumentando o tempo de exibição para mensagens com mais de 50 caracteres | |
| if (newAlert.message.length > 50) { | |
| setTimeout(() => { | |
| this.alerts.splice(0, 1); | |
| }, 12000); | |
| } else { | |
| setTimeout(() => { | |
| this.alerts.splice(0, 1); | |
| }, 7000); | |
| } | |
| this.alertSource.next(newAlert); | |
| } | |
| public removeAlert(alert: IAlert) { | |
| const index = this.alerts.indexOf(alert); | |
| this.alerts.splice(index, 1); | |
| } | |
| } | |
| public static slideBottomToTop = trigger("slideBottomToTop", [ | |
| state("in", style({ transform: "translateY(0)" })), | |
| transition(":enter", [ | |
| style({ | |
| transform: "translateY(10%)", | |
| opacity: 0 | |
| }), | |
| animate("250ms cubic-bezier(0.25, 0.46, 0.45, 0.94)") | |
| ]), | |
| transition(":leave", [ | |
| animate( | |
| "200ms ease-in", | |
| style({ | |
| transform: "translateY(10%)", | |
| opacity: 0 | |
| }) | |
| ) | |
| ]) | |
| ]); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment