Project: Mall App Client: Maiora
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

outlet-details.page.ts 3.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3. import { Location } from '@angular/common';
  4. import { Mall, Outlet, MenuItem, MallService } from '../services/mall.service';
  5. @Component({
  6. selector: 'app-outlet-details',
  7. templateUrl: './outlet-details.page.html',
  8. styleUrls: ['./outlet-details.page.scss'],
  9. })
  10. export class OutletDetailsPage implements OnInit {
  11. mall_details: Mall;
  12. outlet_details: Outlet;
  13. temp_outlet_details: Outlet;
  14. show_top_bar: boolean = false;
  15. show_only_veg: boolean = false;
  16. selected_tag: string = null;
  17. selected_description: string = null;
  18. show_sort_popup: boolean = false;
  19. selected_sort: string = null;
  20. constructor(
  21. private route: ActivatedRoute,
  22. private location: Location,
  23. private mallService: MallService,
  24. ) { }
  25. ngOnInit() {
  26. let mall_id = this.route.snapshot.paramMap.get('mall_id');
  27. let outlet_id = this.route.snapshot.paramMap.get('outlet_id');
  28. this.mallService.getMallByID(mall_id).then((data: Mall) => {
  29. this.mall_details = data;
  30. this.outlet_details = this.mall_details.outlets.find((outlet) => outlet.id === outlet_id);
  31. this.temp_outlet_details = JSON.parse(JSON.stringify(this.outlet_details));
  32. });
  33. }
  34. back() {
  35. this.location.back();
  36. }
  37. onScroll(event: any) {
  38. if (event.detail.scrollTop > 100) {
  39. this.show_top_bar = true;
  40. } else {
  41. this.show_top_bar = false;
  42. }
  43. }
  44. calculateDiscount(price: number, discount: number) {
  45. return price - (price * discount / 100);
  46. }
  47. toggleBookmark() {
  48. this.outlet_details.is_bookmarked = !this.outlet_details.is_bookmarked;
  49. }
  50. filterByTag(tag: string) {
  51. if (this.selected_tag === tag) {
  52. this.selected_tag = null;
  53. this.temp_outlet_details.menu_items = JSON.parse(JSON.stringify(this.outlet_details.menu_items));
  54. } else {
  55. this.selected_tag = tag;
  56. let menu_items: Array<MenuItem> = [];
  57. for (let i = 0; i < this.outlet_details.menu_items.length; i += 1) {
  58. if (this.outlet_details.menu_items[i].tags.includes(tag)) {
  59. menu_items.push(this.outlet_details.menu_items[i]);
  60. }
  61. }
  62. this.temp_outlet_details.menu_items = menu_items;
  63. }
  64. }
  65. sortBy(type: string) {
  66. this.selected_sort = type;
  67. switch(this.selected_sort) {
  68. case 'name': this.temp_outlet_details.menu_items.sort(function(a, b){
  69. if(a.name < b.name) { return -1; }
  70. if(a.name > b.name) { return 1; }
  71. return 0;
  72. });
  73. break;
  74. case 'rating': this.temp_outlet_details.menu_items.sort(function(a, b){
  75. if(a.rating < b.rating) { return -1; }
  76. if(a.rating > b.rating) { return 1; }
  77. return 0;
  78. }).reverse();
  79. break;
  80. case 'price': this.temp_outlet_details.menu_items.sort(function(a, b){
  81. if(a.price < b.price) { return -1; }
  82. if(a.price > b.price) { return 1; }
  83. return 0;
  84. });
  85. break;
  86. case 'duration': this.temp_outlet_details.menu_items.sort(function(a, b){
  87. if(a.wait_duration < b.wait_duration) { return -1; }
  88. if(a.wait_duration > b.wait_duration) { return 1; }
  89. return 0;
  90. });
  91. break;
  92. }
  93. }
  94. togglePopup() {
  95. this.show_sort_popup = !this.show_sort_popup;
  96. }
  97. }