25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

bookmarks.page.ts 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Component, OnInit } from '@angular/core';
  2. import { Location } from '@angular/common';
  3. import { UserService } from '../services/user.service';
  4. import { NewsService, IMAGE_BASE_URL } from '../services/news.service';
  5. import { Platform } from '@ionic/angular';
  6. import { Router } from '@angular/router';
  7. @Component({
  8. selector: 'app-bookmarks',
  9. templateUrl: './bookmarks.page.html',
  10. styleUrls: ['./bookmarks.page.scss'],
  11. })
  12. export class BookmarksPage implements OnInit {
  13. bookmarked_articles: Array<{
  14. title: string,
  15. alias: string,
  16. image: string,
  17. type: string,
  18. }> = [];
  19. image_url = IMAGE_BASE_URL;
  20. constructor(
  21. private location: Location,
  22. private userService: UserService,
  23. private newsService: NewsService,
  24. private router: Router,
  25. private platform: Platform,
  26. ) { }
  27. back() {
  28. this.location.back();
  29. }
  30. getType(type: string) {
  31. let returnType: string = '';
  32. console.log(type);
  33. switch(type) {
  34. case 'Photos': returnType = 'gallery'; break;
  35. case 'Videos': returnType = 'videos'; break;
  36. case 'News': returnType = 'news'; break;
  37. }
  38. return returnType;
  39. }
  40. showNewsDetails(alias_title: string, type: string) {
  41. this.router.navigate(['/home-details', { alias_title: alias_title, type: 'news' }]);
  42. }
  43. ngOnInit() {
  44. this.userService.getUserProfile().then((data: any) => {
  45. let bookmarked_articles: Array<string> = data.bookmarked_articles;
  46. this.bookmarked_articles = [];
  47. for (let i = 0; i < bookmarked_articles.length; i += 1) {
  48. this.newsService.getArticleDetails(bookmarked_articles[i]).then((info: any) => {
  49. if (this.platform.is('android') || this.platform.is('capacitor')) {
  50. this.bookmarked_articles.push({
  51. title: JSON.parse(info.data)['content'].data.short_title ? JSON.parse(info.data)['content'].data.short_title : JSON.parse(info.data)['content'].data.asset_title,
  52. alias: bookmarked_articles[i],
  53. image: this.image_url + JSON.parse(info.data)['content'].data.image_path + JSON.parse(info.data)['content'].data.image_file_name,
  54. type: this.getType(JSON.parse(info.data)['EntityData'].entities[0].ent_display_name)
  55. });
  56. } else {
  57. this.bookmarked_articles.push({
  58. title: info.content.data.short_title ? info.content.data.short_title : info.content.data.asset_title,
  59. alias: bookmarked_articles[i],
  60. image: this.image_url + info.content.data.image_path + info.content.data.image_file_name,
  61. type: this.getType(info.EntityData.entities[0].ent_display_name)
  62. });
  63. }
  64. }, (e) => {
  65. // alert(JSON.stringify(e));
  66. });
  67. }
  68. }, () => {
  69. this.bookmarked_articles = [];
  70. });
  71. }
  72. }