;
}
//convert string to numeric
function tonumeric (value) {
return parseFloat(
value.toString().replace(/[^0-9\.]+/g, '')
);
}
// Covert numeric to money string
function tomoney(numeric,currency) {
if (typeof numeric == 'string') {
numeric = parseFloat(numeric);
}
let strcur='';
if(currency===undefined){
strcur=MainData.Currency;
}
else {
strcur=currency;
}
return numeric.toFixed(0).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') + ' '+strcur;
}
// return the sum of an array
function sum(obj) {
const val=Object.values(obj);
var total = 0;
for (var i = 0; i < val.length; i++) {
total = total + tonumeric(val[i]);
}
return total;
}
// Comapare two obj return true is similar
Object.compare = function (obj1, obj2) {
//Loop through properties in object 1
for (var p in obj1) {
//Check property exists on both objects
if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p)) return false;
switch (typeof (obj1[p])) {
//Deep compare objects
case 'object':
if (!Object.compare(obj1[p], obj2[p])) return false;
break;
//Compare function code
case 'function':
if (typeof (obj2[p]) == 'undefined' || (p != 'compare' && obj1[p].toString() != obj2[p].toString())) return false;
break;
//Compare values
default:
if (obj1[p] != obj2[p]) return false;
}
}
//Check object 2 for any extra properties
for (var p in obj2) {
if (typeof (obj1[p]) == 'undefined') return false;
}
return true;
};
// Generate a random int
function randomint(not){
var rnd;
do {
rnd=Math.floor(Math.random() * 100);
var cont=false;
for (let i = 0; i < not.length ; i++) {
if (not[i]===rnd){
cont=true;
}
}
} while(cont);
return rnd;
}
// Inputs Definition
// ---------------------
// ---------------------
// Display the amount selector
class AmountInput extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.props.onChange(e.target.value);
}
render() {
const value = this.props.value;
+ let label=null;
+ if(this.props.name!=null && this.props.name!==""){
+ label=;
+ }
return (
);
}
// Display the total cost
final_cost(conv){
let disps='';
if(projectduration>1) disps='s';
let convout='';
if (conv.Enable) convout=;
return(
{/**/}
Total Cost for {projectduration} year{disps}
{convout}
);
}
// Define the head (top) of the page
page_head(){
return(
EPFL Library Cost Calculator for Data Management
Welcome to our cost calculator this tool will help researcher to have an
estimate of the cost of managing, storing and publishing data.
Many providers are included in the service and you will be able to calculate a cost
based on your needs.
Total cost is calculated dynamically based on your inputs.
We hope you will enjoy this tool and it will be useful for you.
);
}
//Define the foot (bottom) of the page
page_foot(){
return(
The values published on this service are only informative and cannot be used for exact calculation. If you see some mistake or would like to
have another services please contact us.
Last Database Update : {MainData.Updated}
This service has been developed by the Resarch Data Management Team of the EPFL Library
This software is publish under GPL-3.0-only license and your are using Version {MainData.Version}
Source code can be download here
Icons are from the Noun Project (Book by Randi NI, Storage by I Pitu, Database by Novalyi, data cloud by Vectors Market, Information and Next by Gregor Cresnar, Database by Creative Mahira)
);
}
// Define the howto (user guide)
howto(){
return(
HOWTO
Categories
This tool is divided by categories (for example Activate storage). Click
on the category name, and it will expand.
Providers
Providers can be chosen from the Select a provider box. You can then tune your setting for this provider to fit your needs.
If the provider you want is not registered, you can add it manually with Provide your own provider and then enter your provider/service and cost.
Add or Remove Line
If you want to add a new provider use the }
tips={"Add a new category"} onClick={this.fctnull}/> button.
You can also remove a provider with }
tips={"Remove this line"} onClick={this.fctnull}/> button.
To know more about
Some extra information about the category or the provider can be obtained with the }
tips={"Know more"} onClick={this.fctnull}/> button.
Comments your input
Comments are for your own usage, you can use for remembering what each section is and for a nice export.
Export
You can export your work into different format : HTML : This format can be used in any wordprocessing software (such as Microsoft Word or Libreoffice). HTML Source code, Markdown, and CSV formats are also possible.
Click on the in order to copy your work into your clipboard. A simple Paste will transfer your work into any software.
);
}
// Function use by the howto btn to move the page
move2howto(){
$('html,body').animate({
scrollTop: $("#howto").offset().top},
'slow');
}
fctnull(){}
}
//Main Declaration
// ---------------------
// ---------------------
ReactDOM.render(,document.getElementById('root'));
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
diff --git a/js/costcalc_money.jsx b/js/costcalc_money.jsx
index cad5868..d1c4ca4 100644
--- a/js/costcalc_money.jsx
+++ b/js/costcalc_money.jsx
@@ -1,107 +1,202 @@
"use strict";
// Money is the http://openexchangerates.github.io/money.js/#playground Lib
var Money = fx.noConflict();
// Become true if money conv is configured and connected correctly
var Money_Enable=false;
class CurrencySelect extends React.Component {
constructor(props) {
super(props);
this.handleCurChange = this.handleCurChange.bind(this);
- let selectable=MainData.Conv;
+ let selectable=MainData.Conv.slice(0);
selectable.unshift(MainData.Currency);
this.state={
Enable:false,
SelectCur : 0,
Cur : selectable[0],
Selectable: selectable,
prevselec:-1,
};
- //this.make_export();
this.moneyset(0);
}
moneyset(select){
Money.settings =
{
from: MainData.Currency,
to: this.state.Selectable[select],
};
}
handleCurChange(select) {
if(select==='0'){
this.setState({Enable: false});
}
else{
this.setState({Enable: true});
}
this.setState({SelectCur: select});
this.setState({Cur: this.state.Selectable[select]});
this.moneyset(select);
}
componentDidUpdate(){
if(this.state.prevselec!==this.state.SelectCur) {
this.props.money({Enable: this.state.Enable, Cur: this.state.Cur});
this.state.prevselec = this.state.SelectCur;
}
}
render() {
+ let r=0;
+ let rate=null;
+ //only display the module if conversion is enable and running ok
if (Money_Enable) {
- if(this.state.Enable){
- let r = Money.convert(1).toFixed(2);;
- let rate = '1' + MainData.Currency + '=' + r + this.state.Cur;
+ if(this.state.Enable) {
+ r = Money.convert(1).toFixed(2);
+ rate = '1' + MainData.Currency + '=' + r + this.state.Cur;
+ }
return (
-
);
- }else{
- return(
-
- );
- }
} else {
return (null);
}
}
}
+
+class PluginsCurrencyChange extends React.Component {
+ constructor(props) {
+ super(props);
+ this.handleCurChange = this.handleCurChange.bind(this);
+ this.handleCostChange = this.handleCostChange.bind(this);
+ let selectable=MainData.Conv.slice(0);
+ selectable.unshift(MainData.Currency);
+ this.state={
+ Enable:false,
+ SelectCur : 0,
+ Cur : selectable[0],
+ Selectable: selectable,
+ prevvalue:-1,
+ CostError:false,
+ value:0,
+ };
+ }
+
+ handleCurChange(select) {
+ if(select==='0'){
+ this.setState({Enable: false});
+ }
+ else{
+ this.setState({Enable: true});
+ }
+ this.setState({SelectCur: select});
+ this.setState({Cur: this.state.Selectable[select]});
+ this.setState({prevvalue: -1});
+ }
+ handleCostChange(value){
+ value=value.replace(/ /g, "");
+ if (isNaN(value)||value===''||typeof value == 'number'){
+ this.setState({CostError: true});
+ value=0;
+ }else{
+ this.setState({CostError: false});
+ }
+ this.setState({value:value});
+ }
+ makecost(){
+ let value=this.state.value;
+ // Convert money from another currency to the main if needed
+ if(this.state.Enable){
+ value=Money(value).from(this.state.Cur).to(MainData.Currency);
+ }
+ // Send the value to parent plugin
+ this.props.onCostChange(value);
+ }
+ componentDidUpdate(){
+ if(this.state.prevvalue!==this.state.value) {
+ this.makecost();
+ this.state.prevvalue = this.state.value;
+ }
+
+ }
+
+ selector(){
+ if (Money_Enable) {
+ return(
+