Merge develop into stats-profile
This commit is contained in:
commit
23a47cc5da
|
@ -95,13 +95,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<modal-alert #inviteModal (alertOutput)="invite()" [overflowBody]="false" classTitle="uk-background-primary uk-light"
|
<modal-alert #inviteModal (alertOutput)="invite()" [overflowBody]="false" classTitle="uk-background-primary uk-light"
|
||||||
[okDisabled]="invited && invited.invalid">
|
[okDisabled]="!valid">
|
||||||
<div *ngIf="message" class="uk-margin-medium-bottom uk-text-small">
|
<div *ngIf="message" class="uk-margin-medium-bottom uk-text-small">
|
||||||
<div [innerHTML]="message | safeHtml"></div>
|
<div [innerHTML]="message | safeHtml"></div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="invited">
|
<div *ngIf="emailsForm">
|
||||||
<div input [formInput]="invited"
|
<div #emailInput input [formInput]="emailsForm" type="chips"
|
||||||
placeholder="Email"></div>
|
placeholder="Recipients" hint="Add a recipient" [visibleChips]="3"
|
||||||
|
[addExtraChips]="true" [validators]="validators" [separators]="[',']">
|
||||||
|
<div note>Separate emails with commas</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</modal-alert>
|
</modal-alert>
|
||||||
<modal-alert #deleteModal [overflowBody]="false" (alertOutput)="deleteActive()" classTitle="uk-background-primary uk-light">
|
<modal-alert #deleteModal [overflowBody]="false" (alertOutput)="deleteActive()" classTitle="uk-background-primary uk-light">
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from '@angular/core';
|
import {
|
||||||
import {UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from '@angular/forms';
|
ChangeDetectorRef,
|
||||||
|
Component,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
SimpleChanges,
|
||||||
|
ViewChild
|
||||||
|
} from '@angular/core';
|
||||||
|
import {
|
||||||
|
UntypedFormArray,
|
||||||
|
UntypedFormBuilder,
|
||||||
|
UntypedFormControl,
|
||||||
|
UntypedFormGroup,
|
||||||
|
ValidatorFn,
|
||||||
|
Validators
|
||||||
|
} from '@angular/forms';
|
||||||
import {AlertModal} from "../../../utils/modal/alert";
|
import {AlertModal} from "../../../utils/modal/alert";
|
||||||
import {UserRegistryService} from "../../../services/user-registry.service";
|
import {UserRegistryService} from "../../../services/user-registry.service";
|
||||||
import {EnvProperties} from "../../../utils/properties/env-properties";
|
import {EnvProperties} from "../../../utils/properties/env-properties";
|
||||||
|
@ -9,9 +25,22 @@ import {UserManagementService} from "../../../services/user-management.service";
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {StringUtils} from "../../../utils/string-utils.class";
|
import {StringUtils} from "../../../utils/string-utils.class";
|
||||||
import {NotificationService} from "../../../notifications/notification.service";
|
import {NotificationService} from "../../../notifications/notification.service";
|
||||||
import {Subscription} from "rxjs";
|
import {forkJoin, of, Subscription} from "rxjs";
|
||||||
import {NotificationHandler} from "../../../utils/notification-handler";
|
import {NotificationHandler} from "../../../utils/notification-handler";
|
||||||
import {ClearCacheService} from "../../../services/clear-cache.service";
|
import {ClearCacheService} from "../../../services/clear-cache.service";
|
||||||
|
import {catchError, map, tap} from "rxjs/operators";
|
||||||
|
import notification = CKEDITOR.plugins.notification;
|
||||||
|
import {InputComponent} from "../../../sharedComponents/input/input.component";
|
||||||
|
|
||||||
|
class InvitationResponse {
|
||||||
|
email: string;
|
||||||
|
invitation: any;
|
||||||
|
|
||||||
|
constructor(email, invitation) {
|
||||||
|
this.email = email;
|
||||||
|
this.invitation = invitation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'role-users',
|
selector: 'role-users',
|
||||||
|
@ -49,7 +78,8 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
public loadActive: boolean = true;
|
public loadActive: boolean = true;
|
||||||
public loadPending: boolean = true;
|
public loadPending: boolean = true;
|
||||||
public selectedUser: string = null;
|
public selectedUser: string = null;
|
||||||
public invited: UntypedFormControl;
|
public emailsForm: UntypedFormArray;
|
||||||
|
public validators: ValidatorFn[] = [Validators.email];
|
||||||
public properties: EnvProperties = properties;
|
public properties: EnvProperties = properties;
|
||||||
public exists: boolean = true;
|
public exists: boolean = true;
|
||||||
public roleFb: UntypedFormGroup;
|
public roleFb: UntypedFormGroup;
|
||||||
|
@ -60,6 +90,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
/** Search */
|
/** Search */
|
||||||
filterForm: UntypedFormGroup;
|
filterForm: UntypedFormGroup;
|
||||||
@ViewChild('inviteModal') inviteModal: AlertModal;
|
@ViewChild('inviteModal') inviteModal: AlertModal;
|
||||||
|
@ViewChild('emailInput') emailInput: InputComponent;
|
||||||
@ViewChild('deleteModal') deleteModal: AlertModal;
|
@ViewChild('deleteModal') deleteModal: AlertModal;
|
||||||
@ViewChild('deletePendingModal') deletePendingModal: AlertModal;
|
@ViewChild('deletePendingModal') deletePendingModal: AlertModal;
|
||||||
@ViewChild('createRoleModal') createRoleModal: AlertModal;
|
@ViewChild('createRoleModal') createRoleModal: AlertModal;
|
||||||
|
@ -69,6 +100,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
private clearCacheService: ClearCacheService,
|
private clearCacheService: ClearCacheService,
|
||||||
private notificationService: NotificationService,
|
private notificationService: NotificationService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
private cdr: ChangeDetectorRef,
|
||||||
private fb: UntypedFormBuilder) {
|
private fb: UntypedFormBuilder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +204,8 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
this.inviteModal.alertTitle = 'Invite ' + this.role;
|
this.inviteModal.alertTitle = 'Invite ' + this.role;
|
||||||
this.inviteModal.okButtonLeft = false;
|
this.inviteModal.okButtonLeft = false;
|
||||||
this.inviteModal.okButtonText = 'Send';
|
this.inviteModal.okButtonText = 'Send';
|
||||||
this.invited = this.fb.control('', [Validators.required, Validators.email]);
|
this.emailsForm = this.fb.array([], Validators.required);
|
||||||
|
this.cdr.detectChanges();
|
||||||
this.inviteModal.open();
|
this.inviteModal.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,33 +257,56 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
this.loadPending = false;
|
this.loadPending = false;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get valid() {
|
||||||
|
return this.emailsForm && this.emailsForm.valid || (this.emailInput && this.emailInput.searchControl.getRawValue() && this.emailInput.searchControl.valid);
|
||||||
|
}
|
||||||
|
|
||||||
invite() {
|
invite() {
|
||||||
|
if(this.emailInput.searchControl.getRawValue() && this.emailInput.searchControl.valid) {
|
||||||
|
this.emailInput.add(null,true);
|
||||||
|
}
|
||||||
this.showCurrent = false;
|
this.showCurrent = false;
|
||||||
this.loadPending = true;
|
this.loadPending = true;
|
||||||
this.selectedUser = this.invited.value;
|
let current = null;
|
||||||
let details = {
|
let invitations = (<Array<any>>this.emailsForm.value).map(email => {
|
||||||
link: this.link,
|
current = email;
|
||||||
email: this.emailComposer(this.name, this.invited.value, this.role)
|
return this.userRegistryService.invite(this.type, this.id, {
|
||||||
}
|
link: this.link,
|
||||||
this.subs.push(this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(invitation => {
|
email: this.emailComposer(this.name, email, this.role)
|
||||||
if (!this.pending.includes(this.invited.value)) {
|
}, this.role).pipe(map(invitation => new InvitationResponse(email, invitation), catchError(error => {
|
||||||
this.pending.push(this.invited.value);
|
return of(new InvitationResponse(current, null));
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
this.subs.push(forkJoin(invitations).subscribe(responses => {
|
||||||
|
let notifications = responses.map(response => {
|
||||||
|
if(response.invitation) {
|
||||||
|
NotificationHandler.rise(StringUtils.capitalize(this.role) + ' invitation to ' + response.email + ' has been <b>sent</b>');
|
||||||
|
if (!this.pending.includes(response.email)) {
|
||||||
|
this.pending.push(response.email);
|
||||||
|
}
|
||||||
|
if(this.notificationFn) {
|
||||||
|
return this.notificationService.sendNotification(this.notificationFn(this.name, response.email, this.role, response.invitation)).pipe(map(notification => {
|
||||||
|
return notification;
|
||||||
|
}), tap(() => {
|
||||||
|
NotificationHandler.rise('A notification has been <b>sent</b> successfully to ' + response.email);
|
||||||
|
}), catchError( error => {
|
||||||
|
NotificationHandler.rise('An error has occurred while sending a notification to ' + response.email + '. Please try again later', 'danger');
|
||||||
|
return of(null);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
return of(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NotificationHandler.rise('An error has occurred while sending the invitation mail to ' + response.email + '.Please try again later', 'danger');
|
||||||
|
return of(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.subs.push(forkJoin(notifications).subscribe(() => {
|
||||||
this.pendingPage = Math.ceil(this.pending.length / this.pageSize);
|
this.pendingPage = Math.ceil(this.pending.length / this.pageSize);
|
||||||
this.filterPendingBySearch(this.filterForm.value.pending);
|
this.filterPendingBySearch(this.filterForm.value.pending);
|
||||||
}
|
this.loadPending = false;
|
||||||
if (this.notificationFn) {
|
}))
|
||||||
this.subs.push(this.notificationService.sendNotification(this.notificationFn(this.name, this.invited.value, this.role, invitation)).subscribe(notification => {
|
|
||||||
NotificationHandler.rise('A notification has been <b>sent</b> successfully');
|
|
||||||
}, error => {
|
|
||||||
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
NotificationHandler.rise(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>sent</b>');
|
|
||||||
this.loadPending = false;
|
|
||||||
}, error => {
|
|
||||||
NotificationHandler.rise('An error has occurred. Please try again later', 'danger');
|
|
||||||
this.loadPending = false;
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,9 @@ import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||||
import {UserManagementService} from "../services/user-management.service";
|
import {UserManagementService} from "../services/user-management.service";
|
||||||
import {map, tap} from "rxjs/operators";
|
import {map, tap} from "rxjs/operators";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class AdminLoginGuard implements CanActivate, CanActivateChild {
|
export class AdminLoginGuard implements CanActivate, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
|
|
|
@ -6,15 +6,17 @@ import {
|
||||||
CanLoad,
|
CanLoad,
|
||||||
Route,
|
Route,
|
||||||
Router,
|
Router,
|
||||||
RouterStateSnapshot, UrlTree
|
RouterStateSnapshot,
|
||||||
|
UrlTree
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {Session} from './utils/helper.class';
|
|
||||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||||
import {map, tap} from "rxjs/operators";
|
import {map, tap} from "rxjs/operators";
|
||||||
import {UserManagementService} from "../services/user-management.service";
|
import {UserManagementService} from "../services/user-management.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class LoginGuard implements CanActivate, CanLoad, CanActivateChild {
|
export class LoginGuard implements CanActivate, CanLoad, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
|
|
|
@ -6,14 +6,20 @@ export class User {
|
||||||
fullname: string;
|
fullname: string;
|
||||||
expirationDate: number;
|
expirationDate: number;
|
||||||
role: string[];
|
role: string[];
|
||||||
jwt: string;
|
accessToken?: string;
|
||||||
|
refreshToken?: string;
|
||||||
|
|
||||||
constructor(info: any) {
|
constructor(info: any) {
|
||||||
this.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub;
|
this.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub;
|
||||||
this.firstname = (info.given_name) ? info.given_name : "";
|
this.firstname = (info.given_name) ? info.given_name : "";
|
||||||
this.lastname = (info.family_name) ? info.family_name : "";
|
this.lastname = (info.family_name) ? info.family_name : "";
|
||||||
this.email = info.email.toLowerCase(); // TODO remove, is a quick fix
|
this.email = info.email.toLowerCase(); // TODO remove, is a quick fix
|
||||||
|
if(info.accessToken) {
|
||||||
|
this.accessToken = info.accessToken;
|
||||||
|
}
|
||||||
|
if(info.refreshToken) {
|
||||||
|
this.refreshToken = info.refreshToken;
|
||||||
|
}
|
||||||
this.fullname = (info.name) ? info.name : "";
|
this.fullname = (info.name) ? info.name : "";
|
||||||
if (this.fullname == "") {
|
if (this.fullname == "") {
|
||||||
if (this.firstname != "") {
|
if (this.firstname != "") {
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class ReloadComponent {
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
let URL = Session.getReloadUrl();
|
let URL = Session.getReloadUrl();
|
||||||
|
console.log(URL);
|
||||||
if (URL && URL["path"] && URL["path"] != "") {
|
if (URL && URL["path"] && URL["path"] != "") {
|
||||||
let url: string = URL["path"];
|
let url: string = URL["path"];
|
||||||
let host = URL["host"];
|
let host = URL["host"];
|
||||||
|
@ -23,6 +24,7 @@ export class ReloadComponent {
|
||||||
if (host == (location.protocol + "//" + location.host)) {
|
if (host == (location.protocol + "//" + location.host)) {
|
||||||
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
|
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
|
||||||
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
|
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
|
||||||
|
console.log(url);
|
||||||
if (paramsObject) {
|
if (paramsObject) {
|
||||||
Session.setReloadUrl("", "", "", "");
|
Session.setReloadUrl("", "", "", "");
|
||||||
if(URL['fragment'] && URL['fragment'] !== '') {
|
if(URL['fragment'] && URL['fragment'] !== '') {
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class UserManagementService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public setRedirectUrl(url: string = null) {
|
public setRedirectUrl(url: string = null) {
|
||||||
if (url) {
|
if (url) {
|
||||||
let parts = url.split('?');
|
let parts = url.split('?');
|
||||||
|
|
|
@ -405,7 +405,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
}
|
}
|
||||||
|
|
||||||
click(event: ClickEvent) {
|
click(event: ClickEvent) {
|
||||||
this.focus(!event.clicked, event);
|
this.focus(!event.clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -532,8 +532,10 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
||||||
if (this.focused) {
|
if (this.focused) {
|
||||||
this.open(true);
|
this.open(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.searchInput.nativeElement.focus();
|
if(this.searchInput) {
|
||||||
this.searchInput.nativeElement.value = value;
|
this.searchInput.nativeElement.focus();
|
||||||
|
this.searchInput.nativeElement.value = value;
|
||||||
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Component, Input, OnDestroy, OnInit} from "@angular/core";
|
import {Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
||||||
import {AbstractControl, FormBuilder, FormGroup, ValidationErrors, ValidatorFn, Validators} from "@angular/forms";
|
import {AbstractControl, FormBuilder, FormGroup, ValidationErrors, ValidatorFn, Validators} from "@angular/forms";
|
||||||
import {Subscriber} from "rxjs";
|
import {Subscriber} from "rxjs";
|
||||||
import {StringUtils} from "../../utils/string-utils.class";
|
import {StringUtils} from "../../utils/string-utils.class";
|
||||||
|
@ -11,13 +11,14 @@ import {EmailService} from "../../utils/email/email.service";
|
||||||
import {properties} from "../../../../environments/environment";
|
import {properties} from "../../../../environments/environment";
|
||||||
import {CommunityInfo} from "../../connect/community/communityInfo";
|
import {CommunityInfo} from "../../connect/community/communityInfo";
|
||||||
import {NotificationHandler} from "../../utils/notification-handler";
|
import {NotificationHandler} from "../../utils/notification-handler";
|
||||||
|
import {InputComponent} from "../input/input.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'subscriber-invite',
|
selector: 'subscriber-invite',
|
||||||
template: `
|
template: `
|
||||||
<div *ngIf="body" class="uk-grid uk-child-width-1-1" uk-grid [formGroup]="inviteForm">
|
<div *ngIf="body" class="uk-grid uk-child-width-1-1" uk-grid [formGroup]="inviteForm">
|
||||||
<div input [formInput]="inviteForm.get('name')" placeholder="From"></div>
|
<div input [formInput]="inviteForm.get('name')" placeholder="From"></div>
|
||||||
<div input [formInput]="inviteForm.get('recipients')" type="chips"
|
<div #emailInput input [formInput]="inviteForm.get('recipients')" type="chips"
|
||||||
placeholder="Recipients" hint="Add a recipient" [visibleChips]="3"
|
placeholder="Recipients" hint="Add a recipient" [visibleChips]="3"
|
||||||
[addExtraChips]="true" [validators]="validators" [separators]="[',']">
|
[addExtraChips]="true" [validators]="validators" [separators]="[',']">
|
||||||
<div note>Separate emails with commas</div>
|
<div note>Separate emails with commas</div>
|
||||||
|
@ -61,7 +62,8 @@ export class SubscriberInviteComponent implements OnInit, OnDestroy {
|
||||||
public validators: ValidatorFn[] = [Validators.email];
|
public validators: ValidatorFn[] = [Validators.email];
|
||||||
public loading: boolean = true;
|
public loading: boolean = true;
|
||||||
private subscriptions: any[] = [];
|
private subscriptions: any[] = [];
|
||||||
|
@ViewChild('emailInput') emailInput: InputComponent;
|
||||||
|
|
||||||
constructor(private fb: FormBuilder,
|
constructor(private fb: FormBuilder,
|
||||||
private emailService: EmailService,
|
private emailService: EmailService,
|
||||||
private communityService: CommunityService) {
|
private communityService: CommunityService) {
|
||||||
|
@ -105,6 +107,9 @@ export class SubscriberInviteComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
invite() {
|
invite() {
|
||||||
|
if(this.emailInput.searchControl.getRawValue() && this.emailInput.searchControl.valid) {
|
||||||
|
this.emailInput.add(null,true);
|
||||||
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.body.paragraphs = this.inviteForm.getRawValue().message;
|
this.body.paragraphs = this.inviteForm.getRawValue().message;
|
||||||
this.email.body = Composer.formatEmailBodyForInvitation(this.body);
|
this.email.body = Composer.formatEmailBodyForInvitation(this.body);
|
||||||
|
@ -129,6 +134,6 @@ export class SubscriberInviteComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
get valid() {
|
get valid() {
|
||||||
return !this.loading && this.inviteForm && this.inviteForm.valid;
|
return !this.loading && this.inviteForm && this.inviteForm.valid || (this.emailInput && this.emailInput.searchControl.getRawValue() && this.emailInput.searchControl.valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ export interface EnvProperties {
|
||||||
registryUrl?: string;
|
registryUrl?: string;
|
||||||
logoutUrl?: string;
|
logoutUrl?: string;
|
||||||
userInfoUrl?: string;
|
userInfoUrl?: string;
|
||||||
|
clientManagementUrl?: string,
|
||||||
cookieDomain?: string;
|
cookieDomain?: string;
|
||||||
feedbackmail?: string;
|
feedbackmail?: string;
|
||||||
feedbackmailForMissingEntities?: string;
|
feedbackmailForMissingEntities?: string;
|
||||||
|
|
|
@ -266,6 +266,8 @@ export class StringUtils {
|
||||||
'[a-zA-Z0-9]+\\.[^\\s]{2,}';
|
'[a-zA-Z0-9]+\\.[^\\s]{2,}';
|
||||||
|
|
||||||
public static routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$';
|
public static routeRegex = '^[a-zA-Z0-9\/][a-zA-Z0-9\/-]*$';
|
||||||
|
|
||||||
|
public static jsonRegex = /^[\],:{}\s]*$/;
|
||||||
|
|
||||||
public static urlPrefix(url: string): string {
|
public static urlPrefix(url: string): string {
|
||||||
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) {
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) {
|
||||||
|
@ -325,6 +327,19 @@ export class StringUtils {
|
||||||
public static urlValidator(): ValidatorFn {
|
public static urlValidator(): ValidatorFn {
|
||||||
return Validators.pattern(StringUtils.urlRegex);
|
return Validators.pattern(StringUtils.urlRegex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static jsonValidator(error: string = ''): ValidatorFn {
|
||||||
|
return (control: AbstractControl): ValidationErrors | null => {
|
||||||
|
if(control.value) {
|
||||||
|
let test = control.getRawValue().replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, '');
|
||||||
|
console.log('test')
|
||||||
|
if(!new RegExp(this.jsonRegex).test(test)) {
|
||||||
|
return {error: 'Please provide a valid JSON.' + error}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static validatorType(options: string[]): ValidatorFn {
|
public static validatorType(options: string[]): ValidatorFn {
|
||||||
return (control: AbstractControl): { [key: string]: boolean } | null => {
|
return (control: AbstractControl): { [key: string]: boolean } | null => {
|
||||||
|
|
Loading…
Reference in New Issue