Skip to content

Commit bff6d50

Browse files
authored
Demos: replace endpoint urls (DevExpress#29453)
1 parent 14e3d4f commit bff6d50

File tree

5 files changed

+130
-11
lines changed

5 files changed

+130
-11
lines changed

apps/demos/Demos/DataGrid/BatchUpdateRequest/Angular/app/app.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!/localhost/.test(document.location.host)) {
1010
enableProdMode();
1111
}
1212

13-
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi';
13+
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridBatchUpdateWebApi';
1414

1515
let modulePrefix = '';
1616
// @ts-ignore
@@ -40,13 +40,14 @@ export class AppComponent {
4040
e.cancel = true;
4141

4242
if (e.changes.length) {
43-
e.promise = this.processBatchRequest(`${URL}/Batch`, e.changes, e.component);
43+
const changes = this.normalizeChanges(e.changes);
44+
e.promise = this.processBatchRequest(`${URL}/Batch`, changes, e.component);
4445
}
4546
}
4647

4748
async processBatchRequest(
4849
url: string,
49-
changes: Array<DxDataGridTypes.DataChange>,
50+
changes: DxDataGridTypes.DataChange[],
5051
component: DxDataGridComponent['instance'],
5152
): Promise<void> {
5253
await lastValueFrom(
@@ -60,6 +61,29 @@ export class AppComponent {
6061
await component.refresh(true);
6162
component.cancelEditData();
6263
}
64+
65+
normalizeChanges(changes: DxDataGridTypes.DataChange[]): DxDataGridTypes.DataChange[] {
66+
return changes.map(c => {
67+
switch (c.type) {
68+
case 'insert':
69+
return {
70+
type: c.type,
71+
data: c.data,
72+
};
73+
case 'update':
74+
return {
75+
type: c.type,
76+
key: c.key,
77+
data: c.data,
78+
};
79+
case 'remove':
80+
return {
81+
type: c.type,
82+
key: c.key,
83+
};
84+
}
85+
}) as DxDataGridTypes.DataChange[];
86+
}
6387
}
6488

6589
@NgModule({

apps/demos/Demos/DataGrid/BatchUpdateRequest/React/App.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import DataGrid, { DataGridRef, Column, DataGridTypes, Editing, Pager, } from 'd
33
import { createStore } from 'devextreme-aspnet-data-nojquery';
44
import 'whatwg-fetch';
55

6-
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi';
6+
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridBatchUpdateWebApi';
77

88
const ordersStore = createStore({
99
key: 'OrderID',
@@ -13,6 +13,29 @@ const ordersStore = createStore({
1313
},
1414
});
1515

16+
function normalizeChanges(changes: DataGridTypes.DataChange[]): DataGridTypes.DataChange[] {
17+
return changes.map(c => {
18+
switch (c.type) {
19+
case 'insert':
20+
return {
21+
type: c.type,
22+
data: c.data,
23+
};
24+
case 'update':
25+
return {
26+
type: c.type,
27+
key: c.key,
28+
data: c.data,
29+
};
30+
case 'remove':
31+
return {
32+
type: c.type,
33+
key: c.key,
34+
};
35+
}
36+
}) as DataGridTypes.DataChange[];
37+
}
38+
1639
async function sendBatchRequest(url: string, changes: DataGridTypes.DataChange[]) {
1740
const result = await fetch(url, {
1841
method: 'POST',
@@ -40,7 +63,8 @@ const onSaving = (e: DataGridTypes.SavingEvent) => {
4063
e.cancel = true;
4164

4265
if (e.changes.length) {
43-
e.promise = processBatchRequest(`${URL}/Batch`, e.changes, e.component);
66+
const changes = normalizeChanges(e.changes);
67+
e.promise = processBatchRequest(`${URL}/Batch`, changes, e.component);
4468
}
4569
};
4670

apps/demos/Demos/DataGrid/BatchUpdateRequest/ReactJs/App.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,36 @@ import DataGrid, { Column, Editing, Pager } from 'devextreme-react/data-grid';
33
import { createStore } from 'devextreme-aspnet-data-nojquery';
44
import 'whatwg-fetch';
55

6-
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi';
6+
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridBatchUpdateWebApi';
77
const ordersStore = createStore({
88
key: 'OrderID',
99
loadUrl: `${URL}/Orders`,
1010
onBeforeSend: (method, ajaxOptions) => {
1111
ajaxOptions.xhrFields = { withCredentials: true };
1212
},
1313
});
14+
function normalizeChanges(changes) {
15+
return changes.map((c) => {
16+
switch (c.type) {
17+
case 'insert':
18+
return {
19+
type: c.type,
20+
data: c.data,
21+
};
22+
case 'update':
23+
return {
24+
type: c.type,
25+
key: c.key,
26+
data: c.data,
27+
};
28+
case 'remove':
29+
return {
30+
type: c.type,
31+
key: c.key,
32+
};
33+
}
34+
});
35+
}
1436
async function sendBatchRequest(url, changes) {
1537
const result = await fetch(url, {
1638
method: 'POST',
@@ -33,7 +55,8 @@ async function processBatchRequest(url, changes, component) {
3355
const onSaving = (e) => {
3456
e.cancel = true;
3557
if (e.changes.length) {
36-
e.promise = processBatchRequest(`${URL}/Batch`, e.changes, e.component);
58+
const changes = normalizeChanges(e.changes);
59+
e.promise = processBatchRequest(`${URL}/Batch`, changes, e.component);
3760
}
3861
};
3962
const App = () => (

apps/demos/Demos/DataGrid/BatchUpdateRequest/Vue/App.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
import { createStore } from 'devextreme-aspnet-data-nojquery';
3737
import 'whatwg-fetch';
3838
39-
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi';
39+
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridBatchUpdateWebApi';
4040
4141
const ordersStore = createStore({
4242
key: 'OrderID',
@@ -50,10 +50,34 @@ const onSaving = (e: DxDataGridTypes.SavingEvent) => {
5050
e.cancel = true;
5151
5252
if (e.changes.length) {
53-
e.promise = processBatchRequest(`${URL}/Batch`, e.changes, e.component);
53+
const changes = normalizeChanges(e.changes);
54+
e.promise = processBatchRequest(`${URL}/Batch`, changes, e.component);
5455
}
5556
};
5657
58+
function normalizeChanges(changes: DxDataGridTypes.DataChange[]): DxDataGridTypes.DataChange[] {
59+
return changes.map(c => {
60+
switch (c.type) {
61+
case 'insert':
62+
return {
63+
type: c.type,
64+
data: c.data,
65+
};
66+
case 'update':
67+
return {
68+
type: c.type,
69+
key: c.key,
70+
data: c.data,
71+
};
72+
case 'remove':
73+
return {
74+
type: c.type,
75+
key: c.key,
76+
};
77+
}
78+
}) as DxDataGridTypes.DataChange[];
79+
}
80+
5781
async function processBatchRequest(
5882
url: string, changes: DxDataGridTypes.DataChange[], component: DxDataGrid['instance'],
5983
) {

apps/demos/Demos/DataGrid/BatchUpdateRequest/jQuery/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$(() => {
2-
const URL = 'https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi';
2+
const URL = 'https://js.devexpress.com/Demos/NetCore/api/DataGridWebApi';
33

44
$('#gridContainer').dxDataGrid({
55
dataSource: DevExpress.data.AspNet.createStore({
@@ -25,7 +25,8 @@ $(() => {
2525
e.cancel = true;
2626

2727
if (e.changes.length) {
28-
e.promise = sendBatchRequest(`${URL}/Batch`, e.changes).done(() => {
28+
const changes = normalizeChanges(e.changes);
29+
e.promise = sendBatchRequest(`${URL}/Batch`, changes).done(() => {
2930
e.component.refresh(true).done(() => {
3031
e.component.cancelEditData();
3132
});
@@ -51,6 +52,29 @@ $(() => {
5152
}],
5253
});
5354

55+
function normalizeChanges(changes) {
56+
return changes.map(c => {
57+
switch (c.type) {
58+
case 'insert':
59+
return {
60+
type: c.type,
61+
data: c.data,
62+
};
63+
case 'update':
64+
return {
65+
type: c.type,
66+
key: c.key,
67+
data: c.data,
68+
};
69+
case 'remove':
70+
return {
71+
type: c.type,
72+
key: c.key,
73+
};
74+
}
75+
});
76+
}
77+
5478
function sendBatchRequest(url, changes) {
5579
const d = $.Deferred();
5680

0 commit comments

Comments
 (0)