Browse Source

Refactor stats.js

pull/10/head
Hironsan 6 years ago
parent
commit
4b19063771
2 changed files with 14 additions and 10 deletions
  1. 14
      app/server/static/bundle/stats.js
  2. 10
      app/server/static/js/stats.js

14
app/server/static/bundle/stats.js

@ -2551,6 +2551,18 @@ eval("module.exports = function(module) {\n\tif (!module.webpackPolyfill) {\n\t\
/***/ }),
/***/ "./static/js/http.js":
/*!***************************!*\
!*** ./static/js/http.js ***!
\***************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n\n\naxios__WEBPACK_IMPORTED_MODULE_0___default.a.defaults.xsrfCookieName = 'csrftoken';\naxios__WEBPACK_IMPORTED_MODULE_0___default.a.defaults.xsrfHeaderName = 'X-CSRFToken';\nconst baseUrl = window.location.href.split('/').slice(3, 5).join('/');\nconst HTTP = axios__WEBPACK_IMPORTED_MODULE_0___default.a.create({\n baseURL: `/api/${baseUrl}/`,\n});\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (HTTP);\n\n\n//# sourceURL=webpack:///./static/js/http.js?");
/***/ }),
/***/ "./static/js/stats.js":
/*!****************************!*\
!*** ./static/js/stats.js ***!
@ -2559,7 +2571,7 @@ eval("module.exports = function(module) {\n\tif (!module.webpackPolyfill) {\n\t\
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue_chartjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue-chartjs */ \"./node_modules/vue-chartjs/es/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n\n\n\n\nconst { reactiveProp, reactiveData } = vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"mixins\"];\n\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfCookieName = 'csrftoken';\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfHeaderName = 'X-CSRFToken';\nconst baseURL = window.location.href.split('/').slice(3, 5).join('/');\nconst HTTP = axios__WEBPACK_IMPORTED_MODULE_1___default.a.create({\n baseURL: `/api/${baseURL}/`,\n});\n\n\nvue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].component('line-chart', {\n extends: vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"HorizontalBar\"],\n mixins: [reactiveProp],\n props: ['chartData'],\n data() {\n return {\n options: {\n scales: {\n yAxes: [{\n barPercentage: 0.3,\n }],\n xAxes: [{\n ticks: {\n beginAtZero: true,\n min: 0,\n },\n }],\n },\n maintainAspectRatio: false,\n },\n };\n },\n\n mounted() {\n this.renderChart(this.chartData, this.options);\n },\n});\n\n\nvue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].component('doughnut-chart', {\n extends: vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"Doughnut\"],\n mixins: [reactiveProp],\n props: ['chartData'],\n data() {\n return {\n options: {\n maintainAspectRatio: false,\n },\n };\n },\n\n mounted() {\n this.renderChart(this.chartData, this.options);\n },\n});\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n data: {\n labelData: null,\n userData: null,\n progressData: null,\n },\n\n methods: {\n makeData(data, labels, label) {\n const res = {\n labels: labels,\n datasets: [{\n label: label,\n backgroundColor: '#00d1b2',\n data: data,\n }],\n };\n return res;\n },\n },\n\n created() {\n HTTP.get('stats').then((response) => {\n this.labelData = this.makeData(response.data.label.data, response.data.label.labels, 'Label stats');\n this.userData = this.makeData(response.data.user.data, response.data.user.users, 'User stats');\n });\n HTTP.get('progress').then((response) => {\n const complete = response.data.total - response.data.remaining;\n const incomplete = response.data.remaining;\n this.progressData = {\n datasets: [{\n data: [complete, incomplete],\n backgroundColor: ['#00d1b2', '#ffdd57'],\n }],\n\n labels: [\n 'Completed',\n 'Incomplete',\n ],\n };\n });\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/stats.js?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue_chartjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue-chartjs */ \"./node_modules/vue-chartjs/es/index.js\");\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./http */ \"./static/js/http.js\");\n\n\n\n\nconst { reactiveProp, reactiveData } = vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"mixins\"];\n\nvue__WEBPACK_IMPORTED_MODULE_1__[\"default\"].component('line-chart', {\n extends: vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"HorizontalBar\"],\n mixins: [reactiveProp],\n props: ['chartData'],\n data() {\n return {\n options: {\n scales: {\n yAxes: [{\n barPercentage: 0.3,\n }],\n xAxes: [{\n ticks: {\n beginAtZero: true,\n min: 0,\n },\n }],\n },\n maintainAspectRatio: false,\n },\n };\n },\n\n mounted() {\n this.renderChart(this.chartData, this.options);\n },\n});\n\n\nvue__WEBPACK_IMPORTED_MODULE_1__[\"default\"].component('doughnut-chart', {\n extends: vue_chartjs__WEBPACK_IMPORTED_MODULE_0__[\"Doughnut\"],\n mixins: [reactiveProp],\n props: ['chartData'],\n data() {\n return {\n options: {\n maintainAspectRatio: false,\n },\n };\n },\n\n mounted() {\n this.renderChart(this.chartData, this.options);\n },\n});\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_1__[\"default\"]({\n el: '#mail-app',\n delimiters: ['[[', ']]'],\n data: {\n labelData: null,\n userData: null,\n progressData: null,\n },\n\n methods: {\n makeData(data, labels, label) {\n const res = {\n labels: labels,\n datasets: [{\n label: label,\n backgroundColor: '#00d1b2',\n data: data,\n }],\n };\n return res;\n },\n },\n\n created() {\n _http__WEBPACK_IMPORTED_MODULE_2__[\"default\"].get('stats').then((response) => {\n this.labelData = this.makeData(response.data.label.data, response.data.label.labels, 'Label stats');\n this.userData = this.makeData(response.data.user.data, response.data.user.users, 'User stats');\n });\n _http__WEBPACK_IMPORTED_MODULE_2__[\"default\"].get('progress').then((response) => {\n const complete = response.data.total - response.data.remaining;\n const incomplete = response.data.remaining;\n this.progressData = {\n datasets: [{\n data: [complete, incomplete],\n backgroundColor: ['#00d1b2', '#ffdd57'],\n }],\n\n labels: [\n 'Completed',\n 'Incomplete',\n ],\n };\n });\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/stats.js?");
/***/ })

10
app/server/static/js/stats.js

@ -1,17 +1,9 @@
import { HorizontalBar, mixins, Doughnut } from 'vue-chartjs';
import axios from 'axios';
import Vue from 'vue';
import HTTP from './http';
const { reactiveProp, reactiveData } = mixins;
axios.defaults.xsrfCookieName = 'csrftoken';
axios.defaults.xsrfHeaderName = 'X-CSRFToken';
const baseURL = window.location.href.split('/').slice(3, 5).join('/');
const HTTP = axios.create({
baseURL: `/api/${baseURL}/`,
});
Vue.component('line-chart', {
extends: HorizontalBar,
mixins: [reactiveProp],

Loading…
Cancel
Save