Просмотр исходного кода

actualización de los modelos user y role

oscarleiva 5 лет назад
Родитель
Сommit
50a120b2c1

+ 0 - 19
db.json

@@ -1,19 +0,0 @@
-{
-  "posts": [
-    {
-      "id": 1,
-      "title": "json-server",
-      "author": "typicode"
-    }
-  ],
-  "comments": [
-    {
-      "id": 1,
-      "body": "some comment",
-      "postId": 1
-    }
-  ],
-  "profile": {
-    "name": "typicode"
-  }
-}

+ 0 - 14
src/app/components/dashboard/dashboard.component.html

@@ -1,24 +1,12 @@
 <h2 class="floating-title">{{ title }}</h2>
-
 <div class="main-content">
   <div class="container-fluid">
-    <div class="row">
-      <!-- <div class="col-lg-12">
-        <a href="#!" class="btn btn-sm btn-warning pull-right"
-          >Actualizar a usuario pro</a
-        >
-      </div> -->
-    </div>
-    <br />
     <div class="row">
       <div class="col-lg-12">
         <div *ngIf="tarifa" class="card">
-
           <div class="card-header card-header-inverlec">
             <p class="card-category">Tarifas de Energía al Usuario Final</p>
             <h3 class="card-title">{{tarifa.distribuidora}}</h3>
-
-
           </div>
           <div class="card-body">
             <div class="row no-gutters">
@@ -35,10 +23,8 @@
           </div>
         </div>
       </div>
-
     </div>
   </div>
-  <br />
   <div class="container-fluid" *ngIf="listAssets">
     <div class="row">
       <div class="col-lg-6 col-md-6 col-sm-6">

+ 17 - 17
src/app/components/plugins/weather-card/weather-card.component.scss

@@ -1,5 +1,4 @@
-div.widget
-{
+div.widget {
   position: relative;
   width: 100%;
   //margin: 150px auto;
@@ -10,22 +9,24 @@ div.widget
   height: 155px;
 }
 
-div.date
-{
+div.date {
   font-size: .9em;
+
   @media screen and (max-width: 680px) {
     font-size: .75em;
   }
+
   font-weight: bold;
-  color: rgba(0,0,0,0.5);
+  color: rgba(0, 0, 0, 0.5);
 }
 
-div.city
-{
+div.city {
   font-size: 1.3em;
+
   @media screen and (max-width: 680px) {
     font-size: 1em;
   }
+
   font-weight: bold;
   text-transform: uppercase;
   padding-top: 5px;
@@ -33,14 +34,13 @@ div.city
   margin: 5px 0 10px;
 }
 
-div.temp
-{
-  color: rgba(0,0,0,0.9);
+div.temp {
+  color: rgba(0, 0, 0, 0.9);
   font-weight: 400;
   display: inline-block;
   text-align: right;
   width: 100%;
-  
+
   span,
   img {
     display: inline-block;
@@ -50,21 +50,21 @@ div.temp
     text-align: right;
     margin-bottom: 20px;
     font-size: 3em;
+
     @media screen and (max-width: 800px) {
       font-size: 2.5em;
       margin-right: 5px;
     }
+
     font-weight: 400;
   }
 }
 
-div.panel
-{
+div.panel {
   display: inline-block;
 }
 
-div.right-panel
-{
+div.right-panel {
   position: absolute;
   float: right;
   top: 0;
@@ -79,9 +79,9 @@ div.right-panel
   padding: 5px;
   line-height: 10px;
   font-size: 10px;
-  color:rgba(0, 0, 0, 0.5);
+  color: rgba(0, 0, 0, 0.5);
   margin: 5px 0;
-  background: #FFF3CD;
+  //background: #FFF3CD;
   width: 100%;
 
   .close {

+ 26 - 39
src/app/components/profile/profile.component.html

@@ -1,12 +1,12 @@
 <h2 class="floating-title">{{ title }}</h2>
 <div class="main-content">
-  <div class="container-fluid">
+  <div *ngIf="user" class="container-fluid">
     <div class="row justify-content-center">
       <div class="col-12">
         <div class="align-container">
           <div class="card">
             <div class="card-header">
-              <h2>Hola {{ first_name }}</h2>
+              <h2>Hola {{ user.first_name }} {{ user.last_name }}</h2>
               <p class="card-category">Aquí podras editar la información general de la cuenta.</p>
             </div>
           </div>
@@ -21,7 +21,7 @@
             <p class="card-category">Información del Usuario</p>
           </div>
           <div class="card-body" *ngIf="editProfile">
-            <form class="form-auth-small ng-untouched ng-pristine ng-valid" [formGroup]="userForm"
+            <form *ngIf="userForm" class="form-auth-small ng-untouched ng-pristine ng-valid" [formGroup]="userForm"
               (ngSubmit)="editUser()">
               <div class="pl-lg-4">
                 <div class="row">
@@ -56,7 +56,7 @@
                       <label for="email">Email: </label>
                       <input type="text" formControlName="email" class="form-control" [ngClass]="{
                             'is-invalid': submitted && f.email.errors
-                          }" readonly />
+                          }" />
                       <div *ngIf="submitted && f.email.errors" class="invalid-feedback">
                         <div *ngIf="f.email.errors.required">
                           Campo requerido
@@ -66,7 +66,7 @@
                   </div>
                   <div class="col-lg-6">
                     <div class="form-group">
-                      <label for="phone">Telefono: </label>
+                      <label for="phone">Teléfono: </label>
                       <input type="text" formControlName="phone" class="form-control" [ngClass]="{
                             'is-invalid': submitted && f.phone.errors
                           }" />
@@ -79,47 +79,36 @@
                   </div>
 
                   <div class="col-lg-6">
-                    <div class="form-group">
-                      <label for="distribuidora">Distribuidora: </label>
-
-                      <input *ngIf="user.distribuidora" type="text" class="form-control" [value]="user.distribuidora"
-                        readonly />
-                      <select *ngIf="!user.distribuidora" class="custom-select" formControlName="distribuidora"
-                        [ngClass]="{
-                            'is-invalid': submitted && f.distribuidora.errors
-                          }">
-                        <option *ngFor="let item of distributor" [value]="item.codigo"
-                          [selected]="item.codigo == user.distribuidora">{{ item.nombre }}</option>
-                      </select>
-                      <div *ngIf="submitted && f.distribuidora.errors" class="invalid-feedback">
-                        <div *ngIf="f.distribuidora.errors.required">
-                          Campo requerido
-                        </div>
-                      </div>
-                    </div>
+                    <mat-form-field>
+                      <label>Distribuidora:</label>
+                      <mat-select formControlName="distribuidora" [ngClass]="{
+                        'is-invalid': submitted && f.distribuidora.errors}" [value]="user.distribuidora">
+                        <mat-option *ngFor="let item of distributor" [value]="item.codigo">{{ item.nombre }}
+                        </mat-option>
+                      </mat-select>
+                    </mat-form-field>
                   </div>
                   <div class="col-lg-6">
-                    <div class="form-group">
-                      <label for="tarifa">Código de tarifa: </label>
-                      <input *ngIf="user.cod_tarifa" type="text" class="form-control" [value]="user.cod_tarifa"
-                        readonly />
-                      <select *ngIf="!user.cod_tarifa" class="custom-select" formControlName="tarifa" [ngClass]="{
-                            'is-invalid': submitted && f.tarifa.errors
-                          }">
-                        <option *ngFor="let item of codigo_tarifa" [value]="item.codigo"
-                          [selected]="item.codigo == user.cod_tarifa">{{ item.nombre }}</option>
-                      </select>
+                    <mat-form-field>
+                      <label>Código de Tarifa:</label>
+                      <mat-select formControlName="tarifa" [ngClass]="{
+                        'is-invalid': submitted && f.distribuidora.errors}" [value]="user.cod_tarifa">
+                        <mat-option *ngFor="let item of codigosTarifas" [value]="item.codigo">{{ item.nombre }}
+                        </mat-option>
+                      </mat-select>
                       <div *ngIf="submitted && f.tarifa.errors" class="invalid-feedback">
                         <div *ngIf="f.tarifa.errors.required">
                           Campo requerido
                         </div>
                       </div>
-                      <button class="btn btn-sm btn-info" (click)="helpModal()">
-                        ¿Donde encuentro mi tarifa?
-                      </button>
+                    </mat-form-field>
+                    <div class="hint-wrapper">
+                      <small class="hint help" (click)="helpModal()">
+                        ¿En dónde encuentro mi código de tarifa?
+                        <i class="fas fa-question-circle"></i>
+                      </small>
                     </div>
                   </div>
-
                   <div class="col-lg-12">
                     <div class="form-group">
 
@@ -160,8 +149,6 @@
                         </small>
                       </div>
                     </div>
-
-                    <br />
                     <button class="btn btn-primary">
                       Actualizar información
                     </button>

+ 6 - 0
src/app/components/profile/profile.component.scss

@@ -1,10 +1,12 @@
 .profile {
   background: url("/assets/img/dawn.jpg") 0 320px;
 }
+
 .header {
   position: relative;
   padding: 10px 20px;
 }
+
 .bg-gradient-default {
   background: linear-gradient(87deg, #172b4d 0, #1a174d 100%) !important;
 }
@@ -17,3 +19,7 @@
   height: 100%;
   transition: all 0.15s ease;
 }
+
+.help {
+  cursor: pointer;
+}

+ 56 - 31
src/app/components/profile/profile.component.ts

@@ -1,8 +1,10 @@
 import { Component, OnInit } from '@angular/core';
 import { Title } from '@angular/platform-browser';
 import { FormGroup, FormBuilder, Validators, FormArray } from '@angular/forms';
+
 import { UserService } from '@app/services/user.service';
 import { CatalogsService } from '@app/services/catalogs.service';
+import { User } from '@app/models/user';
 
 import Swal from 'sweetalert2';
 import { AuthService } from '@app/services/auth2.service';
@@ -10,6 +12,7 @@ import {
   ValidatorComponent,
   PasswordStrengthValidator,
 } from '../plugins/validator/validator.component';
+import { CodigoTarifa } from '@app/models/codigoTarifa';
 
 @Component({
   selector: 'app-profile',
@@ -17,15 +20,17 @@ import {
   styleUrls: ['./profile.component.scss'],
 })
 export class ProfileComponent implements OnInit {
-  title = 'Perfil del usuario';
+  title = 'Perfil del Usuario';
   userForm: FormGroup;
-  submitted: boolean = false;
+  submitted = false;
   isLoadingOrganization: boolean;
-  first_name: string;
-  user: any;
+
+  user: User;
   editProfile: boolean;
   distributor: any;
-  codigo_tarifa: any;
+  codigosTarifas: CodigoTarifa[];
+  email: string;
+  tarifaForm: CodigoTarifa;
 
   constructor(
     private titleService: Title,
@@ -36,7 +41,7 @@ export class ProfileComponent implements OnInit {
     private authService: AuthService
   ) { }
 
-  email: string;
+
 
   ngOnInit() {
     Swal.fire({
@@ -51,27 +56,28 @@ export class ProfileComponent implements OnInit {
     });
 
     this.catalogsService.getCatalogByName('tarifas').subscribe((res) => {
-      this.codigo_tarifa = res.data.catalogo.records;
+      this.codigosTarifas = res.data.catalogo.records;
     });
 
     this.userService
       .getUserById(this.authService.getUserId())
       .subscribe((ans) => {
-        this.user = ans.data.user;
-        Swal.close();
+        this.user = ans;
+
         this.editProfile = true;
-        this.first_name = this.user.first_name;
+
+
         this.userForm = this.formBuilder.group(
           {
             first_name: [this.user.first_name, Validators.required],
             last_name: [this.user.last_name, Validators.required],
-            email: [this.user.email, Validators.required],
+            email: [{ value: this.user.email, disabled: true }, Validators.required],
             phone: [
-              this.user.phone_number == undefined ? '' : this.user.phone_number,
+              this.user.phone_number === undefined ? '' : this.user.phone_number,
               Validators.required,
             ],
-            distribuidora: [this.user.distribuidora],
-            tarifa: [this.user.cod_tarifa],
+            distribuidora: [{ value: this.user.distribuidora, disabled: this.user.info_complete }],
+            tarifa: [{ value: this.user.cod_tarifa, disabled: this.user.info_complete }],
             password: [
               '',
               [Validators.minLength(8), PasswordStrengthValidator],
@@ -82,9 +88,19 @@ export class ProfileComponent implements OnInit {
             validator: ValidatorComponent('password', 'confirm_password'),
           }
         );
+        Swal.close();
+      }, error => {
+        Swal.fire({
+          type: 'error',
+          title: 'Oops...',
+          text: 'Algo salio mal. Por favor intentalo de nuevo o contacta con nuestro Soporte',
+          footer: '<a href="mailto:soporte@grupomerelec.com">soporte@grupomerelec.com</a>'
+        });
       });
 
     this.titleService.setTitle(this.title);
+
+
   }
 
   get f() {
@@ -98,19 +114,18 @@ export class ProfileComponent implements OnInit {
       return;
     }
 
-    let user = {
+    const user = {
       first_name: this.f.first_name.value,
       last_name: this.f.last_name.value,
       email: this.f.email.value,
       phone_number: this.f.phone.value,
       distribuidora: this.f.distribuidora.value,
       cod_tarifa: this.f.tarifa.value,
+      password: (this.f.password.value === '' ? this.user.password : this.f.password.value),
+      organizations: this.user.organizations,
+      is_active: this.user.is_active,
     };
 
-    if (this.f.password.value != '' && this.f.confirm_password.value != '') {
-      user['password'] = this.f.password.value;
-      user['confirm_password'] = this.f.confirm_password.value;
-    }
 
     Swal.fire({
       allowOutsideClick: false,
@@ -118,6 +133,7 @@ export class ProfileComponent implements OnInit {
       text: 'Espere por favor...',
     });
     Swal.showLoading();
+
     this.userService.editCustomer(this.authService.getUserId(), user).subscribe(
       (success) => {
         if (success) {
@@ -129,7 +145,7 @@ export class ProfileComponent implements OnInit {
             confirmButtonText: 'Se ha actualizado su perfil exitosamente',
           }).then((result) => {
             Swal.close();
-            window.location.reload();
+            this.ngOnInit();
           });
         }
       },
@@ -145,21 +161,30 @@ export class ProfileComponent implements OnInit {
 
   helpModal() {
     Swal.fire({
-      title: '<strong>¿Dónde encuentro mi tipo de tarifa?</strong>',
+      title: '<strong>¿Dónde encuentro mi Código de Tarifa?</strong>',
       type: 'info',
       html:
-        '<p style=\'text-align: left\'>Si tu distribuidora de energía es del grupo de empresas AES, puedes verificar el tipo de tarifa en la siguiente imagen:</p>' +
-        '<img alt="Factura AES" src="./assets/img/AESFactura.png" style="width: 100%;"/><br><br> ' +
-        '<p style="text-align: left">Para más información puedes visitar el sitio oficial de <a href="http://www.aes-elsalvador.com/servicio-al-cliente/conoce-tu-factura/" target="_blank">AES</a></p>' +
-        '<br><br>' +
-        '<p style=\'text-align: left\'>Si tu distribuidora de energía es DelSur, puedes verificar el tipo de tarifa en la siguiente imagen:</p>' +
-        '<img alt="Factura AES" src="./assets/img/DelSurFactura2.png" style="width: 100%;"/>' +
-        '<p style="text-align: left">Para más información puedes visitar el sitio oficial de <a href="https://www.delsur.com.sv/conoce-tu-factura/" target="_blank">DelSur</a></p>' +
-        '<br><br>',
+        `<p style=\'text-align: left\'>
+          Si tu distribuidora de energía es del grupo de empresas AES,
+          puedes verificar el tipo de tarifa en la siguiente imagen:</p>
+        <img alt="Factura AES" src="./assets/img/AESFactura.png" style="width: 100%;"/><br>
+        <p style="text-align: left">
+          Para más información puedes visitar el sitio oficial de
+            <a href="http://www.aes-elsalvador.com/servicio-al-cliente/conoce-tu-factura/" target="_blank">AES</a>
+        </p>
+        <p style=\'text-align: left\'>
+        Si tu distribuidora de energía es DelSur, 
+        puedes verificar el tipo de tarifa en la siguiente imagen:</p>
+        <img alt="Factura AES" src="./assets/img/DelSurFactura2.png" style="width: 100%;"/>
+        <p style="text-align: left">
+        Para más información puedes visitar el sitio oficial de
+        <a href="https://www.delsur.com.sv/conoce-tu-factura/" target="_blank">DelSur</a>
+        </p>`,
       showCloseButton: true,
       width: 600,
-      confirmButtonText: '<i class="fa fa-thumbs-up"></i> Cerrar',
+      confirmButtonText: 'Cerrar',
       confirmButtonAriaLabel: 'Thumbs up, great!',
-    });
+    }
+    );
   }
 }

+ 10 - 6
src/app/components/rates/rates.component.ts

@@ -19,6 +19,7 @@ import { Rate } from '@app/models/rate';
 import { stringify } from 'querystring';
 import { Tariff } from '@app/models/tariff';
 import { Cargo } from '@app/models/cargo';
+import { switchAll } from 'rxjs/operators';
 
 @Component({
   selector: 'app-rates',
@@ -137,18 +138,17 @@ export class RatesComponent implements OnInit {
     //DEMO
     this.userLevel = +this.authService.getUserLevel();
 
+
+  }
+
+  ngOnInit() {
+
     Swal.fire({
       allowOutsideClick: false,
       type: 'info',
       text: 'Espere por favor...',
     });
     Swal.showLoading();
-  }
-
-  ngOnInit() {
-    setTimeout(() => {
-      Swal.close();
-    }, 3000);
 
     this.getCurretTariff();
 
@@ -322,6 +322,10 @@ export class RatesComponent implements OnInit {
       ],
     ];
 
+    setTimeout(() => {
+      Swal.close();
+    }, 1000);
+
   }
 
   ngOnChanges(): void { }

+ 156 - 156
src/app/components/shared/navbar/navbar.component.ts

@@ -2,9 +2,9 @@ import { Observable } from 'rxjs';
 
 import { Component, OnInit, ElementRef } from '@angular/core';
 import { ROUTES } from '../sidebar/sidebar.component';
-import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
+import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
 import { Router, ActivatedRoute } from '@angular/router';
-//import { AuthenticationService } from 'src/app/services/authentication.service';
+// import { AuthenticationService } from 'src/app/services/authentication.service';
 import { AdminLayoutRoutes } from 'src/app/layouts/admin/admin.routing';
 import { AuthService } from '../../../services/auth2.service';
 import Swal from 'sweetalert2';
@@ -15,174 +15,174 @@ import Swal from 'sweetalert2';
   styleUrls: ['./navbar.component.scss']
 })
 export class NavbarComponent implements OnInit {
-    private listTitles: any[];
-
-    private leTitles: any[];
-
-    location: Location;
-      mobile_menu_visible: any = 0;
-    private toggleButton: any;
-    private sidebarVisible: boolean;
-    private sidebarMini: boolean;
-    constructor(location: Location,  private element: ElementRef, private router: Router, private auth: AuthService, private route: ActivatedRoute) {
-      this.location = location;
-      this.sidebarVisible = false;
-      this.sidebarMini = false;
+  private listTitles: any[];
+
+  private leTitles: any[];
+
+  location: Location;
+  mobile_menu_visible: any = 0;
+  private toggleButton: any;
+  private sidebarVisible: boolean;
+  private sidebarMini: boolean;
+  constructor(location: Location, private element: ElementRef, private router: Router, private auth: AuthService, private route: ActivatedRoute) {
+    this.location = location;
+    this.sidebarVisible = false;
+    this.sidebarMini = false;
+  }
+
+  ngOnInit() {
+    this.listTitles = ROUTES.filter(listTitle => listTitle);
+    this.leTitles = AdminLayoutRoutes.filter(listTitle => listTitle);
+    const navbar: HTMLElement = this.element.nativeElement;
+    this.toggleButton = navbar.getElementsByClassName('navbar-toggler')[0];
+    this.router.events.subscribe((event) => {
+      this.sidebarClose();
+      var $layer: any = document.getElementsByClassName('close-layer')[0];
+      if ($layer) {
+        $layer.remove();
+        this.mobile_menu_visible = 0;
+      }
+    });
+  }
+
+  sidebarMiniOn() {
+    const toggleButton = this.toggleButton;
+    const body = document.getElementsByTagName('body')[0];
+    setTimeout(() => {
+      toggleButton.classList.add('sidebar-mini');
+    }, 500);
+    body.classList.add('sidebar-mini');
+
+    this.sidebarMini = true;
+  }
+
+  sidebarMiniOff() {
+    const body = document.getElementsByTagName('body')[0];
+    //this.toggleButton.classList.remove('');
+    this.sidebarMini = false;
+    body.classList.remove('sidebar-mini');
+  }
+
+  menuToggle() {
+    const body = document.getElementsByTagName('body')[0];
+    // body.classList.add('sidebar-mini');
+    if (this.sidebarMini === false) {
+      this.sidebarMiniOn();
+    } else {
+      this.sidebarMiniOff();
     }
-
-    ngOnInit(){
-      this.listTitles = ROUTES.filter(listTitle => listTitle);
-      this.leTitles = AdminLayoutRoutes.filter(listTitle => listTitle);
-      const navbar: HTMLElement = this.element.nativeElement;
-      this.toggleButton = navbar.getElementsByClassName('navbar-toggler')[0];
-      this.router.events.subscribe((event) => {
-        this.sidebarClose();
-         var $layer: any = document.getElementsByClassName('close-layer')[0];
-         if ($layer) {
-           $layer.remove();
-           this.mobile_menu_visible = 0;
-         }
-     });
+  }
+
+  sidebarOpen() {
+    const toggleButton = this.toggleButton;
+    const body = document.getElementsByTagName('body')[0];
+    setTimeout(function () {
+      toggleButton.classList.add('toggled');
+    }, 500);
+
+    body.classList.add('nav-open');
+
+    this.sidebarVisible = true;
+  };
+  sidebarClose() {
+    const body = document.getElementsByTagName('body')[0];
+    this.toggleButton.classList.remove('toggled');
+    this.sidebarVisible = false;
+    body.classList.remove('nav-open');
+  };
+  sidebarToggle() {
+    // const toggleButton = this.toggleButton;
+    // const body = document.getElementsByTagName('body')[0];
+    var $toggle = document.getElementsByClassName('navbar-toggler')[0];
+
+    if (this.sidebarVisible === false) {
+      this.sidebarOpen();
+    } else {
+      this.sidebarClose();
     }
+    const body = document.getElementsByTagName('body')[0];
 
-    sidebarMiniOn() {
-      const toggleButton = this.toggleButton;
-      const body = document.getElementsByTagName('body')[0];
-      setTimeout(function(){
-        toggleButton.classList.add('sidebar-mini');
-      }, 500);
-      body.classList.add('sidebar-mini');
-
-      this.sidebarMini = true;
-    };
-
-    sidebarMiniOff() {
-      const body = document.getElementsByTagName('body')[0];
-      //this.toggleButton.classList.remove('');
-      this.sidebarMini = false;
-      body.classList.remove('sidebar-mini');
-    };
-
-    menuToggle(){
-      const body = document.getElementsByTagName('body')[0];
-      //body.classList.add('sidebar-mini');
-      if (this.sidebarMini === false) {
-          this.sidebarMiniOn();
-      } else {
-          this.sidebarMiniOff();
+    if (this.mobile_menu_visible == 1) {
+      // $('html').removeClass('nav-open');
+      body.classList.remove('nav-open');
+      if ($layer) {
+        $layer.remove();
+      }
+      setTimeout(function () {
+        $toggle.classList.remove('toggled');
+      }, 400);
+
+      this.mobile_menu_visible = 0;
+    } else {
+      setTimeout(function () {
+        $toggle.classList.add('toggled');
+      }, 430);
+
+      var $layer = document.createElement('div');
+      $layer.setAttribute('class', 'close-layer');
+
+      if (body.querySelectorAll('.main-panel')) {
+        document.getElementsByClassName('main-panel')[0].appendChild($layer);
+      } else if (body.classList.contains('off-canvas-sidebar')) {
+        document.getElementsByClassName('wrapper-full-page')[0].appendChild($layer);
       }
-    }
 
-    sidebarOpen() {
-      const toggleButton = this.toggleButton;
-      const body = document.getElementsByTagName('body')[0];
-      setTimeout(function(){
-        toggleButton.classList.add('toggled');
-      }, 500);
+      setTimeout(function () {
+        $layer.classList.add('visible');
+      }, 100);
+
+      $layer.onclick = function () { //asign a function
+        body.classList.remove('nav-open');
+        this.mobile_menu_visible = 0;
+        $layer.classList.remove('visible');
+        setTimeout(function () {
+          $layer.remove();
+          $toggle.classList.remove('toggled');
+        }, 400);
+      }.bind(this);
 
       body.classList.add('nav-open');
+      this.mobile_menu_visible = 1;
+    }
+  };
 
-      this.sidebarVisible = true;
-    };
-    sidebarClose() {
-      const body = document.getElementsByTagName('body')[0];
-      this.toggleButton.classList.remove('toggled');
-      this.sidebarVisible = false;
-      body.classList.remove('nav-open');
-    };
-    sidebarToggle() {
-      // const toggleButton = this.toggleButton;
-      // const body = document.getElementsByTagName('body')[0];
-      var $toggle = document.getElementsByClassName('navbar-toggler')[0];
-
-      if (this.sidebarVisible === false) {
-          this.sidebarOpen();
-      } else {
-          this.sidebarClose();
-      }
-      const body = document.getElementsByTagName('body')[0];
-
-      if (this.mobile_menu_visible == 1) {
-          // $('html').removeClass('nav-open');
-          body.classList.remove('nav-open');
-          if ($layer) {
-              $layer.remove();
-          }
-          setTimeout(function() {
-              $toggle.classList.remove('toggled');
-          }, 400);
-
-          this.mobile_menu_visible = 0;
-      } else {
-        setTimeout(function() {
-            $toggle.classList.add('toggled');
-        }, 430);
-
-        var $layer = document.createElement('div');
-        $layer.setAttribute('class', 'close-layer');
-
-        if (body.querySelectorAll('.main-panel')) {
-          document.getElementsByClassName('main-panel')[0].appendChild($layer);
-        }else if (body.classList.contains('off-canvas-sidebar')) {
-          document.getElementsByClassName('wrapper-full-page')[0].appendChild($layer);
-        }
-
-        setTimeout(function() {
-            $layer.classList.add('visible');
-        }, 100);
-
-        $layer.onclick = function() { //asign a function
-          body.classList.remove('nav-open');
-          this.mobile_menu_visible = 0;
-          $layer.classList.remove('visible');
-          setTimeout(function() {
-            $layer.remove();
-            $toggle.classList.remove('toggled');
-          }, 400);
-        }.bind(this);
-
-        body.classList.add('nav-open');
-        this.mobile_menu_visible = 1;
-      }
-    };
+  logout() {
 
-    logout() {
+    Swal.fire({
+      allowOutsideClick: false,
+      type: 'info',
+      text: 'Espere por favor...'
+    });
+    Swal.showLoading();
 
-      Swal.fire({
-        allowOutsideClick: false,
-        type: 'info',
-        text: 'Espere por favor...'
-      });
-      Swal.showLoading();
+    this.auth.logout();
 
-      this.auth.logout();
+    //this.router.navigateByUrl("login");
+  }
 
-      //this.router.navigateByUrl("login");
-    }
+  getTitle() {
+    var titlee = this.location.prepareExternalUrl(this.location.path());
+    var component_local = this.router.url;
+    var main_title: string;
 
-    getTitle(){
-      var titlee = this.location.prepareExternalUrl(this.location.path());
-      var component_local = this.router.url;
-      var main_title:string;
+    if (titlee.charAt(0) === '#') {
+      titlee = titlee.slice(1);
+    }
+    var item = 0
+    while (item < this.leTitles.length) {
 
-      if(titlee.charAt(0) === '#'){
-        titlee = titlee.slice( 1 );
-      }
-      var item=0
-      while( item < this.leTitles.length){
-        
-        if("/"+this.leTitles[item].path === titlee){
-          main_title = this.leTitles[item].data['title'];
-          break;
-        }
-        item++;
-      }
-      if (main_title === undefined) {
-        return 'Dashboard';
-      }
-      else {
-        return main_title;
+      if ("/" + this.leTitles[item].path === titlee) {
+        main_title = this.leTitles[item].data['title'];
+        break;
       }
-
+      item++;
+    }
+    if (main_title === undefined) {
+      return 'Dashboard';
     }
+    else {
+      return main_title;
+    }
+
+  }
 }

+ 29 - 29
src/app/components/shared/sidebar/sidebar.component.ts

@@ -1,8 +1,8 @@
-import { Component, OnInit } from "@angular/core";
-import { AuthService } from "../../../services/auth2.service";
-import { Router } from "@angular/router";
-import * as CryptoJS from "crypto-js";
-import Swal from "sweetalert2";
+import { Component, OnInit } from '@angular/core';
+import { AuthService } from '../../../services/auth2.service';
+import { Router } from '@angular/router';
+import * as CryptoJS from 'crypto-js';
+import Swal from 'sweetalert2';
 
 declare const $: any;
 declare interface RouteInfo {
@@ -13,11 +13,11 @@ declare interface RouteInfo {
   allowed_roles?: any;
 }
 export const ROUTES: RouteInfo[] = [
-  { path: "/dashboard", title: "Dashboard", icon: "dashboard", class: "" },
-  { path: "/assets", title: "Plantas", icon: "wb_sunny", class: "" },
-  { path: "/rates", title: "Tarifas", icon: "bubble_chart", class: "" },
+  { path: '/dashboard', title: 'Dashboard', icon: 'dashboard', class: '' },
+  { path: '/assets', title: 'Plantas', icon: 'wb_sunny', class: '' },
+  { path: '/rates', title: 'Tarifas', icon: 'bubble_chart', class: '' },
 
-  { path: "/profile", title: "Perfil", icon: "person", class: "" },
+  { path: '/profile', title: 'Perfil', icon: 'person', class: '' },
   /*{ path: '/table-list', title: 'Table List',  icon:'content_paste', class: '' },
     { path: '/typography', title: 'Typography',  icon:'library_books', class: '' },
     { path: '/icons', title: 'Icons',  icon:'bubble_chart', class: '' },
@@ -31,32 +31,32 @@ export const ROUTES: RouteInfo[] = [
 // Extra options to show to the admin
 export const ADMIN_ROUTES: RouteInfo[] = [
   {
-    path: "/organizations",
-    title: "Organizaciones",
-    icon: "location_city",
-    class: "",
+    path: '/organizations',
+    title: 'Organizaciones',
+    icon: 'location_city',
+    class: '',
     allowed_roles: [2, 3],
   },
   {
-    path: "/plants",
-    title: "Plantas",
-    icon: "poll",
-    class: "",
+    path: '/plants',
+    title: 'Plantas',
+    icon: 'poll',
+    class: '',
     allowed_roles: [2, 3],
   },
   {
-    path: "/users",
-    title: "Usuarios",
-    icon: "people",
-    class: "",
+    path: '/users',
+    title: 'Usuarios',
+    icon: 'people',
+    class: '',
     allowed_roles: [3],
   },
 ];
 
 @Component({
-  selector: "app-sidebar",
-  templateUrl: "./sidebar.component.html",
-  styleUrls: ["./sidebar.component.scss"],
+  selector: 'app-sidebar',
+  templateUrl: './sidebar.component.html',
+  styleUrls: ['./sidebar.component.scss'],
 })
 export class SidebarComponent implements OnInit {
   menuItems: any[];
@@ -65,9 +65,9 @@ export class SidebarComponent implements OnInit {
   role_number: any;
 
   constructor(private auth: AuthService, private router: Router) {
-    var bytes = CryptoJS.AES.decrypt(
-      localStorage.getItem("USER_MENU"),
-      "soma-inverlec-2019"
+    const bytes = CryptoJS.AES.decrypt(
+      localStorage.getItem('USER_MENU'),
+      'soma-inverlec-2019'
     );
     this.role_number = bytes.toString(CryptoJS.enc.Utf8);
   }
@@ -92,8 +92,8 @@ export class SidebarComponent implements OnInit {
   logout() {
     Swal.fire({
       allowOutsideClick: false,
-      type: "info",
-      text: "Espere por favor...",
+      type: 'info',
+      text: 'Espere por favor...',
     });
     Swal.showLoading();
 

+ 4 - 0
src/app/models/codigoTarifa.ts

@@ -0,0 +1,4 @@
+export class CodigoTarifa {
+    codigo: string;
+    nombre: string;
+}

+ 2 - 2
src/app/models/role.ts

@@ -1,4 +1,4 @@
 export enum Role {
-    User = 'User',
-    Admin = 'Admin'
+    User = 0,
+    Admin = 1
 }

+ 29 - 12
src/app/models/user.ts

@@ -1,18 +1,35 @@
 import { Role } from "./role";
 
 export class User {
+    // email: string;
+    // password: string;
+    // firstName?: string;
+    // lastName?: string;
+    // uniqueid?: number;
+    // role?: Role;
+    // token?: string;
+    // birthdate?: Date;
+    // username?: string;
+    // address?: string;
+    // city?: string;
+    // country?: string;
+    // phone?: string;
+    // gender?: string;
+    id: string;
     email: string;
     password: string;
-    firstName?: string;
-    lastName?: string;
-    uniqueid?: number;
-    role?: Role;
-    token?: string;
-    birthdate?: Date;
-    username?: string;
-    address?: string;
-    city?: string;
-    country?: string;
-    phone?: string;
-    gender?: string;
+    first_name: string;
+    last_name: string;
+    role: number;
+    phone_number: string;
+    distribuidora: string;
+    cod_tarifa: string;
+    info_complete: boolean;
+    is_active: boolean;
+    meta_data: {
+        created_on: Date;
+        updated_on: Date;
+    };
+    organizations: string[];
+
 }