neo.mjs 4.0.94 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/table/covid/MainContainer.mjs +36 -0
- package/examples/table/covid/Model.mjs +65 -0
- package/examples/table/covid/Store.mjs +35 -0
- package/examples/table/covid/TableContainer.mjs +112 -0
- package/examples/table/covid/TableContainerController.mjs +62 -0
- package/examples/table/covid/Util.mjs +165 -0
- package/examples/table/covid/app.mjs +6 -0
- package/examples/table/covid/index.html +11 -0
- package/examples/table/covid/neo-config.json +8 -0
- package/package.json +3 -3
- package/resources/scss/src/examples/table/covid/TableContainer.scss +21 -0
- package/src/grid/README.md +2 -1
@@ -0,0 +1,36 @@
|
|
1
|
+
import TableContainer from './TableContainer.mjs';
|
2
|
+
import Viewport from '../../../src/container/Viewport.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @class Neo.examples.table.covid.MainContainer
|
6
|
+
* @extends Neo.container.Viewport
|
7
|
+
*/
|
8
|
+
class MainContainer extends Viewport {
|
9
|
+
static getConfig() {return {
|
10
|
+
/**
|
11
|
+
* @member {String} className='Neo.examples.table.covid.MainContainer'
|
12
|
+
* @protected
|
13
|
+
*/
|
14
|
+
className: 'Neo.examples.table.covid.MainContainer',
|
15
|
+
/**
|
16
|
+
* @member {Boolean} autoMount=true
|
17
|
+
*/
|
18
|
+
autoMount: true,
|
19
|
+
/**
|
20
|
+
* @member {Object[]} items=[TableContainer]
|
21
|
+
*/
|
22
|
+
items: [TableContainer],
|
23
|
+
/**
|
24
|
+
* @member {Object} layout={ntype:'fit'}
|
25
|
+
*/
|
26
|
+
layout: {ntype: 'fit'},
|
27
|
+
/**
|
28
|
+
* @member {Object} style={padding:'20px'}
|
29
|
+
*/
|
30
|
+
style: {padding: '20px'}
|
31
|
+
}}
|
32
|
+
}
|
33
|
+
|
34
|
+
Neo.applyClassConfig(MainContainer);
|
35
|
+
|
36
|
+
export default MainContainer;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import BaseModel from '../../../src/data/Model.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @class Neo.examples.table.covid.Model
|
5
|
+
* @extends Neo.data.Model
|
6
|
+
*/
|
7
|
+
class Model extends BaseModel {
|
8
|
+
static getConfig() {return {
|
9
|
+
/**
|
10
|
+
* @member {String} className='Neo.examples.table.covid.Model'
|
11
|
+
* @protected
|
12
|
+
*/
|
13
|
+
className: 'Neo.examples.table.covid.Model',
|
14
|
+
/**
|
15
|
+
* @member {Object[]} fields
|
16
|
+
*/
|
17
|
+
fields: [{
|
18
|
+
name: 'active',
|
19
|
+
type: 'Integer'
|
20
|
+
}, {
|
21
|
+
name: 'cases',
|
22
|
+
type: 'Integer'
|
23
|
+
}, {
|
24
|
+
name: 'casesPerOneMillion',
|
25
|
+
type: 'Integer'
|
26
|
+
}, {
|
27
|
+
name: 'country',
|
28
|
+
type: 'String'
|
29
|
+
}, {
|
30
|
+
name: 'countryInfo',
|
31
|
+
type: 'Object' // _id, flag, iso2, iso3, lat, long
|
32
|
+
}, {
|
33
|
+
name: 'critical',
|
34
|
+
type: 'Integer'
|
35
|
+
}, {
|
36
|
+
name: 'deaths',
|
37
|
+
type: 'Integer'
|
38
|
+
}, {
|
39
|
+
name: 'index',
|
40
|
+
type: 'Integer'
|
41
|
+
}, {
|
42
|
+
name: 'infected', // renderer parses to % of population
|
43
|
+
type: 'Integer'
|
44
|
+
}, {
|
45
|
+
name: 'recovered',
|
46
|
+
type: 'Integer'
|
47
|
+
}, {
|
48
|
+
name: 'tests',
|
49
|
+
type: 'Integer'
|
50
|
+
}, {
|
51
|
+
name: 'testsPerOneMillion',
|
52
|
+
type: 'Integer'
|
53
|
+
}, {
|
54
|
+
name: 'todayCases',
|
55
|
+
type: 'Integer'
|
56
|
+
}, {
|
57
|
+
name: 'todayDeaths',
|
58
|
+
type: 'Integer'
|
59
|
+
}]
|
60
|
+
}}
|
61
|
+
}
|
62
|
+
|
63
|
+
Neo.applyClassConfig(Model);
|
64
|
+
|
65
|
+
export default Model;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import BaseStore from '../../../src/data/Store.mjs';
|
2
|
+
import Model from './Model.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @class Neo.examples.table.covid.Store
|
6
|
+
* @extends Neo.data.Store
|
7
|
+
*/
|
8
|
+
class Store extends BaseStore {
|
9
|
+
static getConfig() {return {
|
10
|
+
/**
|
11
|
+
* @member {String} className='Neo.examples.table.covid.Store'
|
12
|
+
* @protected
|
13
|
+
*/
|
14
|
+
className: 'Neo.examples.table.covid.Store',
|
15
|
+
/**
|
16
|
+
* @member {String} keyProperty='country'
|
17
|
+
*/
|
18
|
+
keyProperty: 'country',
|
19
|
+
/**
|
20
|
+
* @member {Neo.data.Model} model=Model
|
21
|
+
*/
|
22
|
+
model: Model,
|
23
|
+
/**
|
24
|
+
* @member {Object[]} sorters
|
25
|
+
*/
|
26
|
+
sorters: [{
|
27
|
+
property : 'active',
|
28
|
+
direction: 'DESC'
|
29
|
+
}]
|
30
|
+
}}
|
31
|
+
}
|
32
|
+
|
33
|
+
Neo.applyClassConfig(Store);
|
34
|
+
|
35
|
+
export default Store;
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import BaseTableContainer from '../../../src/table/Container.mjs';
|
2
|
+
import Store from './Store.mjs';
|
3
|
+
import TableContainerController from './TableContainerController.mjs';
|
4
|
+
import Util from './Util.mjs';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @class Neo.examples.table.covid.TableContainer
|
8
|
+
* @extends Neo.table.Container
|
9
|
+
*/
|
10
|
+
class TableContainer extends BaseTableContainer {
|
11
|
+
static getConfig() {return {
|
12
|
+
/**
|
13
|
+
* @member {String} className='Neo.examples.table.covid.TableContainer'
|
14
|
+
* @protected
|
15
|
+
*/
|
16
|
+
className: 'Neo.examples.table.covid.TableContainer',
|
17
|
+
/**
|
18
|
+
* @member {String[]} cls=['covid-country-table', 'neo-table-container']
|
19
|
+
*/
|
20
|
+
cls: ['covid-country-table', 'neo-table-container'],
|
21
|
+
/**
|
22
|
+
* Default configs for each column
|
23
|
+
* @member {Object} columnDefaults
|
24
|
+
*/
|
25
|
+
columnDefaults: {
|
26
|
+
align : 'right',
|
27
|
+
defaultSortDirection: 'DESC',
|
28
|
+
renderer : Util.formatNumber
|
29
|
+
},
|
30
|
+
/**
|
31
|
+
* @member {Object[]} columns
|
32
|
+
*/
|
33
|
+
columns: [{
|
34
|
+
cls : ['neo-index-column', 'neo-table-header-button'],
|
35
|
+
dataField: 'index',
|
36
|
+
dock : 'left',
|
37
|
+
minWidth : 40,
|
38
|
+
text : '#',
|
39
|
+
renderer : Util.indexRenderer,
|
40
|
+
width : 40
|
41
|
+
}, {
|
42
|
+
align : 'left',
|
43
|
+
dataField : 'country',
|
44
|
+
defaultSortDirection: 'ASC',
|
45
|
+
dock : 'left',
|
46
|
+
text : 'Country',
|
47
|
+
width : 200,
|
48
|
+
|
49
|
+
renderer: data => {
|
50
|
+
return {
|
51
|
+
cls : ['neo-country-column', 'neo-table-cell'],
|
52
|
+
html: [
|
53
|
+
'<div style="display: flex; align-items: center">',
|
54
|
+
'<img style="height:20px; margin-right:10px; width:20px;" src="' + Util.getCountryFlagUrl(data.value) + '">' + data.value,
|
55
|
+
'</div>'
|
56
|
+
].join('')
|
57
|
+
};
|
58
|
+
}
|
59
|
+
}, {
|
60
|
+
dataField: 'cases',
|
61
|
+
text : 'Cases'
|
62
|
+
}, {
|
63
|
+
dataField: 'casesPerOneMillion',
|
64
|
+
text : 'Cases / 1M'
|
65
|
+
}, {
|
66
|
+
dataField: 'infected',
|
67
|
+
text : 'Infected',
|
68
|
+
renderer : data => Util.formatInfected(data)
|
69
|
+
}, {
|
70
|
+
dataField: 'active',
|
71
|
+
text : 'Active',
|
72
|
+
renderer : data => Util.formatNumber(data, '#64B5F6')
|
73
|
+
}, {
|
74
|
+
dataField: 'recovered',
|
75
|
+
text : 'Recovered',
|
76
|
+
renderer : data => Util.formatNumber(data, '#28ca68')
|
77
|
+
}, {
|
78
|
+
dataField: 'critical',
|
79
|
+
text : 'Critical',
|
80
|
+
renderer : data => Util.formatNumber(data, 'orange')
|
81
|
+
}, {
|
82
|
+
dataField: 'deaths',
|
83
|
+
text : 'Deaths',
|
84
|
+
renderer : data => Util.formatNumber(data, '#fb6767')
|
85
|
+
}, {
|
86
|
+
dataField: 'todayCases',
|
87
|
+
text : 'Cases today'
|
88
|
+
}, {
|
89
|
+
dataField: 'todayDeaths',
|
90
|
+
text : 'Deaths today',
|
91
|
+
renderer : data => Util.formatNumber(data, '#fb6767')
|
92
|
+
}, {
|
93
|
+
dataField: 'tests',
|
94
|
+
text : 'Tests'
|
95
|
+
}, {
|
96
|
+
dataField: 'testsPerOneMillion',
|
97
|
+
text : 'Tests / 1M'
|
98
|
+
}],
|
99
|
+
/**
|
100
|
+
* @member {Neo.controller.Component} controller=TableContainerController
|
101
|
+
*/
|
102
|
+
controller: TableContainerController,
|
103
|
+
/**
|
104
|
+
* @member {Object[]} store=MainStore
|
105
|
+
*/
|
106
|
+
store: Store
|
107
|
+
}}
|
108
|
+
}
|
109
|
+
|
110
|
+
Neo.applyClassConfig(TableContainer);
|
111
|
+
|
112
|
+
export default TableContainer;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import Controller from '../../../src/controller/Component.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @class Neo.examples.table.covid.TableContainerController
|
5
|
+
* @extends Neo.controller.Component
|
6
|
+
*/
|
7
|
+
class TableContainerController extends Controller {
|
8
|
+
/**
|
9
|
+
* @member {String} apiUrl='https://disease.sh/v3/covid-19/countries'
|
10
|
+
*/
|
11
|
+
apiUrl = 'https://disease.sh/v3/covid-19/countries'
|
12
|
+
|
13
|
+
static getConfig() {return {
|
14
|
+
/**
|
15
|
+
* @member {String} className='Neo.examples.table.covid.TableContainerController'
|
16
|
+
* @protected
|
17
|
+
*/
|
18
|
+
className: 'Neo.examples.table.covid.TableContainerController'
|
19
|
+
}}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @param {Object} config
|
23
|
+
*/
|
24
|
+
construct(config) {
|
25
|
+
super.construct(config);
|
26
|
+
this.loadData();
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @param {Object[]} data
|
31
|
+
*/
|
32
|
+
addStoreItems(data) {
|
33
|
+
let store = this.component.store;
|
34
|
+
|
35
|
+
data.forEach(item => {
|
36
|
+
if (item.country.includes('"')) {
|
37
|
+
item.country = item.country.replace('"', "\'");
|
38
|
+
}
|
39
|
+
|
40
|
+
item.casesPerOneMillion = item.casesPerOneMillion > item.cases ? 'N/A' : item.casesPerOneMillion || 0;
|
41
|
+
item.infected = item.casesPerOneMillion;
|
42
|
+
});
|
43
|
+
|
44
|
+
store.data = data;
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
*/
|
50
|
+
loadData() {
|
51
|
+
let me = this;
|
52
|
+
|
53
|
+
fetch(me.apiUrl)
|
54
|
+
.then(response => response.json())
|
55
|
+
.catch(err => console.log('Can’t access ' + me.apiUrl, err))
|
56
|
+
.then(data => me.addStoreItems(data));
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
Neo.applyClassConfig(TableContainerController);
|
61
|
+
|
62
|
+
export default TableContainerController;
|
@@ -0,0 +1,165 @@
|
|
1
|
+
import Base from '../../../src/core/Base.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Static utility class
|
5
|
+
* @class Neo.examples.table.covid.Util
|
6
|
+
* @extends Neo.core.Base
|
7
|
+
*/
|
8
|
+
class Util extends Base {
|
9
|
+
static getStaticConfig() {return {
|
10
|
+
/**
|
11
|
+
* A regex to replace blank chars
|
12
|
+
* @member {RegExp} flagRegEx=/ /gi
|
13
|
+
* @protected
|
14
|
+
* @static
|
15
|
+
*/
|
16
|
+
flagRegEx: / /gi,
|
17
|
+
/**
|
18
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
|
19
|
+
* Change this config to enforce a county specific formatting (e.g. 'de-DE')
|
20
|
+
* @member {String} locales='default'
|
21
|
+
* @protected
|
22
|
+
* @static
|
23
|
+
*/
|
24
|
+
locales: 'default'
|
25
|
+
}}
|
26
|
+
|
27
|
+
static getConfig() {return {
|
28
|
+
/**
|
29
|
+
* @member {String} className='Neo.examples.table.covid.Util'
|
30
|
+
* @protected
|
31
|
+
*/
|
32
|
+
className: 'Neo.examples.table.covid.Util'
|
33
|
+
}}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Used for the casesPerOneMillion column to show % of population
|
37
|
+
* @param {Object} data
|
38
|
+
* @param {Number} data.value
|
39
|
+
* @returns {String}
|
40
|
+
*/
|
41
|
+
static formatInfected(data) {
|
42
|
+
let value = data.value;
|
43
|
+
|
44
|
+
if (!Neo.isNumber(value)) {
|
45
|
+
return value || 'N/A';
|
46
|
+
}
|
47
|
+
|
48
|
+
value = Math.round(value / 100);
|
49
|
+
value /= 100;
|
50
|
+
|
51
|
+
value = value.toFixed(2) + ' %';
|
52
|
+
|
53
|
+
return value.toLocaleString(Util.locales);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* This method will get used as a grid renderer, so the 2nd param is an overload (would be {Object} record)
|
58
|
+
* @param {Object} data
|
59
|
+
* @param {Number} data.value
|
60
|
+
* @param {String} [color]
|
61
|
+
* @returns {String}
|
62
|
+
*/
|
63
|
+
static formatNumber(data, color) {
|
64
|
+
let value = data.value;
|
65
|
+
|
66
|
+
if (!Neo.isNumber(value)) {
|
67
|
+
return value || 'N/A';
|
68
|
+
}
|
69
|
+
|
70
|
+
value = value.toLocaleString(Util.locales);
|
71
|
+
|
72
|
+
return typeof color !== 'string' ? value : `<span style="color:${color};">${value}</span>`;
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @param {String} name
|
77
|
+
* @returns {String} url
|
78
|
+
*/
|
79
|
+
static getCountryFlagUrl(name) {
|
80
|
+
const map = {
|
81
|
+
'bosnia' : 'bosnia-and-herzegovina',
|
82
|
+
'cabo-verde' : 'cape-verde',
|
83
|
+
'car' : 'central-african-republic',
|
84
|
+
'caribbean-netherlands' : 'netherlands',
|
85
|
+
'channel-islands' : 'jersey',
|
86
|
+
'côte-d\'ivoire' : 'ivory-coast',
|
87
|
+
'congo' : 'republic-of-the-congo',
|
88
|
+
'congo,-the-democratic-republic-of-the': 'democratic-republic-of-congo',
|
89
|
+
'curaçao' : 'curacao',
|
90
|
+
'czechia' : 'czech-republic',
|
91
|
+
'diamond-princess' : 'japan', // cruise ship
|
92
|
+
'drc' : 'democratic-republic-of-congo',
|
93
|
+
'el-salvador' : 'salvador',
|
94
|
+
'eswatini' : 'swaziland',
|
95
|
+
'faeroe-islands' : 'faroe-islands',
|
96
|
+
'falkland-islands-(malvinas)' : 'falkland-islands',
|
97
|
+
'french-guiana' : 'france', // ?
|
98
|
+
'guadeloupe' : 'france', // ?
|
99
|
+
'holy-see-(vatican-city-state)' : 'vatican-city',
|
100
|
+
'iran,-islamic-republic-of' : 'iran',
|
101
|
+
'lao-people\'s-democratic-republic' : 'laos',
|
102
|
+
'libyan-arab-jamahiriya' : 'libya',
|
103
|
+
'macedonia' : 'republic-of-macedonia',
|
104
|
+
'marshall-islands' : 'marshall-island',
|
105
|
+
'mayotte' : 'france', // ?
|
106
|
+
'moldova,-republic-of' : 'moldova',
|
107
|
+
'ms-zaandam' : 'netherlands', // cruise ship
|
108
|
+
'new-caledonia' : 'france',
|
109
|
+
'palestinian-territory,-occupied' : 'palestine',
|
110
|
+
'poland' : 'republic-of-poland',
|
111
|
+
'réunion' : 'france',
|
112
|
+
's.-korea' : 'south-korea',
|
113
|
+
'st.-barth' : 'st-barts',
|
114
|
+
'saint-helena' : 'united-kingdom', // sorry, icon not included
|
115
|
+
'saint-lucia' : 'st-lucia',
|
116
|
+
'saint-martin' : 'sint-maarten',
|
117
|
+
'saint-pierre-miquelon' : 'france',
|
118
|
+
'saint-vincent-and-the-grenadines' : 'st-vincent-and-the-grenadines',
|
119
|
+
'syrian-arab-republic' : 'syria',
|
120
|
+
'tanzania,-united-republic-of' : 'tanzania',
|
121
|
+
'timor-leste' : 'east-timor',
|
122
|
+
'turks-and-caicos-islands' : 'turks-and-caicos',
|
123
|
+
'u.s.-virgin-islands' : 'virgin-islands',
|
124
|
+
'uae' : 'united-arab-emirates',
|
125
|
+
'uk' : 'united-kingdom',
|
126
|
+
'usa' : 'united-states-of-america',
|
127
|
+
'uzbekistan' : 'uzbekistn',
|
128
|
+
'venezuela,-bolivarian-republic-of' : 'venezuela',
|
129
|
+
'viet-nam' : 'vietnam',
|
130
|
+
'wallis-and-futuna' : 'france'
|
131
|
+
};
|
132
|
+
|
133
|
+
let imageName = name.toLowerCase().replace(Util.flagRegEx, '-');
|
134
|
+
|
135
|
+
imageName = map[imageName] || imageName;
|
136
|
+
|
137
|
+
if (Neo.config.isGitHubPages) {
|
138
|
+
let path = `../../../../resources/images/flaticon/country_flags/png/${imageName}.png`;
|
139
|
+
|
140
|
+
if (Neo.config.environment !== 'development') {
|
141
|
+
path = `../../${path}`;
|
142
|
+
}
|
143
|
+
|
144
|
+
return path;
|
145
|
+
}
|
146
|
+
|
147
|
+
return `https://raw.githubusercontent.com/neomjs/pages/master/resources/images/flaticon/country_flags/png/${imageName}.png`;
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* @param {Object} data
|
152
|
+
* @param {Number} data.index
|
153
|
+
* @returns {Object}
|
154
|
+
*/
|
155
|
+
static indexRenderer(data) {
|
156
|
+
return {
|
157
|
+
cls : ['neo-index-column', 'neo-table-cell'],
|
158
|
+
html: data.index + 1
|
159
|
+
};
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
Neo.applyClassConfig(Util);
|
164
|
+
|
165
|
+
export default Util;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!DOCTYPE HTML>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
<title>Neo CovidTable</title>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<script src="../../../src/MicroLoader.mjs" type="module"></script>
|
10
|
+
</body>
|
11
|
+
</html>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "neo.mjs",
|
3
|
-
"version": "4.0
|
3
|
+
"version": "4.1.0",
|
4
4
|
"description": "The webworkers driven UI framework",
|
5
5
|
"type": "module",
|
6
6
|
"repository": {
|
@@ -54,10 +54,10 @@
|
|
54
54
|
"neo-jsdoc": "^1.0.1",
|
55
55
|
"neo-jsdoc-x": "^1.0.4",
|
56
56
|
"postcss": "^8.4.16",
|
57
|
-
"sass": "^1.54.
|
57
|
+
"sass": "^1.54.6",
|
58
58
|
"webpack": "^5.74.0",
|
59
59
|
"webpack-cli": "^4.10.0",
|
60
|
-
"webpack-dev-server": "4.10.
|
60
|
+
"webpack-dev-server": "4.10.1",
|
61
61
|
"webpack-hook-plugin": "^1.0.7",
|
62
62
|
"webpack-node-externals": "^3.0.0"
|
63
63
|
},
|
@@ -0,0 +1,21 @@
|
|
1
|
+
.neo-table-wrapper {
|
2
|
+
width: 100%
|
3
|
+
}
|
4
|
+
|
5
|
+
.neo-table-container.covid-country-table {
|
6
|
+
.neo-country-column {
|
7
|
+
min-width: 200px;
|
8
|
+
width : initial;
|
9
|
+
}
|
10
|
+
|
11
|
+
.neo-index-column {
|
12
|
+
max-width: 40px;
|
13
|
+
min-width: 40px;
|
14
|
+
width : 40px;
|
15
|
+
}
|
16
|
+
|
17
|
+
td, th {
|
18
|
+
min-width: 100px;
|
19
|
+
width : 300px;
|
20
|
+
}
|
21
|
+
}
|
package/src/grid/README.md
CHANGED