educoreapp2 1.0.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/README.md +29 -0
- package/dist/Tools.js +238 -0
- package/dist/index.js +20 -0
- package/dist/lib/ApiCode.js +13 -0
- package/package.json +74 -0
package/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# README #
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get your application up and running.
|
4
|
+
|
5
|
+
### What is this repository for? ###
|
6
|
+
|
7
|
+
* Quick summary
|
8
|
+
* Version
|
9
|
+
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
10
|
+
|
11
|
+
### How do I get set up? ###
|
12
|
+
|
13
|
+
* Summary of set up
|
14
|
+
* Configuration
|
15
|
+
* Dependencies
|
16
|
+
* Database configuration
|
17
|
+
* How to run tests
|
18
|
+
* Deployment instructions
|
19
|
+
|
20
|
+
### Contribution guidelines ###
|
21
|
+
|
22
|
+
* Writing tests
|
23
|
+
* Code review
|
24
|
+
* Other guidelines
|
25
|
+
|
26
|
+
### Who do I talk to? ###
|
27
|
+
|
28
|
+
* Repo owner or admin
|
29
|
+
* Other community or team contact
|
package/dist/Tools.js
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _cryptoJs = require("crypto-js");
|
8
|
+
var _ApiCode = _interopRequireDefault(require("./lib/ApiCode"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
12
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
13
|
+
Date.isLeapYear = function (year) {
|
14
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
15
|
+
};
|
16
|
+
Date.getDaysInMonth = function (year, month) {
|
17
|
+
return [31, Date.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
|
18
|
+
};
|
19
|
+
Date.prototype.isLeapYear = function () {
|
20
|
+
return Date.isLeapYear(this.getFullYear());
|
21
|
+
};
|
22
|
+
Date.prototype.getDaysInMonth = function () {
|
23
|
+
return Date.getDaysInMonth(this.getFullYear(), this.getMonth());
|
24
|
+
};
|
25
|
+
Date.prototype.addMonths = function (value) {
|
26
|
+
var n = this.getDate();
|
27
|
+
this.setDate(1);
|
28
|
+
this.setMonth(this.getMonth() + value);
|
29
|
+
this.setDate(Math.min(n, this.getDaysInMonth()));
|
30
|
+
return this;
|
31
|
+
};
|
32
|
+
class Tools {
|
33
|
+
static isTrue(val) {
|
34
|
+
if (Tools.empty(val)) {
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
return val === 1 || val === "1" || val === true || val === "true";
|
38
|
+
}
|
39
|
+
static timestamp() {
|
40
|
+
return Date.now();
|
41
|
+
}
|
42
|
+
static downloadBase64File(contentType, base64Data, fileName) {
|
43
|
+
const linkSource = "data:".concat(contentType, ";base64,").concat(base64Data);
|
44
|
+
const downloadLink = document.createElement("a");
|
45
|
+
downloadLink.href = linkSource;
|
46
|
+
downloadLink.download = fileName;
|
47
|
+
downloadLink.click();
|
48
|
+
}
|
49
|
+
static addMountsToDate(date, mm) {
|
50
|
+
return date.addMonths(mm);
|
51
|
+
}
|
52
|
+
static GetCurrentTimeStamp() {
|
53
|
+
return Date.now();
|
54
|
+
}
|
55
|
+
static DivSize(str, n) {
|
56
|
+
if (str.indexOf("px") >= 1) {
|
57
|
+
str = Number.parseInt(Number.parseInt(str.replace("px", "")) * n / 100) + "px";
|
58
|
+
return str;
|
59
|
+
}
|
60
|
+
if (str.indexOf("%") >= 1) {
|
61
|
+
str = Number.parseInt(Number.parseInt(str.replace("%", "")) * n / 100) + "%";
|
62
|
+
return str;
|
63
|
+
}
|
64
|
+
return str;
|
65
|
+
}
|
66
|
+
static copy(obj) {
|
67
|
+
let isStatic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
68
|
+
return Tools.empty(obj) ? null : JSON.parse(JSON.stringify(obj));
|
69
|
+
}
|
70
|
+
static LSGet(key) {
|
71
|
+
let val = localStorage.getItem(key);
|
72
|
+
// console.log("AAA",val);
|
73
|
+
if (!Tools.isset(val)) {
|
74
|
+
return null;
|
75
|
+
}
|
76
|
+
let js = "";
|
77
|
+
try {
|
78
|
+
js = JSON.parse(val);
|
79
|
+
} catch (e) {
|
80
|
+
js = val;
|
81
|
+
}
|
82
|
+
return js;
|
83
|
+
}
|
84
|
+
static LSClean() {
|
85
|
+
localStorage.clear();
|
86
|
+
}
|
87
|
+
static LSHas(key) {
|
88
|
+
let val = localStorage.getItem(key);
|
89
|
+
return Tools.isset(val);
|
90
|
+
}
|
91
|
+
static LSDel(key) {
|
92
|
+
localStorage.removeItem(key);
|
93
|
+
}
|
94
|
+
static alert(mess) {
|
95
|
+
alert(mess);
|
96
|
+
}
|
97
|
+
static LSSet(key, val) {
|
98
|
+
let v = JSON.stringify(val);
|
99
|
+
localStorage.setItem(key, v);
|
100
|
+
}
|
101
|
+
static GetLang() {
|
102
|
+
var lang = navigator.language || navigator.userLanguage;
|
103
|
+
let MAP = {
|
104
|
+
"en-US": "en_GB",
|
105
|
+
"pl-PL": "pl_PL"
|
106
|
+
};
|
107
|
+
if (!Tools.empty(lang) && !Tools.empty(MAP[lang])) {
|
108
|
+
return MAP[lang];
|
109
|
+
}
|
110
|
+
return 'en_GB';
|
111
|
+
}
|
112
|
+
static isset(obj) {
|
113
|
+
return !(typeof obj === "undefined" || obj === null);
|
114
|
+
}
|
115
|
+
static log(mm, mm2) {
|
116
|
+
console.log("log", mm, mm2);
|
117
|
+
let xx = JSON.stringify(mm);
|
118
|
+
alert(xx);
|
119
|
+
}
|
120
|
+
static DeviceIdGen() {
|
121
|
+
let obj = {};
|
122
|
+
obj.app = window.navigator.userAgent;
|
123
|
+
obj.rand = crypto.randomUUID();
|
124
|
+
let hash = Tools.SHA1(JSON.stringify(obj));
|
125
|
+
Tools.LSSet("DEVICE_ID", hash);
|
126
|
+
return hash;
|
127
|
+
}
|
128
|
+
static async GetDeviceId() {
|
129
|
+
let v = Tools.LSGet("DEVICE_ID");
|
130
|
+
if (Tools.empty(v)) {
|
131
|
+
let h = Tools.DeviceIdGen();
|
132
|
+
return h;
|
133
|
+
}
|
134
|
+
return v;
|
135
|
+
}
|
136
|
+
static SHA1(str) {
|
137
|
+
return (0, _cryptoJs.SHA256)(str).toString();
|
138
|
+
}
|
139
|
+
static IsFunction(obj) {
|
140
|
+
return typeof obj === 'function';
|
141
|
+
}
|
142
|
+
static IsObject(obj) {
|
143
|
+
return typeof obj === 'object';
|
144
|
+
}
|
145
|
+
static IsArray(obj) {
|
146
|
+
if (!Tools.IsObject(obj)) {
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
return obj instanceof Array;
|
150
|
+
}
|
151
|
+
static arrayToStringSQL(arr) {
|
152
|
+
let str = "'" + arr.join("', '") + "'";
|
153
|
+
return str;
|
154
|
+
}
|
155
|
+
static firtLeterUpper(str) {
|
156
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
157
|
+
}
|
158
|
+
static firstIndexOfText(ff, text) {
|
159
|
+
return text.indexOf(ff);
|
160
|
+
}
|
161
|
+
static empty(obj) {
|
162
|
+
if (!Tools.isset(obj)) {
|
163
|
+
return true;
|
164
|
+
}
|
165
|
+
if (obj === undefined || typeof obj === 'undefined' || obj === null || obj === "null" || obj === "" || obj === "[]") {
|
166
|
+
return true;
|
167
|
+
}
|
168
|
+
if (obj.length === 0) {
|
169
|
+
return true;
|
170
|
+
}
|
171
|
+
return false;
|
172
|
+
}
|
173
|
+
static SendToApi(url, data, success, error) {
|
174
|
+
//console.log("url",url,data);
|
175
|
+
let formData = new FormData();
|
176
|
+
for (let k in data) {
|
177
|
+
formData.append(k, data[k]);
|
178
|
+
}
|
179
|
+
fetch(url, {
|
180
|
+
method: 'POST',
|
181
|
+
headers: {
|
182
|
+
// 'Content-Type': 'application/json'
|
183
|
+
},
|
184
|
+
body: formData,
|
185
|
+
// body: JSON.stringify(data),
|
186
|
+
mode: 'cors'
|
187
|
+
}).then(response => response.json()).then(data2 => {
|
188
|
+
//Tools.log(data2);
|
189
|
+
// console.log("succ",data2);
|
190
|
+
let code = data2.code;
|
191
|
+
//Tools.log(code);
|
192
|
+
if (code === _ApiCode.default.OK) {
|
193
|
+
success(data2);
|
194
|
+
} else if (code === _ApiCode.default.ERROR) {
|
195
|
+
error(data2);
|
196
|
+
}
|
197
|
+
}).catch(error2 => {
|
198
|
+
error(error2);
|
199
|
+
// Tools.log(error2);
|
200
|
+
console.error("EEr", error2);
|
201
|
+
});
|
202
|
+
}
|
203
|
+
static SendToApi2(url, data, success, error) {
|
204
|
+
const xhr = new XMLHttpRequest();
|
205
|
+
xhr.open('POST', url, false);
|
206
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
207
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
208
|
+
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
|
209
|
+
xhr.setRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
210
|
+
xhr.setRequestHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Option, Content-Type, Authorization, X-Content-Type-Options, Accept, X-Requested-With, Origin, Access-Control-Request-Method, Access-Control-Request-Headers");
|
211
|
+
xhr.setRequestHeader("Access-Control-Allow-Credentials", true);
|
212
|
+
xhr.setRequestHeader("Access-Control-Allow-Private-Network", true);
|
213
|
+
xhr.onreadystatechange = function () {
|
214
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
215
|
+
let text = xhr.responseText;
|
216
|
+
//console.log(text);
|
217
|
+
let resp = null;
|
218
|
+
try {
|
219
|
+
resp = JSON.parse(text);
|
220
|
+
success(resp);
|
221
|
+
} catch (e) {
|
222
|
+
// EduLog.AddLog("Tools::SendToApi",{"url":url,"data":data,"resp":resp});
|
223
|
+
}
|
224
|
+
} else if (xhr.readyState === 4 && xhr.status !== 200) {
|
225
|
+
// Handle error
|
226
|
+
error(xhr.responseText);
|
227
|
+
}
|
228
|
+
};
|
229
|
+
xhr.send(JSON.stringify(data));
|
230
|
+
}
|
231
|
+
}
|
232
|
+
_defineProperty(Tools, "fileToBase64", file => new Promise((resolve, reject) => {
|
233
|
+
const reader = new FileReader();
|
234
|
+
reader.readAsDataURL(file);
|
235
|
+
reader.onload = () => resolve(reader.result);
|
236
|
+
reader.onerror = reject;
|
237
|
+
}));
|
238
|
+
var _default = exports.default = Tools;
|
package/dist/index.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "ApiCode", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _ApiCode.default;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "Tools", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _Tools.default;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _Tools = _interopRequireDefault(require("./Tools"));
|
19
|
+
var _ApiCode = _interopRequireDefault(require("./lib/ApiCode"));
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
9
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
10
|
+
class ApiCode {}
|
11
|
+
_defineProperty(ApiCode, "ERROR", 500);
|
12
|
+
_defineProperty(ApiCode, "OK", 200);
|
13
|
+
var _default = exports.default = ApiCode;
|
package/package.json
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
{
|
2
|
+
"name": "educoreapp2",
|
3
|
+
"private": false,
|
4
|
+
"version": "1.0.0",
|
5
|
+
"description": "This README would normally document whatever steps are necessary to get your application up and running.",
|
6
|
+
"main": "dist/index.js",
|
7
|
+
"files": [
|
8
|
+
"dist","dist/lib"
|
9
|
+
|
10
|
+
],
|
11
|
+
"exports": {
|
12
|
+
".": {
|
13
|
+
"types": "./dist/index.d.ts",
|
14
|
+
"default": "./dist/index.js"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"babel": {
|
18
|
+
"presets": [
|
19
|
+
"@babel/preset-react",
|
20
|
+
"@babel/preset-env"
|
21
|
+
|
22
|
+
]
|
23
|
+
},
|
24
|
+
|
25
|
+
"scripts": {
|
26
|
+
"start": "react-scripts start",
|
27
|
+
"build": "react-scripts build",
|
28
|
+
"test": "react-scripts test",
|
29
|
+
"eject": "react-scripts eject",
|
30
|
+
"publish:npm": "rm -rf dist && mkdir dist && babel ./src/lib --out-dir dist/lib && babel ./src -d dist --copy-files" },
|
31
|
+
"eslintConfig": {
|
32
|
+
"extends": "react-app"
|
33
|
+
},
|
34
|
+
"repository": {
|
35
|
+
"type": "git",
|
36
|
+
"url": "git+https://edupaneldev@bitbucket.org/edupanelpl/educoreapp.git"
|
37
|
+
},
|
38
|
+
"author": "Edupanel.pl",
|
39
|
+
"license": "ISC",
|
40
|
+
"bugs": {
|
41
|
+
"url": "https://bitbucket.org/edupanelpl/educoreapp/issues"
|
42
|
+
},
|
43
|
+
"browserslist": {
|
44
|
+
"production": [
|
45
|
+
">0.2%",
|
46
|
+
"not dead",
|
47
|
+
"not op_mini all"
|
48
|
+
],
|
49
|
+
"development": [
|
50
|
+
"last 1 chrome version",
|
51
|
+
"last 1 firefox version",
|
52
|
+
"last 1 safari version"
|
53
|
+
]
|
54
|
+
},
|
55
|
+
"homepage": "https://bitbucket.org/edupanelpl/educoreapp#readme",
|
56
|
+
"peerDependencies": {
|
57
|
+
"@babel/cli": ">=7.24.5",
|
58
|
+
"@babel/core": ">=7.24.5",
|
59
|
+
"@babel/preset-env": ">=7.24.5",
|
60
|
+
"@babel/preset-react": ">=7.0.0",
|
61
|
+
"crypto-js": ">=4.2.0",
|
62
|
+
"react-dom": ">=18.3.1",
|
63
|
+
"react-scripts": ">=5.0.1"
|
64
|
+
},
|
65
|
+
"devDependencies": {
|
66
|
+
"@babel/cli": ">=7.24.5",
|
67
|
+
"@babel/core": ">=7.24.5",
|
68
|
+
"@babel/preset-env": ">=7.24.5",
|
69
|
+
"@babel/preset-react": ">=7.0.0",
|
70
|
+
"crypto-js": ">=4.2.0",
|
71
|
+
"react-dom": ">=18.3.1",
|
72
|
+
"react-scripts": ">=5.0.1"
|
73
|
+
}
|
74
|
+
}
|