forked from polypheny/Polypheny-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sulea/feature/merge-columns
The MergeColumns feature
- Loading branch information
Showing
8 changed files
with
319 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="source-column"> | ||
<span>{{ sourceTitle }}</span> | ||
<div class="list-container"> | ||
<div *ngFor="let option of _getSourceOptions()" class="list-item" (click)="_onAddOption(option)"> | ||
<span>{{ option[labelProperty] }}</span> | ||
<em class="fa fa-solid fa-chevron-right"></em> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="target-column"> | ||
<span>{{ targetTitle }}</span> | ||
<div id="target-container" class="list-container" cdkDropList (cdkDropListDropped)="_onMoveOption($event)"> | ||
<div *ngFor="let option of _value; let first = first; let last = last;" class="list-item" | ||
(click)="_onRemoveOption(option)" cdkDrag [cdkDragData]="option" [cdkDragDisabled]="disableSort" | ||
cdkDragBoundary="#target-container"> | ||
<span> | ||
<em *ngIf="!disableSort" class="fa fa-solid fa-sort"></em> {{ option[labelProperty] }}</span> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.app-list-picker { | ||
display: flex; | ||
gap: 10px; | ||
|
||
.source-column, | ||
.target-column { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.list-container { | ||
min-width: 200px; | ||
min-height: 200px; | ||
max-height: 200px; | ||
border: 1px #e4e7ea solid; | ||
flex: 1 1 auto; | ||
border-radius: 0.2rem; | ||
overflow-y: scroll; | ||
} | ||
|
||
.list-container .list-item:not(.cdk-drag-dragging) { | ||
opacity: 1; | ||
padding: 0.2rem 0.5rem; | ||
transition: all 0.2s; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
border: 1px var(--white) solid; | ||
border-radius: 0; | ||
box-shadow: none; | ||
border: 1x var(--white) solid; | ||
background: var(--white); | ||
|
||
em { | ||
color: var(--gray); | ||
font-size: 10px; | ||
} | ||
} | ||
|
||
.list-container .list-item:not(.cdk-drag-dragging):hover { | ||
background: var(--light); | ||
cursor: pointer; | ||
} | ||
|
||
.list-container .list-item.cdk-drag-placeholder { | ||
opacity: 0.2; | ||
} | ||
} | ||
|
||
.cdk-drag.list-item { | ||
opacity: 1; | ||
padding: 0.2rem 0.5rem; | ||
transition: all 0.1s; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
background: var(--light); | ||
border: 1px var(--gray) solid; | ||
border-radius: 0.2rem; | ||
box-shadow: 0px 0px 5px var(--light); | ||
|
||
em { | ||
color: var(--gray); | ||
font-size: 10px; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
src/app/components/list-picker/list-picker.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; | ||
import { Component, EventEmitter, forwardRef, HostBinding, Input, Output, ViewEncapsulation } from '@angular/core'; | ||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||
|
||
/** | ||
* ListPickerComponent is used to select multiple values from a list of options. | ||
*/ | ||
@Component({ | ||
selector: 'app-list-picker', | ||
templateUrl: './list-picker.component.html', | ||
styleUrls: ['./list-picker.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => ListPickerComponent), | ||
multi: true, | ||
}, | ||
], | ||
}) | ||
export class ListPickerComponent<T> implements ControlValueAccessor { | ||
|
||
@HostBinding("class") | ||
classes = ["app-list-picker"] | ||
|
||
/** | ||
* Title of the source options | ||
*/ | ||
@Input() | ||
sourceTitle = "Source"; | ||
|
||
/** | ||
* Title of the target options | ||
*/ | ||
@Input() | ||
targetTitle = "Target"; | ||
|
||
/** | ||
* An array of objects to display as the available options. | ||
*/ | ||
@Input() | ||
sourceOptions: Array<T> | ||
|
||
/** | ||
* Name of the label field of an option. | ||
*/ | ||
@Input() | ||
labelProperty: keyof T | null; | ||
|
||
/** | ||
* Number of maximum options that can be selected. | ||
*/ | ||
@Input() | ||
selectionLimit = Infinity; | ||
|
||
/** | ||
* Disable drag and drop sorting | ||
*/ | ||
@Input() | ||
disableSort = false; | ||
|
||
/** | ||
* Callback to invoke when selection limit is reached. | ||
*/ | ||
@Output() | ||
selectionLimitReached = new EventEmitter<void>(); | ||
|
||
_value: Array<T> | null; | ||
|
||
_disabled: boolean; | ||
|
||
_onChange: (value: Array<T>) => void | ||
|
||
_onTouched: () => void | ||
|
||
writeValue(value: Array<T>): void { | ||
this._value = value | ||
} | ||
|
||
registerOnChange(fn: (value: Array<T>) => void): void { | ||
this._onChange = fn | ||
} | ||
|
||
registerOnTouched(fn: () => void): void { | ||
this._onTouched = fn | ||
} | ||
|
||
setDisabledState?(isDisabled: boolean): void { | ||
this._disabled = isDisabled; | ||
} | ||
|
||
_getSourceOptions = () => { | ||
return this.sourceOptions?.filter(option => !this._value?.includes(option)); | ||
} | ||
|
||
_onAddOption = (option: T) => { | ||
this._onTouched(); | ||
if((this._value?.length ?? 0) < this.selectionLimit) { | ||
this._value = [...this._value ?? [], option]; | ||
this._onChange(this._value); | ||
} else { | ||
this.selectionLimitReached.emit() | ||
} | ||
} | ||
|
||
_onRemoveOption = (option: T) => { | ||
this._value?.splice( this._value?.indexOf(option), 1); | ||
this._onChange(this._value); | ||
this._onTouched(); | ||
} | ||
|
||
|
||
_onMoveOption = (event: CdkDragDrop<T, any>) => { | ||
moveItemInArray(this._value, event.previousIndex, event.currentIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.