removed notification + new react structure
This commit is contained in:
113
react/shared/api.js
Normal file
113
react/shared/api.js
Normal file
@@ -0,0 +1,113 @@
|
||||
// import 'babel-polyfill';
|
||||
|
||||
export default class API {
|
||||
constructor() {
|
||||
this.loggedIn = false;
|
||||
this.user = { };
|
||||
}
|
||||
|
||||
csrfToken() {
|
||||
return this.loggedIn ? this.user.session.csrf_token : null;
|
||||
}
|
||||
|
||||
async apiCall(method, params) {
|
||||
params = params || { };
|
||||
params.csrf_token = this.csrfToken();
|
||||
let response = await fetch("/api/" + method, {
|
||||
method: 'post',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(params)
|
||||
});
|
||||
|
||||
let res = await response.json();
|
||||
if (!res.success && res.msg === "You are not logged in.") {
|
||||
document.location.reload();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
async fetchUser() {
|
||||
let response = await fetch("/api/user/info");
|
||||
let data = await response.json();
|
||||
this.user = data["user"];
|
||||
this.loggedIn = data["loggedIn"];
|
||||
return data && data.success && data.loggedIn;
|
||||
}
|
||||
|
||||
async editUser(id, username, email, password, groups, confirmed) {
|
||||
return this.apiCall("user/edit", { id: id, username: username, email: email, password: password, groups: groups, confirmed: confirmed });
|
||||
}
|
||||
|
||||
async logout() {
|
||||
return this.apiCall("user/logout");
|
||||
}
|
||||
|
||||
async getUser(id) {
|
||||
return this.apiCall("user/get", { id: id });
|
||||
}
|
||||
|
||||
async deleteUser(id) {
|
||||
return this.apiCall("user/delete", { id: id });
|
||||
}
|
||||
|
||||
async fetchUsers(pageNum = 1, count = 20) {
|
||||
return this.apiCall("user/fetch", { page: pageNum, count: count });
|
||||
}
|
||||
|
||||
async fetchGroups(pageNum = 1, count = 20) {
|
||||
return this.apiCall("groups/fetch", { page: pageNum, count: count });
|
||||
}
|
||||
|
||||
async inviteUser(username, email) {
|
||||
return this.apiCall("user/invite", { username: username, email: email });
|
||||
}
|
||||
|
||||
async createUser(username, email, password, confirmPassword) {
|
||||
return this.apiCall("user/create", { username: username, email: email, password: password, confirmPassword: confirmPassword });
|
||||
}
|
||||
|
||||
async getStats() {
|
||||
return this.apiCall("stats");
|
||||
}
|
||||
|
||||
async getRoutes() {
|
||||
return this.apiCall("routes/fetch");
|
||||
}
|
||||
|
||||
async saveRoutes(routes) {
|
||||
return this.apiCall("routes/save", { routes: routes });
|
||||
}
|
||||
|
||||
async createGroup(name, color) {
|
||||
return this.apiCall("groups/create", { name: name, color: color });
|
||||
}
|
||||
|
||||
async deleteGroup(id) {
|
||||
return this.apiCall("groups/delete", { id: id });
|
||||
}
|
||||
|
||||
async getSettings(key = "") {
|
||||
return this.apiCall("settings/get", { key: key });
|
||||
}
|
||||
|
||||
async saveSettings(settings) {
|
||||
return this.apiCall("settings/set", { settings: settings });
|
||||
}
|
||||
|
||||
async sendTestMail(receiver) {
|
||||
return this.apiCall("mail/test", { receiver: receiver });
|
||||
}
|
||||
|
||||
async fetchPermissions() {
|
||||
return this.apiCall("permission/fetch");
|
||||
}
|
||||
|
||||
async savePermissions(permissions) {
|
||||
return this.apiCall("permission/save", { permissions: permissions });
|
||||
}
|
||||
|
||||
async getVisitors(type, date) {
|
||||
return this.apiCall("visitors/stats", { type: type, date: date });
|
||||
}
|
||||
};
|
||||
24
react/shared/elements/icon.jsx
Normal file
24
react/shared/elements/icon.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
|
||||
export default function Icon(props) {
|
||||
|
||||
let classes = props.className || [];
|
||||
classes = Array.isArray(classes) ? classes : classes.toString().split(" ");
|
||||
let type = props.type || "fas";
|
||||
let icon = props.icon;
|
||||
|
||||
classes.push(type);
|
||||
classes.push("fa-" + icon);
|
||||
|
||||
if (icon === "spinner" || icon === "circle-notch") {
|
||||
classes.push("fa-spin");
|
||||
}
|
||||
|
||||
let newProps = {...props, className: classes.join(" ") };
|
||||
delete newProps["type"];
|
||||
delete newProps["icon"];
|
||||
|
||||
return (
|
||||
<i {...newProps} />
|
||||
);
|
||||
}
|
||||
26
react/shared/global.js
Normal file
26
react/shared/global.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import moment from 'moment';
|
||||
|
||||
function getPeriodString(date) {
|
||||
return moment(date).fromNow();
|
||||
}
|
||||
|
||||
export default function humanReadableSize(bytes, dp = 1) {
|
||||
const thresh = 1024;
|
||||
|
||||
if (Math.abs(bytes) < thresh) {
|
||||
return bytes + ' B';
|
||||
}
|
||||
|
||||
const units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||
let u = -1;
|
||||
const r = 10**dp;
|
||||
|
||||
do {
|
||||
bytes /= thresh;
|
||||
++u;
|
||||
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
||||
|
||||
return bytes.toFixed(dp) + ' ' + units[u];
|
||||
}
|
||||
|
||||
export { getPeriodString };
|
||||
8
react/shared/package.json
Normal file
8
react/shared/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "shared",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": { },
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": ""
|
||||
}
|
||||
Reference in New Issue
Block a user