Skip to content

Commit b41a1c1

Browse files
Simone-RamundiMattia Vianelli
authored andcommitted
DSC-1603 Last changes and package.json and yarn.lock sortable replaced + lint fix
[DURACOM-237] Fix tests [DURACOM-237] - Refactoring based on @angular/cdk/drag-drop [DURACOM-237] - Added DragDropModule which replaced the SortablejsModule inside form.module.ts
1 parent 07b6d05 commit b41a1c1

7 files changed

Lines changed: 45 additions & 56 deletions

File tree

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
"ng2-nouislider": "^2.0.0",
141141
"ngx-infinite-scroll": "^15.0.0",
142142
"ngx-pagination": "6.0.3",
143-
"ngx-sortablejs": "^11.1.0",
144143
"ngx-ui-switch": "^14.0.3",
145144
"nouislider": "^15.7.1",
146145
"pem": "1.14.7",
@@ -149,7 +148,6 @@
149148
"reflect-metadata": "^0.1.13",
150149
"rxjs": "^7.8.0",
151150
"sanitize-html": "^2.10.0",
152-
"sortablejs": "1.15.0",
153151
"uuid": "^8.3.2",
154152
"webfontloader": "1.6.28",
155153
"zone.js": "~0.11.5"

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

Lines changed: 10 additions & 12 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"
21+
cdkDrag
22+
(cdkDragStarted)="onDrag(i)"
2423
href="javascript:void(0);"
25-
[class.disabled]="(editable && c.editMode) || dragged == i || !clickable"
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: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
.chip-selected {
2-
background-color: var(--bs-secondary) !important;
3-
}
1+
//.example-custom-placeholder {
2+
//background: #ccc;
3+
//border: none;
4+
//min-height: 30px;
5+
//border: 2px solid red;
6+
//}
47

5-
.chip-label {
6-
max-width: 10rem;
8+
.cdk-drag-placeholder {
9+
filter: grayscale(100%);
10+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
11+
}
12+
.cdk-drag-preview {
13+
color: white;
14+
box-sizing: border-box;
15+
border-radius: 0.25rem;
16+
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
17+
0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
718
}
819

20+
//.example-drag-preview.nav-item {
21+
// margin-right: 2px;
22+
// margin-bottom: 1px;
23+
//}
24+
925
.chip-stacked-icons {
1026
display: inline-block;
1127
position: relative;

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 & 17 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,22 +78,23 @@ 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();
99-
this.dragged = -1;
86+
onDrop(event: CdkDragDrop<ChipsItem[]>) {
87+
moveItemInArray(this.chips.chipsItems.getValue(), event.previousIndex, event.currentIndex);
10088
this.chips.updateOrder();
10189
this.isDragging.next(false);
10290
}
10391

10492
showTooltip(tooltip: NgbTooltip, index, field?) {
10593
tooltip.close();
10694
let canShowToolTip = true;
95+
if (this.isDragging.value) {
96+
return;
97+
}
10798
const chipsItem = this.chips.getChipByIndex(index);
10899
const textToDisplay: string[] = [];
109100
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,

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)