kj1352 5 лет назад
Родитель
Сommit
6280782c71
6 измененных файлов: 55 добавлений и 6 удалений
  1. +1
    -1
      angular.json
  2. +5
    -3
      src/app/app.component.ts
  3. +3
    -1
      src/app/app.module.ts
  4. +16
    -0
      src/app/services/update.service.spec.ts
  5. +29
    -0
      src/app/services/update.service.ts
  6. +1
    -1
      src/app/welcome/welcome.component.ts

+ 1
- 1
angular.json Просмотреть файл

@@ -1,6 +1,6 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"version": 2.0,
"newProjectRoot": "projects",
"projects": {
"lms-app-new": {


+ 5
- 3
src/app/app.component.ts Просмотреть файл

@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { UpdateService } from './services/update.service';

@Component({
selector: 'app-root',
@@ -7,9 +7,11 @@ import { Component } from '@angular/core';
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
constructor(
private updateService: UpdateService,
) {
if (!localStorage.demoType) {
localStorage.demoType = 'Teacher';
localStorage.demoType = 'Student';
}
}
}

+ 3
- 1
src/app/app.module.ts Просмотреть файл

@@ -11,6 +11,7 @@ import { DragDropModule } from '@angular/cdk/drag-drop';

// Import services
import { DemoService } from './services/demo.service';
import { UpdateService } from './services/update.service';

// Component imports
import { AppComponent } from './app.component';
@@ -85,7 +86,8 @@ import { QuestionComponent } from './tabs/courses/test/question-sheet/question/q
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [
DemoService
DemoService,
UpdateService
],
bootstrap: [AppComponent]
})


+ 16
- 0
src/app/services/update.service.spec.ts Просмотреть файл

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { UpdateService } from './update.service';

describe('UpdateService', () => {
let service: UpdateService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UpdateService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});

+ 29
- 0
src/app/services/update.service.ts Просмотреть файл

@@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';

@Injectable({
providedIn: 'root'
})
export class UpdateService {

constructor(private swUpdate: SwUpdate) {
if (!this.swUpdate.isEnabled) {
console.log('Nope SW');
} else {
this.swUpdate.checkForUpdate().then((ev) => {
console.log(ev);
}, (err) => {
console.log(err);
});
}

this.swUpdate.available.subscribe((evt: any) => {
this.presentToastWithOptions('Update Available');
});
}

public async presentToastWithOptions(message: string) {
alert('New Update');
location.reload();
}
}

+ 1
- 1
src/app/welcome/welcome.component.ts Просмотреть файл

@@ -14,7 +14,7 @@ export class WelcomeComponent implements OnInit {
private demoService: DemoService
) { }

ngOnInit(): void {
ngOnInit(): void {
this.demoType = localStorage.demoType;
if (this.demoType === 'Student') {
this.classList = this.demoService.studentClassList;