@tech4good/angular-schematics 13.5.0 → 13.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tech4good/angular-schematics",
3
- "version": "13.5.0",
3
+ "version": "13.6.0",
4
4
  "description": "A set of schematics for generating modules, containers, components, and entities",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig.json",
@@ -5,9 +5,8 @@ name: Angular Github CI
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [ master ]
8
+ branches: [ master, main ]
9
9
  pull_request:
10
- branches: [ master ]
11
10
 
12
11
  jobs:
13
12
  build:
@@ -1,3 +1,4 @@
1
1
  <div class="content-container">
2
+ <app-redeployment-warning></app-redeployment-warning>
2
3
  <router-outlet></router-outlet>
3
4
  </div>
@@ -1,4 +1,11 @@
1
1
  .content-container {
2
2
  height: 100%;
3
3
  width: 100%;
4
+ position: relative;
5
+
6
+ app-redeployment-warning {
7
+ position: fixed;
8
+ top: 15px;
9
+ right: 15px;
10
+ }
4
11
  }
@@ -5,6 +5,7 @@ import * as fromStore from './core/store/app.reducer';
5
5
  import { LoadAuth } from './core/store/auth/auth.actions';
6
6
  import { RoutingStateService } from './core/router/routing-state.service';
7
7
  import { TimeAnalyticsService } from './core/analytics/time-analytics.service';
8
+ import { DetectRedeploymentService } from './shared/components/redeployment-warning/redeployment-warning.service';
8
9
 
9
10
  @Component({
10
11
  selector: 'app-root',
@@ -17,6 +18,7 @@ export class AppComponent implements OnInit {
17
18
  private routingState: RoutingStateService,
18
19
  private store: Store<fromStore.State>,
19
20
  private analytics: TimeAnalyticsService,
21
+ private detectRedeployment: DetectRedeploymentService,
20
22
  ) {
21
23
  }
22
24
 
@@ -37,5 +39,8 @@ export class AppComponent implements OnInit {
37
39
  }
38
40
  document.getElementsByClassName('content-container')[0].scrollTop = 0;
39
41
  });
42
+
43
+ // Continually check whether a new app version has been deployed.
44
+ this.detectRedeployment.init();
40
45
  }
41
46
  }
@@ -0,0 +1,10 @@
1
+ <div
2
+ class="warning-container"
3
+ *ngIf="showRedeploymentWarning"
4
+ >
5
+ <div class="header">
6
+ <div class="title">This version is out of date!</div>
7
+ <img (click)="close()" src="/assets/img/close-x.svg" />
8
+ </div>
9
+ <button (click)="update()" class="update">Update Now</button>
10
+ </div>
@@ -0,0 +1,46 @@
1
+ :host {
2
+ z-index: 100;
3
+
4
+ .warning-container {
5
+ padding: 10px 13px;
6
+ display: flex;
7
+ flex-direction: column;
8
+ width: 350px;
9
+ height: 63px;
10
+ background: #fff;
11
+ border-radius: 5px;
12
+ border: 1px solid #999;
13
+ box-shadow: 0px 1px 4px #999;
14
+
15
+ .header {
16
+ display: flex;
17
+ width: 100%;
18
+
19
+ .title {
20
+ text-transform: uppercase;
21
+ color: #283262;
22
+ font-weight: bold;
23
+ font-size: 13px;
24
+ }
25
+
26
+ img {
27
+ cursor: pointer;
28
+ margin-left: auto;
29
+ }
30
+ }
31
+
32
+ button {
33
+ margin-top: auto;
34
+ border: none;
35
+ padding: 0;
36
+ width: fit-content;
37
+ outline: 0;
38
+ font-weight: bold;
39
+ font-size: 13px;
40
+ text-decoration-line: underline;
41
+ background: none;
42
+ text-transform: capitalize;
43
+ cursor: pointer;
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,24 @@
1
+ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { RedeploymentWarningComponent } from './redeployment-warning.component';
4
+
5
+ describe('RedeploymentWarningComponent', () => {
6
+ let component: RedeploymentWarningComponent;
7
+ let fixture: ComponentFixture<RedeploymentWarningComponent>;
8
+
9
+ beforeEach(waitForAsync(() => {
10
+ TestBed.configureTestingModule({
11
+ declarations: [RedeploymentWarningComponent],
12
+ }).compileComponents();
13
+ }));
14
+
15
+ beforeEach(() => {
16
+ fixture = TestBed.createComponent(RedeploymentWarningComponent);
17
+ component = fixture.componentInstance;
18
+ fixture.detectChanges();
19
+ });
20
+
21
+ it('should create', () => {
22
+ expect(component).toBeTruthy();
23
+ });
24
+ });
@@ -0,0 +1,29 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+ import { DetectRedeploymentService } from './redeployment-warning.service';
3
+
4
+ @Component({
5
+ selector: 'app-redeployment-warning',
6
+ templateUrl: './redeployment-warning.component.html',
7
+ styleUrls: ['./redeployment-warning.component.scss'],
8
+ })
9
+ export class RedeploymentWarningComponent implements OnInit {
10
+ showRedeploymentWarning: boolean = false;
11
+
12
+ constructor(public detectRedeployment: DetectRedeploymentService) {}
13
+
14
+ ngOnInit() {
15
+ this.detectRedeployment.redeployed().subscribe(() => {
16
+ this.showRedeploymentWarning = true;
17
+ });
18
+ }
19
+
20
+ /** Triggers a refresh. */
21
+ update() {
22
+ this.detectRedeployment.refresh();
23
+ }
24
+
25
+ /** Ignores the warning. */
26
+ close() {
27
+ this.showRedeploymentWarning = false;
28
+ }
29
+ }
@@ -0,0 +1,63 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { BehaviorSubject, Observable, interval, Subject, from, ConnectableObservable } from 'rxjs';
3
+ import { startWith, multicast, distinctUntilChanged, tap, skip, map, filter, mergeMap } from 'rxjs/operators';
4
+
5
+ @Injectable({
6
+ providedIn: 'root',
7
+ })
8
+ export class DetectRedeploymentService {
9
+ /** Event stream that emits when an app redeployment is detected. */
10
+ private redeployed$: Observable<void>;
11
+ private initialized$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
12
+
13
+ constructor() {}
14
+
15
+ /** Sets redeployed$ and returns it. */
16
+ public init() {
17
+ // Matches the filename of the main javascript file, which contains the hash in the name
18
+ const regexp = /main[-a-z0-9]*\.([a-f0-9]*)\.js/;
19
+
20
+ const observable: ConnectableObservable<void> = interval(2 * 60 * 1000) // every 2 minutes
21
+ .pipe(
22
+ startWith(0),
23
+ // Fetch index.html with a timestamp query parameter so it definitely doesn't get cached anywhere.
24
+ mergeMap(() => fetch('/index.html?t=' + Date.now())),
25
+ mergeMap((urlResponse) => urlResponse.text()),
26
+ map((responseText) => {
27
+ const m = responseText.match(regexp);
28
+ if (m === null) {
29
+ // Probably running a dev build or something where there's no hash.
30
+ // No biggie, we'll just do nothing.
31
+ return null;
32
+ } else {
33
+ return m[1];
34
+ }
35
+ }),
36
+ filter((val) => !!val),
37
+ // Only emit when there are unique versions
38
+ distinctUntilChanged(),
39
+ // Skip the first starting version so we only get changes
40
+ skip(1),
41
+ // Modeled after example 1 in: https://www.learnrxjs.io/operators/multicasting/multicast.html
42
+ multicast(() => new Subject()),
43
+ ) as ConnectableObservable<void>;
44
+
45
+ observable.connect();
46
+
47
+ this.redeployed$ = observable;
48
+ this.initialized$.next(true);
49
+
50
+ return observable;
51
+ }
52
+
53
+ public redeployed() {
54
+ return this.initialized$.pipe(
55
+ filter((val) => val),
56
+ mergeMap(() => this.redeployed$),
57
+ );
58
+ }
59
+
60
+ public refresh() {
61
+ window.location.reload();
62
+ }
63
+ }
@@ -23,6 +23,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
23
23
  // Containers
24
24
 
25
25
  // Components
26
+ import { RedeploymentWarningComponent } from './components/redeployment-warning/redeployment-warning.component';
26
27
 
27
28
  // Pipes
28
29
 
@@ -53,6 +54,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
53
54
  declarations: [
54
55
  // Containers
55
56
  // Components
57
+ RedeploymentWarningComponent,
56
58
  // Pipes
57
59
  ],
58
60
  exports: [
@@ -75,6 +77,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
75
77
  MatRadioModule,
76
78
  // Containers
77
79
  // Components
80
+ RedeploymentWarningComponent,
78
81
  // Pipes
79
82
  ],
80
83
  })