Angular LMS app
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。

chat-page.component.ts 5.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import { Component, OnInit } from '@angular/core';
  2. import { Location } from '@angular/common';
  3. import * as moment from 'moment';
  4. @Component({
  5. selector: 'app-chat-page',
  6. templateUrl: './chat-page.component.html',
  7. styleUrls: ['./chat-page.component.scss']
  8. })
  9. export class ChatPageComponent implements OnInit {
  10. selectedSegment: string = 'broadcasts';
  11. selectedChat: any = null;
  12. selectedBroadcastChat: any;
  13. showSearch: boolean = false;
  14. searchTerm: string = '';
  15. searchList = {
  16. chatList: [],
  17. broadCastList: []
  18. };
  19. showAddBroadCast: boolean = false;
  20. chatList = [{
  21. user: {
  22. id: 1,
  23. name: 'Jordan Janardhan',
  24. imgUrl: 'https://c-sf.smule.com/rs-s79/arr/c1/0b/83a9328a-1469-4bfd-9e94-622f7ca7b1b5.jpg'
  25. },
  26. conversation: [{
  27. message: 'Hi, What\'s up!?',
  28. user: 1
  29. }, {
  30. message: 'Nothing, Was checking upon you!',
  31. user: 0
  32. }, {
  33. message: 'How you?',
  34. user: 1
  35. }, {
  36. message: 'All Good! you?',
  37. user: 0
  38. }, {
  39. message: 'Dont you feel sad?',
  40. user: 1
  41. }, {
  42. message: 'Why?',
  43. user: 0
  44. }, {
  45. message: 'Cause you flunked the quiz and probably will end up writing a lot of assignments',
  46. user: 1
  47. }, {
  48. message: 'Meh, I will game!',
  49. user: 0
  50. }, {
  51. message: 'Nice! Which game?',
  52. user: 1
  53. }, {
  54. message: 'WOW',
  55. user: 0
  56. }, {
  57. message: 'WOW?',
  58. user: 1
  59. }, {
  60. message: 'World of warcraft you newb!',
  61. user: 0
  62. }]
  63. }, {
  64. user: {
  65. id: 2,
  66. name: 'Sannidhi Mahajan',
  67. imgUrl: 'https://pbs.twimg.com/profile_images/416884752377843712/MW2qg7-f.jpeg'
  68. },
  69. conversation: [{
  70. message: 'Did you get to answer Today\'s Quiz?',
  71. user: 2
  72. }, {
  73. message: 'Yes!, wbu?',
  74. user: 0
  75. }, {
  76. message: 'I Flunked as usual',
  77. user: 0
  78. }, {
  79. message: 'Oh, tats sad! Learn to study daa',
  80. user: 2
  81. }, {
  82. message: 'I topped the class, hehe',
  83. user: 2
  84. }, {
  85. message: 'Did you get to answer Today\'s Quiz?',
  86. user: 2
  87. }, {
  88. message: 'Yes!, wbu?',
  89. user: 0
  90. }, {
  91. message: 'I Flunked as usual',
  92. user: 0
  93. }, {
  94. message: 'Oh, tats sad! Learn to study daa',
  95. user: 2
  96. }, {
  97. message: 'I topped the class, hehe',
  98. user: 2
  99. }]
  100. }, {
  101. user: {
  102. id: 3,
  103. name: 'Dwayne The Rock',
  104. imgUrl: 'https://pbs.twimg.com/profile_images/3478244961/01ebfc40ecc194a2abc81e82ab877af4.jpeg'
  105. },
  106. conversation: []
  107. }];
  108. broadCastList = [{
  109. user: {
  110. id: 1,
  111. name: '10th Standard Channel',
  112. imgUrl: 'https://lh3.googleusercontent.com/9vppS4or0GIIqIdxU7vrMFbHMOOhO3FgFWPN1WYUH4xXd9GwFvZzeCGYrhezckELzAM'
  113. },
  114. members: [],
  115. conversation: [{
  116. message: 'Hi Students, Hope your all are doing well. You will have special classes tomorrow by DK sir @4.30PM. \n Followed by Quiz. ATB!',
  117. user: 0
  118. }, {
  119. message: 'Hi Students, I have uploaded a question in the forum. Please take a look!',
  120. user: 0
  121. }]
  122. }];
  123. constructor(
  124. private location: Location
  125. ) { }
  126. ngOnInit(): void {
  127. this.searchList.chatList = this.chatList;
  128. this.searchList.broadCastList = this.broadCastList;
  129. }
  130. back() {
  131. this.location.back();
  132. }
  133. openPersonalChat(index: number) {
  134. this.selectedChat = this.chatList[index];
  135. }
  136. openBroadcastChat(index: number) {
  137. this.selectedChat = this.broadCastList[index];
  138. }
  139. getChatEvent(e: string) {
  140. if (e === 'close') {
  141. this.selectedChat = null;
  142. }
  143. if (e === 'edit') {
  144. this.showAddBroadCast = true;
  145. this.selectedBroadcastChat = JSON.parse(JSON.stringify(this.selectedChat));
  146. this.selectedChat = null;
  147. }
  148. }
  149. getChatList() {
  150. return this.chatList.filter((chat) => {
  151. return chat.conversation && chat.conversation.length > 0;
  152. })
  153. }
  154. getFormattedDate() {
  155. return moment().format('ddd, hh:MM a');
  156. }
  157. searchChats() {
  158. if (this.searchTerm) {
  159. this.searchList.chatList = this.chatList.filter((chat) => {
  160. return chat.user.name.toLowerCase().includes(this.searchTerm.toLowerCase());
  161. });
  162. this.searchList.broadCastList = this.broadCastList.filter((chat) => {
  163. return chat.user.name.toLowerCase().includes(this.searchTerm.toLowerCase());
  164. });
  165. } else {
  166. this.searchList.chatList = this.chatList;
  167. this.searchList.broadCastList = this.broadCastList;
  168. }
  169. }
  170. getAddBroadcastEvents(e: any) {
  171. if (e.type === 'close') {
  172. this.showAddBroadCast = false;
  173. }
  174. if (e.type === 'data') {
  175. let broadcastData = e.data;
  176. if (!broadcastData.user.id) {
  177. broadcastData.user.id = this.broadCastList[this.broadCastList.length - 1].user.id + 1;
  178. this.broadCastList.push(broadcastData);
  179. } else {
  180. let index = this.broadCastList.findIndex((broadcast) => {
  181. return broadcast.user.id === broadcastData.user.id;
  182. });
  183. this.broadCastList[index] = broadcastData;
  184. }
  185. this.showAddBroadCast = false;
  186. }
  187. }
  188. }