mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Refactored moment.js out of app
Reduces bundle size by 25%
This commit is contained in:
parent
736d7118b0
commit
0ade9b5b9b
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ nbproject
|
|||||||
.buildpath
|
.buildpath
|
||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
|
webpack-stats.json
|
@ -275,11 +275,10 @@ class PageController extends Controller
|
|||||||
$draft = $this->entityRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
|
$draft = $this->entityRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
|
||||||
|
|
||||||
$updateTime = $draft->updated_at->timestamp;
|
$updateTime = $draft->updated_at->timestamp;
|
||||||
$utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => trans('entities.pages_edit_draft_save_at'),
|
'message' => trans('entities.pages_edit_draft_save_at'),
|
||||||
'timestamp' => $utcUpdateTimestamp
|
'timestamp' => $updateTime
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
package-lock.json
generated
19
package-lock.json
generated
@ -3645,15 +3645,6 @@
|
|||||||
"is-extglob": "1.0.0"
|
"is-extglob": "1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract-loader": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/extract-loader/-/extract-loader-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-hwlXWGHwzBXRNQCkDnLJuNgSkRsmYOwNz7wG9pHfA2EAgQaBCuQR71az7qL3rQT1JAMujiKPc+laet0kddVXWQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"loader-utils": "1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extract-text-webpack-plugin": {
|
"extract-text-webpack-plugin": {
|
||||||
"version": "4.0.0-beta.0",
|
"version": "4.0.0-beta.0",
|
||||||
"resolved": "https://registry.npmjs.org/extract-text-webpack-plugin/-/extract-text-webpack-plugin-4.0.0-beta.0.tgz",
|
"resolved": "https://registry.npmjs.org/extract-text-webpack-plugin/-/extract-text-webpack-plugin-4.0.0-beta.0.tgz",
|
||||||
@ -3710,16 +3701,6 @@
|
|||||||
"escape-string-regexp": "1.0.5"
|
"escape-string-regexp": "1.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"file-loader": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-TGR4HU7HUsGg6GCOPJnFk06RhWgEWFLAGWiT6rcD+GRC2keU3s9RGJ+b3Z6/U73jwwNb2gKLJ7YCrp+jvU4ALg==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"loader-utils": "1.1.0",
|
|
||||||
"schema-utils": "0.4.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"filename-regex": {
|
"filename-regex": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack",
|
"build": "webpack",
|
||||||
"production": "NODE_ENV=production webpack && rm -f ./public/dist/*styles.js",
|
"production": "NODE_ENV=production webpack && rm -f ./public/dist/*styles.js",
|
||||||
|
"build-profile": "NODE_ENV=production webpack --profile --json > webpack-stats.json && rm -f ./public/dist/*styles.js",
|
||||||
"dev": "npm-run-all --parallel watch livereload",
|
"dev": "npm-run-all --parallel watch livereload",
|
||||||
"watch": "webpack --watch",
|
"watch": "webpack --watch",
|
||||||
"livereload": "livereload ./public/dist/",
|
"livereload": "livereload ./public/dist/",
|
||||||
@ -34,7 +35,6 @@
|
|||||||
"jquery": "^3.3.1",
|
"jquery": "^3.3.1",
|
||||||
"markdown-it": "^8.3.1",
|
"markdown-it": "^8.3.1",
|
||||||
"markdown-it-task-lists": "^2.0.0",
|
"markdown-it-task-lists": "^2.0.0",
|
||||||
"moment": "^2.21.0",
|
|
||||||
"vue": "^2.2.6",
|
"vue": "^2.2.6",
|
||||||
"vuedraggable": "^2.14.1"
|
"vuedraggable": "^2.14.1"
|
||||||
},
|
},
|
||||||
|
15
resources/assets/js/services/dates.js
Normal file
15
resources/assets/js/services/dates.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
export function getCurrentDay() {
|
||||||
|
let date = new Date();
|
||||||
|
let month = date.getMonth() + 1;
|
||||||
|
let day = date.getDate();
|
||||||
|
|
||||||
|
return `${date.getFullYear()}-${(month>9?'':'0') + month}-${(day>9?'':'0') + day}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function utcTimeStampToLocalTime(timestamp) {
|
||||||
|
let date = new Date(timestamp * 1000);
|
||||||
|
let hours = date.getHours();
|
||||||
|
let mins = date.getMinutes();
|
||||||
|
return `${(hours>9?'':'0') + hours}:${(mins>9?'':'0') + mins}`;
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
const moment = require('moment');
|
import * as Dates from "../services/dates";
|
||||||
require('moment/locale/en-gb');
|
|
||||||
moment.locale('en-gb');
|
|
||||||
|
|
||||||
let autoSaveFrequency = 30;
|
let autoSaveFrequency = 30;
|
||||||
|
|
||||||
@ -96,9 +94,8 @@ let methods = {
|
|||||||
let url = window.baseUrl(`/ajax/page/${this.pageId}/save-draft`);
|
let url = window.baseUrl(`/ajax/page/${this.pageId}/save-draft`);
|
||||||
window.$http.put(url, data).then(response => {
|
window.$http.put(url, data).then(response => {
|
||||||
draftErroring = false;
|
draftErroring = false;
|
||||||
let updateTime = moment.utc(moment.unix(response.data.timestamp)).toDate();
|
|
||||||
if (!this.isNewDraft) this.isUpdateDraft = true;
|
if (!this.isNewDraft) this.isUpdateDraft = true;
|
||||||
this.draftNotifyChange(response.data.message + moment(updateTime).format('HH:mm'));
|
this.draftNotifyChange(`${response.data.message } ${Dates.utcTimeStampToLocalTime(response.data.timestamp)}`);
|
||||||
lastSave = Date.now();
|
lastSave = Date.now();
|
||||||
}, errorRes => {
|
}, errorRes => {
|
||||||
if (draftErroring) return;
|
if (draftErroring) return;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const moment = require('moment');
|
import * as Dates from "../services/dates";
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
terms: '',
|
terms: '',
|
||||||
@ -153,7 +153,7 @@ let methods = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
enableDate(optionName) {
|
enableDate(optionName) {
|
||||||
this.search.dates[optionName.toLowerCase()] = moment().format('YYYY-MM-DD');
|
this.search.dates[optionName.toLowerCase()] = Dates.getCurrentDay();
|
||||||
this.dateChange(optionName);
|
this.dateChange(optionName);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user