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:
Giuseppe Digilio
2019-03-08 09:52:47 +01:00
123 changed files with 3987 additions and 463 deletions

View 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();
}
}
}

View File

@@ -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);
}

View File

@@ -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);
}
});

View 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);
}
}

View 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;
}
}

View 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 } }
};
}