mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts: # src/app/+item-page/edit-item-page/item-status/item-status.component.spec.ts # src/app/core/cache/builders/remote-data-build.service.ts # src/app/core/core.effects.ts # src/app/core/core.reducers.ts # src/app/core/data/comcol-data.service.spec.ts # src/app/core/data/data.service.spec.ts # src/app/core/data/data.service.ts # src/app/core/shared/dspace-object.model.ts # src/app/shared/shared.module.ts # src/styles/_custom_variables.scss
This commit is contained in:
28
src/app/shared/utils/auto-focus.directive.ts
Normal file
28
src/app/shared/utils/auto-focus.directive.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Directive, AfterViewInit, ElementRef, Input } from '@angular/core';
|
||||
import { isNotEmpty } from '../empty.util';
|
||||
|
||||
/**
|
||||
* Directive to set focus on an element when it is rendered
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[dsAutoFocus]'
|
||||
})
|
||||
export class AutoFocusDirective implements AfterViewInit {
|
||||
|
||||
/**
|
||||
* Optional input to specify which element in a component should get the focus
|
||||
* If left empty, the component itself will get the focus
|
||||
*/
|
||||
@Input() autoFocusSelector: string = undefined;
|
||||
|
||||
constructor(private el: ElementRef) {
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
if (isNotEmpty(this.autoFocusSelector)) {
|
||||
return this.el.nativeElement.querySelector(this.autoFocusSelector).focus();
|
||||
} else {
|
||||
return this.el.nativeElement.focus();
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,9 +16,11 @@ export class ClickOutsideDirective {
|
||||
constructor(private _elementRef: ElementRef) {
|
||||
}
|
||||
|
||||
@HostListener('document:click', ['$event.target'])
|
||||
public onClick(targetElement) {
|
||||
const clickedInside = this._elementRef.nativeElement.contains(targetElement);
|
||||
@HostListener('document:click')
|
||||
public onClick() {
|
||||
const hostElement = this._elementRef.nativeElement;
|
||||
const focusElement = hostElement.ownerDocument.activeElement;
|
||||
const clickedInside = hostElement.contains(focusElement);
|
||||
if (!clickedInside) {
|
||||
this.dsClickOutside.emit(null);
|
||||
}
|
||||
|
@@ -25,11 +25,6 @@ export class DebounceDirective implements OnInit, OnDestroy {
|
||||
@Input()
|
||||
public dsDebounce = 500;
|
||||
|
||||
/**
|
||||
* True if no changes have been made to the input field's value
|
||||
*/
|
||||
private isFirstChange = true;
|
||||
|
||||
/**
|
||||
* Subject to unsubscribe from
|
||||
*/
|
||||
@@ -46,11 +41,9 @@ export class DebounceDirective implements OnInit, OnDestroy {
|
||||
this.model.valueChanges.pipe(
|
||||
takeUntil(this.subject),
|
||||
debounceTime(this.dsDebounce),
|
||||
distinctUntilChanged(),)
|
||||
distinctUntilChanged())
|
||||
.subscribe((modelValue) => {
|
||||
if (this.isFirstChange) {
|
||||
this.isFirstChange = false;
|
||||
} else {
|
||||
if (this.model.dirty) {
|
||||
this.onDebounce.emit(modelValue);
|
||||
}
|
||||
});
|
||||
|
29
src/app/shared/utils/in-list-validator.directive.ts
Normal file
29
src/app/shared/utils/in-list-validator.directive.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Directive, Input } from '@angular/core';
|
||||
import { FormControl, NG_VALIDATORS, ValidationErrors, Validator } from '@angular/forms';
|
||||
import { inListValidator } from './validator.functions';
|
||||
|
||||
/**
|
||||
* Directive for validating if a ngModel value is in a given list
|
||||
*/
|
||||
@Directive({
|
||||
selector: '[ngModel][dsInListValidator]',
|
||||
// We add our directive to the list of existing validators
|
||||
providers: [
|
||||
{ provide: NG_VALIDATORS, useExisting: InListValidator, multi: true }
|
||||
]
|
||||
})
|
||||
export class InListValidator implements Validator {
|
||||
/**
|
||||
* The list to look in
|
||||
*/
|
||||
@Input()
|
||||
dsInListValidator: string[];
|
||||
|
||||
/**
|
||||
* The function that checks if the form control's value is currently valid
|
||||
* @param c The FormControl
|
||||
*/
|
||||
validate(c: FormControl): ValidationErrors | null {
|
||||
return inListValidator(this.dsInListValidator)(c);
|
||||
}
|
||||
}
|
18
src/app/shared/utils/object-values-pipe.ts
Normal file
18
src/app/shared/utils/object-values-pipe.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { PipeTransform, Pipe } from '@angular/core';
|
||||
|
||||
@Pipe({name: 'dsObjectValues'})
|
||||
/**
|
||||
* Pipe for parsing all values of an object to an array of values
|
||||
*/
|
||||
export class ObjectValuesPipe implements PipeTransform {
|
||||
|
||||
/**
|
||||
* @param value An object
|
||||
* @returns {any} Array with all values of the input object
|
||||
*/
|
||||
transform(value, args:string[]): any {
|
||||
const values = [];
|
||||
Object.values(value).forEach((v) => values.push(v));
|
||||
return values;
|
||||
}
|
||||
}
|
17
src/app/shared/utils/validator.functions.ts
Normal file
17
src/app/shared/utils/validator.functions.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { isNotEmpty } from '../empty.util';
|
||||
|
||||
/**
|
||||
* Returns a validator function to check if the control's value is in a given list
|
||||
* @param list The list to look in
|
||||
*/
|
||||
export function inListValidator(list: string[]): ValidatorFn {
|
||||
return (control: AbstractControl): { [key: string]: any } | null => {
|
||||
const hasValue = isNotEmpty(control.value);
|
||||
let inList = true;
|
||||
if (isNotEmpty(list)) {
|
||||
inList = list.indexOf(control.value) > -1;
|
||||
}
|
||||
return (hasValue && inList) ? null : { inList: { value: control.value } }
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user