Merge branch 'main' of https://github.com/dm1sh/timetable-generator into main
This commit is contained in:
commit
03dfa117b2
@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-console": "warn",
|
"no-console": "warn",
|
||||||
"prettier/prettier": "error"
|
"prettier/prettier": "warn"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"react": {
|
"react": {
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,3 +19,5 @@ localName.json
|
|||||||
|
|
||||||
yarn.lock
|
yarn.lock
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
|
test.pdf
|
@ -15,9 +15,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.12.10",
|
"@babel/core": "^7.12.10",
|
||||||
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
||||||
"@babel/preset-env": "^7.12.10",
|
"@babel/preset-env": "^7.12.10",
|
||||||
"@babel/preset-react": "^7.12.10",
|
"@babel/preset-react": "^7.12.10",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
|
||||||
"@types/node": "^14.14.12",
|
"@types/node": "^14.14.12",
|
||||||
"@types/react": "^15.0.0 || ^16.0.0 || ^17.0.0 ",
|
"@types/react": "^15.0.0 || ^16.0.0 || ^17.0.0 ",
|
||||||
"@types/react-dom": "^17.0.0",
|
"@types/react-dom": "^17.0.0",
|
||||||
@ -41,8 +41,9 @@
|
|||||||
"webpack-dev-server": "^3.11.0"
|
"webpack-dev-server": "^3.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/pdfmake": "^0.1.16",
|
||||||
|
"pdfmake": "^0.1.68",
|
||||||
"react": "^15.0.0 || ^16.0.0 || ^17.0.0 ",
|
"react": "^15.0.0 || ^16.0.0 || ^17.0.0 ",
|
||||||
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 ",
|
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 "
|
||||||
"serve": "^11.3.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styles from "./styles/App.module.css";
|
import styles from "./styles/App.module.css";
|
||||||
|
import { createDocument } from "./utils/pdf";
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 className={styles.title}>Hello, world</h1>
|
<h1 className={styles.title}>Hello, world</h1>
|
||||||
|
<button onClick={() => createDocument(11, 18)}>Create</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
4
src/custom.d.ts
vendored
4
src/custom.d.ts
vendored
@ -7,3 +7,7 @@ declare module "*.module.css" {
|
|||||||
const classes: { [key: string]: string };
|
const classes: { [key: string]: string };
|
||||||
export default classes;
|
export default classes;
|
||||||
}
|
}
|
||||||
|
declare module "*.ttf" {
|
||||||
|
const content: string;
|
||||||
|
export default content;
|
||||||
|
}
|
||||||
|
BIN
src/fonts/PTSerif-Bold.ttf
Normal file
BIN
src/fonts/PTSerif-Bold.ttf
Normal file
Binary file not shown.
BIN
src/fonts/PTSerif-Regular.ttf
Normal file
BIN
src/fonts/PTSerif-Regular.ttf
Normal file
Binary file not shown.
@ -2,6 +2,6 @@
|
|||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
/*just test sunlime merge*/
|
/*just test sunlime merge*/
|
||||||
body{
|
body {
|
||||||
background-color: blue;
|
background-color: blue;
|
||||||
}
|
}
|
114
src/utils/pdf.ts
Normal file
114
src/utils/pdf.ts
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import pdfMake from "pdfmake/build/pdfmake";
|
||||||
|
import { TableCell, TDocumentDefinitions } from "pdfmake/interfaces";
|
||||||
|
|
||||||
|
import vfs from "./vfsFonts";
|
||||||
|
|
||||||
|
pdfMake.vfs = vfs;
|
||||||
|
|
||||||
|
pdfMake.fonts = {
|
||||||
|
PTSerif: {
|
||||||
|
normal: "PTSerifRegular.ttf",
|
||||||
|
bold: "PTSerifBold.ttf",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const months = [
|
||||||
|
"Января",
|
||||||
|
"Февраля",
|
||||||
|
"Марта",
|
||||||
|
"Апреля",
|
||||||
|
"Мая",
|
||||||
|
"Июня",
|
||||||
|
"Июля",
|
||||||
|
"Августа",
|
||||||
|
"Сентября",
|
||||||
|
"Октября",
|
||||||
|
"Ноября",
|
||||||
|
"Декабря",
|
||||||
|
];
|
||||||
|
|
||||||
|
const getDate = () => {
|
||||||
|
const now = new Date();
|
||||||
|
return `${now.getDate()} ${months[now.getDay()]} ${now.getFullYear()} года`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGroupNumber = (gen: number): number => {
|
||||||
|
while (gen > 9) {
|
||||||
|
gen -= 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
return gen;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createDocument = (
|
||||||
|
classNumber: number,
|
||||||
|
generation: number
|
||||||
|
): void => {
|
||||||
|
const doc: TDocumentDefinitions = {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
text: "УТВЕРЖДЕН",
|
||||||
|
style: "ral",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "приказом БОУ «Югорский физико-математический лицей-интернат»",
|
||||||
|
style: "ral",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: `№ от ${getDate()}`,
|
||||||
|
style: "ral",
|
||||||
|
margin: [0, 0, 0, 10],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
table: {
|
||||||
|
widths: [
|
||||||
|
"4.37%",
|
||||||
|
"4.37%",
|
||||||
|
"8.8%",
|
||||||
|
"13.7%",
|
||||||
|
"13.7%",
|
||||||
|
"13.7%",
|
||||||
|
"13.7%",
|
||||||
|
"13.7%",
|
||||||
|
"13.7%",
|
||||||
|
],
|
||||||
|
body: [
|
||||||
|
[
|
||||||
|
{ text: "Пара", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||||
|
{ text: "Урок", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||||
|
{ text: "Время", rowSpan: 2, margin: [0, 10, 0, 0] },
|
||||||
|
...["А", "Б", "В"].flatMap<TableCell>(word => [
|
||||||
|
{
|
||||||
|
colSpan: 2,
|
||||||
|
text: `${classNumber} «${word}» класс`,
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
...[1, 2, 3, 4, 5, 6].map<TableCell>(groupIndex => ({
|
||||||
|
text: `${getGroupNumber(generation)}${groupIndex} группа`,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
defaultStyle: {
|
||||||
|
font: "PTSerif",
|
||||||
|
fontSize: 12,
|
||||||
|
alignment: "center",
|
||||||
|
},
|
||||||
|
styles: {
|
||||||
|
ral: {
|
||||||
|
alignment: "right",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pageOrientation: "landscape",
|
||||||
|
};
|
||||||
|
|
||||||
|
pdfMake.createPdf(doc).download("test.pdf");
|
||||||
|
};
|
12
src/utils/vfsFonts.ts
Normal file
12
src/utils/vfsFonts.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import regular from "../fonts/PTSerif-Regular.ttf";
|
||||||
|
import bold from "../fonts/PTSerif-Bold.ttf";
|
||||||
|
|
||||||
|
import pdfFonts from "pdfmake/build/vfs_fonts";
|
||||||
|
|
||||||
|
pdfFonts.pdfMake.vfs["PTSerifRegular.ttf"] = regular.slice(
|
||||||
|
regular.indexOf(",")
|
||||||
|
);
|
||||||
|
|
||||||
|
pdfFonts.pdfMake.vfs["PTSerifBold.ttf"] = bold.slice(bold.indexOf(","));
|
||||||
|
|
||||||
|
export default pdfFonts.pdfMake.vfs;
|
@ -8,6 +8,7 @@
|
|||||||
"module": "es6",
|
"module": "es6",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
|
"lib": ["ES2020"],
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"allowSyntheticDefaultImports": true
|
"allowSyntheticDefaultImports": true
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const ESLintPlugin = require("eslint-webpack-plugin");
|
|
||||||
|
|
||||||
const getScopedName = require("./utils/getScopedName.js");
|
const getScopedName = require("./utils/getScopedName.js");
|
||||||
|
|
||||||
@ -13,17 +12,16 @@ const plugins = [
|
|||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: path.join(__dirname, "public", "index.html"),
|
template: path.join(__dirname, "public", "index.html"),
|
||||||
}),
|
}),
|
||||||
]
|
];
|
||||||
|
|
||||||
if (!isDev)
|
if (!isDev) {
|
||||||
{
|
|
||||||
plugins.push(
|
plugins.push(
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
"process.env": {
|
||||||
NODE_ENV: JSON.stringify('production')
|
NODE_ENV: JSON.stringify("production"),
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -39,11 +37,11 @@ module.exports = {
|
|||||||
include: path.resolve(__dirname, "src"),
|
include: path.resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test:/\.js$/,
|
test: /\.js$/,
|
||||||
include: /src/,
|
include: /src/,
|
||||||
use:{
|
use: {
|
||||||
loader:"babel-loader"
|
loader: "babel-loader",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
@ -76,7 +74,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: true,
|
minimize: !isDev,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".tsx", ".ts", ".js"],
|
extensions: [".tsx", ".ts", ".js"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user