app.component.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import { Component, ViewChild } from '@angular/core';
  2. import { Nav, Platform, Loading, LoadingController, AlertController } from 'ionic-angular';
  3. import { StatusBar, Splashscreen } from 'ionic-native';
  4. import { LoginPage } from "../pages/login/login";
  5. import { HomePage } from "../pages/home/home";
  6. import { CustomersPage } from "../pages/customers/customers";
  7. import { ProductsPage } from "../pages/products/products";
  8. import { VariantsPage } from "../pages/variants/variants";
  9. import { OrdersPage } from "../pages/orders/orders";
  10. import { LeadsPage } from "../pages/leads/leads";
  11. import { PhonecallsPage } from "../pages/phonecalls/phonecalls";
  12. import { ToolsPage } from "../pages/tools/tools";
  13. import { AboutPage } from "../pages/about/about";
  14. import { EventsManager } from "../base/events/event-manager";
  15. @Component({
  16. templateUrl: 'app.html'
  17. })
  18. export class MyApp {
  19. @ViewChild(Nav) nav: Nav;
  20. rootPage: any = LoginPage;
  21. homePage: any = HomePage;
  22. entries: Array<{ visible: boolean, title: string, pages: Array<{ visible: boolean, title: string, icon: string, component: any, params?: any }> }>;
  23. loader: Loading;
  24. constructor(
  25. public platform: Platform,
  26. public loadingCtrl: LoadingController,
  27. public alertCtrl: AlertController
  28. ) {
  29. this.initializeApp();
  30. this.entries = [
  31. {
  32. visible: true,
  33. title: "Ventas",
  34. pages: [
  35. {
  36. visible: true,
  37. title: "Clientes",
  38. icon: "people",
  39. component: CustomersPage
  40. },
  41. {
  42. visible: true,
  43. title: "Presupuestos",
  44. icon: "basket",
  45. component: OrdersPage,
  46. params: {
  47. kind: "budget",
  48. filters: [["state", "=", "draft"]]
  49. }
  50. },
  51. {
  52. visible: true,
  53. title: "Ventas",
  54. icon: "cart",
  55. component: OrdersPage,
  56. params: {
  57. kind: "sale",
  58. filters: [["state", "!=", "draft"]]
  59. }
  60. },
  61. {
  62. visible: true,
  63. title: 'Productos',
  64. icon: "cube",
  65. component: ProductsPage
  66. },
  67. {
  68. visible: true,
  69. title: 'Variantes',
  70. icon: "list-box",
  71. component: VariantsPage
  72. },
  73. ]
  74. },
  75. {
  76. visible: true,
  77. title: "CRM",
  78. pages: [
  79. {
  80. visible: true,
  81. title: 'Iniciativas',
  82. icon: "flag",
  83. component: LeadsPage,
  84. params: {
  85. kind: "lead",
  86. filters: [["type", "=", "lead"]]
  87. }
  88. },
  89. {
  90. visible: true,
  91. title: "Oportunidades",
  92. icon: "bonfire",
  93. component: LeadsPage,
  94. params: {
  95. kind: "opportunity",
  96. filters: [["type", "=", "opportunity"]]
  97. }
  98. },
  99. {
  100. visible: true,
  101. title: "Llamadas",
  102. icon: "call",
  103. component: PhonecallsPage
  104. }
  105. ]
  106. },
  107. {
  108. visible: true,
  109. title: "Herramientas",
  110. pages: [
  111. {
  112. visible: true,
  113. title: 'Herramientas',
  114. icon: "build",
  115. component: ToolsPage
  116. },
  117. {
  118. visible: true,
  119. title: "Acerca",
  120. icon: "information-circle",
  121. component: AboutPage
  122. }
  123. ]
  124. }
  125. ];
  126. }
  127. /**
  128. *
  129. */
  130. initializeApp() {
  131. this.platform.ready().then(() => {
  132. StatusBar.styleDefault();
  133. Splashscreen.hide();
  134. EventsManager.subscribe("app:loading", data => {
  135. if (data) {
  136. this.loader = this.loadingCtrl.create({
  137. content: "Cargando, espere..."
  138. });
  139. this.loader.present();
  140. } else {
  141. this.loader.dismiss();
  142. }
  143. });
  144. EventsManager.subscribe("app:error", data => {
  145. this.alertCtrl.create({
  146. title: "Error",
  147. message: "Ha ocurrido un error",
  148. buttons: [
  149. {
  150. text: "Ver detalles",
  151. handler: () => {
  152. this.alertCtrl.create({
  153. title: "Detalles del error",
  154. message: data,
  155. buttons: [{ text: "Cerrar" }]
  156. }).present();
  157. }
  158. },
  159. {
  160. text: "Cerrar"
  161. }
  162. ]
  163. }).present();
  164. });
  165. });
  166. }
  167. /**
  168. *
  169. */
  170. openPage(page) {
  171. this.nav.setRoot(page.component, page);
  172. }
  173. }