pui9-dashboard 1.16.4

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.
@@ -0,0 +1,155 @@
1
+ <template>
2
+ <v-card outlined elevation="1" :style="{ width: width, height: height }">
3
+ <v-card-title>
4
+ <span>{{ title }}</span>
5
+ <v-spacer />
6
+ <pui-text-field
7
+ v-if="searchable"
8
+ v-model="search"
9
+ append-icon="fas fa-search"
10
+ placeholder="search"
11
+ noeditable
12
+ realtime
13
+ hide-details
14
+ ></pui-text-field>
15
+ </v-card-title>
16
+ <v-divider />
17
+ <v-card-text>
18
+ <v-data-table
19
+ :headers="headers"
20
+ :items="items"
21
+ class="elevation-1"
22
+ :loading="loading"
23
+ :height="tableHeight"
24
+ :search="search"
25
+ dense
26
+ fixed-header
27
+ :hide-default-footer="hideFooter"
28
+ ></v-data-table>
29
+ </v-card-text>
30
+ </v-card>
31
+ </template>
32
+
33
+ <script>
34
+ import defaultOptions from './PuiWidgetDatatableOptions.js';
35
+
36
+ export default {
37
+ name: 'PuiWidgetDatatable',
38
+ props: {
39
+ definition: {
40
+ type: Object,
41
+ required: false
42
+ },
43
+ resized: {
44
+ type: Object,
45
+ required: false
46
+ }
47
+ },
48
+ data() {
49
+ return {
50
+ width: '100%',
51
+ height: '100%',
52
+ loading: true,
53
+ title: null,
54
+ headers: [],
55
+ items: [],
56
+ search: null
57
+ };
58
+ },
59
+ computed: {
60
+ tableHeight() {
61
+ if (this.resized && this.resized.height) {
62
+ return this.resized.height - 150;
63
+ }
64
+ return '100%';
65
+ },
66
+ searchable() {
67
+ return (this.definition && this.definition.searchable && this.definition.searchable.value) || false;
68
+ },
69
+ hideFooter() {
70
+ return (this.definition && this.definition.hidePagination && this.definition.hidePagination.value) || false;
71
+ }
72
+ },
73
+ created() {
74
+ this.initDatatable();
75
+ },
76
+ methods: {
77
+ initDatatable() {
78
+ if (!this.definition) {
79
+ (this.title = 'Example Datatable'), (this.columns = defaultOptions.columns);
80
+ this.headers = defaultOptions.headers;
81
+ this.items = defaultOptions.items;
82
+ this.loading = false;
83
+ return;
84
+ }
85
+
86
+ this.title = this.definition.title.value;
87
+ const model = this.$store.getters.getModelByName(this.definition.entityName.value);
88
+
89
+ if (model) {
90
+ this.initDatatableFromModel(model);
91
+ } else {
92
+ console.log(this.definition.entityName.value, 'not exist in PUI9 models');
93
+ this.initDatatableFromPuiWidget();
94
+ }
95
+
96
+ },
97
+ initDatatableFromModel(model) {
98
+ const modelColumns = model.columns;
99
+ this.headers = modelColumns.map((col) => {
100
+ return { text: this.$t(col.title), value: col.name };
101
+ });
102
+
103
+ const data = {
104
+ model: this.definition.entityName.value,
105
+ filter: this.definition.filter,
106
+ rows: 1000,
107
+ columns:
108
+ this.definition.columns ||
109
+ modelColumns.map((col) => {
110
+ return col.name;
111
+ })
112
+ };
113
+
114
+ this.$puiRequests.postRequest('/puisearch', data, (response) => {
115
+ if (response && response.data && response.data.data) {
116
+ this.items = response.data.data;
117
+ this.loading = false;
118
+ }
119
+ },
120
+ (error) => {
121
+ console.log(error);
122
+ this.loading = false;
123
+ }
124
+ );
125
+ },
126
+ initDatatableFromPuiWidget() {
127
+ const url = '/puiwidget/getVuetifyDatatableValues';
128
+ const params = {
129
+ entity: this.definition.entityName.value
130
+ };
131
+
132
+ this.$puiRequests.getRequest(url, params, (response) => {
133
+ if (response && response.data) {
134
+ for (let i = 0, dataLength = response.data.length; i < dataLength; i++) {
135
+ const item = response.data[i];
136
+
137
+ if (i === 0) {
138
+ for (const [key] of Object.entries(item)) {
139
+ this.headers.push({ text: key, value: key });
140
+ }
141
+ }
142
+ this.items.push(item);
143
+ }
144
+ this.loading = false;
145
+ }
146
+ },
147
+ (error) => {
148
+ console.log(error);
149
+ this.loading = false;
150
+ }
151
+ );
152
+ }
153
+ }
154
+ };
155
+ </script>
@@ -0,0 +1,13 @@
1
+ export default {
2
+ headers: [
3
+ { text: 'Code', value: 'code' },
4
+ { text: 'Name', value: 'name' },
5
+ { text: 'Description', value: 'description' }
6
+ ],
7
+ items: [
8
+ { code: 1, name: 'Test 1', description: 'Test 1 description' },
9
+ { code: 2, name: 'Test 2', description: 'Test 2 description' },
10
+ { code: 3, name: 'Test 3', description: 'Test 3 description' },
11
+ { code: 4, name: 'Test 4', description: 'Test 4 description' }
12
+ ]
13
+ };
@@ -0,0 +1,188 @@
1
+ <template>
2
+ <v-card outlined elevation="1" class="overflow-y-hidden" :style="{ width: width, height: height }" :loading="loading" v-resize="onResize">
3
+ <v-card-title v-if="title">{{ title }}</v-card-title>
4
+ <v-divider v-if="title" />
5
+ <v-card-text>
6
+ <div class="chart" :style="{ width: defaultWidth, height: defaultHeight }" ref="echart" />
7
+ <span v-if="noData">{{ noData }}</span>
8
+ </v-card-text>
9
+ </v-card>
10
+ </template>
11
+
12
+ <script>
13
+ import * as echarts from 'echarts';
14
+ // echarts themes (macarons | roma | shine | vintage)
15
+ require('echarts/theme/macarons');
16
+ require('echarts/theme/roma');
17
+ require('echarts/theme/shine');
18
+ require('echarts/theme/vintage');
19
+
20
+ import defaultOptions from './PuiWidgetEChartOptions.js';
21
+
22
+ export default {
23
+ name: 'PuiWidgetEChart',
24
+ props: {
25
+ type: {
26
+ type: String,
27
+ required: true
28
+ },
29
+ /**
30
+ * definition.title.value (String)
31
+ * definition.theme.value (String) (macarons | roma | shine | vintage)
32
+ * definition.model.value (String)
33
+ */
34
+ definition: {
35
+ type: Object,
36
+ required: false
37
+ },
38
+ filter: {
39
+ type: Object,
40
+ required: false
41
+ },
42
+ resized: {
43
+ type: Object,
44
+ required: false
45
+ }
46
+ },
47
+ data() {
48
+ return {
49
+ width: '100%',
50
+ height: '100%',
51
+ echartMethods: {
52
+ EChartsBar: 'getEChartsLineBarOptions',
53
+ EChartsLine: 'getEChartsLineBarOptions',
54
+ EChartsPie: 'getEChartsPieOptions'
55
+ },
56
+ echartTypes: {
57
+ EChartsBar: 'bar',
58
+ EChartsLine: 'line',
59
+ EChartsPie: 'pie'
60
+ },
61
+ loading: true,
62
+ title: null,
63
+ chart: null,
64
+ noData: null
65
+ };
66
+ },
67
+ computed: {
68
+ defaultWidth() {
69
+ if (this.resized && this.resized.width) {
70
+ //return `${this.resized.width - 50}px`;
71
+ }
72
+ return '100%';
73
+ },
74
+ defaultHeight() {
75
+ if (this.resized && this.resized.height) {
76
+ return `${this.resized.height - 100}px`;
77
+ }
78
+ return '100%';
79
+ }
80
+ },
81
+ watch: {
82
+ resized: {
83
+ handler() {
84
+ this.onResize();
85
+ },
86
+ deep: true
87
+ }
88
+ },
89
+ mounted() {
90
+ this.$nextTick(() => {
91
+ this.initChart();
92
+ });
93
+ },
94
+ beforeDestroy() {
95
+ if (!this.chart) {
96
+ return;
97
+ }
98
+ this.chart.dispose();
99
+ this.chart = null;
100
+ },
101
+ methods: {
102
+ onResize() {
103
+ if (this.chart) {
104
+ this.chart.resize();
105
+ }
106
+ },
107
+ initChart() {
108
+ if (!this.definition) {
109
+ this.title = `Example ${this.type} Chart`;
110
+ this.chart = echarts.init(this.$refs.echart);
111
+ this.chart.setOption(defaultOptions[this.type]);
112
+ this.loading = false;
113
+ return;
114
+ }
115
+
116
+ this.title = this.definition.title.value;
117
+
118
+ const theme = (this.definition.theme && this.definition.theme.value) || null;
119
+ const url = `/puiwidget/${this.echartMethods[this.type]}`;
120
+ const params = {
121
+ entity: this.definition.entityName.value,
122
+ name: this.definition.columnName.value,
123
+ value: this.definition.columnValue.value,
124
+ type: this.echartTypes[this.type]
125
+ };
126
+
127
+ this.$puiRequests.postRequest(
128
+ url,
129
+ this.filter,
130
+ (response) => {
131
+ if (response && response.data) {
132
+ const chartOptions = this.getChartOptions();
133
+
134
+ if (response.data.categories) {
135
+ chartOptions.xAxis.data = response.data.categories;
136
+ }
137
+
138
+ chartOptions.series = [];
139
+ for (let i = 0; i < response.data.series.length; i++) {
140
+ const serie = response.data.series[i];
141
+ chartOptions.series.push(serie);
142
+ }
143
+
144
+ this.chart = echarts.init(this.$refs.echart, theme);
145
+ this.chart.setOption(chartOptions);
146
+ this.loading = false;
147
+ } else {
148
+ console.log('No response data');
149
+ this.noData = this.$t('puiwidget.nodata');
150
+ this.loading = false;
151
+ }
152
+ },
153
+ (error) => {
154
+ console.log(error);
155
+ this.noData = this.$t('puiwidget.nodata');
156
+ this.loading = false;
157
+ },
158
+ null,
159
+ params
160
+ );
161
+ },
162
+ getChartOptions() {
163
+ // do copy of default chart options
164
+ const chartOptions = JSON.parse(JSON.stringify(defaultOptions[this.type]));
165
+
166
+ if (this.definition.legend && this.definition.legend.value) {
167
+ chartOptions.legend = {};
168
+ }
169
+ if (this.definition.toolbox && this.definition.toolbox.value) {
170
+ chartOptions.toolbox = {
171
+ show: true,
172
+ feature: {
173
+ dataZoom: {
174
+ yAxisIndex: 'none'
175
+ },
176
+ dataView: {readOnly: false},
177
+ magicType: {type: ['line', 'bar']},
178
+ restore: {},
179
+ saveAsImage: {}
180
+ }
181
+ };
182
+ }
183
+
184
+ return chartOptions;
185
+ }
186
+ }
187
+ };
188
+ </script>
@@ -0,0 +1,79 @@
1
+ const tooltip = {
2
+ trigger: 'axis',
3
+ axisPointer: {
4
+ type: 'shadow' // 'line' | 'shadow'
5
+ }
6
+ };
7
+ const grid = {
8
+ top: 10,
9
+ left: '2%',
10
+ right: '2%',
11
+ bottom: '3%',
12
+ containLabel: true
13
+ };
14
+ const legend = null;
15
+ const xAxis = {
16
+ type: 'category',
17
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
18
+ };
19
+ const yAxis = { type: 'value' };
20
+
21
+ const barChartOptions = {
22
+ tooltip,
23
+ grid,
24
+ legend,
25
+ xAxis,
26
+ yAxis,
27
+ series: [
28
+ {
29
+ data: [120, 200, 150, 80, 70, 110, 130],
30
+ type: 'bar'
31
+ }
32
+ ]
33
+ };
34
+
35
+ const lineChartOptions = {
36
+ tooltip,
37
+ grid,
38
+ legend,
39
+ xAxis,
40
+ yAxis,
41
+ series: [
42
+ {
43
+ data: [820, 932, 901, 934, 1290, 1330, 1300],
44
+ type: 'line'
45
+ }
46
+ ]
47
+ };
48
+
49
+ const pieChartOptions = {
50
+ tooltip: {
51
+ trigger: 'item',
52
+ formatter: '{b} : {c} ({d}%)'
53
+ },
54
+ legend,
55
+ series: [
56
+ {
57
+ type: 'pie',
58
+ //roseType: 'area',
59
+ //radius: [15, 120],
60
+ //animationEasing: 'cubicInOut',
61
+ //animationDuration: 2600,
62
+ data: [
63
+ { value: 320, name: '1' },
64
+ { value: 240, name: '2' },
65
+ { value: 149, name: '3' },
66
+ { value: 100, name: '4' },
67
+ { value: 59, name: '5' }
68
+ ]
69
+ }
70
+ ]
71
+ };
72
+
73
+ const echartTypes = {
74
+ EChartsBar: barChartOptions,
75
+ EChartsLine: lineChartOptions,
76
+ EChartsPie: pieChartOptions
77
+ };
78
+
79
+ export default echartTypes;