You've already forked nginx-proxy-manager
mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-15 03:41:48 +03:00
Frontend
This commit is contained in:
117
src/frontend/js/lib/marionette.js
Normal file
117
src/frontend/js/lib/marionette.js
Normal file
@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('underscore');
|
||||
const Mn = require('backbone.marionette');
|
||||
const moment = require('moment');
|
||||
const numeral = require('numeral');
|
||||
|
||||
let render = Mn.Renderer.render;
|
||||
|
||||
Mn.Renderer.render = function (template, data, view) {
|
||||
|
||||
data = _.clone(data);
|
||||
|
||||
/**
|
||||
* @param {Integer} number
|
||||
* @returns {String}
|
||||
*/
|
||||
data.niceNumber = function (number) {
|
||||
return numeral(number).format('0,0');
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Integer} seconds
|
||||
* @returns {String}
|
||||
*/
|
||||
data.secondsToTime = function (seconds) {
|
||||
let sec_num = parseInt(seconds, 10);
|
||||
let minutes = Math.floor(sec_num / 60);
|
||||
let sec = sec_num - (minutes * 60);
|
||||
|
||||
if (sec < 10) {
|
||||
sec = '0' + sec;
|
||||
}
|
||||
|
||||
return minutes + ':' + sec;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} date
|
||||
* @returns {String}
|
||||
*/
|
||||
data.shortDate = function (date) {
|
||||
let shortdate = '';
|
||||
|
||||
if (typeof date === 'number') {
|
||||
shortdate = moment.unix(date).format('YYYY-MM-DD');
|
||||
} else {
|
||||
shortdate = moment(date).format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
return moment().format('YYYY-MM-DD') === shortdate ? 'Today' : shortdate;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} date
|
||||
* @returns {String}
|
||||
*/
|
||||
data.shortTime = function (date) {
|
||||
let shorttime = '';
|
||||
|
||||
if (typeof date === 'number') {
|
||||
shorttime = moment.unix(date).format('H:mm A');
|
||||
} else {
|
||||
shorttime = moment(date).format('H:mm A');
|
||||
}
|
||||
|
||||
return shorttime;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} string
|
||||
* @returns {String}
|
||||
*/
|
||||
data.escape = function (string) {
|
||||
let entityMap = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
'\'': ''',
|
||||
'/': '/'
|
||||
};
|
||||
|
||||
return String(string).replace(/[&<>"'\/]/g, function (s) {
|
||||
return entityMap[s];
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} string
|
||||
* @param {Integer} length
|
||||
* @returns {String}
|
||||
*/
|
||||
data.trim = function (string, length) {
|
||||
if (string.length > length) {
|
||||
let trimmedString = string.substr(0, length);
|
||||
return trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(' '))) + '...';
|
||||
}
|
||||
|
||||
return string;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
* @returns {String}
|
||||
*/
|
||||
data.niceVarName = function (name) {
|
||||
return name.replace('_', ' ')
|
||||
.replace(/^(.)|\s+(.)/g, function ($1) {
|
||||
return $1.toUpperCase();
|
||||
});
|
||||
};
|
||||
|
||||
return render.call(this, template, data, view);
|
||||
};
|
||||
|
||||
module.exports = Mn;
|
Reference in New Issue
Block a user