diff --git a/src/app/guards/home.guard.spec.ts b/src/app/guards/home.guard.spec.ts new file mode 100644 index 000000000..b14fb3fe3 --- /dev/null +++ b/src/app/guards/home.guard.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { HomeGuard } from './home.guard'; + +describe('HomeGuard', () => { + let guard: HomeGuard; + + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(HomeGuard); + }); + + it('should be created', () => { + expect(guard).toBeTruthy(); + }); +}); diff --git a/src/app/guards/home.guard.ts b/src/app/guards/home.guard.ts new file mode 100644 index 000000000..3fcf2d2e8 --- /dev/null +++ b/src/app/guards/home.guard.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; +import { Observable } from 'rxjs'; +import { AuthConnstants } from '../config/auth-constants'; +import { StorageService } from '../services/storage.service'; + +@Injectable({ + providedIn: 'root' +}) +export class HomeGuard implements CanActivate { + constructor( + public storageService:StorageService, + private router:Router + ){} + + canActivate(): Promise{ + return new Promise(resolve => { + this.storageService.get(AuthConnstants.AUTH).then(res => { + if(res){ + resolve(true); + } + else{ + this.router.navigate(['']); + resolve(false); + } + }).catch(err =>{ + resolve(false); + }) + }); + } + +} diff --git a/src/app/guards/index.guard.spec.ts b/src/app/guards/index.guard.spec.ts new file mode 100644 index 000000000..7c19426b5 --- /dev/null +++ b/src/app/guards/index.guard.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { IndexGuard } from './index.guard'; + +describe('IndexGuard', () => { + let guard: IndexGuard; + + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(IndexGuard); + }); + + it('should be created', () => { + expect(guard).toBeTruthy(); + }); +}); diff --git a/src/app/guards/index.guard.ts b/src/app/guards/index.guard.ts new file mode 100644 index 000000000..3689b53c2 --- /dev/null +++ b/src/app/guards/index.guard.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; +import { Observable } from 'rxjs'; +import { AuthConnstants } from '../config/auth-constants'; +import { StorageService } from '../services/storage.service'; + +@Injectable({ + providedIn: 'root' +}) +export class IndexGuard implements CanActivate { + constructor( + public storageService:StorageService, + private router:Router + ){} + canActivate(): Promise{ + return new Promise(resolve => { + this.storageService.get(AuthConnstants.AUTH).then(res => { + if(res){ + this.router.navigate(['home']); + resolve(false); + } + else{ + resolve(true); + } + }).catch(err =>{ + resolve(false); + }) + }); + } + +} diff --git a/src/app/home/home-routing.module.ts b/src/app/home/home-routing.module.ts index 7ad26d765..d2ab39539 100644 --- a/src/app/home/home-routing.module.ts +++ b/src/app/home/home-routing.module.ts @@ -1,5 +1,7 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; +import { HomeGuard } from '../guards/home.guard'; +import { UserDataResolver } from '../resolvers/userData.resolver'; import { HomePage } from './home.page'; @@ -7,6 +9,10 @@ const routes: Routes = [ { path: 'home', component: HomePage, + /* canActivate: [HomeGuard], */ + resolve: { + userData: UserDataResolver + }, children: [ { path: 'events', diff --git a/src/app/index/index-routing.module.ts b/src/app/index/index-routing.module.ts index ac32c6fd4..3f55beadb 100644 --- a/src/app/index/index-routing.module.ts +++ b/src/app/index/index-routing.module.ts @@ -1,11 +1,13 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; +import { IndexGuard } from '../guards/index.guard'; import { IndexPage } from './index.page'; const routes: Routes = [ { path: '', component: IndexPage, + /* canActivate: [IndexGuard], */ children: [ /*{ path: '', diff --git a/src/app/pages/chat/chat-routing.module.ts b/src/app/pages/chat/chat-routing.module.ts index 2f67102f3..7c66d7d68 100644 --- a/src/app/pages/chat/chat-routing.module.ts +++ b/src/app/pages/chat/chat-routing.module.ts @@ -1,17 +1,25 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; - -import { ChatPage } from './chat.page'; - -const routes: Routes = [ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { ChatPage } from './chat.page'; + +const routes: Routes = [ + { + path: '', + component: ChatPage + }, { + path: 'conversation', + loadChildren: () => import('./conversation/conversation.module').then( m => m.ConversationPageModule) + }, { - path: '', - component: ChatPage + path: 'newchat', + loadChildren: () => import('./newchat/newchat.module').then( m => m.NewchatPageModule) } -]; -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], -}) -export class ChatPageRoutingModule {} +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class ChatPageRoutingModule {} diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index f00f3899c..fbf8ddb3e 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -1,39 +1,51 @@ - chat + Chat + + - - -

{{message.user}}

- {{message.msg}} -
{{message.createdAt | date: 'HH:mm'}}
-
- - -

{{message.user}}

- {{message.msg}} -
{{message.createdAt | date: 'HH:mm'}}
-
-
- -
+ + + + Contactos + + + Grupos + + + +
+ + + + + +
+

Secretario Assuntos Sociais

+

Podemos marcar reunião para amanha

+
+
+
+
+
+ + + + + +
+

Viagem a Maputo

+

Grande momento.

+
+
+
+
+ +
+
- - - - - - - - - - - - - - + diff --git a/src/app/pages/chat/chat.page.scss b/src/app/pages/chat/chat.page.scss index 89c4e3b15..e91f81b0e 100644 --- a/src/app/pages/chat/chat.page.scss +++ b/src/app/pages/chat/chat.page.scss @@ -1,50 +1,23 @@ -ion-content{ - background-color:#fefefe; +.iconschatnew-group{ + width: 30px; + height: 30px; + object-fit: contain; + margin: 0 5px 0 5px; } -.chat-container{ - margin: 10px 10px 0 10px; +.iconschatgroup-chat-40 { + width: 40px; + height: 40px; + object-fit: contain; } -.message { - padding: 5px 5px 5px 10px; - border-radius: 10px; - margin-bottom: 10px; - white-space: pre-wrap; - } - - .my-message { - background: var(--ion-color-primary); - color: #fff; - } - .my-message p{ - margin: 0; - padding: 0; - color: #9ab8e9; - } - .message-date{ - font-size: 10px; - text-align: right; - margin-right: 5px; - } - - .other-message { - background: #f2f3f7; - color: #333; - } - .other-message p{ - margin: 0; - padding: 0; - color:#959ba7; -} - - .message-input { - margin-top: 0px; - border: 1px solid var(--ion-color-medium); - border-radius: 20px; - background: #fff; - padding: 0; - margin: 0; - } - - - +.iconschatnew-conversation{ + width: 30px; + height: 30px; + object-fit: contain; + margin: 0 5px 0 5px; +} +.iconschatchat-40 { + width: 40px; + height: 40px; + object-fit: contain; +} \ No newline at end of file diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index b6cee9d1e..b87c25260 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -1,8 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { Socket } from 'ngx-socket-io'; -import { ToastController } from '@ionic/angular'; -import { WebsocketService } from 'src/app/services/websocket.service'; -import { fromEvent } from 'rxjs'; +import { AuthService } from 'src/app/services/auth.service'; +import { ChatService } from 'src/app/services/chat.service'; @Component({ selector: 'app-chat', @@ -10,43 +8,32 @@ import { fromEvent } from 'rxjs'; styleUrls: ['./chat.page.scss'], }) export class ChatPage implements OnInit { + loggedUser: any; + /* Set segment variable */ + segment:string; + groupList: any[]; + result:any; - message = ''; - messages = []; - currentUser = ''; - - constructor(private websocket:WebsocketService, private socket: Socket) { } + constructor( + private chatService: ChatService, + private authService: AuthService) { } ngOnInit() { - console.log("ON"); - this.socket.connect(); - - /* Set current user */ - let name = `User-${new Date().getTime()}`; - this.currentUser=name; - - this.socket.emit('set-name', name); - - /* Reat from event calling "fromEvent" */ - this.socket.fromEvent('users-changed').subscribe(data =>{ - console.log('gOT data:', data); + this.segment = "Contactos"; + this.authService.userData$.subscribe((res:any)=>{ + this.loggedUser=res; }); - - /* Add message to the array of messages */ - this.socket.fromEvent('message').subscribe(message =>{ - console.log('New:', message); - this.messages.push(message); + /* this.getGroups(); */ + } + onSegmentChange(){ + this.RefreshEvents(); + } + RefreshEvents(){} + /* getGroups(){ + this.result = this.chatService.getPrivateGroups().subscribe((res:any)=>{ + this.groupList = res.users; + console.log(this.groupList); + }); - - - } - sendMessage(){ - this.socket.emit('send-message', {text: this.message}); - this.message=""; - } - - ionViewWillLeave(){ - this.socket.disconnect(); - } - + } */ } diff --git a/src/app/pages/chat/conversation/conversation-routing.module.ts b/src/app/pages/chat/conversation/conversation-routing.module.ts new file mode 100644 index 000000000..07d2654ce --- /dev/null +++ b/src/app/pages/chat/conversation/conversation-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { ConversationPage } from './conversation.page'; + +const routes: Routes = [ + { + path: '', + component: ConversationPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class ConversationPageRoutingModule {} diff --git a/src/app/pages/chat/conversation/conversation.module.ts b/src/app/pages/chat/conversation/conversation.module.ts new file mode 100644 index 000000000..22dca4438 --- /dev/null +++ b/src/app/pages/chat/conversation/conversation.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { ConversationPageRoutingModule } from './conversation-routing.module'; + +import { ConversationPage } from './conversation.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + ConversationPageRoutingModule + ], + declarations: [ConversationPage] +}) +export class ConversationPageModule {} diff --git a/src/app/pages/chat/conversation/conversation.page.html b/src/app/pages/chat/conversation/conversation.page.html new file mode 100644 index 000000000..7ef609bfc --- /dev/null +++ b/src/app/pages/chat/conversation/conversation.page.html @@ -0,0 +1,49 @@ + + + + + + {{chatUser.name}} + + + + + + +

{{message.user}}

+ {{message.msg}} +
{{message.createdAt | date: 'HH:mm'}}
+
+ + +

{{message.user}}

+ {{message.msg}} +
{{message.createdAt | date: 'HH:mm'}}
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/app/pages/chat/conversation/conversation.page.scss b/src/app/pages/chat/conversation/conversation.page.scss new file mode 100644 index 000000000..67e5a83e2 --- /dev/null +++ b/src/app/pages/chat/conversation/conversation.page.scss @@ -0,0 +1,55 @@ +ion-content{ + background-color:#fefefe; +} +.chat-container{ + margin: 10px 10px 0 10px; +} +.message { + padding: 5px 5px 5px 10px; + border-radius: 10px; + margin-bottom: 10px; + white-space: pre-wrap; + } + + .my-message { + background: var(--ion-color-primary); + color: #fff; + } + .my-message p{ + margin: 0; + padding: 0; + color: #9ab8e9; + } + .message-date{ + font-size: 10px; + text-align: right; + margin-right: 5px; + } + + .other-message { + background: #f2f3f7; + color: #333; + } + .other-message p{ + margin: 0; + padding: 0; + color:#959ba7; +} + + .message-input { + margin-top: 0px; + + background: #fff; + padding: 0; + margin: 0; + } + + + .div-message{ + border: 1px solid var(--ion-color-medium); + border-radius: 20px; + } + + + + diff --git a/src/app/pages/chat/conversation/conversation.page.spec.ts b/src/app/pages/chat/conversation/conversation.page.spec.ts new file mode 100644 index 000000000..9e1cc5cee --- /dev/null +++ b/src/app/pages/chat/conversation/conversation.page.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { ConversationPage } from './conversation.page'; + +describe('ConversationPage', () => { + let component: ConversationPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ConversationPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(ConversationPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/chat/conversation/conversation.page.ts b/src/app/pages/chat/conversation/conversation.page.ts new file mode 100644 index 000000000..be26471fb --- /dev/null +++ b/src/app/pages/chat/conversation/conversation.page.ts @@ -0,0 +1,73 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { ModalController, NavParams } from '@ionic/angular'; +import { AuthService } from 'src/app/services/auth.service'; + +@Component({ + selector: 'app-conversation', + templateUrl: './conversation.page.html', + styleUrls: ['./conversation.page.scss'], +}) +export class ConversationPage implements OnInit { + + message = ''; + messages = []; + currentUser = ''; + + constructor( + private authService: AuthService, + private router:Router, + private modalController: ModalController, + private navParams: NavParams) { } + + loggedUser: any; + chatUser: any; + + ngOnInit() { + this.authService.userData$.subscribe((res:any)=>{ + this.loggedUser=res; + }) + this.chatUser = this.navParams.get('user'); + console.log(this.navParams.get('user')); + + console.log(this.chatUser.name); + + + /* console.log("ON"); + this.socket.connect(); + + //Set current user + let name = `User-${new Date().getTime()}`; + this.currentUser=name; + + this.socket.emit('set-name', name); + + //Reat from event calling "fromEvent" + this.socket.fromEvent('users-changed').subscribe(data =>{ + console.log('gOT data:', data); + }); + + //Add message to the array of messages + this.socket.fromEvent('message').subscribe(message =>{ + console.log('New:', message); + this.messages.push(message); + }); */ + + } + close(){ + this.router.navigate(['/home/chat']); + this.modalController.dismiss(null); + } + sendMessage(){ + + } + /* sendMessage(){ + this.socket.emit('send-message', {text: this.message}); + this.message=""; + } + + ionViewWillLeave(){ + this.socket.disconnect(); + } */ + +} diff --git a/src/app/pages/chat/newchat/newchat-routing.module.ts b/src/app/pages/chat/newchat/newchat-routing.module.ts new file mode 100644 index 000000000..98eb05c20 --- /dev/null +++ b/src/app/pages/chat/newchat/newchat-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { NewchatPage } from './newchat.page'; + +const routes: Routes = [ + { + path: '', + component: NewchatPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class NewchatPageRoutingModule {} diff --git a/src/app/pages/chat/newchat/newchat.module.ts b/src/app/pages/chat/newchat/newchat.module.ts new file mode 100644 index 000000000..ea115e8f4 --- /dev/null +++ b/src/app/pages/chat/newchat/newchat.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { NewchatPageRoutingModule } from './newchat-routing.module'; + +import { NewchatPage } from './newchat.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + NewchatPageRoutingModule + ], + declarations: [NewchatPage] +}) +export class NewchatPageModule {} diff --git a/src/app/pages/chat/newchat/newchat.page.html b/src/app/pages/chat/newchat/newchat.page.html new file mode 100644 index 000000000..736a366e0 --- /dev/null +++ b/src/app/pages/chat/newchat/newchat.page.html @@ -0,0 +1,20 @@ + + + + + + Nova Conversa + + + + + + + + + + {{user.name}} + + + + diff --git a/src/app/pages/chat/newchat/newchat.page.scss b/src/app/pages/chat/newchat/newchat.page.scss new file mode 100644 index 000000000..8759df7f9 --- /dev/null +++ b/src/app/pages/chat/newchat/newchat.page.scss @@ -0,0 +1,3 @@ +ion-searchbar{ + --border-radius: 20px; +} \ No newline at end of file diff --git a/src/app/pages/chat/newchat/newchat.page.spec.ts b/src/app/pages/chat/newchat/newchat.page.spec.ts new file mode 100644 index 000000000..70ff90072 --- /dev/null +++ b/src/app/pages/chat/newchat/newchat.page.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { NewchatPage } from './newchat.page'; + +describe('NewchatPage', () => { + let component: NewchatPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NewchatPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(NewchatPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/chat/newchat/newchat.page.ts b/src/app/pages/chat/newchat/newchat.page.ts new file mode 100644 index 000000000..277d2469c --- /dev/null +++ b/src/app/pages/chat/newchat/newchat.page.ts @@ -0,0 +1,65 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { ModalController } from '@ionic/angular'; +import { Observable } from 'rxjs'; +import { ChatService } from 'src/app/services/chat.service'; +import { ConversationPage } from '../conversation/conversation.page'; + +@Component({ + selector: 'app-newchat', + templateUrl: './newchat.page.html', + styleUrls: ['./newchat.page.scss'], +}) +export class NewchatPage implements OnInit { + userList: any[]; + + constructor( + private chatService: ChatService, + private modalController: ModalController, + private router:Router) { } + + result:any; + searchCountryString:any; + searchedItem:any; + + ngOnInit() { + this.getUsers(); + } + + getUsers(){ + this.result = this.chatService.getAllUsers().subscribe((res:any)=>{ + this.userList = res.users; + this.searchedItem = this.userList; + }); + } + + userSelected(id){ + console.log(id); + this.router.navigate(['/home/chat/conversation']); + + } + onChange(event){ + const val = event.detail.value; + this.searchedItem = this.userList; + if(val && val.trim() != ''){ + this.searchedItem = this.searchedItem.filter((item:any) =>{ + return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1); + }); + } + } + + async starConversation(selectedUser) { + const modal = await this.modalController.create({ + component: ConversationPage, + cssClass: 'conversation', + backdropDismiss: false, + componentProps: { + user: selectedUser, + } + }); + await modal.present(); + modal.onDidDismiss(); + } + + +} diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index c72618466..e7305a989 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -5,6 +5,8 @@ import { User } from 'src/app/models/user.model'; import { ToastService } from 'src/app/services/toast.service'; import { environment } from 'src/environments/environment'; import { AlertController } from '@ionic/angular'; +import { StorageService } from 'src/app/services/storage.service'; +import { AuthConnstants } from 'src/app/config/auth-constants'; @Component({ @@ -19,9 +21,13 @@ export class LoginPage implements OnInit { password: string = environment.defaultuserpwd; userattempt: User; + public body = {"user": this.username,"password": this.password}; + public postData = {"user": "admin","password": this.password}; + constructor( private router: Router, private authService: AuthService, + private storageService: StorageService, private toastService: ToastService, public alertController: AlertController) { } @@ -47,6 +53,29 @@ export class LoginPage implements OnInit { await alert.present(); } + loginAction(){ + + if(this.validateInput()){ + this.authService.loginChat2(this.postData).subscribe((res: any) =>{ + if(res.data){ + this.storageService.store(AuthConnstants.AUTH, res.data); + console.log('Log RockectChat OK'); + console.log(res.data); + + } + else{ + console.log("Invalid username or password!"); + } + }, + (error:any) =>{ + console.log('Network error'); + }) + } + else{ + this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.'); + } + } + async Login(){ try { //Go to our home in home/feed. @@ -57,9 +86,10 @@ export class LoginPage implements OnInit { domainName: environment.domain, BasicAuthKey: "" } - if (await this.authService.login(this.userattempt)) { + this.loginAction(); + console.log('Log Gabinete Digital OK'); this.router.navigate(['/home/events']); } else diff --git a/src/app/resolvers/userData.resolver.ts b/src/app/resolvers/userData.resolver.ts new file mode 100644 index 000000000..b5b5bbc93 --- /dev/null +++ b/src/app/resolvers/userData.resolver.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { AuthService } from '../services/auth.service'; + +@Injectable({ + providedIn: 'root' +}) +export class UserDataResolver{ + constructor(private authService: AuthService){} + + resolve(){ + return this.authService.getUserData(); + } +} \ No newline at end of file diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 7726e15f4..3c2a6ea92 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,19 +1,23 @@ import { Injectable } from '@angular/core'; import { StorageService } from './storage.service'; import { Router } from '@angular/router'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { User } from '../models/user.model'; import { environment } from 'src/environments/environment'; +import { HttpService } from './http.service'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { AuthConnstants } from '../config/auth-constants'; @Injectable({ providedIn: 'root' }) export class AuthService { - - - + userData$ = new BehaviorSubject(''); constructor( - private http: HttpClient + private http: HttpClient, + private httpService: HttpService, + private storageService:StorageService, + private router:Router ) { } public ValidatedUser:User; @@ -31,12 +35,40 @@ export class AuthService { if (result) { this.ValidatedUser = user; - } - + } return result; } logout(){ this.ValidatedUser = null; + + } + + loginChat(){ + const body = {"user": "admin","password": "tabteste@006"}; + const url = "http://192.168.100.111:3000/api/v1/login"; + return this.http.post(url, body); + } + + //Login to rocketChat server + loginChat2(postData: any):Observable { + return this.httpService.post('login', postData); + } + + //Get user data from RocketChat + getUserData(){ + this.storageService.get(AuthConnstants.AUTH).then(res=>{ + this.userData$.next(res); + }) + } + + logoutChat(){ + //this.storageService.clear(); + this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{ + this.userData$.next(''); + this.router.navigate(['']); + }) + + } } diff --git a/src/app/services/chat.service.spec.ts b/src/app/services/chat.service.spec.ts new file mode 100644 index 000000000..4d8abdfc0 --- /dev/null +++ b/src/app/services/chat.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ChatService } from './chat.service'; + +describe('ChatService', () => { + let service: ChatService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ChatService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts new file mode 100644 index 000000000..668e1ad19 --- /dev/null +++ b/src/app/services/chat.service.ts @@ -0,0 +1,41 @@ +import { HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from "rxjs" +import { AuthService } from './auth.service'; +import { HttpService } from './http.service'; +import { StorageService } from './storage.service'; +import { HttpClient, HttpHeaderResponse } from '@angular/common/http'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class ChatService { + headers: HttpHeaders; + options:any; + + + constructor( + private http:HttpClient, + private httpService: HttpService, + private authService: AuthService, + private storageService:StorageService,) { + this.headers = new HttpHeaders(); + this.authService.userData$.subscribe((res:any)=>{ + this.headers = this.headers.set('X-User-Id', res.userId); + this.headers = this.headers.set('X-Auth-Token', res.authToken); + }); + } + + getAllUsers(){ + this.options = { + headers: this.headers, + }; + console.log(this.headers); + + return this.http.get(environment.apiChatUrl+'users.list', this.options); + } + getPrivateGroups(){ + this.http.get(environment.apiChatUrl+'groups.list', this.options); + } +} diff --git a/src/app/services/fcm.service.spec.ts b/src/app/services/fcm.service.spec.ts new file mode 100644 index 000000000..0927099f8 --- /dev/null +++ b/src/app/services/fcm.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { FcmService } from './fcm.service'; + +describe('FcmService', () => { + let service: FcmService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(FcmService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/fcm.service.ts b/src/app/services/fcm.service.ts new file mode 100644 index 000000000..02793945e --- /dev/null +++ b/src/app/services/fcm.service.ts @@ -0,0 +1,64 @@ +import { Injectable } from '@angular/core'; +import { + Plugins, + PushNotification, + PushNotificationToken, + PushNotificationActionPerformed, + Capacitor +} from '@capacitor/core'; +import { Router } from '@angular/router'; + +const { PushNotifications } = Plugins; + +@Injectable({ + providedIn: 'root' +}) +export class FcmService { + + constructor(private router: Router) { } + + initPush() { + if (Capacitor.platform !== 'web') { + this.registerPush(); + } + } + private registerPush() { + PushNotifications.requestPermission().then((permission) => { + if (permission.granted) { + // Register with Apple / Google to receive push via APNS/FCM + PushNotifications.register(); + } else { + // No permission for push granted + } + }); + PushNotifications.addListener( + 'registration', + (token: PushNotificationToken) => { + console.log('My token: ' + JSON.stringify(token)); + } + ); + + PushNotifications.addListener('registrationError', (error: any) => { + console.log('Error: ' + JSON.stringify(error)); + }); + + PushNotifications.addListener( + 'pushNotificationReceived', + async (notification: PushNotification) => { + console.log('Push received: ' + JSON.stringify(notification)); + } + ); + PushNotifications.addListener( + 'pushNotificationActionPerformed', + async (notification: PushNotificationActionPerformed) => { + const data = notification.notification.data; + console.log('Action performed: ' + JSON.stringify(notification.notification)); + if (data.detailsId) { + this.router.navigateByUrl(`/home/notifications/notification-detail${data.detaisId}`); + } + } + ); + } + +} + diff --git a/src/app/services/http.service.spec.ts b/src/app/services/http.service.spec.ts new file mode 100644 index 000000000..7b345d485 --- /dev/null +++ b/src/app/services/http.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { HttpService } from './http.service'; + +describe('HttpService', () => { + let service: HttpService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(HttpService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/http.service.ts b/src/app/services/http.service.ts new file mode 100644 index 000000000..c994ced1a --- /dev/null +++ b/src/app/services/http.service.ts @@ -0,0 +1,26 @@ +import { HttpClient, HttpHeaderResponse, HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class HttpService { + + constructor(private http:HttpClient) { } + + post(serviceName:string, data:any){ + const headers = new HttpHeaders(); + const options = {header: headers, withCredentials: false}; + const url = environment.apiChatUrl+serviceName; + const body = {"user": "admin","password": "tabteste@006"}; + + return this.http.post(url, /* JSON.stringify( */data/* ), options */) + } + + get(serviceName:string, options:any){ + const url = environment.apiChatUrl+serviceName; + return this.http.get(url, options); + } +} + diff --git a/src/assets/images/icons-arrow-arrow-down-25-copy.png b/src/assets/images/icons-arrow-arrow-down-25-copy.png new file mode 100644 index 000000000..1f62f2fd0 Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25-copy.png differ diff --git a/src/assets/images/icons-arrow-arrow-down-25-copy@2x.png b/src/assets/images/icons-arrow-arrow-down-25-copy@2x.png new file mode 100644 index 000000000..c686ecf63 Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25-copy@2x.png differ diff --git a/src/assets/images/icons-arrow-arrow-down-25-copy@3x.png b/src/assets/images/icons-arrow-arrow-down-25-copy@3x.png new file mode 100644 index 000000000..7690374c9 Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25-copy@3x.png differ diff --git a/src/assets/images/icons-arrow-arrow-down-25.png b/src/assets/images/icons-arrow-arrow-down-25.png new file mode 100644 index 000000000..781a18b03 Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25.png differ diff --git a/src/assets/images/icons-arrow-arrow-down-25.svg b/src/assets/images/icons-arrow-arrow-down-25.svg new file mode 100644 index 000000000..0823c7065 --- /dev/null +++ b/src/assets/images/icons-arrow-arrow-down-25.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-arrow-arrow-down-25@2x.png b/src/assets/images/icons-arrow-arrow-down-25@2x.png new file mode 100644 index 000000000..b599dec79 Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25@2x.png differ diff --git a/src/assets/images/icons-arrow-arrow-down-25@3x.png b/src/assets/images/icons-arrow-arrow-down-25@3x.png new file mode 100644 index 000000000..ee09dec1c Binary files /dev/null and b/src/assets/images/icons-arrow-arrow-down-25@3x.png differ diff --git a/src/assets/images/icons-chat-chat-40.png b/src/assets/images/icons-chat-chat-40.png new file mode 100644 index 000000000..c65d88703 Binary files /dev/null and b/src/assets/images/icons-chat-chat-40.png differ diff --git a/src/assets/images/icons-chat-chat-40.svg b/src/assets/images/icons-chat-chat-40.svg new file mode 100644 index 000000000..015ed6c23 --- /dev/null +++ b/src/assets/images/icons-chat-chat-40.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-chat-chat-40@2x.png b/src/assets/images/icons-chat-chat-40@2x.png new file mode 100644 index 000000000..be985f238 Binary files /dev/null and b/src/assets/images/icons-chat-chat-40@2x.png differ diff --git a/src/assets/images/icons-chat-chat-40@3x.png b/src/assets/images/icons-chat-chat-40@3x.png new file mode 100644 index 000000000..cc9d0087b Binary files /dev/null and b/src/assets/images/icons-chat-chat-40@3x.png differ diff --git a/src/assets/images/icons-chat-group-chat-40.png b/src/assets/images/icons-chat-group-chat-40.png new file mode 100644 index 000000000..834216e48 Binary files /dev/null and b/src/assets/images/icons-chat-group-chat-40.png differ diff --git a/src/assets/images/icons-chat-group-chat-40.svg b/src/assets/images/icons-chat-group-chat-40.svg new file mode 100644 index 000000000..b2038a4f2 --- /dev/null +++ b/src/assets/images/icons-chat-group-chat-40.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-chat-group-chat-40@2x.png b/src/assets/images/icons-chat-group-chat-40@2x.png new file mode 100644 index 000000000..65b0ce8cd Binary files /dev/null and b/src/assets/images/icons-chat-group-chat-40@2x.png differ diff --git a/src/assets/images/icons-chat-group-chat-40@3x.png b/src/assets/images/icons-chat-group-chat-40@3x.png new file mode 100644 index 000000000..a2c471272 Binary files /dev/null and b/src/assets/images/icons-chat-group-chat-40@3x.png differ diff --git a/src/assets/images/icons-chat-new-conversation.png b/src/assets/images/icons-chat-new-conversation.png new file mode 100644 index 000000000..8bd5ca5c5 Binary files /dev/null and b/src/assets/images/icons-chat-new-conversation.png differ diff --git a/src/assets/images/icons-chat-new-conversation.svg b/src/assets/images/icons-chat-new-conversation.svg new file mode 100644 index 000000000..78ae9c52b --- /dev/null +++ b/src/assets/images/icons-chat-new-conversation.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-chat-new-conversation@2x.png b/src/assets/images/icons-chat-new-conversation@2x.png new file mode 100644 index 000000000..f2670b0cd Binary files /dev/null and b/src/assets/images/icons-chat-new-conversation@2x.png differ diff --git a/src/assets/images/icons-chat-new-conversation@3x.png b/src/assets/images/icons-chat-new-conversation@3x.png new file mode 100644 index 000000000..8fa36026d Binary files /dev/null and b/src/assets/images/icons-chat-new-conversation@3x.png differ diff --git a/src/assets/images/icons-chat-new-group.png b/src/assets/images/icons-chat-new-group.png new file mode 100644 index 000000000..64ef3bd7b Binary files /dev/null and b/src/assets/images/icons-chat-new-group.png differ diff --git a/src/assets/images/icons-chat-new-group.svg b/src/assets/images/icons-chat-new-group.svg new file mode 100644 index 000000000..d0159e97f --- /dev/null +++ b/src/assets/images/icons-chat-new-group.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-chat-new-group@2x.png b/src/assets/images/icons-chat-new-group@2x.png new file mode 100644 index 000000000..b9e0f9434 Binary files /dev/null and b/src/assets/images/icons-chat-new-group@2x.png differ diff --git a/src/assets/images/icons-chat-new-group@3x.png b/src/assets/images/icons-chat-new-group@3x.png new file mode 100644 index 000000000..dbd84fdc8 Binary files /dev/null and b/src/assets/images/icons-chat-new-group@3x.png differ diff --git a/src/assets/images/icons-chat-send.png b/src/assets/images/icons-chat-send.png new file mode 100644 index 000000000..a133db5fa Binary files /dev/null and b/src/assets/images/icons-chat-send.png differ diff --git a/src/assets/images/icons-chat-send.svg b/src/assets/images/icons-chat-send.svg new file mode 100644 index 000000000..ef257f54f --- /dev/null +++ b/src/assets/images/icons-chat-send.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/images/icons-chat-send@2x.png b/src/assets/images/icons-chat-send@2x.png new file mode 100644 index 000000000..3339da57f Binary files /dev/null and b/src/assets/images/icons-chat-send@2x.png differ diff --git a/src/assets/images/icons-chat-send@3x.png b/src/assets/images/icons-chat-send@3x.png new file mode 100644 index 000000000..c2827356d Binary files /dev/null and b/src/assets/images/icons-chat-send@3x.png differ diff --git a/src/assets/images/icons-nav-grupos-active.png b/src/assets/images/icons-nav-grupos-active.png new file mode 100644 index 000000000..b09208d84 Binary files /dev/null and b/src/assets/images/icons-nav-grupos-active.png differ diff --git a/src/assets/images/icons-nav-grupos-active@2x.png b/src/assets/images/icons-nav-grupos-active@2x.png new file mode 100644 index 000000000..b08a54b16 Binary files /dev/null and b/src/assets/images/icons-nav-grupos-active@2x.png differ diff --git a/src/assets/images/icons-nav-grupos-active@3x.png b/src/assets/images/icons-nav-grupos-active@3x.png new file mode 100644 index 000000000..a0304a91a Binary files /dev/null and b/src/assets/images/icons-nav-grupos-active@3x.png differ diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 1a12d4d56..640e53a5a 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,7 @@ export const environment = { production: true, apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/v1/api/', + apiChatUrl: 'http://192.168.100.111:3000/api/v1/', domain: 'gabinetedigital.local', defaultuser: '', defaultuserpwd: '' diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4fb899a73..0ae4f7ae8 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -5,8 +5,9 @@ export const environment = { production: false, apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/v2/api/', + apiChatUrl: 'http://192.168.100.111:3000/api/v1/', domain: 'gabinetedigital.local', - defaultuser: 'tiago.kayaya', + defaultuser: 'paulo.pinto', defaultuserpwd: 'tabteste@006' };