Skip to content

Commit

Permalink
ASP.NET Core 3.1/ Angular 9 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebenezer Monney committed May 15, 2020
1 parent d3c481e commit 0a082a3
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<label for="language" class="col-sm-3 col-form-label">{{'preferences.Language' | translate}} </label>
<div class="col-sm-4">
<ng-select id="language" [(ngModel)]="configurations.language" [searchable]="false" [clearable]="false" class="form-control">
<ng-option [value]="'en'">{{'preferences.English' | translate}} <small class="text-muted">({{'preferences.Default' | translate}})</small></ng-option>
<ng-option [value]="'en'">{{'preferences.English' | translate}} <small class="text-muted"><i>({{'preferences.Default' | translate}})</i></small></ng-option>
<ng-option [value]="'fr'">{{'preferences.French' | translate}}</ng-option>
<ng-option [value]="'de'">{{'preferences.German' | translate}}</ng-option>
<ng-option [value]="'pt'">{{'preferences.Portuguese' | translate}}</ng-option>
Expand All @@ -44,7 +44,7 @@
<label for="homePage" class="col-sm-3 col-form-label">{{'preferences.HomePage' | translate}} </label>
<div class="col-sm-4">
<ng-select id="homePage" [(ngModel)]="configurations.homeUrl" [searchable]="false" [clearable]="false" class="form-control">
<ng-option [value]="'/'"><i class=" fa fa-tachometer"></i> {{'preferences.Dashboard' | translate}} <small class="text-muted">({{'preferences.Default' | translate}})</small></ng-option>
<ng-option [value]="'/'"><i class=" fa fa-tachometer"></i> {{'preferences.Dashboard' | translate}} <small class="text-muted"><i>({{'preferences.Default' | translate}})</i></small></ng-option>
<ng-option [value]="'/customers'" *ngIf="canViewCustomers"><i class=" fa fa-handshake-o"></i> {{'preferences.Customers' | translate}}</ng-option>
<ng-option [value]="'/products'" *ngIf="canViewProducts"><i class=" fa fa-truck"></i> {{'preferences.Products' | translate}}</ng-option>
<ng-option [value]="'/orders'" *ngIf="canViewOrders"><i class=" fa fa-shopping-cart"></i> {{'preferences.Orders' | translate}}</ng-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Subscription, fromEvent } from 'rxjs';

declare var $: any;

interface EventArg { type: string; target: Element; relatedTarget: Element }
interface EventArg { type: string; target: Element; relatedTarget: Element; }

@Directive({
selector: '[appBootstrapTab]',
Expand Down
19 changes: 1 addition & 18 deletions QuickApp/ClientApp/src/app/services/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AccountEndpoint } from './account-endpoint.service';
import { AuthService } from './auth.service';
import { User } from '../models/user.model';
import { Role } from '../models/role.model';
import { Permission, PermissionNames, PermissionValues } from '../models/permission.model';
import { Permission, PermissionValues } from '../models/permission.model';
import { UserEdit } from '../models/user-edit.model';

export type RolesChangedOperation = 'add' | 'delete' | 'modify';
Expand Down Expand Up @@ -54,7 +54,6 @@ export class AccountService {
this.accountEndpoint.getRolesEndpoint<Role[]>()]);
}


updateUser(user: UserEdit) {
if (user.id) {
return this.accountEndpoint.getUpdateUserEndpoint(user, user.id);
Expand All @@ -71,7 +70,6 @@ export class AccountService {
return this.accountEndpoint.getNewUserEndpoint<User>(user);
}


getUserPreferences() {
return this.accountEndpoint.getUserPreferencesEndpoint<string>();
}
Expand All @@ -80,14 +78,11 @@ export class AccountService {
return this.accountEndpoint.getUpdateUserPreferencesEndpoint(configuration);
}


deleteUser(userOrUserId: string | User): Observable<User> {

if (typeof userOrUserId === 'string' || userOrUserId instanceof String) {
return this.accountEndpoint.getDeleteUserEndpoint<User>(userOrUserId as string).pipe<User>(
tap(data => this.onRolesUserCountChanged(data.roles)));
} else {

if (userOrUserId.id) {
return this.deleteUser(userOrUserId.id);
} else {
Expand All @@ -97,17 +92,14 @@ export class AccountService {
}
}


unblockUser(userId: string) {
return this.accountEndpoint.getUnblockUserEndpoint(userId);
}


userHasPermission(permissionValue: PermissionValues): boolean {
return this.permissions.some(p => p === permissionValue);
}


refreshLoggedInUser() {
return this.accountEndpoint.refreshLogin();
}
Expand All @@ -117,15 +109,13 @@ export class AccountService {
return this.accountEndpoint.getRolesEndpoint<Role[]>(page, pageSize);
}


getRolesAndPermissions(page?: number, pageSize?: number) {

return forkJoin([
this.accountEndpoint.getRolesEndpoint<Role[]>(page, pageSize),
this.accountEndpoint.getPermissionsEndpoint<Permission[]>()]);
}


updateRole(role: Role) {
if (role.id) {
return this.accountEndpoint.getUpdateRoleEndpoint(role, role.id).pipe(
Expand All @@ -140,13 +130,11 @@ export class AccountService {
}
}


newRole(role: Role) {
return this.accountEndpoint.getNewRoleEndpoint<Role>(role).pipe<Role>(
tap(data => this.onRolesChanged([role], AccountService.roleAddedOperation)));
}


deleteRole(roleOrRoleId: string | Role): Observable<Role> {

if (typeof roleOrRoleId === 'string' || roleOrRoleId instanceof String) {
Expand All @@ -168,23 +156,18 @@ export class AccountService {
return this.accountEndpoint.getPermissionsEndpoint<Permission[]>();
}


private onRolesChanged(roles: Role[] | string[], op: RolesChangedOperation) {
this.rolesChanged.next({ roles, operation: op });
}


onRolesUserCountChanged(roles: Role[] | string[]) {
return this.onRolesChanged(roles, AccountService.roleModifiedOperation);
}


getRolesChangedEvent(): Observable<RolesChangedEventArg> {
return this.rolesChanged.asObservable();
}



get permissions(): PermissionValues[] {
return this.authService.userPermissions;
}
Expand Down
9 changes: 0 additions & 9 deletions QuickApp/ClientApp/src/app/services/alert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { Observable, Subject } from 'rxjs';

import { Utilities } from '../services/utilities';



@Injectable()
export class AlertService {
private messages = new Subject<AlertCommand>();
Expand All @@ -33,14 +31,11 @@ export class AlertService {
this.dialogs.next({ message, type, okCallback, cancelCallback, okLabel, cancelLabel, defaultValue });
}



showMessage(summary: string);
showMessage(summary: string, detail: string, severity: MessageSeverity);
showMessage(summaryAndDetails: string[], summaryAndDetailsSeparator: string, severity: MessageSeverity);
showMessage(response: HttpResponseBase, ignoreValueUseNull: string, severity: MessageSeverity);
showMessage(data: any, separatorOrDetail?: string, severity?: MessageSeverity) {

if (!severity) {
severity = MessageSeverity.default;
}
Expand All @@ -61,7 +56,6 @@ export class AlertService {
}
}


showStickyMessage(summary: string);
showStickyMessage(summary: string, detail: string, severity: MessageSeverity, error?: any);
showStickyMessage(summary: string, detail: string, severity: MessageSeverity, error?: any, onRemove?: () => any);
Expand All @@ -78,17 +72,14 @@ export class AlertService {
separatorOrDetail = Utilities.captionAndMessageSeparator;
}


if (data instanceof Array) {
for (const message of data) {
const msgObject = Utilities.splitInTwo(message, separatorOrDetail);

this.showMessageHelper(msgObject.firstPart, msgObject.secondPart, severity, true);
}
} else {

if (error) {

const msg = `Severity: "${MessageSeverity[severity]}", Summary: "${data}", Detail: "${separatorOrDetail}", Error: "${Utilities.safeStringify(error)}"`;

switch (severity) {
Expand Down
14 changes: 7 additions & 7 deletions QuickApp/ClientApp/src/app/services/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import { animate, state, style, transition, trigger } from '@angular/animations'


export const fadeInOut = trigger('fadeInOut', [
transition(':enter', [style({ opacity: 0 }), animate('0.4s ease-in', style({ opacity: 1 }))]),
transition(':leave', [animate('0.4s 10ms ease-out', style({ opacity: 0 }))])
transition(':enter', [style({ opacity: 0 }), animate('0.4s ease-in', style({ opacity: 1 }))]),
transition(':leave', [animate('0.4s 10ms ease-out', style({ opacity: 0 }))])
]);



export function flyInOut(duration: number = 0.2) {
return trigger('flyInOut', [
state('in', style({ opacity: 1, transform: 'translateX(0)' })),
transition('void => *', [style({ opacity: 0, transform: 'translateX(-100%)' }), animate(`${duration}s ease-in`)]),
transition('* => void', [animate(`${duration}s 10ms ease-out`, style({ opacity: 0, transform: 'translateX(100%)' }))])
]);
return trigger('flyInOut', [
state('in', style({ opacity: 1, transform: 'translateX(0)' })),
transition('void => *', [style({ opacity: 0, transform: 'translateX(-100%)' }), animate(`${duration}s ease-in`)]),
transition('* => void', [animate(`${duration}s 10ms ease-out`, style({ opacity: 0, transform: 'translateX(100%)' }))])
]);
}
76 changes: 37 additions & 39 deletions QuickApp/ClientApp/src/app/services/app-title.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,44 @@ import { Title } from '@angular/platform-browser';

import { Utilities } from './utilities';


@Injectable()
export class AppTitleService {

sub: Subscription;
appName: string;

constructor(private titleService: Title, private router: Router) {
this.sub = this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
map(_ => this.router.routerState.root),
map(route => {
while (route.firstChild) {
route = route.firstChild;
}

return route;
}),
flatMap(route => route.data))
.subscribe(data => {
let title = data.title;

if (title) {
const fragment = this.router.url.split('#')[1];

if (fragment) {
title += ' | ' + Utilities.toTitleCase(fragment);
}
}

if (title && this.appName) {
title += ' - ' + this.appName;
} else if (this.appName) {
title = this.appName;
}

if (title) {
this.titleService.setTitle(title);
}
});
}
sub: Subscription;
appName: string;

constructor(private titleService: Title, private router: Router) {
this.sub = this.router.events.pipe(
filter(event => event instanceof NavigationEnd),
map(_ => this.router.routerState.root),
map(route => {
while (route.firstChild) {
route = route.firstChild;
}

return route;
}),
flatMap(route => route.data))
.subscribe(data => {
let title = data.title;

if (title) {
const fragment = this.router.url.split('#')[1];

if (fragment) {
title += ' | ' + Utilities.toTitleCase(fragment);
}
}

if (title && this.appName) {
title += ' - ' + this.appName;
} else if (this.appName) {
title = this.appName;
}

if (title) {
this.titleService.setTitle(title);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ export class AppTranslationService {
return language;
}


getTranslation(key: string | Array<string>, interpolateParams?: object): string | any {
return this.translate.instant(key, interpolateParams);
}


getTranslationAsync(key: string | Array<string>, interpolateParams?: object): Observable<string | any> {
return this.translate.get(key, interpolateParams);
}
Expand All @@ -88,9 +86,7 @@ export class AppTranslationService {
export class TranslateLanguageLoader implements TranslateLoader {

public getTranslation(lang: string): any {

// Note Dynamic require(variable) will not work. Require is always at compile time

switch (lang) {
case 'en':
return of(require('../assets/locale/en.json'));
Expand Down
42 changes: 21 additions & 21 deletions QuickApp/ClientApp/src/app/services/auth-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
// =============================

import { Injectable } from '@angular/core';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, NavigationExtras, CanLoad, Route } from '@angular/router';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, CanLoad, Route } from '@angular/router';
import { AuthService } from './auth.service';


@Injectable()
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
constructor(private authService: AuthService, private router: Router) { }
constructor(private authService: AuthService, private router: Router) { }

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {

const url: string = state.url;
return this.checkLogin(url);
}
const url: string = state.url;
return this.checkLogin(url);
}

canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(route, state);
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(route, state);
}

canLoad(route: Route): boolean {
canLoad(route: Route): boolean {

const url = `/${route.path}`;
return this.checkLogin(url);
}
const url = `/${route.path}`;
return this.checkLogin(url);
}

checkLogin(url: string): boolean {
checkLogin(url: string): boolean {

if (this.authService.isLoggedIn) {
return true;
}
if (this.authService.isLoggedIn) {
return true;
}

this.authService.loginRedirectUrl = url;
this.router.navigate(['/login']);
this.authService.loginRedirectUrl = url;
this.router.navigate(['/login']);

return false;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { CanDeactivate } from '@angular/router';
import { Observable } from 'rxjs';

export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}

@Injectable()
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
canDeactivate(component: CanComponentDeactivate) {
return component.canDeactivate ? component.canDeactivate() : true;
}
canDeactivate(component: CanComponentDeactivate) {
return component.canDeactivate ? component.canDeactivate() : true;
}
}
Loading

0 comments on commit 0a082a3

Please sign in to comment.