Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit 34123aa

Browse files
authored
Merge pull request #394 from ovh-ux/develop
Develop
2 parents c86a845 + 1441a71 commit 34123aa

File tree

10 files changed

+104
-36
lines changed

10 files changed

+104
-36
lines changed

packages/oui-datagrid/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ Or you can use the `page-size` property. It takes precedence over value configur
281281
</oui-datagrid>
282282
```
283283

284+
You can also add custom behaviour on pagination changes
285+
286+
```html:preview
287+
<p>Page size : {{ $ctrl.pageSize }}</p>
288+
<p>Offset : {{ $ctrl.offset }}</p>
289+
<oui-datagrid rows="$ctrl.data" on-page-change="$ctrl.onPageChange($pagination)" page-size="5">
290+
<oui-column title="'firstName'" property="firstName"></oui-column>
291+
<oui-column title="$ctrl.lastNameText" property="lastName"></oui-column>
292+
</oui-datagrid>
293+
```
294+
284295
### Custom cell templates
285296

286297
```html
@@ -718,6 +729,7 @@ call `rows-loader` and then a `row-loader` call for each line.
718729
| `columns-parameters` | array | <? | no | n/a | `undefined` | columns parameters (see below)
719730
| `on-columns-parameters-change` | function | & | no | n/a | n/a | triggered on column parameter change when datagrid is customizable
720731
| `on-row-select` | function | & | no | n/a | n/a | triggered when a row is selected
732+
| `on-page-change` | function | & | no | n/a | n/a | triggered when pagination is changed
721733

722734
`columns-parameters` is an array describing all basic parameters of each column.
723735

packages/oui-datagrid/src/datagrid.controller.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,23 @@ export default class DatagridController {
246246
this.refreshData(() => {
247247
this.paging.setOffset(1);
248248
this.paging.setCriteria(criteria);
249-
}, false, false);
249+
}, false);
250250
}
251251

252-
onPaginationChange ($event) {
252+
onPaginationChange ({ offset, pageSize }) {
253253
this.refreshData(() => {
254-
this.paging.setOffset($event.offset);
255-
this.paging.setPageSize($event.pageSize);
256-
}, true, true);
257-
}
258-
259-
scrollToTop () {
260-
// Small delay otherwise rows could not be rendered
261-
// yet and position would be wrong
262-
this.$timeout(() => {
263-
this.$element[0].scrollIntoView(true);
264-
});
254+
this.paging.setOffset(offset);
255+
this.paging.setPageSize(pageSize);
256+
this.onPageChange({
257+
$pagination: {
258+
offset,
259+
pageSize
260+
}
261+
});
262+
}, true);
265263
}
266264

267-
refreshData (callback, skipSortAndFilter, requireScrollToTop, hideLoader, forceLoadRows) {
265+
refreshData (callback, skipSortAndFilter, hideLoader, forceLoadRows) {
268266
if (this.loading) {
269267
return this.$q.when();
270268
}
@@ -281,9 +279,6 @@ export default class DatagridController {
281279
.then(() => this.paging.loadData(skipSortAndFilter, forceLoadRows))
282280
.then(result => {
283281
this.displayedRows = result.data;
284-
if (requireScrollToTop) {
285-
this.scrollToTop();
286-
}
287282
if (this.hasActionMenu) {
288283
setTimeout(() => this.checkScroll(), checkScrollOnRefreshDataDelay);
289284
}

packages/oui-datagrid/src/datagrid.directive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default () => {
1818
rowLoader: "&?",
1919
emptyPlaceholder: "@?",
2020
onColumnsParametersChange: "&",
21-
onRowSelect: "&"
21+
onRowSelect: "&",
22+
onPageChange: "&"
2223
},
2324
compile: elm => {
2425
// Transclude can't be used here otherwise transcluded

packages/oui-datagrid/src/datagrid.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class DatagridService {
2828
const datagridController = this.datagrids[datagridId];
2929

3030
if (datagridController) {
31-
datagridController.refreshData(false, false, false, !showSpinner, true);
31+
datagridController.refreshData(false, false, !showSpinner, true);
3232
}
3333
}
3434
}

packages/oui-datagrid/src/index.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,24 @@ describe("ouiDatagrid", () => {
12701270
expect(getCell($secondRow, 1).children().html()).toBe(fakeData[3].lastName);
12711271
});
12721272

1273+
it("should execute callback when pagination changes", () => {
1274+
const onPageChangeSpy = jasmine.createSpy("onPaginationChangeSpy");
1275+
const element = TestUtils.compileTemplate(`
1276+
<oui-datagrid rows="$ctrl.rows" page-size="2" on-page-change="$ctrl.onPageChange($pagination)">
1277+
<oui-column property="firstName"></oui-column>
1278+
<oui-column property="lastName"></oui-column>
1279+
</oui-datagrid>
1280+
`, {
1281+
rows: fakeData.slice(0, 5),
1282+
onPageChange: onPageChangeSpy
1283+
}
1284+
);
1285+
1286+
getNextPagePaginationButton(element).triggerHandler("click");
1287+
1288+
expect(onPageChangeSpy).toHaveBeenCalled();
1289+
});
1290+
12731291
it("should support action-menu as column", () => {
12741292
const element = TestUtils.compileTemplate(`
12751293
<oui-datagrid rows="$ctrl.rows">

packages/oui-guide-menu/src/guide-menu.html

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
<oui-dropdown class="oui-dropdown_guide-menu" arrow
22
align="{{::$ctrl.align}}">
33
<button class="oui-guide-button oui-dropdown__trigger" oui-dropdown-trigger>
4-
<span class="oui-guide-button__icon">
5-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 17.15" width="22px">
6-
<polygon points="11.5 15.64 3.5 12.52 3.5 0.53 11.5 3.8 11.5 15.64" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.06"/>
7-
<polygon points="11.54 3.8 19.54 0.53 19.54 12.52 11.54 15.64 11.54 3.8" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.06"/>
8-
<line x1="13.44" y1="5.83" x2="17.58" y2="4.58" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
9-
<line x1="13.44" y1="8.78" x2="17.58" y2="7.54" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
10-
<line x1="13.44" y1="11.73" x2="17.58" y2="10.49" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
11-
<path d="M3.1,4.65H1.69A1.15,1.15,0,0,0,.5,5.75v9.79c0,.61.53,1.1,2.17,1.1H11.5" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round"/>
12-
<path d="M10.5,16.65h9.83c1.64,0,2.17-.49,2.17-1.1V5.75a1.15,1.15,0,0,0-1.19-1.1H19.5" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round"/>
13-
<line x1="5.31" y1="4.58" x2="9.58" y2="6.06" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
14-
<line x1="5.31" y1="7.54" x2="9.58" y2="9.01" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
15-
<line x1="5.31" y1="10.49" x2="9.58" y2="11.96" fill="none" stroke="#122844" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.22"/>
16-
</svg>
17-
</span>
4+
<span class="oui-guide-button__icon oui-icon oui-icon-guides"></span>
185
<span class="oui-guide-button__text" ng-bind="::$ctrl.text"></span>
196
</button>
207
<oui-dropdown-content class="oui-guide-menu"

packages/oui-stepper/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@
9898
</oui-stepper>
9999
```
100100

101+
### Open Steps
102+
103+
```html:preview
104+
<oui-stepper
105+
current-index="$ctrl.currentStep">
106+
<oui-step-form
107+
header="Step1">
108+
<p>Random content</p>
109+
</oui-step-form>
110+
<oui-step-form
111+
header="Step2">
112+
<oui-button variant="link" on-click="$ctrl.currentStep = 0">
113+
<span>Go to Step 1</span>
114+
</oui-button>
115+
</oui-step-form>
116+
</oui-stepper>
117+
```
118+
101119
### Events on `oui-stepper`
102120

103121
**Note**: If you want to access the forms inside `on-finish` callback, you need to use the `forms` variable as below.
@@ -154,6 +172,7 @@
154172
| ---- | ---- | ---- | ---- | ---- | ---- | ----
155173
| `name` | string | @? | yes | n/a | n/a | stepper name used to identify step
156174
| `id` | string | @? | yes | n/a | n/a | stepper id used to identify step
175+
| `current-index` | number | =? | no | n/a | 0 | current step index
157176
| `on-init` | function | & | no | n/a | n/a | initialization function
158177
| `on-finish` | function | & | no | n/a | n/a | submit all steps function
159178

packages/oui-stepper/src/index.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,33 @@ describe("ouiStepper", () => {
230230
expect(form2.hasClass(disabledClass)).toBe(false);
231231
expect(form3.hasClass(disabledClass)).toBe(true);
232232
});
233+
234+
it("should open designated step", () => {
235+
const element = TestUtils.compileTemplate(`
236+
<oui-stepper current-index="$ctrl.index">
237+
<oui-step-form name="form1"></oui-step-form>
238+
<oui-step-form name="form2"></oui-step-form>
239+
<oui-step-form name="form3"></oui-step-form>
240+
</oui-stepper>`, { index: 1 });
241+
242+
$timeout.flush();
243+
244+
const form1 = element.find("form").eq(0);
245+
const form2 = element.find("form").eq(1);
246+
const form3 = element.find("form").eq(2);
247+
248+
expect(form1.scope().$ctrl.stepper.focused).toBe(false);
249+
expect(form2.scope().$ctrl.stepper.focused).toBe(true);
250+
expect(form3.scope().$ctrl.stepper.focused).toBe(false);
251+
252+
element.scope().$ctrl.index = 2;
253+
254+
element.scope().$digest();
255+
256+
expect(form1.scope().$ctrl.stepper.focused).toBe(false);
257+
expect(form2.scope().$ctrl.stepper.focused).toBe(false);
258+
expect(form3.scope().$ctrl.stepper.focused).toBe(true);
259+
});
233260
});
234261
});
235262
});

packages/oui-stepper/src/stepper.component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default {
66
name: "@",
77
id: "@",
88
onInit: "&",
9-
onFinish: "&"
9+
onFinish: "&",
10+
currentIndex: "=?"
1011
},
1112
controller,
1213
template,

packages/oui-stepper/src/stepper.controller.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import get from "lodash/get";
2+
13
export default class {
2-
constructor ($attrs, $element, $timeout) {
4+
constructor ($attrs, $element, $scope, $timeout) {
35
"ngInject";
46

57
this.$attrs = $attrs;
68
this.$element = $element;
9+
this.$scope = $scope;
710
this.$timeout = $timeout;
811
}
912

1013
$onInit () {
1114
this.forms = [];
1215
this.steps = [];
13-
this.currentIndex = 0;
16+
this.currentIndex = get(this, "currentIndex", 0);
1417
this.onInit();
1518
}
1619

@@ -21,6 +24,11 @@ export default class {
2124
.removeAttr("name")
2225
.addClass("oui-stepper")
2326
);
27+
28+
this.$scope.$watch(
29+
() => this.currentIndex,
30+
(index) => this.focusStep(index)
31+
);
2432
}
2533

2634
addStep (step) {

0 commit comments

Comments
 (0)