Skip to content

Commit

Permalink
Merge pull request #172 from USEPA/add_new_home_dialog
Browse files Browse the repository at this point in the history
Add new home dialog
  • Loading branch information
tbock authored Sep 9, 2024
2 parents a8768bc + 8f61a10 commit 960cc03
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions AGOLAccountRequestor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'AGOLAccountRequestor.views.redirect_middleware'
]

ROOT_URLCONF = 'AGOLAccountRequestor.urls'
Expand Down
27 changes: 27 additions & 0 deletions AGOLAccountRequestor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from rest_framework.response import Response
from django.conf import settings
from django.views.decorators.csrf import ensure_csrf_cookie
from django.contrib import messages
from django.shortcuts import redirect

logger = logging.getLogger('django')

Expand Down Expand Up @@ -81,3 +83,28 @@ def email_field_coordinator_request(request):

def error_test(request):
raise Exception("this should log")



def redirect_middleware(get_response):
# One-time configuration and initialization.

def middleware(request):
# Code to be executed for each request before
# the view (and later middleware) are called.
if 'redirect' in request.GET:
query_string = request.GET.copy()
del query_string['redirect']

messages.add_message(request, messages.WARNING, "The Account Request Tool has a new home. Please update your bookmarks to https://gpdashboard.epa.gov/request/")
path = f'{request.path}?{query_string.urlencode()}' if query_string else request.path
response = redirect(path)
else:
response = get_response(request)

# Code to be executed for each request/response after
# the view is called.

return response

return middleware
4 changes: 3 additions & 1 deletion ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {LoginService} from './auth/login.service';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatIconModule} from '@angular/material/icon';
import {MatLegacySnackBarModule} from '@angular/material/legacy-snack-bar';

describe('AppComponent', () => {
beforeEach(async(() => {
Expand All @@ -14,7 +15,8 @@ describe('AppComponent', () => {
RouterTestingModule,
HttpClientTestingModule,
MatToolbarModule,
MatIconModule
MatIconModule,
MatLegacySnackBarModule
],
declarations: [
AppComponent
Expand Down
18 changes: 16 additions & 2 deletions ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {BehaviorSubject, Observable, ReplaySubject, Subject} from 'rxjs';
import {NavigationEnd, Router, ActivatedRoute} from '@angular/router';
import {UserConfig, UserConfigService} from './auth/user-config.service';
import {environment} from '../environments/environment';
import {filter} from 'rxjs/operators';
import {filter, tap} from 'rxjs/operators';
import {MatLegacySnackBar as MatSnackBar} from '@angular/material/legacy-snack-bar';

declare var gtag;

Expand All @@ -21,7 +22,8 @@ export class AppComponent implements OnInit {
public loginService: LoginService,
public router: Router,
public route: ActivatedRoute,
public userConfig: UserConfigService
public userConfig: UserConfigService,
public snackBar: MatSnackBar
) {
const navEndEvent$ = router.events.pipe(
filter(e => e instanceof NavigationEnd)
Expand All @@ -37,6 +39,10 @@ export class AppComponent implements OnInit {
ngOnInit(): void {
this.admin_url = `${environment.local_service_endpoint}/admin/`;
this.config = this.userConfig.config;
this.route.queryParams.pipe(
filter(q => 'redirect' in q),
tap(() => this.open_redirect_message())
).subscribe()
}

logout() {
Expand All @@ -49,4 +55,12 @@ export class AppComponent implements OnInit {
close_warning() {
this.router.navigate([]);
}

open_redirect_message() {
this.router.navigate([], {queryParams: {redirect: null}, queryParamsHandling: 'merge'})
this.snackBar.open(
'The Account Request Tool has a new home. Please update your bookmarks to https://gpdashboard.epa.gov/request/',
'Dismiss',
{verticalPosition: 'top', panelClass: ['snackbar-error']})
}
}
3 changes: 3 additions & 0 deletions ui/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ mat-list-item.filter-btn div {
.snackbar-error {
background-color: darkorange !important;
color: black !important;
.mat-simple-snackbar-action {
color: black;
}
}

div.mat-dialog-actions {
Expand Down

0 comments on commit 960cc03

Please sign in to comment.