Merge branch 'master' of Software_Engineering_I/greenvironment-frontend into max_dev
commit
8e218da95f
@ -1,37 +1,47 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject} from 'rxjs';
|
import {BehaviorSubject} from 'rxjs';
|
||||||
import {User} from '../models/user';
|
import {User} from '../models/user';
|
||||||
|
import {FriendInfo} from '../models/friendinfo';
|
||||||
|
import {Group} from '../models/group';
|
||||||
|
import {GroupInfo} from '../models/groupinfo';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class DatasharingService {
|
export class DatasharingService {
|
||||||
|
|
||||||
private userInfoSource = new BehaviorSubject<User>(new User());
|
currentUser = new BehaviorSubject<User>(new User());
|
||||||
private chatIDsSource = new BehaviorSubject<number[]>(new Array<number>());
|
|
||||||
currentUserInfo = this.userInfoSource.asObservable();
|
|
||||||
currentChatIDs = this.chatIDsSource.asObservable();
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
changeUserInfo(pUserInfo: User) {
|
|
||||||
this.userInfoSource.next(pUserInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
addSentRequestUserID(id: number) {
|
addSentRequestUserID(id: number) {
|
||||||
const user: User = this.userInfoSource.getValue();
|
const user: User = this.currentUser.getValue();
|
||||||
user.sentRequestUserIDs.push(id);
|
user.sentRequestUserIDs.push(id);
|
||||||
this.changeUserInfo(user);
|
this.currentUser.next(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
addGroupToUser(group: GroupInfo) {
|
||||||
|
const user = this.currentUser.getValue();
|
||||||
|
user.groups.push(group);
|
||||||
|
user.groupCount++;
|
||||||
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addFriendToUser(friend: FriendInfo) {
|
||||||
|
const user = this.currentUser.getValue();
|
||||||
|
user.friends.push(friend);
|
||||||
|
user.friendCount++;
|
||||||
|
this.currentUser.next(user);
|
||||||
|
}
|
||||||
|
|
||||||
setDarkMode(active: boolean) {
|
setDarkMode(active: boolean) {
|
||||||
const user: User = this.userInfoSource.getValue();
|
const user: User = this.currentUser.getValue();
|
||||||
user.darkmode = active;
|
user.darkmode = active;
|
||||||
this.changeUserInfo(user);
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeChatIDs(pChatIDs: number[]) {
|
changeUserInfo(user: User) {
|
||||||
this.chatIDsSource.next(pChatIDs);
|
this.currentUser.next(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import {TestBed} from '@angular/core/testing';
|
|
||||||
|
|
||||||
import {DocumentService} from './document.service';
|
|
||||||
|
|
||||||
describe('DocumentService', () => {
|
|
||||||
beforeEach(() => TestBed.configureTestingModule({}));
|
|
||||||
|
|
||||||
it('should be created', () => {
|
|
||||||
const service: DocumentService = TestBed.get(DocumentService);
|
|
||||||
expect(service).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,39 +0,0 @@
|
|||||||
import {Injectable} from '@angular/core';
|
|
||||||
|
|
||||||
import {Socket} from 'ngx-socket-io';
|
|
||||||
|
|
||||||
import {Document} from '../models/document';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class DocumentService {
|
|
||||||
currentDocument = this.socket.fromEvent<Document>('document');
|
|
||||||
documents = this.socket.fromEvent<string[]>('documents');
|
|
||||||
|
|
||||||
constructor(private socket: Socket) {
|
|
||||||
}
|
|
||||||
|
|
||||||
getDocument(id: string) {
|
|
||||||
this.socket.emit('getDoc', id);
|
|
||||||
}
|
|
||||||
|
|
||||||
newDocument() {
|
|
||||||
this.socket.emit('addDoc', {id: this.docId(), doc: ''});
|
|
||||||
}
|
|
||||||
|
|
||||||
editDocument(document: Document) {
|
|
||||||
this.socket.emit('editDoc', document);
|
|
||||||
}
|
|
||||||
|
|
||||||
private docId() {
|
|
||||||
let text = '';
|
|
||||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
||||||
|
|
||||||
for (let i = 0; i < 5; i++) {
|
|
||||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue