Base view
This commit is contained in:
16
Frontend/src/app/services/data.service.spec.ts
Normal file
16
Frontend/src/app/services/data.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DataService } from './data.service';
|
||||
|
||||
describe('DataService', () => {
|
||||
let service: DataService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DataService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
13
Frontend/src/app/services/data.service.ts
Normal file
13
Frontend/src/app/services/data.service.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { User } from '../models/user';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DataService {
|
||||
currentUser?: User;
|
||||
public showLoader: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
16
Frontend/src/app/services/device.service.spec.ts
Normal file
16
Frontend/src/app/services/device.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DeviceService } from './device.service';
|
||||
|
||||
describe('DeviceService', () => {
|
||||
let service: DeviceService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DeviceService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
50
Frontend/src/app/services/device.service.ts
Normal file
50
Frontend/src/app/services/device.service.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { MediaMatcher } from '@angular/cdk/layout';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DeviceService {
|
||||
|
||||
private TABLET_WIDTH = 1000;
|
||||
private DESKTOP_WIDTH = 1400;
|
||||
|
||||
public orientation?: "landscape" | "portraid";
|
||||
public flipPhone: boolean = false;
|
||||
public width?: number;
|
||||
|
||||
constructor(
|
||||
private mediaMacher: MediaMatcher
|
||||
) {
|
||||
this.checkScreen();
|
||||
window.addEventListener("resize", () => {
|
||||
this.checkScreen();
|
||||
});
|
||||
}
|
||||
checkScreen() {
|
||||
const isPortrait = window.outerWidth < window.outerHeight;
|
||||
if (
|
||||
isPortrait &&
|
||||
window.outerWidth <this.TABLET_WIDTH
|
||||
) {
|
||||
this.flipPhone = true;
|
||||
} else {
|
||||
this.flipPhone = false;
|
||||
}
|
||||
this.orientation = isPortrait ? "portraid" : "landscape";
|
||||
this.width = window.outerWidth;
|
||||
}
|
||||
isMobile(): boolean {
|
||||
return window.outerWidth < this.TABLET_WIDTH;
|
||||
}
|
||||
isTablet(): boolean {
|
||||
return window.outerWidth > this.TABLET_WIDTH && window.outerWidth < this.DESKTOP_WIDTH;
|
||||
}
|
||||
isDesktop(): boolean {
|
||||
return window.outerWidth > this.DESKTOP_WIDTH;
|
||||
}
|
||||
toString() {
|
||||
return `Orientation: ${this.orientation}, Width: ${this.width}, Flip: ${this.flipPhone}, IsMobile: ${this.isMobile()}
|
||||
IsTablet: ${this.isTablet()}, IsDesktop: ${this.isDesktop()}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user