Skip to content

Commit 5d5f439

Browse files
Mattia Vianelliatarix83
authored andcommitted
Merged in DSC-1603-squashed-sortablejs-replace (pull request DSpace#1495)
DSC-1603 Last changes and package.json and yarn.lock sortable replaced + lint fix Approved-by: Giuseppe Digilio
2 parents cffcf46 + f1e8c26 commit 5d5f439

8 files changed

Lines changed: 35 additions & 56 deletions

File tree

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@
143143
"ng2-nouislider": "^2.0.0",
144144
"ngx-infinite-scroll": "^15.0.0",
145145
"ngx-pagination": "6.0.3",
146-
"ngx-sortablejs": "^11.1.0",
147146
"ngx-ui-switch": "^14.0.3",
148147
"nouislider": "^15.7.1",
149148
"pem": "1.14.7",
@@ -152,7 +151,6 @@
152151
"reflect-metadata": "^0.1.13",
153152
"rxjs": "^7.8.0",
154153
"sanitize-html": "^2.10.0",
155-
"sortablejs": "1.15.0",
156154
"uuid": "^8.3.2",
157155
"webfontloader": "1.6.28",
158156
"zone.js": "~0.11.5"

src/app/shared/form/chips/chips.component.html

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
</ng-template>
55

66
<div [className]="'float-left w-100 ' + wrapperClass">
7-
<div *ngIf="isPlatformBrowser" role="list" class="nav nav-pills d-flex flex-column flex-sm-row" [sortablejs]="chips.getChips()" [sortablejsOptions]="options">
7+
<div *ngIf="isPlatformBrowser" role="list" class="nav nav-pills d-flex flex-column flex-sm-row" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="onDrop($event)">
88
<ng-container *ngFor="let c of chips.getChips(); let i = index">
99
<ng-template #tipContent>
1010
<p class="text-left p-0 m-0" *ngFor="let tip of (tipText$ | async)">
1111
{{tip}}
1212
</p>
1313
</ng-template>
14-
1514
<div role="listitem" class="nav-item mr-2 mb-1"
16-
#t="ngbTooltip"
17-
triggers="manual"
18-
[ngbTooltip]="tipContent"
19-
(dragstart)="t.close();onDragStart(i)"
20-
(dragend)="onDragEnd(i)"
21-
(mouseover)="showTooltip(t, i)"
22-
(mouseout)="t.close()">
15+
#t="ngbTooltip"
16+
triggers="manual"
17+
[ngbTooltip]="tipContent"
18+
(mouseover)="showTooltip(t, i)"
19+
(mouseout)="t.close()">
2320
<a class="flex-sm-fill text-sm-center nav-link active bg-info"
24-
href="javascript:void(0);"
25-
[class.disabled]="(editable && c.editMode) || dragged == i || !clickable"
21+
cdkDrag
22+
(cdkDragStarted)="onDrag(i)"
23+
href="#"
24+
[class.disabled]="!clickable || (editable && c.editMode) || dragged == i "
2625
[class.chip-selected]="(editable && c.editMode) || dragged == i"
2726
(click)="chipsSelected($event, i);">
2827
<span>
29-
<i *ngIf="showIcons && !c.isNestedItem()" dsAuthorityConfidenceState [authorityValue]="c.item" class="far fa-circle" aria-hidden="true"></i>
28+
<i *ngIf="showIcons && !c.isNestedItem()" dsAuthorityConfidenceState [authorityValue]="c.item" class="far fa-circle" aria-hidden="true">&nbsp;</i>
3029
<ng-container *ngIf="showIcons && c.hasVisibleIcons()">
3130
<span *ngFor="let icon of c.icons; let l = last" class="chip-stacked-icons">
3231
<i [ngbTooltip]="tipContent"
@@ -41,7 +40,6 @@
4140
[visibleWhenAuthorityEmpty]="icon.visibleWhenAuthorityEmpty"
4241
[showTooltip]="false"
4342
aria-hidden="true"
44-
(dragstart)="t.close();"
4543
(mouseover)="showTooltip(t, i, icon.metadata)"
4644
(mouseout)="t.close()"></i>
4745
<i *ngIf="hasWillBeGenerated(c, icon.metadata)"

src/app/shared/form/chips/chips.component.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
.chip-selected {
2-
background-color: var(--bs-secondary) !important;
1+
.cdk-drag-placeholder {
2+
filter: grayscale(100%);
3+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
34
}
45

5-
.chip-label {
6-
max-width: 10rem;
6+
.cdk-drag-preview {
7+
color: white;
8+
box-sizing: border-box;
9+
border-radius: 0.25rem;
10+
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
11+
0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
712
}
813

914
.chip-stacked-icons {

src/app/shared/form/chips/chips.component.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { createTestComponent } from '../../testing/utils.test';
1111
import { AuthorityConfidenceStateDirective } from '../directives/authority-confidence-state.directive';
1212
import { TranslateModule } from '@ngx-translate/core';
1313
import { ConfidenceType } from '../../../core/shared/confidence-type';
14-
import { SortablejsModule } from 'ngx-sortablejs';
1514
import { environment } from '../../../../environments/environment';
1615

1716
describe('ChipsComponent test suite', () => {
@@ -29,7 +28,6 @@ describe('ChipsComponent test suite', () => {
2928
TestBed.configureTestingModule({
3029
imports: [
3130
NgbModule,
32-
SortablejsModule.forRoot({ animation: 150 }),
3331
TranslateModule.forRoot()
3432
],
3533
declarations: [
@@ -94,18 +92,18 @@ describe('ChipsComponent test suite', () => {
9492
}));
9593

9694
it('should save chips item index when drag and drop start', fakeAsync(() => {
97-
const de = chipsFixture.debugElement.query(By.css('div.nav-item'));
95+
const de = chipsFixture.debugElement.query(By.css('a'));
9896

99-
de.triggerEventHandler('dragstart', null);
97+
de.triggerEventHandler('cdkDragStarted', null);
10098

10199
expect(chipsComp.dragged).toBe(0);
102100
}));
103101

104102
it('should update chips item order when drag and drop end', fakeAsync(() => {
105103
spyOn(chipsComp.chips, 'updateOrder');
106-
const de = chipsFixture.debugElement.query(By.css('div.nav-item'));
104+
const de = chipsFixture.debugElement.query(By.css('div[role="list"]'));
107105

108-
de.triggerEventHandler('dragend', null);
106+
de.triggerEventHandler('cdkDropListDropped', { previousIndex: 0, currentIndex: 1 });
109107

110108
expect(chipsComp.dragged).toBe(-1);
111109
expect(chipsComp.chips.updateOrder).toHaveBeenCalled();

src/app/shared/form/chips/chips.component.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import isObject from 'lodash/isObject';
1515

1616
import { Chips } from './models/chips.model';
1717
import { ChipsItem } from './models/chips-item.model';
18-
import { DragService } from '../../../core/drag.service';
1918
import { TranslateService } from '@ngx-translate/core';
20-
import { Options } from 'sortablejs';
2119
import { BehaviorSubject, forkJoin } from 'rxjs';
2220
import { map, take } from 'rxjs/operators';
2321
import { isNotEmpty } from '../../empty.util';
22+
import { CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
23+
2424

2525
const TOOLTIP_TEXT_LIMIT = 21;
2626
@Component({
@@ -40,7 +40,6 @@ export class ChipsComponent implements OnChanges {
4040
@Output() change: EventEmitter<any> = new EventEmitter<any>();
4141

4242
isDragging: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
43-
options: Options;
4443
dragged = -1;
4544
tipText$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
4645

@@ -52,16 +51,7 @@ export class ChipsComponent implements OnChanges {
5251
constructor(
5352
@Inject(PLATFORM_ID) protected platformId: string,
5453
private cdr: ChangeDetectorRef,
55-
private dragService: DragService,
5654
private translate: TranslateService) {
57-
58-
this.options = {
59-
animation: 300,
60-
chosenClass: 'm-0',
61-
dragClass: 'm-0',
62-
filter: '.chips-sort-ignore',
63-
ghostClass: 'm-0',
64-
};
6555
}
6656

6757
ngOnChanges(changes: SimpleChanges) {
@@ -88,14 +78,13 @@ export class ChipsComponent implements OnChanges {
8878
}
8979
}
9080

91-
onDragStart(index) {
81+
onDrag(index) {
9282
this.isDragging.next(true);
93-
this.dragService.overrideDragOverPage();
9483
this.dragged = index;
9584
}
9685

97-
onDragEnd(event) {
98-
this.dragService.allowDragOverPage();
86+
onDrop(event: CdkDragDrop<ChipsItem[]>) {
87+
moveItemInArray(this.chips.chipsItems.getValue(), event.previousIndex, event.currentIndex);
9988
this.dragged = -1;
10089
this.chips.updateOrder();
10190
this.isDragging.next(false);
@@ -104,6 +93,9 @@ export class ChipsComponent implements OnChanges {
10493
showTooltip(tooltip: NgbTooltip, index, field?) {
10594
tooltip.close();
10695
let canShowToolTip = true;
96+
if (this.isDragging.value) {
97+
return;
98+
}
10799
const chipsItem = this.chips.getChipByIndex(index);
108100
const textToDisplay: string[] = [];
109101
if (!chipsItem.editMode && this.dragged === -1) {

src/app/shared/form/form.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { DynamicFormsNGBootstrapUIModule } from '@ng-dynamic-forms/ui-ng-bootstr
3030
import { ChipsComponent } from './chips/chips.component';
3131
import { NumberPickerComponent } from './number-picker/number-picker.component';
3232
import { AuthorityConfidenceStateDirective } from './directives/authority-confidence-state.directive';
33-
import { SortablejsModule } from 'ngx-sortablejs';
33+
import { DragDropModule } from '@angular/cdk/drag-drop';
3434
import { VocabularyTreeviewComponent } from './vocabulary-treeview/vocabulary-treeview.component';
3535
import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal/vocabulary-treeview-modal.component';
3636
import { FormBuilderService } from './builder/form-builder.service';
@@ -95,11 +95,11 @@ const DIRECTIVES = [
9595
SearchModule,
9696
SharedModule,
9797
TranslateModule,
98-
SortablejsModule,
9998
NgxMaskModule.forRoot(),
10099
NgbDatepickerModule,
101100
NgbTimepickerModule,
102101
CdkTreeModule,
102+
DragDropModule,
103103
],
104104
exports: [
105105
...COMPONENTS,

src/app/shared/object-list/my-dspace-result-list-element/workflow-item-search-result/workflow-item-search-result-list-element.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[context]="badgeContext"
66
[showThumbnails]="showThumbnails"></ds-listable-object-component-loader>
77
<div class="row">
8-
<div [ngClass]="showThumbnails ? 'offset-3 offset-xl-2 pl-3' : ''">
8+
<div [ngClass]="showThumbnails ? 'offset-3 offset-xl-2 pl-3' : 'ml-3'">
99
<ds-workflowitem-actions [object]="dso" (processCompleted)="reloadedObject.emit($event.reloadedObject)"></ds-workflowitem-actions>
1010
</div>
1111
</div>

yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8981,13 +8981,6 @@ ngx-pagination@6.0.3:
89818981
dependencies:
89828982
tslib "^2.3.0"
89838983

8984-
ngx-sortablejs@^11.1.0:
8985-
version "11.1.0"
8986-
resolved "https://registry.yarnpkg.com/ngx-sortablejs/-/ngx-sortablejs-11.1.0.tgz#14e50c48db908c1cb4b37722b28c2d3867c6140a"
8987-
integrity sha512-eM4dHwWSmXDcvF5gUmyMMQ0qqcqBXWCSZ9IRpqx4UkBKfo4N7pk/QuYh5io2fXVHWVFDaxW1yhn2FNpqxV6Jqw==
8988-
dependencies:
8989-
tslib "^2.0.0"
8990-
89918984
ngx-ui-switch@^14.0.3:
89928985
version "14.1.0"
89938986
resolved "https://registry.yarnpkg.com/ngx-ui-switch/-/ngx-ui-switch-14.1.0.tgz#32248361a684257c5ae64cfde61b95de920b901c"
@@ -11325,11 +11318,6 @@ socks@^2.6.2:
1132511318
ip "^2.0.0"
1132611319
smart-buffer "^4.2.0"
1132711320

11328-
sortablejs@1.15.0:
11329-
version "1.15.0"
11330-
resolved "https://registry.yarnpkg.com/sortablejs/-/sortablejs-1.15.0.tgz#53230b8aa3502bb77a29e2005808ffdb4a5f7e2a"
11331-
integrity sha512-bv9qgVMjUMf89wAvM6AxVvS/4MX3sPeN0+agqShejLU5z5GX4C75ow1O2e5k4L6XItUyAK3gH6AxSbXrOM5e8w==
11332-
1133311321
source-list-map@^2.0.0:
1133411322
version "2.0.1"
1133511323
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"

0 commit comments

Comments
 (0)